CMS  Version 3.9
Histogram Class Reference

Public Member Functions

 __construct ($id, $width=300, $height=300, $chartLeft=25, $chartTop=25, $chartWidth=250, $chartHeight=250, $palette="standard")
 
 setSize ($width, $height)
 
 setContainerSize ($width, $height="0")
 
 positionChart ($left, $top, $width, $height)
 
 setLabels ($labels)
 
 setLabelTooltips ($labelTooltips)
 
 setLabelDecorations ($labelDecorations)
 
 setLabelSize ($size)
 
 setYAxisLabels ($labels)
 
 setStrokeWidth ($s)
 
 setPalette ($palette)
 
 showLegend ($show, $x=0, $y=0)
 
 addSeries ($series)
 
 autoScale ()
 
 draw ()
 

Public Attributes

 $cssClass
 
 $width
 
 $height
 
 $orientation = "vertical"
 
 $cssStyles
 
 $containerWidth
 
 $containerHeight
 
 $chartLeft
 
 $chartTop
 
 $chartWidth
 
 $chartHeight
 
 $chartBackground = "#ddd"
 
 $palette
 
 $labelSize = 12
 
 $labelAngle = 0
 
 $labelAnchor = "middle"
 
 $labelOffset = 20
 
 $strokeWidth = 1
 
 $animate = false
 
 $shadow = true
 
 $emboss = false
 
 $legend = false
 
 $legendX = 0
 
 $legendY = 0
 
 $legendSwatchSize = 20
 
 $legendLineHeight = 30
 
 $xAxisTitle = ""
 
 $yAxisTitle = ""
 
 $series = array()
 
 $ticks = 10
 
 $max = 0
 
 $min = 0
 
 $columnMargin = 0.2
 
 $morphing = false
 
 $startIndex = 0
 
 $yAxisLabels = array()
 
 $title = ""
 
 $titleSize = 20
 
 $enableDownload = true
 
 $canvasBackground = "#FFFFFF"
 
 $units = ""
 
 $scaleToFit = false
 
 $onDrawGrid = "null"
 
 $onDrawGridComplete = "null"
 
 $onDrawChart = "null"
 
 $onDrawChartComplete = "null"
 
 $onDrawLegend = "null"
 
 $onDrawLegendComplete = "null"
 
 $gridStrokeWidth = 1
 
 $showGrid = true
 
 $emptyValueLabel = ""
 
 $caption = ""
 
 $captionX = 10
 
 $captionY = 300
 
 $captionWidth = 280
 
 $captionAttributes = array()
 

Detailed Description

Definition at line 150 of file histogram.inc.

Constructor & Destructor Documentation

◆ __construct()

Histogram::__construct (   $id,
  $width = 300,
  $height = 300,
  $chartLeft = 25,
  $chartTop = 25,
  $chartWidth = 250,
  $chartHeight = 250,
  $palette = "standard" 
)

Definition at line 210 of file histogram.inc.

211  {
212  $this->id = $id;
213  $this->setSize($width, $height);
216 
217  $this->palette = $palette;
218  }
setSize($width, $height)
Definition: histogram.inc:220
positionChart($left, $top, $width, $height)
Definition: histogram.inc:232
setContainerSize($width, $height="0")
Definition: histogram.inc:226

Member Function Documentation

◆ addSeries()

Histogram::addSeries (   $series)

Definition at line 282 of file histogram.inc.

283  {
284  $this->series[] = $series;
285  }

◆ autoScale()

Histogram::autoScale ( )

Definition at line 287 of file histogram.inc.

288  {
289  $max = 0;
290  $min = 0;
291 
292  foreach($this->series as $series)
293  {
294  foreach($series->values as $value)
295  {
296  if ($max === null || $value > $max) $max = $value;
297  if ($min === null || $value < $min) $min = $value;
298  }
299  }
300 
301  $logMax = intval(log10($max));
302  $logMin = intval(log10($min));
303  $log = max($logMax, $logMin);
304 
305  $denom = pow(10, $log);
306 
307  if ($max != 0)
308  {
309  $max = floor(($max / $denom) + 1) * $denom;
310  }
311 
312  if ($min != 0)
313  {
314  $min = floor(($min / $denom) - 1) * $denom;
315  }
316 
317  $this->max = $max;
318  $this->min = $min;
319  }
$chart max

◆ draw()

Histogram::draw ( )

Definition at line 321 of file histogram.inc.

