Class: CTioga2::Graphics::Styles::MapAxisStyle
- Inherits:
-
AxisStyle
- Object
- BasicStyle
- AxisStyle
- CTioga2::Graphics::Styles::MapAxisStyle
- Defined in:
- lib/ctioga2/graphics/styles/map-axes.rb
Overview
This class handles the display of a Z axis color map, in the form of a colored bar with ticks and a label.
Constant Summary
Constants inherited from BasicStyle
Instance Attribute Summary collapse
-
#bar_shift ⇒ Object
Space to be left between the graph and the beginning of the graph.
-
#bar_size ⇒ Object
Size of the bar (not counting the label).
-
#bounds ⇒ Object
Zmin and Zmax boundaries.
-
#color_map ⇒ Object
The actual color map.
-
#padding ⇒ Object
Space to be left on the side.
Attributes inherited from AxisStyle
#axis_label, #background_lines, #decoration, #location, #log, #offset, #stroke_color, #tick_label_style, #transform
Instance Method Summary collapse
- #draw_axis(t) ⇒ Object
-
#draw_background_lines(t) ⇒ Object
Draw the axis background lines:.
- #extension(t, style = nil) ⇒ Object
-
#initialize ⇒ MapAxisStyle
constructor
Creates a new MapAxisStyle object at the given location with the given style.
- #set_bounds_for_axis(t, range = nil) ⇒ Object
- #set_color_map(color_map, zmin, zmax) ⇒ Object
-
#vertical? ⇒ Boolean
Whether the axis is vertical or not.
Methods inherited from AxisStyle
current_axis_style, #labels_only_extension
Methods inherited from BasicStyle
attr_accessor, attributes, from_hash, #instance_variable_defined?, #set_from_hash, #to_hash, #update_from_other
Constructor Details
#initialize ⇒ MapAxisStyle
Creates a new MapAxisStyle object at the given location with the given style.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 49 def initialize() super() @bar_size = Types::Dimension.new(:dy, 2, :x) # Shifting away from the location. @bar_shift = Types::Dimension.new(:dy, 0.3, :x) ## @todo maybe use different padding for left and right ? @padding = Types::Dimension.new(:dy, 0.5, :x) @decoration = AXIS_WITH_TICKS_AND_NUMERIC_LABELS # To be implemented one day... @other_side_decoration = nil end |
Instance Attribute Details
#bar_shift ⇒ Object
Space to be left between the graph and the beginning of the graph
42 43 44 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 42 def @bar_shift end |
#bar_size ⇒ Object
Size of the bar (not counting the label)
38 39 40 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 38 def @bar_size end |
#bounds ⇒ Object
Zmin and Zmax boundaries
35 36 37 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 35 def bounds @bounds end |
#color_map ⇒ Object
The actual color map
32 33 34 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 32 def color_map @color_map end |
#padding ⇒ Object
Space to be left on the side
45 46 47 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 45 def padding @padding end |
Instance Method Details
#draw_axis(t) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 72 def draw_axis(t) # Not beautiful at all size = Types::Dimension.new(:dy, extension(t), @location.orientation) label_size = Types::Dimension.new(:dy, labels_only_extension(t, style = nil), @location.orientation) @location.do_sub_frame(t, size) do # This is a necessary workaround for a small bug t.set_subframe([0,0,0,0]) # Here, do the correct setup, using a MarginsBox: # * correctly setup the axes/edges # * handle the sides correctly. # * position the subplot within accordingly # * use draw_axis for the axis ? plot_box = Types::MarginsBox. new(*@location.reorient_margins(@bar_shift, label_size, @padding, @padding)) # We wrap the call within a subplot t.subplot(plot_box.to_frame_margins(t)) do bounds = if @location.vertical? [0, 1, @bounds.last, @bounds.first] else [@bounds.first, @bounds.last, 0, 1] end t.set_bounds(bounds) t.context do t.clip_to_frame cmap, zmin, zmax = *@color_map.to_colormap(t, @bounds.first, @bounds.last) sp = [0.5, zmin] ep = [0.5, zmax] if ! @location.vertical? sp.reverse! ep.reverse! end t.axial_shading( 'start_point' => sp, 'end_point' => ep, 'colormap' => cmap ) end ## @todo handle axis color ? t.stroke_frame ## @todo potentially handle decorations for the other ## side too. ## @todo This is a ugly hack, but Ruby doesn't allow a ## clean one. Though ## http://stackoverflow.com/questions/1251178/calling-another-method-in-super-class-in-ruby ## seems like the way to go ! To be implemented one day. self.class.superclass.instance_method(:draw_axis). bind(self).call(t) end end end |
#draw_background_lines(t) ⇒ Object
Draw the axis background lines:
140 141 142 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 140 def draw_background_lines(t) # Nothing to do end |
#extension(t, style = nil) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 144 def extension(t, style = nil) base = super(t, style) base += @bar_size.to_text_height(t, @location.orientation) base += @bar_shift.to_text_height(t, @location.orientation) return base end |
#set_bounds_for_axis(t, range = nil) ⇒ Object
135 136 137 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 135 def set_bounds_for_axis(t, range = nil) # Useless here end |
#set_color_map(color_map, zmin, zmax) ⇒ Object
66 67 68 69 70 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 66 def set_color_map(color_map, zmin, zmax) @bounds = [zmin, zmax] @color_map = color_map end |
#vertical? ⇒ Boolean
Whether the axis is vertical or not
153 154 155 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 153 def vertical? return @location.vertical? end |