2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Holds the base class that all charts inherit from and some widely used
17 * The base class that all charts inherit from.
21 abstract class PMA_chart
24 * @var array All the default settigs values are here.
26 protected $settings = array(
28 // Default title for every chart.
29 'titleText' => 'Chart',
31 // The style of the chart title.
32 'titleColor' => '#FAFAFA',
34 // Colors for the different slices in the pie chart.
56 // Chart background color.
57 'bgColor' => '#84AD83',
59 // The width of the chart.
62 // The height of the chart.
65 // Default X Axis label. If empty, label will be taken from the data.
68 // Default Y Axis label. If empty, label will be taken from the data.
73 * @var array Options that the user has specified
75 private $userSpecifiedSettings = null;
78 * @var array Error codes will be stored here
80 protected $errors = array();
83 * Store user specified options
84 * @param array $options users specified options
86 function __construct($options = null)
88 $this->userSpecifiedSettings
= $options;
92 * All the variable initialization has to be done here.
94 protected function init()
96 $this->handleOptions();
100 * A function which handles passed parameters. Useful if desired
101 * chart needs to be a little bit different from the default one.
103 private function handleOptions()
105 if (is_null($this->userSpecifiedSettings
)) {
109 $this->settings
= array_merge($this->settings
, $this->userSpecifiedSettings
);
112 protected function getTitleText()
114 return $this->settings
['titleText'];
117 protected function getTitleColor($component)
119 return $this->hexStrToDecComp($this->settings
['titleColor'], $component);
122 protected function getColors()
124 return $this->settings
['colors'];
127 protected function getWidth()
129 return $this->settings
['width'];
132 protected function getHeight()
134 return $this->settings
['height'];
137 protected function getBgColor($component)
139 return $this->hexStrToDecComp($this->settings
['bgColor'], $component);
142 protected function setXLabel($label)
144 $this->settings
['xLabel'] = $label;
147 protected function getXLabel()
149 return $this->settings
['xLabel'];
152 protected function setYLabel($label)
154 $this->settings
['yLabel'] = $label;
157 protected function getYLabel()
159 return $this->settings
['yLabel'];
162 public function getSettings()
164 return $this->settings
;
167 public function getErrors()
169 return $this->errors
;
173 * Get one the dec color component from the hex color string
174 * @param string $colorString color string, i.e. #5F22A99
175 * @param int $component color component to get, i.e. 0 gets red.
177 protected function hexStrToDecComp($colorString, $component)
179 return hexdec(substr($colorString, ($component * 2) +
1, 2));