Class: CTioga2::Graphics::Elements::Parametric2D
- Inherits:
-
TiogaElement
- Object
- TiogaElement
- CTioga2::Graphics::Elements::Parametric2D
- Includes:
- Log, Dobjects
- Defined in:
- lib/ctioga2/graphics/elements/parametric2d.rb
Overview
Find a mechanism to really say what varies. Ideally, one
This class represents a 3D (or more, to be seen later) dataset as markers with various parameters parametrized (color, transparency, marker scale, marker type (discrete), possibly stroke and fill colors ?
would want to say:
-
Y2 is marker color
-
Y3 is marker size
-
Y4 only takes discrete values and represents markers
However, this is complex enough to be left out of the curve factory, I think. Color maps can be used for colors, but for the rest, things will have to be implemented as parameters to the curve generator, or even separated commands.
Instance Attribute Summary collapse
-
#curve_style ⇒ Object
A Styles::CurveStyle object saying how the curve should be drawn.
-
#dataset ⇒ Object
The Data::Dataset object that should get plotted.
-
#function ⇒ Object
For convenience only: xy functions.
-
#planes ⇒ Object
A hash Z value -> corresponding XY functions.
Attributes inherited from TiogaElement
Instance Method Summary collapse
-
#draw_markers(t) ⇒ Object
Draws the markers, if applicable.
-
#draw_path(t) ⇒ Object
Draws the markers, if applicable.
-
#get_boundaries ⇒ Object
Returns the Types::Boundaries of this curve.
-
#initialize(dataset, style = nil) ⇒ Parametric2D
constructor
Creates a new Curve2D object with the given dataset and style.
-
#location ⇒ Object
Returns the LocationStyle object of the curve.
-
#real_do(t) ⇒ Object
Actually draws the curve.
Methods included from Log
debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn
Methods inherited from TiogaElement
Constructor Details
#initialize(dataset, style = nil) ⇒ Parametric2D
Creates a new Curve2D object with the given dataset and style.
69 70 71 72 73 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 69 def initialize(dataset, style = nil) @dataset = dataset @curve_style = style prepare_data end |
Instance Attribute Details
#curve_style ⇒ Object
A Styles::CurveStyle object saying how the curve should be drawn.
Some of the elements will be overridden.
55 56 57 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 55 def curve_style @curve_style end |
#dataset ⇒ Object
The Data::Dataset object that should get plotted.
49 50 51 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 49 def dataset @dataset end |
#function ⇒ Object
For convenience only: xy functions
58 59 60 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 58 def function @function end |
#planes ⇒ Object
A hash Z value -> corresponding XY functions.
61 62 63 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 61 def planes @planes end |
Instance Method Details
#draw_markers(t) ⇒ Object
Draws the markers, if applicable.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 127 def draw_markers(t) min = @dataset.z.values.min max = @dataset.z.values.max if @curve_style.has_marker? # We use a default color map for the markers @curve_style.marker_color_map ||= Styles::ColorMap.from_text("Red--Green") cmap = @curve_style.marker_color_map for zs in @planes.keys.sort ## \todo have the sort ## direction configurable. f = @planes[zs] color = cmap.z_color(zs, min, max) @curve_style.marker.draw_markers_at(t, f.x, f.y, { 'color' => color}) end end end |
#draw_path(t) ⇒ Object
Draws the markers, if applicable.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 103 def draw_path(t) min = @dataset.z.values.min max = @dataset.z.values.max if @curve_style.has_line? # We use a default color map for the lines @curve_style.color_map ||= Styles::ColorMap.from_text("Red--Green") cmap = @curve_style.color_map for zs in @planes.keys.sort ## \todo have the sort ## direction configurable. f = @planes[zs] color = cmap.z_color(zs, min, max) t.context do @curve_style.line.set_stroke_style(t) t.stroke_color = color t.show_polyline(f.x, f.y) end end end end |
#get_boundaries ⇒ Object
Returns the Types::Boundaries of this curve.
98 99 100 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 98 def get_boundaries return Types::Boundaries.bounds(@function.x, @function.y) end |
#location ⇒ Object
Returns the LocationStyle object of the curve. Returns the one from #curve_style.
93 94 95 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 93 def location return @curve_style.location end |
#real_do(t) ⇒ Object
Actually draws the curve
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ctioga2/graphics/elements/parametric2d.rb', line 146 def real_do(t) debug { "Plotting curve #{inspect}" } t.context do ## \todo allow customization of the order of drawing, ## using a simple user-specificable array of path, ## markers... and use the corresponding #draw_path or ## #draw_markers... Ideally, any string could be used, and ## warnings should be issued on missing symbols. # draw_fill(t) # draw_errorbars(t) draw_path(t) draw_markers(t) if @curve_style.zaxis begin @parent.style.get_axis_style(@curve_style.zaxis). set_color_map(@curve_style.marker_color_map, @dataset.z.values.min, @dataset.z.values.max) rescue error { "Could not set Z info to non-existent axis #{@curve_style.zaxis}" } end end # draw_error_bars(t) ?? end end |