~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/elements/contour.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# contour.rb: contouring code for XYZ data
 
2
# copyright (c) 2009 by Vincent Fourmond
 
3
  
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
  
 
9
# This program is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
# General Public License for more details (in the COPYING file).
 
13
 
 
14
 
 
15
require 'ctioga2/graphics/elements/primitive'
 
16
 
 
17
# This module contains all the classes used by ctioga
 
18
module CTioga2
 
19
 
 
20
  Version::register_svn_info('$Revision: 192 $', '$Date: 2010-11-07 18:07:01 +0100 (Sun, 07 Nov 2010) $')
 
21
 
 
22
  module Graphics
 
23
 
 
24
    module Elements
 
25
 
 
26
      module Contours
 
27
 
 
28
        ContoursOptions = {
 
29
          'width' => 'float',
 
30
          'color' => 'color',
 
31
          'style' => 'line-style',
 
32
          'closed' => 'boolean',
 
33
        }
 
34
 
 
35
        ## @todo Maybe this cumbersome level/point thing along with the
 
36
        # $last_curve_style calls for a context for the primitive, ie
 
37
        # which was the state of the dataset/curve stack at the moment
 
38
        # when the primitive was drawn ?
 
39
        TiogaPrimitiveCall.
 
40
          primitive("contour", "contour", [ 'level'],
 
41
                    ContoursOptions) do |t, level,options|
 
42
          options ||= {}
 
43
          # table = PlotMaker.plotmaker.data_stack.last.indexed_table
 
44
          l, d = *level
 
45
          table = d.indexed_table
 
46
          contour = table.make_contour(l)
 
47
          contour << options['closed']
 
48
 
 
49
          ## @todo This $last_curve_style isn't beautiful.
 
50
          ##
 
51
          ## Worse, it won't work !
 
52
          options['color'] ||= $last_curve_style.line.color
 
53
 
 
54
          stroke_style = Styles::StrokeStyle.from_hash(options, '%s')
 
55
          
 
56
 
 
57
          t.context do 
 
58
            stroke_style.set_stroke_style(t)
 
59
            t.append_points_with_gaps_to_path(*contour)
 
60
            t.stroke
 
61
          end
 
62
        end
 
63
      end
 
64
      
 
65
    end
 
66
  end
 
67
end