C:\xampp\htdocs\kptv2\phpMy8181Admin\libraries\chart\pma_pchart_chart.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Holds the base class that all charts using pChart inherit from and some
 * widely used constants
 * @package phpMyAdmin
 */

/**
 * 
 */
define('TOP'0);
define('RIGHT'1);
define('BOTTOM'2);
define('LEFT'3);

require_once 
'pma_chart.php';

require_once 
'pChart/pData.class';
require_once 
'pChart/pChart.class';

/**
 * Base class for every chart implemented using pChart.
 * @abstract
 * @package phpMyAdmin
 */
abstract class PMA_pChart_chart extends PMA_chart
{
    
/**
     * @var String  title text
     */
    
protected $titleText;

    
/**
     * @var array   data for the chart
     */
    
protected $data;

    
/**
     * @var object  pData object that holds the description of the data
     */
    
protected $dataSet;

    
/**
     * @var object  pChart object that holds the chart
     */
    
protected $chart;

    
/**
     * @var array   holds base64 encoded chart image parts
     */
    
protected $partsEncoded = array();

    public function 
__construct($data$options null)
    {
        
parent::__construct($options);

        
$this->data $data;

        
$this->settings['fontPath'] = './libraries/chart/pChart/fonts/';

        
$this->settings['scale'] = SCALE_ADDALLSTART0;

        
$this->settings['labelHeight'] = 20;

        
$this->settings['fontSize'] = 8;

        
$this->settings['continuous'] = 'off';

        
// as in CSS (top, right, bottom, left)
        
$this->setAreaMargins(array(20204060));
        
        
// Get color settings from theme
        
$this->settings array_merge($this->settings,$GLOBALS['cfg']['chartColor']);
    }

