blob: f51e308519b12d6e3ef0b3f86fddf847b52003e5 (
plain)
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
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id: Chart.php 579 2008-07-27 00:32:59Z matt $
*
* @package Piwik_Visualization
*/
require_once "libs/open-flash-chart/php-ofc-library/open-flash-chart.php";
/**
* Generates the data in the Open Flash Chart format, from the given data.
*
* @package Piwik_Visualization
*/
abstract class Piwik_Visualization_Chart implements Piwik_iView
{
/**
* @var Piwik_Visualization_OpenFlashChart
*/
protected $chart = null;
protected $xLabels = array();
protected $xOnClick = array();
protected $xSteps = 2;
protected $yLabels = array();
protected $yValues = array();
protected $yUnit = '';
protected $maxValue;
protected $minValue;
protected $displayPercentageInTooltip = true;
function __construct()
{
$this->chart = new open_flash_chart();
}
public function setAxisXLabels($xLabels)
{
$this->xLabels = $xLabels;
}
public function setAxisXOnClick($onClick)
{
$this->xOnClick = $onClick;
}
public function setAxisYValues($values)
{
$this->yValues = $values;
}
function setAxisYUnit($yUnit)
{
if(!empty($yUnit))
{
$this->yUnit = $yUnit;
}
}
public function setAxisYLabels($labels)
{
$this->yLabels = $labels;
}
public function setDisplayPercentageInTooltip($bool)
{
$this->displayPercentageInTooltip = $bool;
}
//TODO call + make sure matches beginning of period? (hard..)
// day -> every 7 days
// week & year -> 1, plot last
// month -> every 12 months, plot last 24
public function setXSteps($steps)
{
$this->xSteps = $steps;
}
protected function getDataSetsToDisplay()
{
if(empty($this->yValues)) {
return false;
}
return array_keys($this->yValues);
}
public function getMaxValue()
{
$datasetsIds = $this->getDataSetsToDisplay();
if($datasetsIds === false)
{
return 0;
}
$maxCrossDataSets = false;
foreach($datasetsIds as $dataset)
{
$maxValue = max($this->yValues[$dataset]);
if($maxCrossDataSets === false
|| $maxValue > $maxCrossDataSets)
{
$maxCrossDataSets = $maxValue;
}
}
if($maxCrossDataSets > 10)
{
$maxCrossDataSets = $maxCrossDataSets + 10 - $maxCrossDataSets % 10;
}
return $maxCrossDataSets;
}
public function setTitle($text, $css)
{
$title = new title($text);
$title->set_style($css);
$this->chart->set_title($title);
}
public function render()
{
return $this->chart->toPrettyString();
}
function customizeChartProperties()
{
$this->chart->set_number_format($num_decimals = 0,
$is_fixed_num_decimals_forced = true,
$is_decimal_separator_comma = false,
$is_thousand_separator_disabled = false);
$gridColour = '#E0E1E4';
$countValues = count($this->xLabels);
$this->maxValue = $this->getMaxValue();
$this->minValue = 0;
// X Axis
$this->x = new x_axis();
$this->x->set_colour( '#596171' );
$this->x->set_grid_colour( $gridColour );
$this->x->set_steps($this->xSteps);
// X Axis Labels
$this->x_labels = new x_axis_labels();
$this->x_labels->set_size(11);
//manually fix the x labels step as this doesn't work in this OFC release..
$xLabelsStepped = $this->xLabels;
foreach($xLabelsStepped as $i => &$xLabel)
{
if(($i % $this->xSteps) != 0)
{
$xLabel = '';
}
}
$this->x_labels->set_labels($xLabelsStepped);
$this->x_labels->set_steps(2);
$this->x->set_labels($this->x_labels);
// Y Axis
$this->y = new y_axis();
$this->y->set_colour('#ffffff');
$this->y->set_grid_colour($gridColour);
$stepsCount = 2;
$stepsEveryNLabel = ceil(($this->maxValue - $this->minValue) / $stepsCount);
if($this->maxValue == 0)
{
$this->maxValue = 1;
}
$this->y->set_range( $this->minValue, $this->maxValue, $stepsEveryNLabel);
$dataSetsToDisplay = $this->getDataSetsToDisplay();
if($dataSetsToDisplay != false)
{
$dataSetToDisplay = current($dataSetsToDisplay);
$this->y->set_label_text("#val#".$this->yUnit);
}
// Tooltip
$this->tooltip = new tooltip();
$this->tooltip->set_shadow( true );
$this->tooltip->set_stroke( 1 );
// Attach elements to the graph
$this->chart->set_x_axis($this->x);
$this->chart->set_y_axis($this->y);
$this->chart->set_tooltip($this->tooltip);
$this->chart->set_bg_colour('#ffffff');
}
}
|