2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * @author Martynas Mickevicius <mmartynas@gmail.com>
11 require_once 'pma_pchart_chart.php';
14 * Base class for every chart that uses multiple series.
15 * All of these charts will require legend box.
19 abstract class PMA_pChart_multi
extends PMA_pChart_chart
21 public function __construct($data, $options = null)
23 parent
::__construct($data, $options);
25 // as in CSS (top, right, bottom, left)
26 $this->setLegendMargins(array(20, 10, 0, 0));
30 * data set preparation for multi serie graphs
32 protected function prepareDataSet()
34 $values = array_values($this->data
);
35 $keys = array_keys($this->data
);
38 $this->dataSet
->AddPoint($values[0], "Keys");
41 foreach ($values[1] as $seriesName => $seriesData) {
42 $this->dataSet
->AddPoint($seriesData, "Values".$i);
43 $this->dataSet
->SetSerieName($seriesName, "Values".$i);
46 $this->dataSet
->AddAllSeries();
48 $this->dataSet
->RemoveSerie("Keys");
49 $this->dataSet
->SetAbsciseLabelSerie("Keys");
51 $xLabel = $this->getXLabel();
53 $this->setXLabel($keys[0]);
55 $yLabel = $this->getYLabel();
57 $this->setYLabel($keys[1]);
60 $this->dataSet
->SetXAxisName($this->getXLabel());
61 $this->dataSet
->SetYAxisName($this->getYLabel());
65 * set graph area dimensions with respect to legend box size
67 protected function setGraphAreaDimensions()
69 $this->chart
->setGraphArea(
70 $this->getAreaMargin(LEFT
),
71 $this->getLabelHeight() +
$this->getAreaMargin(TOP
),
72 $this->getWidth() - $this->getAreaMargin(RIGHT
) - $this->getLegendBoxWidth() - $this->getLegendMargin(LEFT
) - $this->getLegendMargin(RIGHT
),
73 $this->getHeight() - $this->getAreaMargin(BOTTOM
)
78 * multi serie charts need a legend. draw it
80 protected function drawChart()
88 protected function drawLegend()
91 $this->chart
->drawLegend(
92 $this->getWidth() - $this->getLegendMargin(RIGHT
) - $this->getLegendBoxWidth(),
93 $this->getLabelHeight() +
$this->getLegendMargin(TOP
),
94 $this->dataSet
->GetDataDescription(),
99 protected function setLegendMargins($legendMargins)
101 if (!isset($this->settings
['legendMargins'])) {
102 $this->settings
['legendMargins'] = $legendMargins;
106 protected function getLegendMargin($side)
108 return $this->settings
['legendMargins'][$side];
111 protected function getLegendBoxWidth()
113 $legendSize = $this->chart
->getLegendBoxSize($this->dataSet
->GetDataDescription());
114 return $legendSize[0];