|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ob\HighchartsBundle\Highcharts; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This class is part of the Ob/HighchartsBundle |
|
7
|
|
|
* See Highcharts documentation at http://www.highcharts.com/ref/ |
|
8
|
|
|
* |
|
9
|
|
|
* @method Highchart colors(array $colors) |
|
10
|
|
|
* @method Highchart series(array $series) |
|
11
|
|
|
*/ |
|
12
|
|
|
class Highchart extends AbstractChart implements ChartInterface |
|
13
|
|
|
{ |
|
14
|
|
|
public $colorAxis; |
|
15
|
|
|
|
|
16
|
|
|
public $noData; |
|
17
|
|
|
|
|
18
|
33 |
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
33 |
|
parent::__construct(); |
|
21
|
33 |
|
$this->initChartOption('colorAxis'); |
|
22
|
33 |
|
$this->initChartOption('noData'); |
|
23
|
33 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $engine |
|
27
|
|
|
* |
|
28
|
|
|
* @return string |
|
29
|
|
|
*/ |
|
30
|
32 |
|
public function render($engine = 'jquery') |
|
31
|
|
|
{ |
|
32
|
32 |
|
$chartJS = ""; |
|
33
|
32 |
|
$chartJS .= $this->renderEngine($engine); |
|
34
|
32 |
|
$chartJS .= $this->renderOptions(); |
|
35
|
32 |
|
$chartJS .= "\n var " . (isset($this->chart->renderTo) ? $this->chart->renderTo : 'chart') . " = new Highcharts.Chart({\n"; |
|
36
|
|
|
|
|
37
|
|
|
// Chart |
|
38
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->chart->chart, "chart"); |
|
39
|
|
|
|
|
40
|
|
|
// Colors |
|
41
|
32 |
|
$chartJS .= $this->renderColors(); |
|
42
|
|
|
|
|
43
|
|
|
// Color Axis |
|
44
|
32 |
|
$chartJS .= $this->renderColorAxis(); |
|
45
|
|
|
|
|
46
|
|
|
// Credits |
|
47
|
32 |
|
$chartJS .= $this->renderCredits(); |
|
48
|
|
|
|
|
49
|
|
|
// Exporting |
|
50
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->exporting->exporting, "exporting"); |
|
51
|
|
|
|
|
52
|
|
|
// Labels |
|
53
|
|
|
|
|
54
|
|
|
// Legend |
|
55
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->legend->legend, "legend"); |
|
56
|
|
|
|
|
57
|
|
|
// Loading |
|
58
|
|
|
// Navigation |
|
59
|
|
|
|
|
60
|
|
|
// noData |
|
61
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->noData->noData, "noData"); |
|
62
|
|
|
|
|
63
|
|
|
// Pane |
|
64
|
32 |
|
$chartJS .= $this->renderPane(); |
|
65
|
|
|
|
|
66
|
|
|
// PlotOptions |
|
67
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->plotOptions->plotOptions, "plotOptions"); |
|
68
|
|
|
|
|
69
|
|
|
// Series |
|
70
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->series, "series"); |
|
71
|
|
|
|
|
72
|
|
|
// Scrollbar |
|
73
|
32 |
|
$chartJS .= $this->renderScrollbar(); |
|
74
|
|
|
|
|
75
|
|
|
// Drilldown |
|
76
|
32 |
|
$chartJS .= $this->renderDrilldown(); |
|
77
|
|
|
|
|
78
|
|
|
// Subtitle |
|
79
|
32 |
|
$chartJS .= $this->renderSubtitle(); |
|
80
|
|
|
|
|
81
|
|
|
// Symbols |
|
82
|
|
|
|
|
83
|
|
|
// Title |
|
84
|
32 |
|
$chartJS .= $this->renderTitle(); |
|
85
|
|
|
|
|
86
|
|
|
// Tooltip |
|
87
|
32 |
|
$chartJS .= $this->renderWithJavascriptCallback($this->tooltip->tooltip, "tooltip"); |
|
88
|
|
|
|
|
89
|
|
|
// xAxis |
|
90
|
32 |
|
$chartJS .= $this->renderXAxis(); |
|
91
|
|
|
|
|
92
|
|
|
// yAxis |
|
93
|
32 |
|
$chartJS .= $this->renderYAxis(); |
|
94
|
|
|
|
|
95
|
|
|
// trim last trailing comma and close parenthesis |
|
96
|
32 |
|
$chartJS = rtrim($chartJS, ",\n") . "\n });\n"; |
|
97
|
|
|
|
|
98
|
32 |
|
if ($engine !== false) { |
|
99
|
32 |
|
$chartJS .= "});\n"; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
32 |
|
return trim($chartJS); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
32 |
|
private function renderColorAxis() |
|
109
|
|
|
{ |
|
110
|
32 |
|
if (gettype($this->colorAxis) === 'array') { |
|
111
|
|
|
return $this->renderWithJavascriptCallback($this->colorAxis, "colorAxis"); |
|
112
|
32 |
|
} elseif (gettype($this->colorAxis) === 'object') { |
|
113
|
32 |
|
return $this->renderWithJavascriptCallback($this->colorAxis->colorAxis, "colorAxis"); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
return ""; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
32 |
|
private function renderPane() |
|
123
|
|
|
{ |
|
124
|
32 |
|
if (get_object_vars($this->pane->pane)) { |
|
125
|
3 |
|
return "pane: " . json_encode($this->pane->pane) . ",\n"; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
29 |
|
return ""; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return string |
|
133
|
|
|
*/ |
|
134
|
32 |
|
private function renderDrilldown() |
|
135
|
|
|
{ |
|
136
|
32 |
|
if (get_object_vars($this->drilldown->drilldown)) { |
|
137
|
|
|
return "drilldown: " . json_encode($this->drilldown->drilldown) . ",\n"; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
32 |
|
return ""; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|