322  {
323  global $script;
324 
325  $labels = "'".implode("', '", $this->labels) . "'";
326  $labelTooltips = "'".implode("', '", $this->labelTooltips) . "'";
327 
328  if ($this->labelDecorations)
329  {
330  $decorations = array();
331  foreach($this->labelDecorations as $decoration)
332  {
333  $decorations[] = json_encode($decoration);
334  }
335 
336  $labelDecorations = implode(",", $decorations);
337  }
338 
339  //$labelTooltips = $labels;
340 
341  if (count($this->yAxisLabels))
342  {
343  $yaxis = "'".implode("', '", $this->yAxisLabels) . "'";
344  $yaxis = "\t{$this->id}.yAxisLabels = [ $yaxis ];";
345  }
346 
347  $animate = $this->animate ? "true" : "false";
348  $shadow = $this->shadow ? "true": "false";
349  $emboss = $this->emboss? "true" : "false";
350  $legend = $this->legend ? "true" : "false";
351  $enableDownload = $this->enableDownload ? "true" : "false";
352  $showGrid = $this->showGrid ? "true" : "false";
353 
354  $containerWidth = is_numeric($this->containerWidth) ? $this->containerWidth . "px" : $this->containerWidth;
355  $containerHeight = is_numeric($this->containerHeight) ? $this->containerHeight . "px" : $this->containerHeight;
356 
357  $data = "";
358 
359  foreach($this->series as $s)
360  {
361  $data .= "\t{$this->id}.addSeries(".$s->toScript().");\n";
362  }
363 
364  $jsClass = $this->morphing ? "MorphingHistogram" : "Histogram";
365 
366  if ($this->caption)
367  {
368  $caption = jsSafe($this->caption);
369  $captionAttrs = json_encode($this->captionAttributes);
370  $captionBlock = <<<ENDSCRIPT
371 ,
372  caption: '{$caption}',
373  captionX: {$this->captionX},
374  captionY: {$this->captionY},
375  captionWidth: {$this->captionWidth},
376  captionAttributes: {$captionAttrs}
377 ENDSCRIPT;
378  }
379 
380  $title = jsSafe($this->title);
381 
382  $script .= <<<ENDSCRIPT
383 <script type="text/javascript">
384 window.addEvent('domready', function ()
385 {
386  var {$this->id} = new $jsClass('{$this->id}',
387  {
388  width: {$this->width},
389  height: {$this->height},
390  orientation: '{$this->orientation}',
391  chartLeft: {$this->chartLeft},
392  chartTop: {$this->chartTop},
393  chartWidth: {$this->chartWidth},
394  chartHeight: {$this->chartHeight},
395  chartBackground: '{$this->chartBackground}',
396  palette: '{$this->palette}',
397  labelSize: {$this->labelSize},
398  labelAngle: {$this->labelAngle},
399  labelAnchor: '{$this->labelAnchor}',
400  labelOffset: {$this->labelOffset},
401  emptyValueLabel: '{$this->emptyValueLabel}',
402  strokeWidth: {$this->strokeWidth},
403  gridStrokeWidth: {$this->gridStrokeWidth},
404  showGrid: {$showGrid},
405  animate: {$animate},
406  shadow: {$shadow},
407  emboss: {$emboss},
408  legend: {$legend},
409  legendX: {$this->legendX},
410  legendY: {$this->legendY},
411  legendSwatchSize: {$this->legendSwatchSize},
412  legendLineHeight: {$this->legendLineHeight},
413  ticks: {$this->ticks},
414  max: {$this->max},
415  min: {$this->min},
416  startIndex: {$this->startIndex},
417  columnMargin: {$this->columnMargin},
418  title: '{$title}',
419  titleSize: {$this->titleSize},
420  enableDownload: {$enableDownload},
421  canvasBackground: '{$this->canvasBackground}',
422  units: '{$this->units}',
423  onDrawGrid: {$this->onDrawGrid},
424  onDrawGridComplete: {$this->onDrawGridComplete},
425  onDrawChart: {$this->onDrawChart},
426  onDrawChartComplete: {$this->onDrawChartComplete},
427  onDrawLegend: {$this->onDrawLegend},
428  onDrawLegendComplete: {$this->onDrawLegendComplete}{$captionBlock}
429  });
430 
431  {$this->id}.labels = [ {$labels} ];
432  {$this->id}.labelTooltips = [ {$labelTooltips} ];
433  {$this->id}.labelDecorations = [ {$labelDecorations} ];
434 
435 {$yaxis}
436 {$data}
437  {$this->id}.draw();
438 });
439 </script>
440 ENDSCRIPT;
441 
442  if ($this->scaleToFit)
443  {
444  $dimensions = "width: 100%; height: auto";
445  }
446  else
447  {
448  $dimensions = "width: {$containerWidth}; height: {$containerHeight};";
449  }
450 
451  $cssClass = ($this->cssClass) ? " class='{$this->cssClass}'" : "";
452 
453  echo "<div id='{$this->id}'{$cssClass} style='{$this->cssStyles}'></div>";
454  }
$helpTree width
Definition: tree.inc:45
$bookmark title
$desc height
Definition: event_edit.inc:64
$image caption
$dial scaleToFit
Definition: test_dial.inc:12
$dial shadow
Definition: test_dial.inc:11
$chart ticks
$chart2 orientation
$chart morphing
$pie emboss
Definition: test_pie.inc:10

