1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ballybran\Library; |
4
|
|
|
class SetupXY |
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
public function setupXAxis($percent = '', $color = '') |
9
|
|
|
{ |
10
|
|
|
$this->bool_x_axis_setup = true; |
|
|
|
|
11
|
|
|
if (false === $percent) { |
12
|
|
|
$this->bool_x_axis = false; |
|
|
|
|
13
|
|
|
} else { |
14
|
|
|
$this->bool_x_axis = true; |
15
|
|
|
} |
16
|
|
|
if (!empty($color) && $arr = $this->returnColorArray($color)) { |
17
|
|
|
$this->x_axis_color = imagecolorallocate($this->image, $arr[0], $arr[1], $arr[2]); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
if (is_numeric($percent) && $percent > 0) { |
20
|
|
|
$percent = $percent / 100; |
21
|
|
|
$this->x_axis_margin = round($this->height * $percent); |
|
|
|
|
22
|
|
|
} else { |
23
|
|
|
$percent = self::X_AXIS_MARGIN_PERCENT / 100; |
|
|
|
|
24
|
|
|
$this->x_axis_margin = round($this->height * $percent); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setupYAxis($percent = '', $color = '') |
29
|
|
|
{ |
30
|
|
|
$this->bool_y_axis_setup = true; |
|
|
|
|
31
|
|
|
if (false === $percent) { |
32
|
|
|
$this->bool_y_axis = false; |
|
|
|
|
33
|
|
|
} else { |
34
|
|
|
$this->bool_y_axis = true; |
35
|
|
|
} |
36
|
|
|
if (!empty($color) && $arr = $this->returnColorArray($color)) { |
37
|
|
|
$this->y_axis_color = imagecolorallocate($this->image, $arr[0], $arr[1], $arr[2]); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
if (is_numeric($percent) && $percent > 0) { |
40
|
|
|
$this->y_axis_margin = round($this->width * ($percent / 100)); |
|
|
|
|
41
|
|
|
} else { |
42
|
|
|
$percent = self::Y_AXIS_MARGIN_PERCENT / 100; |
|
|
|
|
43
|
|
|
$this->y_axis_margin = round($this->width * $percent); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setRange($min, $max) |
48
|
|
|
{ |
49
|
|
|
//because of deprecated use of this function as($max, $min) |
50
|
|
|
if ($min > $max) { |
51
|
|
|
$this->data_range_max = $min; |
|
|
|
|
52
|
|
|
$this->data_range_min = $max; |
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
$this->data_range_max = $max; |
55
|
|
|
$this->data_range_min = $min; |
56
|
|
|
} |
57
|
|
|
$this->bool_user_data_range = true; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function returnColorArray($color) |
61
|
|
|
{ |
62
|
|
|
//check to see if color passed through in form '128,128,128' or hex format |
63
|
|
|
if (false !== strpos($color, ',')) { |
64
|
|
|
return explode(',', $color); |
65
|
|
|
} elseif ('#' == substr($color, 0, 1)) { |
66
|
|
|
if (strlen($color) == 7) { |
67
|
|
|
$hex1 = hexdec(substr($color, 1, 2)); |
68
|
|
|
$hex2 = hexdec(substr($color, 3, 2)); |
69
|
|
|
$hex3 = hexdec(substr($color, 5, 2)); |
70
|
|
|
return array($hex1, $hex2, $hex3); |
71
|
|
|
} elseif (strlen($color) == 4) { |
72
|
|
|
$hex1 = hexdec(substr($color, 1, 1) . substr($color, 1, 1)); |
73
|
|
|
$hex2 = hexdec(substr($color, 2, 1) . substr($color, 2, 1)); |
74
|
|
|
$hex3 = hexdec(substr($color, 3, 1) . substr($color, 3, 1)); |
75
|
|
|
return array($hex1, $hex2, $hex3); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
switch (strtolower($color)) { |
80
|
|
|
//named colors based on W3C's recd html colors |
81
|
|
|
case 'black': |
82
|
|
|
return array(0, 0, 0); |
83
|
|
|
break; |
|
|
|
|
84
|
|
|
case 'silver': |
85
|
|
|
return array(192, 192, 192); |
86
|
|
|
break; |
87
|
|
|
case 'gray': |
88
|
|
|
return array(128, 128, 128); |
89
|
|
|
break; |
90
|
|
|
case 'white': |
91
|
|
|
return array(255, 255, 255); |
92
|
|
|
break; |
93
|
|
|
case 'maroon': |
94
|
|
|
return array(128, 0, 0); |
95
|
|
|
break; |
96
|
|
|
case 'red': |
97
|
|
|
return array(255, 0, 0); |
98
|
|
|
break; |
99
|
|
|
case 'purple': |
100
|
|
|
return array(128, 0, 128); |
101
|
|
|
break; |
102
|
|
|
case 'fuscia': |
103
|
|
|
return array(255, 0, 255); |
104
|
|
|
break; |
105
|
|
|
case 'green': |
106
|
|
|
return array(0, 128, 0); |
107
|
|
|
break; |
108
|
|
|
case 'lime': |
109
|
|
|
return array(0, 255, 0); |
110
|
|
|
break; |
111
|
|
|
case 'olive': |
112
|
|
|
return array(128, 128, 0); |
113
|
|
|
break; |
114
|
|
|
case 'yellow': |
115
|
|
|
return array(255, 255, 0); |
116
|
|
|
break; |
117
|
|
|
case 'navy': |
118
|
|
|
return array(0, 0, 128); |
119
|
|
|
break; |
120
|
|
|
case 'blue': |
121
|
|
|
return array(0, 0, 255); |
122
|
|
|
break; |
123
|
|
|
case 'teal': |
124
|
|
|
return array(0, 128, 128); |
125
|
|
|
break; |
126
|
|
|
case 'aqua': |
127
|
|
|
return array(0, 255, 255); |
128
|
|
|
break; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$this->error[] = "Color name \"$color\" not recogized."; |
|
|
|
|
132
|
|
|
return false; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
} |