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

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/elements.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
# elements.rb: all drawable objects
 
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/types'
 
16
require 'ctioga2/graphics/elements/element'
 
17
require 'ctioga2/graphics/elements/containers'
 
18
require 'ctioga2/graphics/elements/subplot'
 
19
require 'ctioga2/graphics/elements/region'
 
20
require 'ctioga2/graphics/elements/gradient-region'
 
21
require 'ctioga2/graphics/elements/curve2d'
 
22
require 'ctioga2/graphics/elements/parametric2d'
 
23
require 'ctioga2/graphics/elements/xyz-map'
 
24
require 'ctioga2/graphics/elements/primitive'
 
25
 
 
26
require 'ctioga2/graphics/elements/tangent'
 
27
require 'ctioga2/graphics/elements/contour'
 
28
 
 
29
module CTioga2
 
30
 
 
31
  Version::register_svn_info('$Revision: 187 $', '$Date: 2010-11-07 11:02:25 +0100 (Sun, 07 Nov 2010) $')
 
32
 
 
33
  module Graphics
 
34
 
 
35
    # Now, various commands pertaining to various drawables
 
36
 
 
37
    PlotCoordinatesGroup = CmdGroup.new('coordinates',
 
38
                                        "Plot coordinates",
 
39
                                        "Plot coordinates", 2)
 
40
    PlotMarginCommand = 
 
41
      Cmd.new("margin",nil,"--margin", 
 
42
              [ CmdArg.new('float') ]) do |plotmaker, margin|
 
43
      plotmaker.root_object.current_plot.style.plot_margin = margin
 
44
    end
 
45
 
 
46
    PlotMarginCommand.describe("Leaves a margin around data points",
 
47
                               <<EOH, PlotCoordinatesGroup)
 
48
Leaves a margin around the data points. Expressed in relative size of the
 
49
whole plot.
 
50
EOH
 
51
 
 
52
 
 
53
    # Various coordinate-related commands:
 
54
    # 
 
55
    # @todo All these commands should be axis-dependent, and not
 
56
    # plot-dependent.
 
57
    CoordinateRelatedCommands = []
 
58
    [:x, :y].each do |x|
 
59
      cmd = 
 
60
        Cmd.new("#{x}range",nil,"--#{x}range", 
 
61
                [ CmdArg.new('partial-float-range') ]) do |plotmaker, range|
 
62
        plotmaker.root_object.current_plot.
 
63
          set_user_boundaries(x.to_s,range)
 
64
      end
 
65
      cmd.describe("Sets the #{x.to_s.upcase} range",
 
66
                           <<EOH, PlotCoordinatesGroup)
 
67
Sets the range of the #{x.to_s.upcase} coordinates.
 
68
EOH
 
69
      CoordinateRelatedCommands << cmd
 
70
 
 
71
      cmd = 
 
72
        Cmd.new("#{x}offset",nil,"--#{x}offset", 
 
73
                [ CmdArg.new('float') ]) do |plotmaker, val|
 
74
        plotmaker.root_object.current_plot.
 
75
          style.transforms.send("#{x}_offset=", val)
 
76
      end
 
77
      cmd.describe("Offset #{x.to_s.upcase} data",
 
78
                           <<EOH, PlotCoordinatesGroup)
 
79
Adds the given offset to all #{x.to_s.upcase} coordinates.
 
80
EOH
 
81
      CoordinateRelatedCommands << cmd
 
82
 
 
83
      cmd = 
 
84
        Cmd.new("#{x}scale",nil,"--#{x}scale", 
 
85
                [ CmdArg.new('float') ]) do |plotmaker, val|
 
86
        plotmaker.root_object.current_plot.
 
87
          style.transforms.send("#{x}_scale=", val)
 
88
      end
 
89
      cmd.describe("Scale #{x.to_s.upcase} data",
 
90
                           <<EOH, PlotCoordinatesGroup)
 
91
Multiplies the #{x.to_s.upcase} coordinates by this factor.
 
92
EOH
 
93
      CoordinateRelatedCommands << cmd
 
94
 
 
95
      # Alias
 
96
      cmd = 
 
97
        Cmd.new("#{x}fact",nil,"--#{x}fact", 
 
98
                [ CmdArg.new('float') ]) do |plotmaker, val|
 
99
        plotmaker.root_object.current_plot.
 
100
          style.transforms.send("#{x}_scale=", val)
 
101
      end
 
102
      cmd.describe("Alias for #{x}scale",
 
103
                           <<EOH, PlotCoordinatesGroup)
 
104
Alias for {command: #{x}scale}.
 
105
EOH
 
106
      CoordinateRelatedCommands << cmd
 
107
 
 
108
      cmd = 
 
109
        Cmd.new("#{x}log",nil,"--#{x}log", 
 
110
                [ CmdArg.new('boolean') ]) do |plotmaker, val|
 
111
        plotmaker.root_object.current_plot.
 
112
          style.send("set_log_scale", x, val)
 
113
      end
 
114
      cmd.describe("Use log scale for #{x.to_s.upcase}",
 
115
                           <<EOH, PlotCoordinatesGroup)
 
116
Uses a logarithmic scale for the #{x.to_s.upcase} axis.
 
117
EOH
 
118
      CoordinateRelatedCommands << cmd
 
119
    end
 
120
  end
 
121
end