ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChartGrid.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "Services/Chart/classes/class.ilChart.php";
5
13class ilChartGrid extends ilChart
14{
15 protected $ticks; // [array]
16 protected $integer_axis; // [array]
17
18 const DATA_LINES = 1;
19 const DATA_BARS = 2;
20 const DATA_POINTS = 3;
21
22 protected function __construct($a_id)
23 {
24 parent::__construct($a_id);
25
26 $this->setXAxisToInteger(false);
27 $this->setYAxisToInteger(false);
28 }
29
30 public function getDataInstance($a_type = null)
31 {
32 switch($a_type)
33 {
34 case self::DATA_BARS:
35 include_once "Services/Chart/classes/class.ilChartDataBars.php";
36 return new ilChartDataBars();
37
39 include_once "Services/Chart/classes/class.ilChartDataPoints.php";
40 return new ilChartDataPoints();
41
42 default:
44 include_once "Services/Chart/classes/class.ilChartDataLines.php";
45 return new ilChartDataLines();
46 }
47 }
48
49 protected function isValidDataType(ilChartData $a_series)
50 {
51 if($a_series instanceof ilChartDataLines
52 || $a_series instanceof ilChartDataBars
53 || $a_series instanceof ilChartDataPoints)
54 {
55 return true;
56 }
57 return false;
58 }
59
67 public function setTicks($a_x, $a_y, $a_labeled = false)
68 {
69 $this->ticks = array("x" => $a_x, "y" => $a_y, "labeled" => (bool)$a_labeled);
70 }
71
77 public function getTicks()
78 {
79 return $this->ticks;
80 }
81
87 public function setYAxisToInteger($a_status)
88 {
89 $this->integer_axis["y"] = (bool)$a_status;
90 }
91
97 public function setXAxisToInteger($a_status)
98 {
99 $this->integer_axis["x"] = (bool)$a_status;
100 }
101
102 public function parseGlobalOptions(stdClass $a_options)
103 {
104 // axis/ticks
105 $tmp = array();
106 $ticks = $this->getTicks();
107 if($ticks)
108 {
109 $labeled = (bool)$ticks["labeled"];
110 unset($ticks["labeled"]);
111 foreach($ticks as $axis => $def)
112 {
113 if(is_numeric($def) || is_array($def))
114 {
115 $a_options->{$axis."axis"} = new stdClass();
116 }
117 if(is_numeric($def))
118 {
119 $a_options->{$axis."axis"}->ticks = $def;
120 }
121 else if(is_array($def))
122 {
123 $a_options->{$axis."axis"}->ticks = array();
124 foreach($def as $idx => $value)
125 {
126 if($labeled)
127 {
128 $a_options->{$axis."axis"}->ticks[] = array($idx, $value);
129 }
130 else
131 {
132 $a_options->{$axis."axis"}->ticks[] = $value;
133 }
134 }
135 }
136 }
137 }
138
139 // optional: remove decimals
140 if($this->integer_axis["x"] && !isset($a_options->xaxis))
141 {
142 $a_options->{"xaxis"} = new stdClass();
143 $a_options->{"xaxis"}->tickDecimals = 0;
144 }
145 if($this->integer_axis["y"] && !isset($a_options->yaxis))
146 {
147 $a_options->{"yaxis"} = new stdClass();
148 $a_options->{"yaxis"}->tickDecimals = 0;
149 }
150 }
151}
152
153?>
An exception for terminatinating execution or to throw for unit testing.
Chart data bars series.
Chart data lines series.
Chart data points series.
Abstract chart data series base class.
Generator for grid-based charts.
setYAxisToInteger($a_status)
Restrict y-axis to integer values.
isValidDataType(ilChartData $a_series)
Validate data series.
getTicks()
Get ticks.
setTicks($a_x, $a_y, $a_labeled=false)
Set ticks.
__construct($a_id)
Constructor.
parseGlobalOptions(stdClass $a_options)
Convert (global) properties to flot config.
getDataInstance($a_type=null)
Get data series instance.
setXAxisToInteger($a_status)
Restrict x-axis to integer values.
Abstract Chart generator base class.
$a_type
Definition: workflow.php:93