1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* JPGraph v4.0.3 |
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
|
|
|
|
16
|
|
|
namespace Amenadiel\JpGraph\Themes; |
17
|
|
|
|
18
|
|
|
use Amenadiel\JpGraph\Graph; |
19
|
|
|
use Amenadiel\JpGraph\Image; |
20
|
|
|
use Amenadiel\JpGraph\Util; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @class |
24
|
|
|
* // Description: |
25
|
|
|
*/ |
26
|
|
|
abstract class Theme |
27
|
|
|
{ |
28
|
|
|
protected $color_index; |
29
|
|
|
|
30
|
21 |
|
public function __construct() |
31
|
|
|
{ |
32
|
21 |
|
$this->color_index = 0; |
33
|
21 |
|
} |
34
|
|
|
|
35
|
|
|
abstract public function GetColorList(); |
36
|
|
|
|
37
|
|
|
abstract public function ApplyPlot($plot); |
38
|
|
|
|
39
|
21 |
|
public function SetupPlot($plot) |
40
|
|
|
{ |
41
|
21 |
|
if (is_array($plot)) { |
42
|
|
|
foreach ($plot as $obj) { |
43
|
|
|
$this->ApplyPlot($obj); |
44
|
|
|
} |
45
|
|
|
} else { |
46
|
21 |
|
$this->ApplyPlot($plot); |
47
|
|
|
} |
48
|
21 |
|
} |
49
|
|
|
|
50
|
21 |
|
public function ApplyGraph($graph) |
51
|
|
|
{ |
52
|
21 |
|
$this->graph = $graph; |
53
|
21 |
|
$method_name = ''; |
54
|
21 |
|
$graphClass = explode('\\', get_class($graph)); |
55
|
21 |
|
$classname = end($graphClass); |
56
|
|
|
|
57
|
21 |
|
if ($classname == 'Graph') { |
58
|
19 |
|
$method_name = 'SetupGraph'; |
59
|
|
|
} else { |
60
|
3 |
|
$method_name = 'Setup' . $classname; |
61
|
|
|
} |
62
|
|
|
|
63
|
21 |
|
if (method_exists($this, $method_name)) { |
64
|
21 |
|
$this->{$method_name}($graph); |
65
|
|
|
} else { |
66
|
|
|
Util\JpGraphError::RaiseL(30001, $method_name, $method_name); //Theme::%s() is not defined. \nPlease make %s(\$graph) function in your theme classs. |
67
|
|
|
} |
68
|
21 |
|
} |
69
|
|
|
|
70
|
|
|
public function PreStrokeApply($graph) |
71
|
|
|
{ |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function GetThemeColors($num = 30) |
75
|
|
|
{ |
76
|
|
|
$result_list = []; |
77
|
|
|
|
78
|
|
|
$old_index = $this->color_index; |
79
|
|
|
$this->color_index = 0; |
80
|
|
|
$count = 0; |
81
|
|
|
|
82
|
|
|
$i = 0; |
83
|
|
|
while (true) { |
84
|
|
|
for ($j = 0; $j < safe_count($this->GetColorList()); ++$j) { |
85
|
|
|
if (++$count > $num) { |
86
|
|
|
break 2; |
87
|
|
|
} |
88
|
|
|
$result_list[] = $this->GetNextColor(); |
89
|
|
|
} |
90
|
|
|
++$i; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$this->color_index = $old_index; |
94
|
|
|
|
95
|
|
|
return $result_list; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function GetNextColor() |
99
|
|
|
{ |
100
|
|
|
$color_list = $this->GetColorList(); |
101
|
|
|
|
102
|
|
|
$color = null; |
103
|
|
|
if (isset($color_list[$this->color_index])) { |
104
|
|
|
$color = $color_list[$this->color_index]; |
105
|
|
|
} else { |
106
|
|
|
$color_count = safe_count($color_list); |
107
|
|
|
if ($color_count <= $this->color_index) { |
108
|
|
|
$color_tmp = $color_list[$this->color_index % $color_count]; |
109
|
|
|
$brightness = 1.0 - (int) ($this->color_index / $color_count) * 0.2; |
110
|
|
|
$rgb = new Image\RGB(); |
111
|
|
|
$color = $color_tmp . ':' . $brightness; |
112
|
|
|
$color = $rgb->Color($color); |
113
|
|
|
$alpha = array_pop($color); |
|
|
|
|
114
|
|
|
$color = $rgb->tryHexConversion($color); |
115
|
|
|
if ($alpha) { |
116
|
|
|
$color .= '@' . $alpha; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
++$this->color_index; |
122
|
|
|
|
123
|
|
|
return $color; |
124
|
|
|
} |
125
|
|
|
} // @class |
126
|
|
|
|