Class: CTioga2::Graphics::Styles::AxisStyle
- Inherits:
-
BasicStyle
- Object
- BasicStyle
- CTioga2::Graphics::Styles::AxisStyle
- Includes:
- Tioga::FigureConstants
- Defined in:
- lib/ctioga2/graphics/styles/axes.rb
Overview
The style of an axis or an egde of the plot. Unlike tioga, ctioga2 does not make any difference.
Direct Known Subclasses
Constant Summary
Constants inherited from BasicStyle
Instance Attribute Summary collapse
-
#axis_label ⇒ Object
The label of the axis, if there is one.
-
#background_lines ⇒ Object
The background lines for the given axis.
-
#decoration ⇒ Object
The type of the edge/axis.
-
#location ⇒ Object
The position of the axis.
-
#log ⇒ Object
Whether the axis should be log scale or not.
-
#offset ⇒ Object
Offset of the axis with respect to its normal position.
-
#stroke_color ⇒ Object
The color of the stroke for the lines of the axis.
-
#tick_label_style ⇒ Object
The style of the tick labels.
-
#transform ⇒ Object
Transform: a Types::Bijection object specifying a coordinate transformation for the axis.
Class Method Summary collapse
-
.current_axis_style(plotmaker, spec) ⇒ Object
Returns the AxisStyle object corresponding to the named axis in the current plot.
Instance Method Summary collapse
-
#draw_axis(t) ⇒ Object
Draws the axis within the current plot.
-
#draw_background_lines(t) ⇒ Object
Draw the axis background lines:.
-
#extension(t, style = nil) ⇒ Object
Returns the extension of the axis (including tick labels and labels if applicable) perpendicular to itself, in units of text height (at scale = current text scale when drawing axes).
-
#initialize(location = nil, decoration = nil, label = nil) ⇒ AxisStyle
constructor
Creates a new AxisStyle object at the given location with the given style.
-
#labels_only_extension(t, style = nil) ⇒ Object
Returns the part of the #extension only due to the labels (ticks and standard label).
-
#set_bounds_for_axis(t, range = nil) ⇒ Object
Sets the current boundaries of the t object to the range SimpleRange object for the direction handled by the AxisStyle, without touching the rest.
Methods inherited from BasicStyle
attr_accessor, attributes, from_hash, #instance_variable_defined?, #set_from_hash, #to_hash, #update_from_other
Constructor Details
#initialize(location = nil, decoration = nil, label = nil) ⇒ AxisStyle
Creates a new AxisStyle object at the given location with the given style.
70 71 72 73 74 75 76 77 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 70 def initialize(location = nil, decoration = nil, label = nil) @location = Types::PlotLocation.new(location) @decoration = decoration @tick_label_style = FullTextStyle.new @axis_label = TextLabel.new(label) @log = false end |
Instance Attribute Details
#axis_label ⇒ Object
The label of the axis, if there is one
55 56 57 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 55 def axis_label @axis_label end |
#background_lines ⇒ Object
The background lines for the given axis. nil for nothing, or a StrokeStyle object if we want to draw something.
49 50 51 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 49 def background_lines @background_lines end |
#decoration ⇒ Object
The type of the edge/axis. Any of the Tioga constants: AXIS_HIDDEN, AXIS_LINE_ONLY, AXIS_WITH_MAJOR_TICKS_ONLY, AXIS_WITH_TICKS_ONLY, AXIS_WITH_MAJOR_TICKS_AND_NUMERIC_LABELS, and AXIS_WITH_TICKS_AND_NUMERIC_LABELS.
36 37 38 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 36 def decoration @decoration end |
#location ⇒ Object
The position of the axis. Can be one of :left, :right, :top, :bottom, :at_y_origin or :at_x_origin.
40 41 42 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 40 def location @location end |
#log ⇒ Object
Whether the axis should be log scale or not
58 59 60 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 58 def log @log end |
#offset ⇒ Object
Offset of the axis with respect to its normal position. It is counted away from the graph. It is either a Types::Dimension object or nil.
45 46 47 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 45 def offset @offset end |
#stroke_color ⇒ Object
The color of the stroke for the lines of the axis
65 66 67 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 65 def stroke_color @stroke_color end |
#tick_label_style ⇒ Object
The style of the tick labels
52 53 54 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 52 def tick_label_style @tick_label_style end |
#transform ⇒ Object
Transform: a Types::Bijection object specifying a coordinate transformation for the axis.
62 63 64 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 62 def transform @transform end |
Class Method Details
.current_axis_style(plotmaker, spec) ⇒ Object
Returns the AxisStyle object corresponding to the named axis in the current plot.
150 151 152 153 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 150 def self.current_axis_style(plotmaker, spec) return PlotStyle.current_plot_style(plotmaker). get_axis_style(spec) end |
Instance Method Details
#draw_axis(t) ⇒ Object
Draws the axis within the current plot. Boundaries are the current plot boundaries. Also draw the #axis_label, if there is one.
todo
-
the offset mechanism, to place the axis away from the place where it should be…
-
non-linear axes (or linear, for that matter, but with a transformation)
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 88 def draw_axis(t) spec = get_axis_specification(t) # Add tick label style: spec.merge!(@tick_label_style.to_hash) if @stroke_color spec['stroke_color'] = @stroke_color end t.show_axis(spec) @axis_label.loc = @location default = vertical? ? 'ylabel' : 'xlabel' @axis_label.draw(t, default) end |
#draw_background_lines(t) ⇒ Object
Draw the axis background lines:
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 122 def draw_background_lines(t) if @background_lines # First, getting major ticks location from tioga info = t.axis_information(get_axis_specification(t)) if info['vertical'] x0 = t.bounds_left x1 = t.bounds_right else y0 = t.bounds_bottom y1 = t.bounds_top end t.context do @background_lines.set_stroke_style(t) values = info['major_ticks'] || info['major'] for val in values if info['vertical'] t.stroke_line(x0, val, x1, val) else t.stroke_line(val, y0, val, y1) end end end end end |
#extension(t, style = nil) ⇒ Object
Returns the extension of the axis (including tick labels and labels if applicable) perpendicular to itself, in units of text height (at scale = current text scale when drawing axes).
style is a PlotStyle object containing the style information for the target plot.
todo handle offset axes when that is implemented.
185 186 187 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 185 def extension(t, style = nil) return labels_only_extension(t, style) end |
#labels_only_extension(t, style = nil) ⇒ Object
Returns the part of the #extension only due to the labels (ticks and standard label).
For now, it returns the same value as #extension, but that might change
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 160 def labels_only_extension(t, style = nil) ticks_shift, ticks_scale = *get_ticks_parameters(t) default = vertical? ? 'ylabel' : 'xlabel' le = @axis_label.label_extension(t, default, @location) case @decoration when AXIS_WITH_MAJOR_TICKS_AND_NUMERIC_LABELS, AXIS_WITH_TICKS_AND_NUMERIC_LABELS te = ticks_shift * ticks_scale else te = 0 end return Dobjects::Dvector[le,te].max * (style ? style.text_scale || 1 : 1) end |
#set_bounds_for_axis(t, range = nil) ⇒ Object
Sets the current boundaries of the t object to the range SimpleRange object for the direction handled by the AxisStyle, without touching the rest.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ctioga2/graphics/styles/axes.rb', line 104 def set_bounds_for_axis(t, range = nil) if ! range return end l,r,top,b = t.bounds_left, t.bounds_right, t.bounds_top, t.bounds_bottom if self.vertical? b = range.first top = range.last else l = range.first r = range.last end t.set_bounds([l,r,top,b]) end |