1
# -*- coding: undecided -*-
2
# parametric2d.rb: a 2D curve whose parameters depend on Z values
3
# copyright (c) 2006, 2007, 2008, 2009, 2010 by Vincent Fourmond
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# General Public License for more details (in the COPYING file).
15
require 'ctioga2/utils'
18
require 'Dobjects/Function'
23
Version::register_svn_info('$Revision: 284 $', '$Date: 2011-02-13 17:23:43 +0100 (Sun, 13 Feb 2011) $')
29
# This class represents a 3D (or more, to be seen later) dataset
30
# as markers with various parameters parametrized (color,
31
# transparency, marker scale, marker type (discrete), possibly
32
# stroke and fill colors ?
34
# @todo Find a mechanism to really say what varies. Ideally, one
36
# * Y2 is marker color
38
# * Y4 only takes discrete values and represents markers
40
# However, this is complex enough to be left out of the curve
41
# factory, I think. Color maps can be used for colors, but for
42
# the rest, things will have to be implemented as parameters to
43
# the curve generator, or even separated commands.
44
class Parametric2D < TiogaElement
49
# The Data::Dataset object that should get plotted.
50
attr_accessor :dataset
52
# A Styles::CurveStyle object saying how the curve should be
55
# Some of the elements will be overridden.
56
attr_accessor :curve_style
58
# For convenience only: xy functions
59
attr_accessor :function
61
# A hash Z value -> corresponding XY functions.
66
undef :location=, :location
68
# Creates a new Curve2D object with the given _dataset_ and
70
def initialize(dataset, style = nil)
76
# Prepares the internal storage of the data, from the @dataset
78
@function = Function.new(@dataset.x.values.dup,
79
@dataset.y.values.dup)
81
## @todo this should eventually use Dataset::index_on_cols.
83
@dataset.each_values do |i, x,y,*zs|
84
@planes[zs[0]] ||= Function.new(Dvector.new, Dvector.new)
90
protected :prepare_data
92
# Returns the LocationStyle object of the curve. Returns the
93
# one from #curve_style.
95
return @curve_style.location
98
# Returns the Types::Boundaries of this curve.
100
return Types::Boundaries.bounds(@function.x, @function.y)
103
# Draws the markers, if applicable.
105
min = @dataset.z.values.min
106
max = @dataset.z.values.max
107
if @curve_style.has_line?
108
# We use a default color map for the lines
109
@curve_style.color_map ||=
110
Styles::ColorMap.from_text("Red--Green")
111
cmap = @curve_style.color_map
113
for zs in @planes.keys.sort ## \todo have the sort
114
## direction configurable.
116
color = cmap.z_color(zs, min, max)
118
@curve_style.line.set_stroke_style(t)
119
t.stroke_color = color
120
t.show_polyline(f.x, f.y)
127
# Draws the markers, if applicable.
129
min = @dataset.z.values.min
130
max = @dataset.z.values.max
131
if @curve_style.has_marker?
132
# We use a default color map for the markers
133
@curve_style.marker_color_map ||=
134
Styles::ColorMap.from_text("Red--Green")
135
cmap = @curve_style.marker_color_map
136
for zs in @planes.keys.sort ## \todo have the sort
137
## direction configurable.
139
color = cmap.z_color(zs, min, max)
140
@curve_style.marker.draw_markers_at(t, f.x, f.y,
146
## Actually draws the curve
148
debug { "Plotting curve #{inspect}" }
150
## \todo allow customization of the order of drawing,
151
## using a simple user-specificable array of path,
152
## markers... and use the corresponding #draw_path or
153
## #draw_markers... Ideally, any string could be used, and
154
## warnings should be issued on missing symbols.
161
if @curve_style.zaxis
163
@parent.style.get_axis_style(@curve_style.zaxis).
164
set_color_map(@curve_style.marker_color_map,
165
@dataset.z.values.min,
166
@dataset.z.values.max)
168
error { "Could not set Z info to non-existent axis #{@curve_style.zaxis}" }
172
# draw_error_bars(t) ??