Subversion Repositories Applications.gtt

Rev

Rev 61 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
60 jpm 1
<?php
2
/*
3
 * This work is hereby released into the Public Domain.
4
 * To view a copy of the public domain dedication,
5
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
6
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
7
 *
8
 */
9
 
10
require_once dirname(__FILE__)."/Plot.class.php";
11
 
12
/**
13
 * ScatterPlot
14
 *
15
 * @package Artichow
16
 */
17
class awScatterPlot extends awPlot implements awLegendable {
18
 
19
	/**
20
	 * Add marks to the scatter plot
21
	 *
22
	 * @var Mark
23
	 */
24
	public $mark;
25
 
26
	/**
27
	 * Labels on the plot
28
	 *
29
	 * @var Label
30
	 */
31
	public $label;
32
 
33
	/**
34
	 * Link points ?
35
	 *
36
	 * @var bool
37
	 */
38
	protected $link = FALSE;
39
 
40
	/**
41
	 * Display impulses
42
	 *
43
	 * @var bool
44
	 */
45
	protected $impulse = NULL;
46
 
47
	/**
48
	 * Link NULL points ?
49
	 *
50
	 * @var bool
51
	 */
52
	protected $linkNull = FALSE;
53
 
54
	/**
55
	 * Line color
56
	 *
57
	 * @var Color
58
	 */
59
	protected $lineColor;
60
 
61
	/**
62
	 * Line type
63
	 *
64
	 * @var int
65
	 */
66
	protected $lineStyle = awLine::SOLID;
67
 
68
	/**
69
	 * Line thickness
70
	 *
71
	 * @var int
72
	 */
73
	protected $lineThickness = 1;
74
 
75
	/**
76
	 * Construct a new awScatterPlot
77
	 *
78
	 * @param array $datay Numeric values for Y axis
79
	 * @param array $datax Numeric values for X axis
80
	 * @param int $mode
81
	 */
82
	public function __construct($datay, $datax = NULL) {
83
 
84
		parent::__construct();
85
 
86
		// Defaults marks
87
		$this->mark = new awMark;
88
		$this->mark->setType(awMark::CIRCLE);
89
		$this->mark->setSize(7);
90
		$this->mark->border->show();
91
 
92
		$this->label = new awLabel;
93
 
94
		$this->setValues($datay, $datax);
95
		$this->setColor(new awBlack);
96
 
97
	}
98
 
99
	/**
100
	 * Display plot as impulses
101
	 *
102
	 * @param awColor $impulse Impulses color (or NULL to disable impulses)
103
	 */
104
	public function setImpulse($color) {
105
		$this->impulse = $color;
106
	}
107
 
108
	/**
109
	 * Link scatter plot points
110
	 *
111
	 * @param bool $link
112
	 * @param awColor $color Line color (default to black)
113
	 */
114
	public function link($link, $color = NULL) {
115
		$this->link = (bool)$link;
116
		if($color instanceof awColor) {
117
			$this->setColor($color);
118
		}
119
	}
120
 
121
	/**
122
	 * Ignore null values for Y data and continue linking
123
	 *
124
	 * @param bool $link
125
	 */
126
	public function linkNull($link) {
127
		$this->linkNull = (bool)$link;
128
	}
129
 
130
	/**
131
	 * Change line color
132
	 *
133
	 * @param awColor $color
134
	 */
135
	public function setColor(awColor $color) {
136
		$this->lineColor = $color;
137
	}
138
 
139
	/**
140
	 * Change line style
141
	 *
142
	 * @param int $style
143
	 */
144
	public function setStyle($style) {
145
		$this->lineStyle = (int)$style;
146
	}
147
 
148
	/**
149
	 * Change line tickness
150
	 *
151
	 * @param int $tickness
152
	 */
153
	public function setThickness($tickness) {
154
		$this->lineThickness = (int)$tickness;
155
	}
156
 
157
	/**
158
	 * Get the line thickness
159
	 *
160
	 * @return int
161
	 */
162
	public function getLegendLineThickness() {
163
		return $this->lineThickness;
164
	}
165
 
166
	/**
167
	 * Get the line type
168
	 *
169
	 * @return int
170
	 */
171
	public function getLegendLineStyle() {
172
		return $this->lineStyle;
173
	}
174
 
175
	/**
176
	 * Get the color of line
177
	 *
178
	 * @return Color
179
	 */
180
	public function getLegendLineColor() {
181
		return $this->lineColor;
182
	}
183
 
184
	/**
185
	 * Get the background color or gradient of an element of the component
186
	 *
187
	 * @return Color, Gradient
188
	 */
189
	public function getLegendBackground() {
190
		return NULL;
191
	}
192
 
193
	/**
194
	 * Get a mark object
195
	 *
196
	 * @return Mark
197
	 */
198
	public function getLegendMark() {
199
		return $this->mark;
200
	}
201
 
202
	public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
203
 
204
		$count = count($this->datay);
205
 
206
		// Get start and stop values
207
		list($start, $stop) = $this->getLimit();
208
 
209
		// Build the polygon
210
		$polygon = new awPolygon;
211
 
212
		for($key = 0; $key < $count; $key++) {
213
 
214
			$x = $this->datax[$key];
215
			$y = $this->datay[$key];
216
 
217
			if($y !== NULL) {
218
				$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
219
				$polygon->set($key, $p);
220
			} else if($this->linkNull === FALSE) {
221
				$polygon->set($key, NULL);
222
			}
223
 
224
		}
225
 
226
		// Link points if needed
227
		if($this->link) {
228
 
229
			$prev = NULL;
230
 
231
			foreach($polygon->all() as $point) {
232
 
233
				if($prev !== NULL and $point !== NULL) {
234
					$driver->line(
235
						$this->lineColor,
236
						new awLine(
237
							$prev,
238
							$point,
239
							$this->lineStyle,
240
							$this->lineThickness
241
						)
242
					);
243
				}
244
				$prev = $point;
245
 
246
			}
247
		}
248
 
249
		// Draw impulses
250
		if($this->impulse instanceof awColor) {
251
 
252
			foreach($polygon->all() as $key => $point) {
253
 
254
				if($point !== NULL) {
255
 
256
					$zero = awAxis::toPosition(
257
						$this->xAxis,
258
						$this->yAxis,
259
						new awPoint($key, 0)
260
					);
261
 
262
					$driver->line(
263
						$this->impulse,
264
						new awLine(
265
							$zero,
266
							$point,
267
							awLine::SOLID,
268
							1
269
						)
270
					);
271
 
272
				}
273
 
274
			}
275
 
276
		}
277
 
278
		// Draw marks and labels
279
		foreach($polygon->all() as $key => $point) {
280
 
281
			$this->mark->draw($driver, $point);
282
			$this->label->draw($driver, $point, $key);
283
 
284
		}
285
 
286
	}
287
 
288
	protected function xAxisPoint($position) {
289
		$y = $this->xAxisZero ? 0 : $this->getRealYMin();
290
		return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
291
	}
292
 
293
	public function getXCenter() {
294
		return FALSE;
295
	}
296
 
297
}
298
 
299
registerClass('ScatterPlot');
300
?>