source: trunk/client/modules/Elezioni/grafici/jpgraph_theme.inc.php@ 266

Last change on this file since 266 was 266, checked in by roby, 5 years ago
File size: 3.2 KB
Line 
1<?php
2//=======================================================================
3// File: JPGRAPH_THEME.INC.PHP
4// Description: Class to define graph theme
5// Created: 2010-09-29
6// Ver: $Id: jpgraph_theme.inc.php 83 2010-10-01 11:24:19Z atsushi $
7//
8// Copyright (c) Asial Corporation. All rights reserved.
9//========================================================================
10
11
12// include Theme classes
13foreach (glob(dirname(__FILE__) . '/themes/*.php') as $theme_class_script) {
14 require_once($theme_class_script);
15}
16
17//===================================================
18// CLASS
19// Description:
20//===================================================
21abstract class Theme {
22 protected $color_index;
23
24 function __construct() {
25 $this->color_index = 0;
26 }
27 /**
28 *
29 */
30 abstract function GetColorList();
31
32 /**
33 *
34 */
35 abstract function ApplyPlot($plot);
36
37
38 /**
39 *
40 */
41 function SetupPlot($plot) {
42 if (is_array($plot)) {
43 foreach ($plot as $obj) {
44 $this->ApplyPlot($obj);
45 }
46 } else {
47 $this->ApplyPlot($plot);
48 }
49 }
50
51 /**
52 *
53 */
54 function ApplyGraph($graph) {
55
56 $this->graph = $graph;
57 $method_name = '';
58
59 if (get_class($graph) == 'Graph') {
60 $method_name = 'SetupGraph';
61 } else {
62 $method_name = 'Setup' . get_class($graph);
63 }
64
65 if (method_exists($this, $method_name)) {
66 $this->$method_name($graph);
67 } else {
68 JpGraphError::RaiseL(30001, $method_name, $method_name); //Theme::%s() is not defined. \nPlease make %s(\$graph) function in your theme classs.
69 }
70 }
71
72 /**
73 *
74 */
75 function PreStrokeApply($graph) {
76 }
77
78 /**
79 *
80 */
81 function GetThemeColors($num = 30) {
82 $result_list = array();
83
84 $old_index = $this->color_index;
85 $this->color_index = 0;
86 $count = 0;
87
88 $i = 0;
89 while (true) {
90 for ($j = 0; $j < count($this->GetColorList()); $j++) {
91 if (++$count > $num) {
92 break 2;
93 }
94 $result_list[] = $this->GetNextColor();
95 }
96 $i++;
97 }
98
99 $this->color_index = $old_index;
100
101 return $result_list;
102 }
103
104 /**
105 *
106 */
107 function GetNextColor() {
108 $color_list = $this->GetColorList();
109
110 $color = null;
111 if (isset($color_list[$this->color_index])) {
112 $color = $color_list[$this->color_index];
113 } else {
114 $color_count = count($color_list);
115 if ($color_count <= $this->color_index) {
116 $color_tmp = $color_list[$this->color_index % $color_count];
117 $brightness = 1.0 - intval($this->color_index / $color_count) * 0.2;
118 $rgb = new RGB();
119 $color = $color_tmp . ':' . $brightness;
120 $color = $rgb->Color($color);
121 $alpha = array_pop($color);
122 $color = $rgb->tryHexConversion($color);
123 if ($alpha) {
124 $color .= '@' . $alpha;
125 }
126 }
127 }
128
129 $this->color_index++;
130
131 return $color;
132 }
133
134} // Class
135
136?>
Note: See TracBrowser for help on using the repository browser.