1
# axes.rb: the style of one axis or edge
2
# copyright (c) 2009 by Vincent Fourmond
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.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details (in the COPYING file).
14
require 'ctioga2/utils'
17
# This module contains all the classes used by ctioga
20
Version::register_svn_info('$Revision$', '$Date$')
27
# This class handles the display of a Z axis color map, in the
28
# form of a colored bar with ticks and a label.
29
class MapAxisStyle < AxisStyle
31
# The actual color map
32
attr_accessor :color_map
34
# Zmin and Zmax boundaries
37
# Size of the bar (not counting the label)
38
attr_accessor :bar_size
40
# Space to be left between the graph and the beginning of the
42
attr_accessor :bar_shift
44
# Space to be left on the side
45
attr_accessor :padding
47
# Creates a new MapAxisStyle object at the given location with
52
@bar_size = Types::Dimension.new(:dy, 2, :x)
54
# Shifting away from the location.
55
@bar_shift = Types::Dimension.new(:dy, 0.3, :x)
57
## @todo maybe use different padding for left and right ?
58
@padding = Types::Dimension.new(:dy, 0.5, :x)
60
@decoration = AXIS_WITH_TICKS_AND_NUMERIC_LABELS
62
# To be implemented one day...
63
@other_side_decoration = nil
66
def set_color_map(color_map, zmin, zmax)
67
@bounds = [zmin, zmax]
68
@color_map = color_map
73
# Not beautiful at all
74
size = Types::Dimension.new(:dy, extension(t),
75
@location.orientation)
77
Types::Dimension.new(:dy, labels_only_extension(t, style = nil),
78
@location.orientation)
80
@location.do_sub_frame(t, size) do
81
# This is a necessary workaround for a small bug
82
t.set_subframe([0,0,0,0])
83
# Here, do the correct setup, using a MarginsBox:
84
# * correctly setup the axes/edges
85
# * handle the sides correctly.
86
# * position the subplot within accordingly
87
# * use draw_axis for the axis ?
89
plot_box = Types::MarginsBox.
90
new(*@location.reorient_margins(@bar_shift, label_size,
93
# We wrap the call within a subplot
94
t.subplot(plot_box.to_frame_margins(t)) do
95
bounds = if @location.vertical?
96
[0, 1, @bounds.last, @bounds.first]
98
[@bounds.first, @bounds.last, 0, 1]
103
cmap, zmin, zmax = *@color_map.to_colormap(t, @bounds.first,
108
if ! @location.vertical?
118
## @todo handle axis color ?
120
## @todo potentially handle decorations for the other
123
## @todo This is a ugly hack, but Ruby doesn't allow a
125
## http://stackoverflow.com/questions/1251178/calling-another-method-in-super-class-in-ruby
126
## seems like the way to go ! To be implemented one day.
127
self.class.superclass.instance_method(:draw_axis).
135
def set_bounds_for_axis(t, range = nil)
139
# Draw the axis background lines:
140
def draw_background_lines(t)
144
def extension(t, style = nil)
145
base = super(t, style)
147
base += @bar_size.to_text_height(t, @location.orientation)
148
base += @bar_shift.to_text_height(t, @location.orientation)
152
# Whether the axis is vertical or not
154
return @location.vertical?
159
ZAxisStyle = FullAxisStyle.dup
160
ZAxisStyle['bar_size'] = CmdArg.new('dimension')
161
ZAxisStyle['bar_shift'] = CmdArg.new('dimension')