Add vim mode lines
[phpmyadmin.git] / libraries / chart / pma_pchart_multi.php
blob685b746a912db4b3f3cbad207e12ccb90c8fa6e5
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * @author Martynas Mickevicius <mmartynas@gmail.com>
5 * @package phpMyAdmin
6 */
8 /**
11 require_once 'pma_pchart_chart.php';
13 /**
14 * Base class for every chart that uses multiple series.
15 * All of these charts will require legend box.
16 * @abstract
17 * @package phpMyAdmin
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));
29 /**
30 * data set preparation for multi serie graphs
32 protected function prepareDataSet()
34 $values = array_values($this->data);
35 $keys = array_keys($this->data);
37 // Dataset definition
38 $this->dataSet->AddPoint($values[0], "Keys");
40 $i = 0;
41 foreach ($values[1] as $seriesName => $seriesData) {
42 $this->dataSet->AddPoint($seriesData, "Values".$i);
43 $this->dataSet->SetSerieName($seriesName, "Values".$i);
44 $i++;
46 $this->dataSet->AddAllSeries();
48 $this->dataSet->RemoveSerie("Keys");
49 $this->dataSet->SetAbsciseLabelSerie("Keys");
51 $xLabel = $this->getXLabel();
52 if (empty($xLabel)) {
53 $this->setXLabel($keys[0]);
55 $yLabel = $this->getYLabel();
56 if (empty($yLabel)) {
57 $this->setYLabel($keys[1]);
60 $this->dataSet->SetXAxisName($this->getXLabel());
61 $this->dataSet->SetYAxisName($this->getYLabel());
64 /**
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)
77 /**
78 * multi serie charts need a legend. draw it
80 protected function drawChart()
82 $this->drawLegend();
85 /**
86 * draws a legend
88 protected function drawLegend()
90 // Draw the legend
91 $this->chart->drawLegend(
92 $this->getWidth() - $this->getLegendMargin(RIGHT) - $this->getLegendBoxWidth(),
93 $this->getLabelHeight() + $this->getLegendMargin(TOP),
94 $this->dataSet->GetDataDescription(),
95 250,250,250,50,50,50
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];