CMS  Version 3.9
dial.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9 Copyright (c) 2016 Sonjara, Inc
10 
11 Permission is hereby granted, free of charge, to any person
12 obtaining a copy of this software and associated documentation
13 files (the "Software"), to deal in the Software without
14 restriction, including without limitation the rights to use,
15 copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the
17 Software is furnished to do so, subject to the following
18 conditions:
19 
20 The above copyright notice and this permission notice shall be
21 included in all copies or substantial portions of the Software.
22 
23 Except as contained in this notice, the name(s) of the above
24 copyright holders shall not be used in advertising or otherwise
25 to promote the sale, use or other dealings in this Software
26 without prior written authorization.
27 
28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35 OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::using("svg_charts");
40 
41 class Dial
42 {
43  var $width;
44  var $height;
47  var $cx;
48  var $cy;
49  var $radius = 0;
50  var $value = 0;
51  var $label = "";
52  var $palette;
53  var $labelSize = 12;
54  var $labelX;
55  var $labelY;
56  var $strokeWidth = 1;
57  var $animate = true;
58  var $shadow = true;
59  var $scaleToFit = false;
60  var $fontFamily = 'Arial, Helvetica';
61  var $min = 0;
62  var $max = 100;
63  var $minColor = '#f00';
64  var $maxColor = '#0f0';
65  var $colorMode = 'fixed';
66  var $showTarget = false;
67  var $target = 0;
68  var $targetLabel = "";
69  var $targetLabelSize = "inherit";
70  var $cssClass = null;
71  var $onDrawChart = "null";
72  var $onDrawChartComplete = "null";
73  var $onDrawLegend = "null";
74  var $onDrawLegendComplete = "null";
75 
76  function __construct($id, $width = 300, $height = 300, $value = 0, $label = '', $palette = "standard")
77  {
78  $this->id = $id;
79  $this->setSize($width, $height);
80  $this->setContainerSize($width, $height);
81  $this->value = $value;
82  $this->label = $label;
83  $this->palette = $palette;
84  }
85 
86  function setSize($width, $height)
87  {
88  $this->width = $width;
89  $this->height = $height;
90  if (!$this->cx) $this->cx = $this->width / 2;
91  if (!$this->cy) $this->cy = $this->height / 2;
92  if (!$this->radius) $this->radius = min($width, $height) * .4;
93  }
94 
95  function setContainerSize($width, $height = "0")
96  {
97  $this->containerWidth = $width;
98  $this->containerHeight = $height;
99  }
100 
101  function setCenter($cx, $cy)
102  {
103  $this->cx = $cx;
104  $this->cy = $cy;
105  }
106 
107  function setRadius($r)
108  {
109  $this->radius = $r;
110  }
111 
112  function setLabelSize($size, $targetLabelSize = "inherit")
113  {
114  $this->labelSize = $size;
115  $this->targetLabelSize = $targetLabelSize;
116  }
117 
118  function setLabelPosition($lx, $ly)
119  {
120  $this->labelX = $lx;
121  $this->labelY = $ly;
122  }
123 
124  function setRange($min, $max)
125  {
126  $this->min = $min;
127  $this->max = $max;
128  }
129 
130  function setColorRange($min, $max = null)
131  {
132  if (!$max)
133  {
134  $max = $min;
135  }
136 
137  if ($max == $min)
138  {
139  $this->colorMode = 'fixed';
140  }
141  else
142  {
143  $this->colorMode = 'interpolated';
144  }
145 
146  $this->minColor = $min;
147  $this->maxColor = $max;
148  }
149 
150  function setStrokeWidth($s)
151  {
152  $this->strokeWidth = $s;
153  }
154 
155  function setFontFamily($font)
156  {
157  $this->fontFamily = $font;
158  }
159 
161  {
162  $this->showTarget = true;
163  $this->target = $target;
164  $this->targetLabel = $targetLabel;
165  }
166 
167  function draw()
168  {
169  global $script;
170  $animate = $this->animate ? "true" : "false";
171  $shadow = $this->shadow ? "true": "false";
172  $legend = $this->legend ? "true" : "false";
173  $percentages = $this->showPercentages ? "true" : "false";
174  $download = $this->enableDownload ? "true" : "false";
175  $showTarget = $this->showTarget ? "true" : "false";
176  $targetLabel = jsSafe($this->targetLabel);
177  $target = ($this->target == '') ? 0 : $this->target;
178 
179  $containerWidth = is_numeric($this->containerWidth) ? $this->containerWidth . "px" : $this->containerWidth;
180  $containerHeight = is_numeric($this->containerHeight) ? $this->containerHeight . "px" : $this->containerHeight;
181 
182  $script .= <<<ENDSCRIPT
183 <script type="text/javascript">
184 window.addEvent('domready', function ()
185 {
186  var {$this->id} = new Dial('{$this->id}', $this->value, '{$this->label}',
187  {
188  width: {$this->width},
189  height: {$this->height},
190  cx: {$this->cx},
191  cy: {$this->cy},
192  radius: {$this->radius},
193  palette: '{$this->palette}',
194  labelSize: {$this->labelSize},
195  labelx: {$this->labelX},
196  labely: {$this->labelY},
197  fontFamily: '{$this->fontFamily}',
198  strokeWidth: {$this->strokeWidth},
199  animate: {$animate},
200  shadow: {$shadow},
201  enableDownload: {$download},
202  min: {$this->min},
203  max: {$this->max},
204  minColor: '{$this->minColor}',
205  maxColor: '{$this->maxColor}',
206  colorMode: '{$this->colorMode}',
208  target: {$target},
209  targetLabel: '{$targetLabel}',
210  targetLabelSize: '{$this->targetLabelSize}',
211  onDrawChart: {$this->onDrawChart},
212  onDrawChartComplete: {$this->onDrawChartComplete},
213  onDrawLegend: {$this->onDrawLegend},
214  onDrawLegendComplete: {$this->onDrawLegendComplete}
215  });
216 
217  {$this->id}.draw();
218 });
219 </script>
220 ENDSCRIPT;
221 
222  if ($this->scaleToFit)
223  {
224  $dimensions = "width: 100%; height: auto";
225  }
226  else
227  {
228  $dimensions = "width: {$containerWidth}; height: {$containerHeight};";
229  }
230 
231  $cssClass = ($this->cssClass) ? " class='{$this->cssClass}'" : "";
232  echo "<div id='{$this->id}'{$cssClass} style='$dimensions'></div>";
233  }
234 }?>
$helpTree width
Definition: tree.inc:45
$siteTree target
Definition: site_map.inc:56
$size
Definition: download.inc:47
Definition: dial.inc:42
$radius
Definition: dial.inc:49
$containerWidth
Definition: dial.inc:45
$label
Definition: dial.inc:51
setLabelPosition($lx, $ly)
Definition: dial.inc:118
$shadow
Definition: dial.inc:58
$width
Definition: dial.inc:43
$labelY
Definition: dial.inc:55
$labelSize
Definition: dial.inc:53
setSize($width, $height)
Definition: dial.inc:86
__construct($id, $width=300, $height=300, $value=0, $label='', $palette="standard")
Definition: dial.inc:76
$max
Definition: dial.inc:62
$showTarget
Definition: dial.inc:66
$palette
Definition: dial.inc:52
$target
Definition: dial.inc:67
setCenter($cx, $cy)
Definition: dial.inc:101
$cy
Definition: dial.inc:48
$fontFamily
Definition: dial.inc:60
$maxColor
Definition: dial.inc:64
setColorRange($min, $max=null)
Definition: dial.inc:130
setFontFamily($font)
Definition: dial.inc:155
$scaleToFit
Definition: dial.inc:59
$onDrawLegend
Definition: dial.inc:73
$cx
Definition: dial.inc:47
setLabelSize($size, $targetLabelSize="inherit")
Definition: dial.inc:112
$targetLabelSize
Definition: dial.inc:69
showTarget($target, $targetLabel)
Definition: dial.inc:160
$containerHeight
Definition: dial.inc:46
setRange($min, $max)
Definition: dial.inc:124
$min
Definition: dial.inc:61
$animate
Definition: dial.inc:57
$onDrawChartComplete
Definition: dial.inc:72
$onDrawLegendComplete
Definition: dial.inc:74
$colorMode
Definition: dial.inc:65
$targetLabel
Definition: dial.inc:68
$labelX
Definition: dial.inc:54
draw()
Definition: dial.inc:167
setRadius($r)
Definition: dial.inc:107
$strokeWidth
Definition: dial.inc:56
$value
Definition: dial.inc:50
$onDrawChart
Definition: dial.inc:71
setContainerSize($width, $height="0")
Definition: dial.inc:95
$height
Definition: dial.inc:44
$minColor
Definition: dial.inc:63
$cssClass
Definition: dial.inc:70
setStrokeWidth($s)
Definition: dial.inc:150
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
$desc height
Definition: event_edit.inc:64
$dial scaleToFit
Definition: test_dial.inc:12
$dial shadow
Definition: test_dial.inc:11
$chart max