Blame view

site/jpgraph/jpgraph_theme.inc.php 3.24 KB
8ec98c9f   Guillaume   MAJ
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
  <?php
  //=======================================================================
  // File:        JPGRAPH_THEME.INC.PHP
  // Description: Class to define graph theme
  // Created:     2010-09-29 
  // Ver:         $Id: jpgraph_theme.inc.php 83 2010-10-01 11:24:19Z atsushi $
  //
  // Copyright (c) Asial Corporation. All rights reserved.
  //========================================================================
  
  
  // include Theme classes
  foreach (glob(dirname(__FILE__) . '/themes/*.php') as $theme_class_script) {
    require_once($theme_class_script);
  }
  
  //===================================================
  // CLASS 
  // Description: 
  //===================================================
  abstract class Theme {
      protected $color_index;
      
      function __construct() {
          $this->color_index = 0;
      }
      /**
      * 
      */
      abstract function GetColorList();
  
      /**
      *
      */
      abstract function ApplyPlot($plot);
  
  
      /**
      *
      */   
      function SetupPlot($plot) {
          if (is_array($plot)) {
              foreach ($plot as $obj) {
                  $this->ApplyPlot($obj);
              }
          } else {
              $this->ApplyPlot($plot);
          }
      }
  
      /**
      *
      */
      function ApplyGraph($graph) {
  
          $this->graph = $graph;
          $method_name = '';
  
          if (get_class($graph) == 'Graph') {
              $method_name = 'SetupGraph';
          } else {
              $method_name = 'Setup' . get_class($graph);
          }
  
          if (method_exists($this, $method_name)) {
              $this->$method_name($graph);
          } else {
              JpGraphError::RaiseL(30001, $method_name, $method_name); //Theme::%s() is not defined. \nPlease make %s(\$graph) function in your theme classs.
          }
      }
  
      /**
      *
      */
      function PreStrokeApply($graph) {
      }
  
      /**
      *
      */
      function GetThemeColors($num = 30) { 
          $result_list = array();
  
          $old_index = $this->color_index;
          $this->color_index = 0;
          $count = 0;
    
          $i = 0;
          while (true) {
              for ($j = 0; $j < count($this->GetColorList()); $j++) {
                  if (++$count > $num) {
                      break 2;
                  }
                  $result_list[] = $this->GetNextColor();
              }
              $i++;
          }
  
          $this->color_index = $old_index;
          
          return $result_list;
      }
  
      /**
      *
      */
      function GetNextColor() {
          $color_list = $this->GetColorList();
  
          $color = null;
          if (isset($color_list[$this->color_index])) {
              $color = $color_list[$this->color_index];
          } else {
              $color_count = count($color_list);
              if ($color_count <= $this->color_index) {
                  $color_tmp = $color_list[$this->color_index % $color_count];
                  $brightness = 1.0 - intval($this->color_index / $color_count) * 0.2;
                  $rgb = new RGB();
                  $color = $color_tmp . ':' . $brightness;
                  $color = $rgb->Color($color);
                  $alpha = array_pop($color);
                  $color = $rgb->tryHexConversion($color);
                  if ($alpha) {
                      $color .= '@' . $alpha;
                  }
              }
          }
  
          $this->color_index++;
  
          return $color;
      }
  
  } // Class
  
  ?>