1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* JPGraph v3.6.15 |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* // File: JPGRAPH_THEME.INC.PHP |
9
|
|
|
* // Description: Class to define graph theme |
10
|
|
|
* // Created: 2010-09-29 |
11
|
|
|
* // Ver: $Id: jpgraph_theme.inc.php 83 2010-10-01 11:24:19Z atsushi $ |
12
|
|
|
* // |
13
|
|
|
* // Copyright (c) Asial Corporation. All rights reserved. |
14
|
|
|
*/ |
15
|
|
|
namespace Amenadiel\JpGraph\Themes; |
16
|
|
|
|
17
|
|
|
use Amenadiel\JpGraph\Graph; |
18
|
|
|
use Amenadiel\JpGraph\Image; |
19
|
|
|
use Amenadiel\JpGraph\Util; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @class |
23
|
|
|
* // Description: |
24
|
|
|
*/ |
25
|
|
|
abstract class Theme |
26
|
|
|
{ |
27
|
|
|
protected $color_index; |
28
|
|
|
|
29
|
18 |
|
public function __construct() |
30
|
|
|
{ |
31
|
18 |
|
$this->color_index = 0; |
32
|
18 |
|
} |
33
|
|
|
|
34
|
|
|
abstract public function GetColorList(); |
35
|
|
|
|
36
|
|
|
abstract public function ApplyPlot($plot); |
37
|
|
|
|
38
|
15 |
|
public function SetupPlot($plot) |
39
|
|
|
{ |
40
|
15 |
|
if (is_array($plot)) { |
41
|
2 |
|
foreach ($plot as $obj) { |
42
|
2 |
|
$this->ApplyPlot($obj); |
43
|
|
|
} |
44
|
|
|
} else { |
45
|
15 |
|
$this->ApplyPlot($plot); |
46
|
|
|
} |
47
|
15 |
|
} |
48
|
|
|
|
49
|
15 |
|
public function ApplyGraph($graph) |
50
|
|
|
{ |
51
|
15 |
|
$this->graph = $graph; |
52
|
15 |
|
$method_name = ''; |
53
|
15 |
|
$graphClass = explode('\\', get_class($graph)); |
54
|
15 |
|
$classname = end($graphClass); |
55
|
|
|
|
56
|
15 |
|
if ($classname == 'Graph') { |
57
|
14 |
|
$method_name = 'SetupGraph'; |
58
|
|
|
} else { |
59
|
2 |
|
$method_name = 'Setup' . $classname; |
60
|
|
|
} |
61
|
|
|
|
62
|
15 |
|
if (method_exists($this, $method_name)) { |
63
|
15 |
|
$this->{$method_name}($graph); |
64
|
|
|
} else { |
65
|
|
|
Util\JpGraphError::RaiseL(30001, $method_name, $method_name); //Theme::%s() is not defined. \nPlease make %s(\$graph) function in your theme classs. |
66
|
|
|
} |
67
|
15 |
|
} |
68
|
|
|
|
69
|
|
|
public function PreStrokeApply($graph) {} |
70
|
|
|
|
71
|
|
|
public function GetThemeColors($num = 30) |
72
|
|
|
{ |
73
|
|
|
$result_list = []; |
74
|
|
|
|
75
|
|
|
$old_index = $this->color_index; |
76
|
|
|
$this->color_index = 0; |
77
|
|
|
$count = 0; |
78
|
|
|
|
79
|
|
|
$i = 0; |
80
|
|
|
while (true) { |
81
|
|
|
for ($j = 0; $j < count($this->GetColorList()); ++$j) { |
|
|
|
|
82
|
|
|
if (++$count > $num) { |
83
|
|
|
break 2; |
84
|
|
|
} |
85
|
|
|
$result_list[] = $this->GetNextColor(); |
86
|
|
|
} |
87
|
|
|
++$i; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->color_index = $old_index; |
91
|
|
|
|
92
|
|
|
return $result_list; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function GetNextColor() |
96
|
|
|
{ |
97
|
|
|
$color_list = $this->GetColorList(); |
98
|
|
|
|
99
|
|
|
$color = null; |
100
|
|
|
if (isset($color_list[$this->color_index])) { |
101
|
|
|
$color = $color_list[$this->color_index]; |
102
|
|
|
} else { |
103
|
|
|
$color_count = count($color_list); |
104
|
|
|
if ($color_count <= $this->color_index) { |
105
|
|
|
$color_tmp = $color_list[$this->color_index % $color_count]; |
106
|
|
|
$brightness = 1.0 - (int) ($this->color_index / $color_count) * 0.2; |
107
|
|
|
$rgb = new Image\RGB(); |
108
|
|
|
$color = $color_tmp . ':' . $brightness; |
109
|
|
|
$color = $rgb->Color($color); |
110
|
|
|
$alpha = array_pop($color); |
111
|
|
|
$color = $rgb->tryHexConversion($color); |
112
|
|
|
if ($alpha) { |
113
|
|
|
$color .= '@' . $alpha; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
++$this->color_index; |
119
|
|
|
|
120
|
|
|
return $color; |
121
|
|
|
} |
122
|
|
|
} // @class |
123
|
|
|
|
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: