2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 require_once 'pma_pchart_chart.php';
13 * Base class for every chart that uses multiple series.
14 * All of these charts will require legend box.
18 abstract class PMA_pChart_multi
extends PMA_pChart_chart
20 public function __construct($data, $options = null)
22 parent
::__construct($data, $options);
24 // as in CSS (top, right, bottom, left)
25 $this->setLegendMargins(array(20, 10, 0, 0));
29 * data set preparation for multi serie graphs
31 protected function prepareDataSet()
33 $values = array_values($this->data
);
34 $keys = array_keys($this->data
);
37 $this->dataSet
->AddPoint($values[0], "Keys");
40 foreach ($values[1] as $seriesName => $seriesData) {
41 $this->dataSet
->AddPoint($seriesData, "Values".$i);
42 $this->dataSet
->SetSerieName($seriesName, "Values".$i);
45 $this->dataSet
->AddAllSeries();
47 $this->dataSet
->RemoveSerie("Keys");
48 $this->dataSet
->SetAbsciseLabelSerie("Keys");
50 $xLabel = $this->getXLabel();
52 $this->setXLabel($keys[0]);
54 $yLabel = $this->getYLabel();
56 $this->setYLabel($keys[1]);
59 $this->dataSet
->SetXAxisName($this->getXLabel());
60 $this->dataSet
->SetYAxisName($this->getYLabel());
64 * set graph area dimensions with respect to legend box size
66 protected function setGraphAreaDimensions()
68 $this->chart
->setGraphArea(
69 $this->getAreaMargin(LEFT
),
70 $this->getLabelHeight() +
$this->getAreaMargin(TOP
),
71 $this->getWidth() - $this->getAreaMargin(RIGHT
) - $this->getLegendBoxWidth() - $this->getLegendMargin(LEFT
) - $this->getLegendMargin(RIGHT
),
72 $this->getHeight() - $this->getAreaMargin(BOTTOM
)
77 * multi serie charts need a legend. draw it
79 protected function drawChart()
87 protected function drawLegend()
90 $this->chart
->drawLegend(
91 $this->getWidth() - $this->getLegendMargin(RIGHT
) - $this->getLegendBoxWidth(),
92 $this->getLabelHeight() +
$this->getLegendMargin(TOP
),
93 $this->dataSet
->GetDataDescription(),
98 protected function setLegendMargins($legendMargins)
100 if (!isset($this->settings
['legendMargins'])) {
101 $this->settings
['legendMargins'] = $legendMargins;
105 protected function getLegendMargin($side)
107 return $this->settings
['legendMargins'][$side];
110 protected function getLegendBoxWidth()
112 $legendSize = $this->chart
->getLegendBoxSize($this->dataSet
->GetDataDescription());
113 return $legendSize[0];