    protected function 
init()
    {
        
parent::init();

        
// create pChart object
        
$this->chart = new pChart($this->getWidth(), $this->getHeight());

        
// create pData object
        
$this->dataSet = new pData;

        
$this->chart->reportWarnings('GD');
        
$this->chart->ErrorFontName $this->getFontPath().'DejaVuSans.ttf';

        
// initialize colors
        
foreach ($this->getColors() as $key => $color) {
            
$this->chart->setColorPalette(
                    
$key,
                    
hexdec(substr($color12)),
                    
hexdec(substr($color32)),
                    
hexdec(substr($color52))
            );
        }

        
$this->chart->setFontProperties($this->getFontPath().'DejaVuSans.ttf'$this->getFontSize());

        
$this->chart->setImageMap(true'mapid');
    }

    
/**
     * data is put to the $dataSet object according to what type chart is
     * @abstract
     */
    
abstract protected function prepareDataSet();

    
/**
     * all components of the chart are drawn
     */
    
protected function prepareChart()
    {
        
$this->drawBackground();
        
$this->drawChart();
    }

    
/**
     * draws the background
     */
    
protected function drawBackground()
    {
        
$this->drawCommon();
        
$this->drawTitle();
        
$this->setGraphAreaDimensions();
        
$this->drawGraphArea();
    }

    
/**
     * draws the part of the background which is common to most of the charts
     */
    
protected function drawCommon()
    {
        
$this->chart->drawGraphAreaGradient(
                
$this->getBgColor(RED),
                
$this->getBgColor(GREEN),
                
$this->getBgColor(BLUE),
                
// With a gradientIntensity of 0 the background does't draw, oddly
                
($this->settings['gradientIntensity']==0)?1:$this->settings['gradientIntensity'],TARGET_BACKGROUND);
                
        if(
is_string($this->settings['border']))
            
$this->chart->addBorder(1,$this->getBorderColor(RED),$this->getBorderColor(GREEN),$this->getBorderColor(BLUE));
    }

    
/**
     * draws the chart title
     */
    
protected function drawTitle()
    {
        
// Draw the title
        
$this->chart->drawTextBox(
                
0,
                
0,
                
$this->getWidth(),
                
$this->getLabelHeight(),
                
$this->getTitleText(),
                
0,
                
$this->getTitleColor(RED),
                
$this->getTitleColor(GREEN),
                
$this->getTitleColor(BLUE),
                
ALIGN_CENTER,
                
false,
                
$this->getTitleBgColor(RED),
                
$this->getTitleBgColor(GREEN),
                
$this->getTitleBgColor(BLUE)
        );
    }

    
/**
     * calculates and sets the dimensions that will be used for the actual graph
     */
    
protected function setGraphAreaDimensions()
    {
        
$this->chart->setGraphArea(
                
$this->getAreaMargin(LEFT),
                
$this->getLabelHeight() + $this->getAreaMargin(TOP),
                
$this->getWidth() - $this->getAreaMargin(RIGHT),
                
$this->getHeight() - $this->getAreaMargin(BOTTOM)
        );
    }

    
/**
     * draws graph area (the area where all bars, lines, points will be seen)
     */
    
protected function drawGraphArea()
    {
        
$this->chart->drawGraphArea(
                
$this->getGraphAreaColor(RED),
                
$this->getGraphAreaColor(GREEN),
                
$this->getGraphAreaColor(BLUE),
                
FALSE
        
);
        
$this->chart->drawScale(
                
$this->dataSet->GetData(),
                
$this->dataSet->GetDataDescription(),
                
$this->getScale(),
                
$this->getScaleColor(RED),
                
$this->getScaleColor(GREEN),
                
$this->getScaleColor(BLUE),
                
TRUE,0,2,TRUE
        
);
        
        if(
$this->settings['gradientIntensity']>0)
            
$this->chart->drawGraphAreaGradient(
                    
$this->getGraphAreaGradientColor(RED),
                    
$this->getGraphAreaGradientColor(GREEN),
                    
$this->getGraphAreaGradientColor(BLUE),
                    
$this->settings['gradientIntensity']
            );
        else
            
$this->chart->drawGraphArea(
                    
$this->getGraphAreaGradientColor(RED),
                    
$this->getGraphAreaGradientColor(GREEN),
                    
$this->getGraphAreaGradientColor(BLUE)
            );
        
        
$this->chart->drawGrid(
                
4,
                
TRUE,
                
$this->getGridColor(RED),
                
$this->getGridColor(GREEN),
                
$this->getGridColor(BLUE),
                
20
        
);
    }

    
/**
     * draws the chart
     * @abstract
     */
    
protected abstract function drawChart();

    
/**
     * Renders the chart, base 64 encodes the output and puts it into
     * array partsEncoded.
     *
     * Parameter can be used to slice the chart vertically into parts. This
     * solves an issue where some browsers (IE8) accept base64 images only up
     * to some length.
     *
     * @param   integer  $parts         number of parts to render.
     *                                  Default value 1 means that all the
     *                                  chart will be in one piece.
     */
    
protected function render($parts 1)
    {
        
$fullWidth 0;

        for (
$i 0$i $parts$i++) {

            
// slicing is vertical so part height is the full height
            
$partHeight $this->chart->YSize;

            
// there will be some rounding erros, will compensate later
            
$partWidth round($this->chart->XSize $parts);
            
$fullWidth += $partWidth;
            
$partX $partWidth $i;

            if (
$i == $parts 1) {
                
// if this is the last part, compensate for the rounding errors
                
$partWidth += $this->chart->XSize $fullWidth;
            }

            
// get a part from the full chart image
            
$part imagecreatetruecolor($partWidth$partHeight);
            
imagecopy($part$this->chart->Picture00$partX0$partWidth$partHeight);

            
// render part and save it to variable
            
ob_start();
            
imagepng($partNULL9PNG_ALL_FILTERS);
            
$output ob_get_contents();
            
ob_end_clean();

            
// base64 encode the current part
            
$partEncoded base64_encode($output);
            
$this->partsEncoded[$i] = $partEncoded;
        }
    }

    
/**
     * get the HTML and JS code for the configured chart
     * @return string   HTML and JS code for the chart
     */
    
public function toString()
    {
        if (!
function_exists('gd_info')) {
            
array_push($this->errorsERR_NO_GD);
            return 
'';
        }

        
$this->init();
        
$this->prepareDataSet();
        
$this->prepareChart();

        
//$this->chart->debugImageMap();
        //$this->chart->printErrors('GD');

        // check if a user wanted a chart in one part
        
if ($this->isContinuous()) {
            
$this->render(1);
        }
        else {
            
$this->render(20);
        }

        
$returnData '<div id="chart">';
        foreach (
$this->partsEncoded as $part) {
            
$returnData .= '<img src="data:image/png;base64,'.$part.'" />';
        }
        
$returnData .= '</div>';

        
// add tooltips only if json is available
        
if (function_exists('json_encode')) {
            
$returnData .= '
                <script type="text/javascript">
                //<![CDATA[
                    imageMap.loadImageMap(\''
.json_encode($this->getImageMap()).'\');
                //]]>
                </script>
            '
;
        }
        else {
            
array_push($this->errorsERR_NO_JSON);
        }

        return 
$returnData;
    }

    protected function 
getLabelHeight()
    {
        return 
$this->settings['labelHeight'];
    }

    protected function 
setAreaMargins($areaMargins)
    {
        
$this->settings['areaMargins'] = $areaMargins;
    }

    protected function 
getAreaMargin($side)
    {
        return 
$this->settings['areaMargins'][$side];
    }

    protected function 
getFontPath()
    {
        return 
$this->settings['fontPath'];
    }

    protected function 
getScale()
    {
        return 
$this->settings['scale'];
    }

    protected function 
getFontSize()
    {
        return 
$this->settings['fontSize'];
    }

    protected function 
isContinuous()
    {
        return 
$this->settings['continuous'] == 'on';
    }

    protected function 
getImageMap()
    {
        return 
$this->chart->getImageMap();
    }

    protected function 
getGraphAreaColor($component)
    {
        return 
$this->hexStrToDecComp($this->settings['graphAreaColor'], $component);
    }

    protected function 
getGraphAreaGradientColor($component)
    {
        return 
$this->hexStrToDecComp($this->settings['graphAreaGradientColor'], $component);
    }

    protected function 
getGridColor($component)
    {
        return 
$this->hexStrToDecComp($this->settings['gridColor'], $component);
    }

    protected function 
getScaleColor($component)
    {
        return 
$this->hexStrToDecComp($this->settings['scaleColor'], $component);
    }

    protected function 
getTitleBgColor($component)
    {
        return 
$this->hexStrToDecComp($this->settings['titleBgColor'], $component);
    }
    
    protected function 
getBorderColor($component
    {
        return 
$this->hexStrToDecComp($this->settings['border'], $component);
    }
}

?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586