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
BasicStyle::AllStyles, BasicStyle::OldAttrAccessor
Instance Attribute Summary collapse
-
#color_map ⇒ Object
The actual color map.
Instance Method Summary collapse
- #draw_axis(t, watcher = nil) ⇒ 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
alias_for, aliases, attr_accessor, attribute_type, attribute_types, attributes, convert_string_hash, defined_aliases, deprecated_attribute, from_hash, inherited, #instance_variable_defined?, normalize_hash, normalize_in, normalize_out, options_hash, #set_from_hash, sub_style, sub_styles, #to_hash, typed_attribute, #update_from_other, #use_defaults_from
Constructor Details
#initialize ⇒ MapAxisStyle
Creates a new MapAxisStyle object at the given location with the given style.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 47 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
#color_map ⇒ Object
The actual color map
30 31 32 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 30 def color_map @color_map end |
Instance Method Details
#draw_axis(t, watcher = nil) ⇒ Object
70 71 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 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 70 def draw_axis(t, watcher = nil) # 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:
138 139 140 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 138 def draw_background_lines(t) # Nothing to do end |
#extension(t, style = nil) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 142 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
133 134 135 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 133 def set_bounds_for_axis(t, range = nil) # Useless here end |
#set_color_map(color_map, zmin, zmax) ⇒ Object
64 65 66 67 68 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 64 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
151 152 153 |
# File 'lib/ctioga2/graphics/styles/map-axes.rb', line 151 def vertical? return @location.vertical? end |