diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-08-31 12:39:06 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-08-31 12:40:18 +0400 |
commit | 53f3d240d4415f7186c3f02acd0f1747cc684bf2 (patch) | |
tree | 786c224966b20136744dd3f55da98b78611f57f1 /plugins/CoreVisualizations/JqplotDataGenerator.php | |
parent | db2c36af7dc4bec72bb1f65b8f0f26161cab9aa1 (diff) |
Refs #4041, refactored jqplot datatable visualizations (mainly the evolution graph),
Notes:
- Fix bugs in DataTable class where getRowFromLabel would fail if summary row label is returned.
- Fix regression caused by datatable visualization refactor (add_total_row property was effectively ignored).
- Added x_axis_step_size property to jqplot graph.
Diffstat (limited to 'plugins/CoreVisualizations/JqplotDataGenerator.php')
-rw-r--r-- | plugins/CoreVisualizations/JqplotDataGenerator.php | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/plugins/CoreVisualizations/JqplotDataGenerator.php b/plugins/CoreVisualizations/JqplotDataGenerator.php index 24be6f7cc5..488d1c94b5 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator.php @@ -35,12 +35,8 @@ class JqplotDataGenerator */ protected $properties; - /** - * This object does most of the work in generating the JQPlot JSON data. - * - * @var Visualization\ - */ - protected $visualization; + + protected $graphType; /** * Creates a new JqplotDataGenerator instance for a graph type and view properties. @@ -54,10 +50,10 @@ class JqplotDataGenerator { switch ($type) { case 'evolution': - return new JqplotDataGenerator\Evolution($properties); + return new JqplotDataGenerator\Evolution($properties, $type); case 'pie': case 'bar': - return new JqplotDataGenerator($properties); + return new JqplotDataGenerator($properties, $type); default: throw new Exception("Unknown JqplotDataGenerator type '$type'."); } @@ -69,10 +65,10 @@ class JqplotDataGenerator * @param Visualization\ $visualization * @param array $properties */ - public function __construct($properties) + public function __construct($properties, $graphType) { - $this->visualization = new Chart(); $this->properties = $properties; + $this->graphType = $graphType; } /** @@ -83,28 +79,29 @@ class JqplotDataGenerator */ public function generate($dataTable) { + $visualization = new Chart(); + if ($dataTable->getRowsCount() > 0) { // if addTotalRow was called in GenerateGraphHTML, add a row containing totals of // different metrics - if (!empty($this->properties['visualization_properties']->add_total_row)) { + if ($this->properties['visualization_properties']->add_total_row) { $dataTable->queueFilter('AddSummaryRow', array(0, Piwik_Translate('General_Total'), null, false)); } - $this->initChartObjectData($dataTable); + $dataTable->applyQueuedFilters(); + $this->initChartObjectData($dataTable, $visualization); } - $this->visualization->customizeChartProperties(); + $visualization->customizeChartProperties(); - return $this->visualization->render(); + return $visualization->render(); } /** * @param DataTable|DataTable\Map $dataTable */ - protected function initChartObjectData($dataTable) + protected function initChartObjectData($dataTable, $visualization) { - $dataTable->applyQueuedFilters(); - // We apply a filter to the DataTable, decoding the label column (useful for keywords for example) $dataTable->filter('ColumnCallbackReplace', array('label', 'urldecode')); @@ -122,13 +119,13 @@ class JqplotDataGenerator $columnNameToValue[$columnName] = $dataTable->getColumn($columnName); } - $visualization = $this->visualization; + $visualization->dataTable = $dataTable; + $visualization->properties = $this->properties; + $visualization->setAxisXLabels($xLabels); $visualization->setAxisYValues($columnNameToValue); $visualization->setAxisYLabels($columnNameToTranslation); $visualization->setAxisYUnit($this->properties['y_axis_unit']); - $visualization->setDisplayPercentageInTooltip( - $this->properties['visualization_properties']->display_percentage_in_tooltip); // show_all_ticks is not real query param, it is set by GenerateGraphHTML. if ($this->properties['visualization_properties']->show_all_ticks) { @@ -152,7 +149,7 @@ class JqplotDataGenerator // the bar charts contain the labels a first series // this series has to be removed from the units - if ($this->visualization instanceof Bar) { + if ($this->graphType == 'bar') { array_shift($units); } |