◆ positionChart()

Histogram::positionChart (   $left,
  $top,
  $width,
  $height 
)

Definition at line 232 of file histogram.inc.

233  {
234  $this->chartLeft = $left;
235  $this->chartTop = $top;
236  $this->chartWidth = $width;
237  $this->chartHeight = $height;
238  }
$left
Definition: help.inc:41

◆ setContainerSize()

Histogram::setContainerSize (   $width,
  $height = "0" 
)

Definition at line 226 of file histogram.inc.

227  {
228  $this->containerWidth = $width;
229  $this->containerHeight = $height;
230  }

◆ setLabelDecorations()

Histogram::setLabelDecorations (   $labelDecorations)

Definition at line 250 of file histogram.inc.

251  {
252  $this->labelDecorations = $labelDecorations;
253  }

◆ setLabels()

Histogram::setLabels (   $labels)

Definition at line 240 of file histogram.inc.

241  {
242  $this->labels = $labels;
243  }

◆ setLabelSize()

Histogram::setLabelSize (   $size)

Definition at line 255 of file histogram.inc.

256  {
257  $this->labelSize = $size;
258  }
$size
Definition: download.inc:47

◆ setLabelTooltips()

Histogram::setLabelTooltips (   $labelTooltips)

Definition at line 245 of file histogram.inc.

246  {
247  $this->labelTooltips = $labelTooltips;
248  }

◆ setPalette()

Histogram::setPalette (   $palette)

Definition at line 270 of file histogram.inc.

271  {
272  $this->palette = $palette;
273  }

◆ setSize()

Histogram::setSize (   $width,
  $height 
)

Definition at line 220 of file histogram.inc.

221  {
222  $this->width = $width;
223  $this->height = $height;
224  }

◆ setStrokeWidth()

Histogram::setStrokeWidth (   $s)

Definition at line 265 of file histogram.inc.

266  {
267  $this->strokeWidth = $s;
268  }

◆ setYAxisLabels()

Histogram::setYAxisLabels (   $labels)

Definition at line 260 of file histogram.inc.

261  {
262  $this->yAxisLabels = $labels;
263  }

◆ showLegend()

Histogram::showLegend (   $show,
  $x = 0,
  $y = 0 
)

Definition at line 275 of file histogram.inc.

276  {
277  $this->legend = $show;
278  $this->legendX = $x;
279  $this->legendY = $y;
280  }

Member Data Documentation

◆ $animate

Histogram::$animate = false

Definition at line 170 of file histogram.inc.

◆ $canvasBackground

Histogram::$canvasBackground = "#FFFFFF"

Definition at line 191 of file histogram.inc.

◆ $caption

Histogram::$caption = ""

Definition at line 204 of file histogram.inc.

◆ $captionAttributes

Histogram::$captionAttributes = array()

Definition at line 208 of file histogram.inc.

◆ $captionWidth

Histogram::$captionWidth = 280

Definition at line 207 of file histogram.inc.

◆ $captionX

Histogram::$captionX = 10

Definition at line 205 of file histogram.inc.

◆ $captionY

Histogram::$captionY = 300

Definition at line 206 of file histogram.inc.

◆ $chartBackground

Histogram::$chartBackground = "#ddd"

Definition at line 163 of file histogram.inc.

◆ $chartHeight

Histogram::$chartHeight

Definition at line 162 of file histogram.inc.

◆ $chartLeft

Histogram::$chartLeft

Definition at line 159 of file histogram.inc.

◆ $chartTop

Histogram::$chartTop

Definition at line 160 of file histogram.inc.

◆ $chartWidth

Histogram::$chartWidth

Definition at line 161 of file histogram.inc.

◆ $columnMargin

Histogram::$columnMargin = 0.2

Definition at line 184 of file histogram.inc.

◆ $containerHeight

