~automne-team/automne/trunk

« back to all changes in this revision

Viewing changes to automne/phpMyAdmin/libraries/chart/pma_chart.php

  • Committer: sebastien-pauchet
  • Date: 2012-02-15 16:47:40 UTC
  • mfrom: (363.2.105 4.2)
  • Revision ID: seb@automne-cms.org-20120215164740-xrk26iafkvztwv6s
Merge stable branch 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/* vim: set expandtab sw=4 ts=4 sts=4: */
 
3
/**
 
4
 * Holds the base class that all charts inherit from and some widely used
 
5
 * constants.
 
6
 * @package phpMyAdmin
 
7
 */
 
8
 
 
9
/**
 
10
 *
 
11
 */
 
12
define('RED', 0);
 
13
define('GREEN', 1);
 
14
define('BLUE', 2);
 
15
 
 
16
/**
 
17
 * The base class that all charts inherit from.
 
18
 * @abstract
 
19
 * @package phpMyAdmin
 
20
 */
 
21
abstract class PMA_chart
 
22
{
 
23
    /**
 
24
     * @var array   All the default settigs values are here.
 
25
     */
 
26
    protected $settings = array(
 
27
 
 
28
        // Default title for every chart.
 
29
        'titleText' => 'Chart',
 
30
 
 
31
        // The style of the chart title.
 
32
        'titleColor' => '#FAFAFA',
 
33
 
 
34
        // Colors for the different slices in the pie chart.
 
35
        'colors' => array(
 
36
            '#BCE02E',
 
37
            '#E0642E',
 
38
            '#E0D62E',
 
39
            '#2E97E0',
 
40
            '#B02EE0',
 
41
            '#E02E75',
 
42
            '#5CE02E',
 
43
            '#E0B02E',
 
44
            '#000000',
 
45
            '#0022E0',
 
46
            '#726CB1',
 
47
            '#481A36',
 
48
            '#BAC658',
 
49
            '#127224',
 
50
            '#825119',
 
51
            '#238C74',
 
52
            '#4C489B',
 
53
            '#87C9BF',
 
54
        ),
 
55
 
 
56
        // Chart background color.
 
57
        'bgColor' => '#84AD83',
 
58
 
 
59
        // The width of the chart.
 
60
        'width' => 520,
 
61
 
 
62
         // The height of the chart.
 
63
        'height' => 325,
 
64
 
 
65
        // Default X Axis label. If empty, label will be taken from the data.
 
66
        'xLabel' => '',
 
67
 
 
68
        // Default Y Axis label. If empty, label will be taken from the data.
 
69
        'yLabel' => '',
 
70
    );
 
71
 
 
72
    /**
 
73
     * @var array   Options that the user has specified
 
74
     */
 
75
    private $userSpecifiedSettings = null;
 
76
 
 
77
    /**
 
78
     * @var array   Error codes will be stored here
 
79
     */
 
80
    protected $errors = array();
 
81
 
 
82
    /**
 
83
     * Store user specified options
 
84
     * @param array $options users specified options
 
85
     */
 
86
    function __construct($options = null)
 
87
    {
 
88
        $this->userSpecifiedSettings = $options;
 
89
    }
 
90
 
 
91
    /**
 
92
     * All the variable initialization has to be done here.
 
93
     */
 
94
    protected function init()
 
95
    {
 
96
        $this->handleOptions();
 
97
    }
 
98
 
 
99
    /**
 
100
     * A function which handles passed parameters. Useful if desired
 
101
     * chart needs to be a little bit different from the default one.
 
102
     */
 
103
    private function handleOptions()
 
104
    {
 
105
        if (is_null($this->userSpecifiedSettings)) {
 
106
            return;
 
107
        }
 
108
 
 
109
        $this->settings = array_merge($this->settings, $this->userSpecifiedSettings);
 
110
    }
 
111
 
 
112
    protected function getTitleText()
 
113
    {
 
114
        return $this->settings['titleText'];
 
115
    }
 
116
 
 
117
    protected function getTitleColor($component)
 
118
    {
 
119
        return $this->hexStrToDecComp($this->settings['titleColor'], $component);
 
120
    }
 
121
 
 
122
    protected function getColors()
 
123
    {
 
124
        return $this->settings['colors'];
 
125
    }
 
126
 
 
127
    protected function getWidth()
 
128
    {
 
129
        return $this->settings['width'];
 
130
    }
 
131
 
 
132
    protected function getHeight()
 
133
    {
 
134
        return $this->settings['height'];
 
135
    }
 
136
 
 
137
    protected function getBgColor($component)
 
138
    {
 
139
        return $this->hexStrToDecComp($this->settings['bgColor'], $component);
 
140
    }
 
141
 
 
142
    protected function setXLabel($label)
 
143
    {
 
144
        $this->settings['xLabel'] = $label;
 
145
    }
 
146
 
 
147
    protected function getXLabel()
 
148
    {
 
149
        return $this->settings['xLabel'];
 
150
    }
 
151
 
 
152
    protected function setYLabel($label)
 
153
    {
 
154
        $this->settings['yLabel'] = $label;
 
155
    }
 
156
 
 
157
    protected function getYLabel()
 
158
    {
 
159
        return $this->settings['yLabel'];
 
160
    }
 
161
 
 
162
    public function getSettings()
 
163
    {
 
164
        return $this->settings;
 
165
    }
 
166
 
 
167
    public function getErrors()
 
168
    {
 
169
        return $this->errors;
 
170
    }
 
171
 
 
172
    /**
 
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.
 
176
     */
 
177
    protected function hexStrToDecComp($colorString, $component)
 
178
    {
 
179
        return hexdec(substr($colorString, ($component * 2) + 1, 2));
 
180
    }
 
181
}
 
182
 
 
183
?>