~ubuntu-branches/ubuntu/wily/ctioga2/wily

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/styles/plot.rb

  • Committer: Package Import Robot
  • Author(s): Vincent Fourmond
  • Date: 2013-07-08 20:58:17 UTC
  • mfrom: (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130708205817-cephnc6etndyxrrp
Tags: 0.4-2
* Upload to unstable
* Already conforms to newer standards

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# This module contains all the classes used by ctioga
20
20
module CTioga2
21
21
 
22
 
  Version::register_svn_info('$Revision: 202 $', '$Date: 2010-11-30 22:21:17 +0100 (Tue, 30 Nov 2010) $')
 
22
  Version::register_svn_info('$Revision: 370 $', '$Date: 2012-12-28 17:40:18 +0100 (Fri, 28 Dec 2012) $')
23
23
 
24
24
  module Graphics
25
25
 
33
33
      # * ticks
34
34
      # * background (uniform fill + watermark if applicable + possibly
35
35
      #   a picture .?)
 
36
      #
 
37
      # This class is way too complex and needs too much flexibility
 
38
      # to be handled by a subclass of BasicStyle. However, all
 
39
      # substyles should be.
36
40
      class PlotStyle
37
41
 
38
42
        include Tioga::FigureConstants
55
59
        attr_accessor :plot_margin
56
60
 
57
61
        # Coordinate tranforms
 
62
        #
 
63
        # @todo they should be axis-specific.
58
64
        attr_accessor :transforms
59
65
 
60
66
        # Style of the background of the plot
75
81
        def initialize
76
82
          # Default style for the plots.
77
83
          @axes = {}
78
 
          @axes[:left] = AxisStyle.new(:left, 
79
 
                                       AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
80
 
                                       '$y$')
81
 
          @axes[:bottom] = AxisStyle.new(:bottom, 
82
 
                                         AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
83
 
                                         '$x$')
 
84
          @axes[:left] = 
 
85
            StyleSheet.style_for(AxisStyle, 'left', :left, 
 
86
                                 AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
 
87
                                 '$y$')
 
88
          @axes[:bottom] = 
 
89
            StyleSheet.style_for(AxisStyle, 'bottom', :bottom, 
 
90
                                 AXIS_WITH_TICKS_AND_NUMERIC_LABELS,
 
91
                                 '$x$')
84
92
 
85
 
          @axes[:right] = AxisStyle.new(:right, AXIS_WITH_TICKS_ONLY)
86
 
          @axes[:top] = AxisStyle.new(:top, AXIS_WITH_TICKS_ONLY)
 
93
          @axes[:right] = 
 
94
            StyleSheet.style_for(AxisStyle, 'right', :right, 
 
95
                                 AXIS_WITH_TICKS_ONLY)
 
96
          @axes[:top] = 
 
97
            StyleSheet.style_for(AxisStyle, 'top', :top, 
 
98
                                 AXIS_WITH_TICKS_ONLY)
87
99
 
88
100
          @xaxis_location = :bottom
89
101
          @yaxis_location = :left
90
102
 
91
 
          @title = TextLabel.new
92
 
          @title.loc = Types::PlotLocation.new(:top)
 
103
          @title = 
 
104
            StyleSheet.style_for(TextLabel, 'title',
 
105
                                 nil, 
 
106
                                 Types::PlotLocation.new(:top))
93
107
 
94
108
          @plot_margin = nil
95
109
 
96
110
          @transforms = CoordinateTransforms.new
97
111
 
98
 
          @background = BackgroundStyle.new
 
112
          @background = 
 
113
            StyleSheet.style_for(BackgroundStyle, 'background')
99
114
 
100
115
          # A padding of 4bp ? Why ?? Why not ?
101
116
          @padding = Types::Dimension.new(:bp, 4)
102
117
        end
103
118
 
 
119
        # Apply (destructively) the current transformations to the
 
120
        # given dataset
 
121
        def apply_transforms!(dataset)
 
122
          @transforms.transform_2d!(dataset)
 
123
        end
 
124
 
 
125
 
104
126
        # Whether to use log scale for the given axis.
105
127
        #
106
128
        # Now the question is: how should that affect user-defined
218
240
                axis.draw_axis(t)
219
241
              rescue Exception => e
220
242
                error { "Impossible to draw axis #{which}: #{e.message}" }
221
 
                debug { "Full message: #{e.inspect}" }
 
243
                debug { "Full message: #{e.inspect}\n#{e.backtrace.join("\n")}" }
222
244
              end
223
245
            end
224
246
          end
310
332
                               "Axes and labels", "Axes and labels", 40)
311
333
 
312
334
 
313
 
      
314
335
      AxisTypeCommands = []