Histogram::$containerHeight

Definition at line 158 of file histogram.inc.

◆ $containerWidth

Histogram::$containerWidth

Definition at line 157 of file histogram.inc.

◆ $cssClass

Histogram::$cssClass

Definition at line 152 of file histogram.inc.

◆ $cssStyles

Histogram::$cssStyles

Definition at line 156 of file histogram.inc.

◆ $emboss

Histogram::$emboss = false

Definition at line 172 of file histogram.inc.

◆ $emptyValueLabel

Histogram::$emptyValueLabel = ""

Definition at line 202 of file histogram.inc.

◆ $enableDownload

Histogram::$enableDownload = true

Definition at line 190 of file histogram.inc.

◆ $gridStrokeWidth

Histogram::$gridStrokeWidth = 1

Definition at line 200 of file histogram.inc.

◆ $height

Histogram::$height

Definition at line 154 of file histogram.inc.

◆ $labelAnchor

Histogram::$labelAnchor = "middle"

Definition at line 167 of file histogram.inc.

◆ $labelAngle

Histogram::$labelAngle = 0

Definition at line 166 of file histogram.inc.

◆ $labelOffset

Histogram::$labelOffset = 20

Definition at line 168 of file histogram.inc.

◆ $labelSize

Histogram::$labelSize = 12

Definition at line 165 of file histogram.inc.

◆ $legend

Histogram::$legend = false

Definition at line 173 of file histogram.inc.

◆ $legendLineHeight

Histogram::$legendLineHeight = 30

Definition at line 177 of file histogram.inc.

◆ $legendSwatchSize

Histogram::$legendSwatchSize = 20

Definition at line 176 of file histogram.inc.

◆ $legendX

Histogram::$legendX = 0

Definition at line 174 of file histogram.inc.

◆ $legendY

Histogram::$legendY = 0

Definition at line 175 of file histogram.inc.

◆ $max

Histogram::$max = 0

Definition at line 182 of file histogram.inc.

◆ $min

Histogram::$min = 0

Definition at line 183 of file histogram.inc.

◆ $morphing

Histogram::$morphing = false

Definition at line 185 of file histogram.inc.

◆ $onDrawChart

Histogram::$onDrawChart = "null"

Definition at line 196 of file histogram.inc.

◆ $onDrawChartComplete

Histogram::$onDrawChartComplete = "null"

Definition at line 197 of file histogram.inc.

◆ $onDrawGrid

Histogram::$onDrawGrid = "null"

Definition at line 194 of file histogram.inc.

◆ $onDrawGridComplete

Histogram::$onDrawGridComplete = "null"

Definition at line 195 of file histogram.inc.

◆ $onDrawLegend

Histogram::$onDrawLegend = "null"

Definition at line 198 of file histogram.inc.

◆ $onDrawLegendComplete

Histogram::$onDrawLegendComplete = "null"

Definition at line 199 of file histogram.inc.

◆ $orientation

Histogram::$orientation = "vertical"

Definition at line 155 of file histogram.inc.

◆ $palette

Histogram::$palette

Definition at line 164 of file histogram.inc.

◆ $scaleToFit

Histogram::$scaleToFit = false

Definition at line 193 of file histogram.inc.

◆ $series

Histogram::$series = array()

Definition at line 180 of file histogram.inc.

◆ $shadow

Histogram::$shadow = true

Definition at line 171 of file histogram.inc.

◆ $showGrid

Histogram::$showGrid = true

Definition at line 201 of file histogram.inc.

◆ $startIndex

Histogram::$startIndex = 0

Definition at line 186 of file histogram.inc.

◆ $strokeWidth

Histogram::$strokeWidth = 1

Definition at line 169 of file histogram.inc.

◆ $ticks

Histogram::$ticks = 10

Definition at line 181 of file histogram.inc.

◆ $title

Histogram::$title = ""

Definition at line 188 of file histogram.inc.

◆ $titleSize

Histogram::$titleSize = 20

Definition at line 189 of file histogram.inc.

◆ $units

Histogram::$units = ""

Definition at line 192 of file histogram.inc.

◆ $width

Histogram::$width

Definition at line 153 of file histogram.inc.

◆ $xAxisTitle

Histogram::$xAxisTitle = ""

Definition at line 178 of file histogram.inc.

◆ $yAxisLabels

Histogram::$yAxisLabels = array()

Definition at line 187 of file histogram.inc.

◆ $yAxisTitle

Histogram::$yAxisTitle = ""

Definition at line 179 of file histogram.inc.


The documentation for this class was generated from the following file: