1
|
|
|
<?php |
2
|
|
|
namespace Amenadiel\JpGraph\Graph; |
3
|
|
|
|
4
|
|
|
use Amenadiel\JpGraph\Util; |
5
|
|
|
use \Amenadiel\JpGraph\Text\Text; |
6
|
|
|
|
7
|
|
|
//=================================================== |
8
|
|
|
// CLASS Axis |
9
|
|
|
// Description: Defines X and Y axis. Notes that at the |
10
|
|
|
// moment the code is not really good since the axis on |
11
|
|
|
// several occasion must know wheter it's an X or Y axis. |
12
|
|
|
// This was a design decision to make the code easier to |
13
|
|
|
// follow. |
14
|
|
|
//=================================================== |
15
|
|
|
class AxisPrototype |
16
|
|
|
{ |
17
|
|
|
public $scale = null; |
18
|
|
|
public $img = null; |
19
|
|
|
public $hide = false; |
20
|
|
|
public $hide_labels = false; |
21
|
|
|
public $title = null; |
22
|
|
|
public $font_family = FF_DEFAULT; |
23
|
|
|
public $font_style = FS_NORMAL; |
24
|
|
|
public $font_size = 8; |
25
|
|
|
public $label_angle = 0; |
26
|
|
|
public $tick_step = 1; |
27
|
|
|
public $pos = false; |
28
|
|
|
public $ticks_label = array(); |
29
|
|
|
|
30
|
|
|
protected $weight = 1; |
31
|
|
|
protected $color = array(0, 0, 0); |
32
|
|
|
protected $label_color = array(0, 0, 0); |
33
|
|
|
protected $ticks_label_colors = null; |
34
|
|
|
protected $show_first_label = true; |
35
|
|
|
protected $show_last_label = true; |
36
|
|
|
protected $label_step = 1; // Used by a text axis to specify what multiple of major steps |
37
|
|
|
// should be labeled. |
38
|
|
|
protected $labelPos = 0; // Which side of the axis should the labels be? |
39
|
|
|
protected $title_adjust; |
40
|
|
|
protected $title_margin; |
41
|
|
|
protected $title_side = SIDE_LEFT; |
42
|
|
|
protected $tick_label_margin = 5; |
43
|
|
|
protected $label_halign = ''; |
44
|
|
|
protected $label_valign = ''; |
45
|
|
|
protected $label_para_align = 'left'; |
46
|
|
|
protected $hide_line = false; |
47
|
|
|
protected $iDeltaAbsPos = 0; |
48
|
|
|
|
49
|
|
|
public function __construct($img, $aScale, $color = array(0, 0, 0)) |
50
|
|
|
{ |
51
|
|
|
$this->img = $img; |
52
|
|
|
$this->scale = $aScale; |
53
|
|
|
$this->color = $color; |
54
|
|
|
$this->title = new Text(''); |
55
|
|
|
|
56
|
|
|
if ($aScale->type == 'y') { |
57
|
|
|
$this->title_margin = 25; |
58
|
|
|
$this->title_adjust = 'middle'; |
59
|
|
|
$this->title->SetOrientation(90); |
60
|
|
|
$this->tick_label_margin = 7; |
61
|
|
|
$this->labelPos = SIDE_LEFT; |
62
|
|
|
} else { |
63
|
|
|
$this->title_margin = 5; |
64
|
|
|
$this->title_adjust = 'high'; |
65
|
|
|
$this->title->SetOrientation(0); |
66
|
|
|
$this->tick_label_margin = 5; |
67
|
|
|
$this->labelPos = SIDE_DOWN; |
68
|
|
|
$this->title_side = SIDE_DOWN; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function SetLabelFormat($aFormStr) |
73
|
|
|
{ |
74
|
|
|
$this->scale->ticks->SetLabelFormat($aFormStr); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function SetLabelFormatString($aFormStr, $aDate = false) |
78
|
|
|
{ |
79
|
|
|
$this->scale->ticks->SetLabelFormat($aFormStr, $aDate); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function SetLabelFormatCallback($aFuncName) |
83
|
|
|
{ |
84
|
|
|
$this->scale->ticks->SetFormatCallback($aFuncName); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function SetLabelAlign($aHAlign, $aVAlign = 'top', $aParagraphAlign = 'left') |
88
|
|
|
{ |
89
|
|
|
$this->label_halign = $aHAlign; |
90
|
|
|
$this->label_valign = $aVAlign; |
91
|
|
|
$this->label_para_align = $aParagraphAlign; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
// Don't display the first label |
95
|
|
|
public function HideFirstTickLabel($aShow = false) |
96
|
|
|
{ |
97
|
|
|
$this->show_first_label = $aShow; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function HideLastTickLabel($aShow = false) |
101
|
|
|
{ |
102
|
|
|
$this->show_last_label = $aShow; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// Manually specify the major and (optional) minor tick position and labels |
106
|
|
|
public function SetTickPositions($aMajPos, $aMinPos = null, $aLabels = null) |
107
|
|
|
{ |
108
|
|
|
$this->scale->ticks->SetTickPositions($aMajPos, $aMinPos, $aLabels); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// Manually specify major tick positions and optional labels |
112
|
|
|
public function SetMajTickPositions($aMajPos, $aLabels = null) |
113
|
|
|
{ |
114
|
|
|
$this->scale->ticks->SetTickPositions($aMajPos, null, $aLabels); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// Hide minor or major tick marks |
118
|
|
|
public function HideTicks($aHideMinor = true, $aHideMajor = true) |
119
|
|
|
{ |
120
|
|
|
$this->scale->ticks->SupressMinorTickMarks($aHideMinor); |
121
|
|
|
$this->scale->ticks->SupressTickMarks($aHideMajor); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// Hide zero label |
125
|
|
|
public function HideZeroLabel($aFlag = true) |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
$this->scale->ticks->SupressZeroLabel(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function HideFirstLastLabel() |
131
|
|
|
{ |
132
|
|
|
// The two first calls to ticks method will supress |
133
|
|
|
// automatically generated scale values. However, that |
134
|
|
|
// will not affect manually specified value, e.g text-scales. |
135
|
|
|
// therefor we also make a kludge here to supress manually |
136
|
|
|
// specified scale labels. |
137
|
|
|
$this->scale->ticks->SupressLast(); |
138
|
|
|
$this->scale->ticks->SupressFirst(); |
139
|
|
|
$this->show_first_label = false; |
140
|
|
|
$this->show_last_label = false; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
// Hide the axis |
144
|
|
|
public function Hide($aHide = true) |
145
|
|
|
{ |
146
|
|
|
$this->hide = $aHide; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
// Hide the actual axis-line, but still print the labels |
150
|
|
|
public function HideLine($aHide = true) |
151
|
|
|
{ |
152
|
|
|
$this->hide_line = $aHide; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function HideLabels($aHide = true) |
156
|
|
|
{ |
157
|
|
|
$this->hide_labels = $aHide; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
// Weight of axis |
161
|
|
|
public function SetWeight($aWeight) |
162
|
|
|
{ |
163
|
|
|
$this->weight = $aWeight; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
// Axis color |
167
|
|
|
public function SetColor($aColor, $aLabelColor = false) |
168
|
|
|
{ |
169
|
|
|
$this->color = $aColor; |
170
|
|
|
if (!$aLabelColor) { |
171
|
|
|
$this->label_color = $aColor; |
172
|
|
|
} else { |
173
|
|
|
$this->label_color = $aLabelColor; |
|
|
|
|
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
// Title on axis |
178
|
|
|
public function SetTitle($aTitle, $aAdjustAlign = 'high') |
179
|
|
|
{ |
180
|
|
|
$this->title->Set($aTitle); |
181
|
|
|
$this->title_adjust = $aAdjustAlign; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
// Specify distance from the axis |
185
|
|
|
public function SetTitleMargin($aMargin) |
186
|
|
|
{ |
187
|
|
|
$this->title_margin = $aMargin; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
// Which side of the axis should the axis title be? |
191
|
|
|
public function SetTitleSide($aSideOfAxis) |
192
|
|
|
{ |
193
|
|
|
$this->title_side = $aSideOfAxis; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function SetTickSide($aDir) |
197
|
|
|
{ |
198
|
|
|
$this->scale->ticks->SetSide($aDir); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function SetTickSize($aMajSize, $aMinSize = 3) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
$this->scale->ticks->SetSize($aMajSize, $aMinSize = 3); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
// Specify text labels for the ticks. One label for each data point |
207
|
|
|
public function SetTickLabels($aLabelArray, $aLabelColorArray = null) |
208
|
|
|
{ |
209
|
|
|
$this->ticks_label = $aLabelArray; |
210
|
|
|
$this->ticks_label_colors = $aLabelColorArray; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function SetLabelMargin($aMargin) |
214
|
|
|
{ |
215
|
|
|
$this->tick_label_margin = $aMargin; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// Specify that every $step of the ticks should be displayed starting |
219
|
|
|
// at $start |
220
|
|
|
public function SetTextTickInterval($aStep, $aStart = 0) |
221
|
|
|
{ |
222
|
|
|
$this->scale->ticks->SetTextLabelStart($aStart); |
223
|
|
|
$this->tick_step = $aStep; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
// Specify that every $step tick mark should have a label |
227
|
|
|
// should be displayed starting |
228
|
|
|
public function SetTextLabelInterval($aStep) |
229
|
|
|
{ |
230
|
|
|
if ($aStep < 1) { |
231
|
|
|
Util\JpGraphError::RaiseL(25058); //(" Text label interval must be specified >= 1."); |
232
|
|
|
} |
233
|
|
|
$this->label_step = $aStep; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function SetLabelSide($aSidePos) |
237
|
|
|
{ |
238
|
|
|
$this->labelPos = $aSidePos; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
// Set the font |
242
|
|
|
public function SetFont($aFamily, $aStyle = FS_NORMAL, $aSize = 10) |
243
|
|
|
{ |
244
|
|
|
$this->font_family = $aFamily; |
245
|
|
|
$this->font_style = $aStyle; |
246
|
|
|
$this->font_size = $aSize; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
// Position for axis line on the "other" scale |
250
|
|
|
public function SetPos($aPosOnOtherScale) |
251
|
|
|
{ |
252
|
|
|
$this->pos = $aPosOnOtherScale; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
// Set the position of the axis to be X-pixels delta to the right |
256
|
|
|
// of the max X-position (used to position the multiple Y-axis) |
257
|
|
|
public function SetPosAbsDelta($aDelta) |
258
|
|
|
{ |
259
|
|
|
$this->iDeltaAbsPos = $aDelta; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
// Specify the angle for the tick labels |
263
|
|
|
public function SetLabelAngle($aAngle) |
264
|
|
|
{ |
265
|
|
|
$this->label_angle = $aAngle; |
266
|
|
|
} |
267
|
|
|
} // Class |
268
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.