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