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: 229 $', '$Date: 2011-01-17 17:34:57 +0100 (Mon, 17 Jan 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 What would be interesting here would be to have indexed
35
# plots, ie draw one curve for each value of Z, with a color
37
class Parametric2D < TiogaElement
42
# The Data::Dataset object that should get plotted.
43
attr_accessor :dataset
45
# A Styles::CurveStyle object saying how the curve should be
48
# Some of the elements will be overridden.
49
attr_accessor :curve_style
51
# For convenience only: xy functions
52
attr_accessor :function
54
# A hash Z value -> corresponding XY functions.
59
undef :location=, :location
61
# Creates a new Curve2D object with the given _dataset_ and
63
def initialize(dataset, style = nil)
69
# Prepares the internal storage of the data, from the @dataset
71
@function = Function.new(@dataset.x.values.dup,
72
@dataset.y.values.dup)
74
## @todo this should eventually use Dataset::index_on_cols.
76
@dataset.each_values do |i, x,y,*zs|
77
@planes[zs[0]] ||= Function.new(Dvector.new, Dvector.new)
83
protected :prepare_data
85
# Returns the LocationStyle object of the curve. Returns the
86
# one from #curve_style.
88
return @curve_style.location
91
# Returns the Types::Boundaries of this curve.
93
return Types::Boundaries.bounds(@function.x, @function.y)
96
# Draws the markers, if applicable.
98
min = @dataset.z.values.min
99
max = @dataset.z.values.max
100
if @curve_style.has_line?
101
# We use a default color map for the lines
102
@curve_style.color_map ||=
103
Styles::ColorMap.from_text("Red--Green")
104
cmap = @curve_style.color_map
106
for zs in @planes.keys.sort ## \todo have the sort
107
## direction configurable.
109
color = cmap.z_color(zs, min, max)
111
@curve_style.line.set_stroke_style(t)
112
t.stroke_color = color
113
t.show_polyline(f.x, f.y)
120
# Draws the markers, if applicable.
122
min = @dataset.z.values.min
123
max = @dataset.z.values.max
124
if @curve_style.has_marker?
125
# We use a default color map for the markers
126
@curve_style.marker_color_map ||=
127
Styles::ColorMap.from_text("Red--Green")
128
cmap = @curve_style.marker_color_map
129
for zs in @planes.keys.sort ## \todo have the sort
130
## direction configurable.
132
color = cmap.z_color(zs, min, max)
133
@curve_style.marker.draw_markers_at(t, f.x, f.y,
139
## Actually draws the curve
141
debug { "Plotting curve #{inspect}" }
143
## \todo allow customization of the order of drawing,
144
## using a simple user-specificable array of path,
145
## markers... and use the corresponding #draw_path or
146
## #draw_markers... Ideally, any string could be used, and
147
## warnings should be issued on missing symbols.
154
if @curve_style.zaxis
156
@parent.style.get_axis_style(@curve_style.zaxis).
157
set_color_map(@curve_style.marker_color_map,
158
@dataset.z.values.min,
159
@dataset.z.values.max)
161
error { "Could not set Z info to non-existent axis #{@curve_style.zaxis}" }
165
# draw_error_bars(t) ??