315
336
      [:left, :right, :top, :bottom].each do |loc|
316
337
        AxisTypeCommands << 
317
338
          Cmd.new("#{loc}",nil,"--#{loc}", 
318
339
                  [
319
 
                   CmdArg.new('axis-decoration'),
 
340
                   AxisStyleOptions['decoration'],
320
341
                  ], PartialAxisStyle) do |plotmaker, dec, opts|
321
342
          style = AxisStyle.current_axis_style(plotmaker, loc)
322
343
          style.decoration = dec
327
348
          describe("Sets the type of the #{loc} axis", 
328
349
                   <<"EOH", AxisGroup)
329
350
Sets the type of the #{loc} axis.
 
351
 
 
352
The options have the same meaning as for {command: define-axis-style},
 
353
see that command for more information.
330
354
EOH
 
355
 
331
356
      end
332
357
 
333
358
      AxisStyleCommand = 
334
359
          Cmd.new("axis-style",nil,"--axis-style", 
335
360
                  [
336
361
                   CmdArg.new('axis'),
337
 
                  ], FullAxisStyle) do |plotmaker, which, opts|
 
362
                  ], AxisStyleOptions) do |plotmaker, which, opts|
338
363
        style = AxisStyle.current_axis_style(plotmaker, which)
339
364
        style.set_from_hash(opts)
340
365
      end
342
367
        describe("Sets the style of the given axis", 
343
368
                 <<"EOH", AxisGroup)
344
369
This command can be used to set various aspects of the style of the 
345
 
given axis, through its various options:
346
 
 * decoration
 
370
given axis, through its various options, which are documented in more details 
 
371
in the {command: define-axis-style} command.
347
372
EOH
348
373
 
349
374
      BackgroundLinesCommand = 
351
376
                [
352
377
                 CmdArg.new('axis'), 
353
378
                 CmdArg.new('color-or-false')
354
 
                ],{
355
 
                  'style' => CmdArg.new('line-style'),
356
 
                  'width' => CmdArg.new('float')
357
 
                }) do |plotmaker, which, color, options|
 
379
                ],
 
380
                StrokeStyle.options_hash().without('color')
 
381
                ) do |plotmaker, which, color, options|
358
382
        axis = AxisStyle.current_axis_style(plotmaker, which)
359
383
        if color
360
384
          style = {'color' => color}
379
403
      %w{x y}.each do |axis|
380
404
        labelcmd = Cmd.new("#{axis}label", "-#{axis}", 
381
405
                            "--#{axis}label", [ CmdArg.new('text') ],
382
 
                            FullTextStyleOptions) do |plotmaker, label, options|
 
406
                            TextLabel.options_hash().without('text')
 
407
                           ) do |plotmaker, label, options|
383
408
          PlotStyle.current_plot_style(plotmaker).
384
409
            set_label_style("#{axis}_label", options, label)
385
410
        end
387
412
                          <<"EOH", AxisGroup)
388
413
Sets the #{axis.upcase} label of the current plot.
389
414
EOH
 
415
 
 
416
        Commands::make_alias_for_option "#{axis}label", 'alignment', 'align', true
390
417
        
391
418
        nolabelcmd = Cmd.new("no-#{axis}label", nil, 
392
419
                             "--no-#{axis}label", []) do |plotmaker|
415
442
      end
416
443
 
417
444
      TitleLabelCommand = 
418
 
        Cmd.new('title', '-t', '--title', [ CmdArg.new('text') ],
419
 
                FullTextStyleOptions) do |plotmaker, label, options|
 
445
        Cmd.new('title', '-t', '--title', 
 
446
                [ CmdArg.new('text') ],
 
447
                TextLabel.options_hash().without('text')
 
448
                ) do |plotmaker, label, options|
420
449
        PlotStyle.current_plot_style(plotmaker).
421
450
          set_label_style('title', options, label)
422
451
      end
426
455
Sets the title of the current plot.
427
456
EOH
428
457
 
 
458
      Commands::make_alias_for_option 'title', 'alignment', 'align', true
 
459
 
429
460
      NoTitleLabelCommand = 
430
461
        Cmd.new('no-title', nil, '--no-title', []) do |plotmaker|
431
462
        PlotStyle.current_plot_style(plotmaker).
492
523
        PlotStyle.current_plot_style(plotmaker).
493
524
          set_label_style(which, options)
494
525
      end
 
526
 
 
527
      Commands::make_alias_for_option 'label-style', 'alignment', 'align', true
495
528
      
496
529
      LabelStyleCommand.describe("Sets the style of the given label", 
497
530
                                 <<"EOH", AxisGroup)
508
541
greater.
509
542
EOH
510
543
 
 
544
 
511
545
    end
512
546
  end
513
547
end