1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* JPGraph - Community Edition |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace Amenadiel\JpGraph\Graph\Axis; |
8
|
|
|
|
9
|
|
|
use Amenadiel\JpGraph\Graph\Configs; |
10
|
|
|
use Amenadiel\JpGraph\Text; |
11
|
|
|
use Amenadiel\JpGraph\Util; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @class Axis |
15
|
|
|
* Description: Defines X and Y axis. Notes that at the |
16
|
|
|
* moment the code is not really good since the axis on |
17
|
|
|
* several occasion must know wheter it's an X or Y axis. |
18
|
|
|
* This was a design decision to make the code easier to |
19
|
|
|
* follow. |
20
|
|
|
*/ |
21
|
|
|
class AxisPrototype extends Configs |
22
|
|
|
{ |
23
|
|
|
public $scale; |
24
|
|
|
|
25
|
|
|
public $img; |
26
|
|
|
|
27
|
|
|
public $hide = false; |
28
|
|
|
|
29
|
|
|
public $hide_labels = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Text\Text |
33
|
|
|
*/ |
34
|
|
|
public $title; |
35
|
|
|
|
36
|
|
|
public $font_family = Configs::FF_DEFAULT; |
37
|
|
|
|
38
|
|
|
public $font_style = Configs::FS_NORMAL; |
39
|
|
|
|
40
|
|
|
public $font_size = 8; |
41
|
|
|
|
42
|
|
|
public $label_angle = 0; |
43
|
|
|
|
44
|
|
|
public $tick_step = 1; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var false|string |
48
|
|
|
*/ |
49
|
|
|
public $pos = false; |
50
|
|
|
|
51
|
|
|
public $ticks_label = []; |
52
|
|
|
|
53
|
|
|
protected $weight = 1; |
54
|
|
|
|
55
|
|
|
protected $color = [0, 0, 0]; |
56
|
|
|
|
57
|
|
|
protected $label_color = [0, 0, 0]; |
58
|
|
|
|
59
|
|
|
protected $ticks_label_colors; |
60
|
|
|
|
61
|
|
|
protected $show_first_label = true; |
62
|
|
|
|
63
|
|
|
protected $show_last_label = true; |
64
|
|
|
|
65
|
|
|
protected $label_step = 1; |
66
|
|
|
|
67
|
|
|
// Used by a text axis to specify what multiple of major steps |
68
|
|
|
// should be labeled. |
69
|
|
|
/** |
70
|
|
|
* @var array|int |
71
|
|
|
*/ |
72
|
|
|
protected $labelPos = 0; // Which side of the axis should the labels be? |
73
|
|
|
|
74
|
|
|
protected $title_adjust; |
75
|
|
|
|
76
|
|
|
protected $title_margin; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var array |
80
|
|
|
*/ |
81
|
|
|
protected $title_side = Configs::SIDE_LEFT; |
82
|
|
|
|
83
|
|
|
protected $tick_label_margin = 5; |
84
|
|
|
|
85
|
|
|
protected $label_halign = ''; |
86
|
|
|
|
87
|
|
|
protected $label_valign = ''; |
88
|
|
|
|
89
|
|
|
protected $label_para_align = 'left'; |
90
|
|
|
|
91
|
|
|
protected $hide_line = false; |
92
|
|
|
|
93
|
|
|
protected $iDeltaAbsPos = 0; |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function __construct($img, $aScale, $color = [0, 0, 0]) |
97
|
|
|
{ |
98
|
|
|
$this->img = $img; |
99
|
|
|
$this->scale = $aScale; |
100
|
|
|
$this->color = $color; |
101
|
|
|
$this->title = new Text\Text(''); |
102
|
|
|
|
103
|
|
|
if ('y' === $aScale->type) { |
104
|
|
|
$this->title_margin = 25; |
105
|
|
|
$this->title_adjust = 'middle'; |
106
|
|
|
$this->title->SetOrientation(90); |
107
|
|
|
$this->tick_label_margin = 7; |
108
|
|
|
$this->labelPos = Configs::getConfig('SIDE_LEFT'); |
109
|
|
|
} else { |
110
|
|
|
$this->title_margin = 5; |
111
|
|
|
$this->title_adjust = 'high'; |
112
|
|
|
$this->title->SetOrientation(0); |
113
|
|
|
$this->tick_label_margin = 5; |
114
|
|
|
$this->labelPos = Configs::getConfig('SIDE_DOWN'); |
115
|
|
|
$this->title_side = Configs::getConfig('SIDE_DOWN'); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
public function getScale() { |
119
|
|
|
return $this->scale; |
120
|
|
|
} |
121
|
|
|
/** |
122
|
|
|
* @return void |
123
|
|
|
*/ |
124
|
|
|
public function SetLabelFormat($aFormStr) |
125
|
|
|
{ |
126
|
|
|
$this->scale->ticks->SetLabelFormat($aFormStr); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $aFormStr |
131
|
|
|
* |
132
|
|
|
* @return void |
133
|
|
|
*/ |
134
|
|
|
public function SetLabelFormatString($aFormStr, $aDate = false) |
135
|
|
|
{ |
136
|
|
|
$this->scale->ticks->SetLabelFormat($aFormStr, $aDate); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return void |
141
|
|
|
*/ |
142
|
|
|
public function SetLabelFormatCallback($aFuncName) |
143
|
|
|
{ |
144
|
|
|
$this->scale->ticks->SetFormatCallback($aFuncName); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param string $aHAlign |
149
|
|
|
* @param string $aVAlign |
150
|
|
|
* |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
|
|
public function SetLabelAlign($aHAlign, $aVAlign = 'top', $aParagraphAlign = 'left') |
154
|
|
|
{ |
155
|
|
|
$this->label_halign = $aHAlign; |
156
|
|
|
$this->label_valign = $aVAlign; |
157
|
|
|
$this->label_para_align = $aParagraphAlign; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// Don't display the first label |
161
|
|
|
/** |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function HideFirstTickLabel($aShow = false) |
165
|
|
|
{ |
166
|
|
|
$this->show_first_label = $aShow; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return void |
171
|
|
|
*/ |
172
|
|
|
public function HideLastTickLabel($aShow = false) |
173
|
|
|
{ |
174
|
|
|
$this->show_last_label = $aShow; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
// Manually specify the major and (optional) minor tick position and labels |
178
|
|
|
/** |
179
|
|
|
* @return void |
180
|
|
|
*/ |
181
|
|
|
public function SetTickPositions($aMajPos, $aMinPos = null, $aLabels = null) |
182
|
|
|
{ |
183
|
|
|
$this->scale->ticks->SetTickPositions($aMajPos, $aMinPos, $aLabels); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
// Manually specify major tick positions and optional labels |
187
|
|
|
/** |
188
|
|
|
* @return void |
189
|
|
|
*/ |
190
|
|
|
public function SetMajTickPositions($aMajPos, $aLabels = null) |
191
|
|
|
{ |
192
|
|
|
$this->scale->ticks->SetTickPositions($aMajPos, null, $aLabels); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
// Hide minor or major tick marks |
196
|
|
|
/** |
197
|
|
|
* @return void |
198
|
|
|
*/ |
199
|
|
|
public function HideTicks($aHideMinor = true, $aHideMajor = true) |
200
|
|
|
{ |
201
|
|
|
$this->scale->ticks->SupressMinorTickMarks($aHideMinor); |
202
|
|
|
$this->scale->ticks->SupressTickMarks($aHideMajor); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
// Hide zero label |
206
|
|
|
/** |
207
|
|
|
* @return void |
208
|
|
|
*/ |
209
|
|
|
public function HideZeroLabel($aFlag = true) |
|
|
|
|
210
|
|
|
{ |
211
|
|
|
$this->scale->ticks->SupressZeroLabel(); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @return void |
216
|
|
|
*/ |
217
|
|
|
public function HideFirstLastLabel() |
218
|
|
|
{ |
219
|
|
|
// The two first calls to ticks method will supress |
220
|
|
|
// automatically generated scale values. However, that |
221
|
|
|
// will not affect manually specified value, e.g text-scales. |
222
|
|
|
// therefor we also make a kludge here to supress manually |
223
|
|
|
// specified scale labels. |
224
|
|
|
$this->scale->ticks->SupressLast(); |
225
|
|
|
$this->scale->ticks->SupressFirst(); |
226
|
|
|
$this->show_first_label = false; |
227
|
|
|
$this->show_last_label = false; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
// Hide the axis |
231
|
|
|
/** |
232
|
|
|
* @return void |
233
|
|
|
*/ |
234
|
|
|
public function Hide($aHide = true) |
235
|
|
|
{ |
236
|
|
|
$this->hide = $aHide; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
// Hide the actual axis-line, but still print the labels |
240
|
|
|
/** |
241
|
|
|
* @return void |
242
|
|
|
*/ |
243
|
|
|
public function HideLine($aHide = true) |
244
|
|
|
{ |
245
|
|
|
$this->hide_line = $aHide; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @return void |
250
|
|
|
*/ |
251
|
|
|
public function HideLabels($aHide = true) |
252
|
|
|
{ |
253
|
|
|
$this->hide_labels = $aHide; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// Weight of axis |
257
|
|
|
/** |
258
|
|
|
* @param int $aWeight |
259
|
|
|
* |
260
|
|
|
* @return void |
261
|
|
|
*/ |
262
|
|
|
public function SetWeight($aWeight) |
263
|
|
|
{ |
264
|
|
|
$this->weight = $aWeight; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// Axis color |
268
|
|
|
/** |
269
|
|
|
* @param string $aColor |
270
|
|
|
* @param false|string $aLabelColor |
271
|
|
|
* |
272
|
|
|
* @return void |
273
|
|
|
*/ |
274
|
|
|
public function SetColor($aColor, $aLabelColor = false) |
275
|
|
|
{ |
276
|
|
|
$this->color = $aColor; |
277
|
|
|
|
278
|
|
|
if (!$aLabelColor) { |
279
|
|
|
$this->label_color = $aColor; |
280
|
|
|
} else { |
281
|
|
|
$this->label_color = $aLabelColor; |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
// Title on axis |
286
|
|
|
/** |
287
|
|
|
* @return void |
288
|
|
|
*/ |
289
|
|
|
public function SetTitle($aTitle, $aAdjustAlign = 'high') |
290
|
|
|
{ |
291
|
|
|
$this->title->Set($aTitle); |
292
|
|
|
$this->title_adjust = $aAdjustAlign; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
// Specify distance from the axis |
296
|
|
|
/** |
297
|
|
|
* @return void |
298
|
|
|
*/ |
299
|
|
|
public function SetTitleMargin($aMargin) |
300
|
|
|
{ |
301
|
|
|
$this->title_margin = $aMargin; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
// Which side of the axis should the axis title be? |
305
|
|
|
/** |
306
|
|
|
* @param array $aSideOfAxis |
307
|
|
|
* |
308
|
|
|
* @return void |
309
|
|
|
*/ |
310
|
|
|
public function SetTitleSide($aSideOfAxis) |
311
|
|
|
{ |
312
|
|
|
$this->title_side = $aSideOfAxis; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @return void |
317
|
|
|
*/ |
318
|
|
|
public function SetTickSide($aDir) |
319
|
|
|
{ |
320
|
|
|
$this->scale->ticks->SetSide($aDir); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* @return void |
325
|
|
|
*/ |
326
|
|
|
public function SetTickSize($aMajSize, $aMinSize = 3) |
|
|
|
|
327
|
|
|
{ |
328
|
|
|
$this->scale->ticks->SetSize($aMajSize, $aMinSize = 3); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
// Specify text labels for the ticks. One label for each data point |
332
|
|
|
/** |
333
|
|
|
* @return void |
334
|
|
|
*/ |
335
|
|
|
public function SetTickLabels($aLabelArray, $aLabelColorArray = null) |
336
|
|
|
{ |
337
|
|
|
$this->ticks_label = $aLabelArray; |
338
|
|
|
$this->ticks_label_colors = $aLabelColorArray; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return void |
343
|
|
|
*/ |
344
|
|
|
public function SetLabelMargin($aMargin) |
345
|
|
|
{ |
346
|
|
|
$this->tick_label_margin = $aMargin; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
// Specify that every $step of the ticks should be displayed starting |
350
|
|
|
// at $start |
351
|
|
|
/** |
352
|
|
|
* @return void |
353
|
|
|
*/ |
354
|
|
|
public function SetTextTickInterval($aStep, $aStart = 0) |
355
|
|
|
{ |
356
|
|
|
$this->scale->ticks->SetTextLabelStart($aStart); |
357
|
|
|
$this->tick_step = $aStep; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
// Specify that every $step tick mark should have a label |
361
|
|
|
// should be displayed starting |
362
|
|
|
/** |
363
|
|
|
* @return void |
364
|
|
|
*/ |
365
|
|
|
public function SetTextLabelInterval($aStep) |
366
|
|
|
{ |
367
|
|
|
if (1 > $aStep) { |
368
|
|
|
Util\JpGraphError::RaiseL(25058); //(" Text label interval must be specified >= 1."); |
369
|
|
|
} |
370
|
|
|
$this->label_step = $aStep; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @param array $aSidePos |
375
|
|
|
* |
376
|
|
|
* @return void |
377
|
|
|
*/ |
378
|
|
|
public function SetLabelSide($aSidePos) |
379
|
|
|
{ |
380
|
|
|
$this->labelPos = $aSidePos; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
// Set the font |
384
|
|
|
/** |
385
|
|
|
* @param int $aFamily |
386
|
|
|
* @param int $aStyle |
387
|
|
|
* @param int $aSize |
388
|
|
|
* |
389
|
|
|
* @return void |
390
|
|
|
*/ |
391
|
|
|
public function SetFont($aFamily, $aStyle = Configs::FS_NORMAL, $aSize = 10) |
392
|
|
|
{ |
393
|
|
|
$this->font_family = $aFamily; |
394
|
|
|
$this->font_style = $aStyle; |
395
|
|
|
$this->font_size = $aSize; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
// Position for axis line on the "other" scale |
399
|
|
|
/** |
400
|
|
|
* @param string $aPosOnOtherScale |
401
|
|
|
* |
402
|
|
|
* @return void |
403
|
|
|
*/ |
404
|
|
|
public function SetPos($aPosOnOtherScale) |
405
|
|
|
{ |
406
|
|
|
$this->pos = $aPosOnOtherScale; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
// Set the position of the axis to be X-pixels delta to the right |
410
|
|
|
// of the max X-position (used to position the multiple Y-axis) |
411
|
|
|
/** |
412
|
|
|
* @return void |
413
|
|
|
*/ |
414
|
|
|
public function SetPosAbsDelta($aDelta) |
415
|
|
|
{ |
416
|
|
|
$this->iDeltaAbsPos = $aDelta; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
// Specify the angle for the tick labels |
420
|
|
|
/** |
421
|
|
|
* @return void |
422
|
|
|
*/ |
423
|
|
|
public function SetLabelAngle($aAngle) |
424
|
|
|
{ |
425
|
|
|
$this->label_angle = $aAngle; |
426
|
|
|
} |
427
|
|
|
} // @class |
428
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.