ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilChart Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilChart:
+ Collaboration diagram for ilChart:

Public Member Functions

 getDataInstance (?int $a_type=null)
 Get data series instance. More...
 
 setSize (string $a_x, string $a_y)
 Set chart size. More...
 
 addData (ilChartData $a_series, ?int $a_idx=null)
 Add data series. More...
 
 setLegend (ilChartLegend $a_legend)
 
 setColors (array $a_values)
 
 getColors ()
 
 setShadow (int $a_value)
 
 getShadow ()
 
 setAutoResize (bool $a_value)
 Toggle auto-resizing on window resize/redraw. More...
 
 setStacked (bool $a_value)
 
 parseGlobalOptions (stdClass $a_options)
 Convert (global) properties to flot config. More...
 
 getHTML ()
 Render. More...
 

Static Public Member Functions

static getInstanceByType (int $a_type, string $a_id)
 
static isValidColor (string $a_value)
 Validate html color code. More...
 
static renderColor (string $a_value, float $a_opacity=1)
 Render html color code. More...
 

Data Fields

const TYPE_GRID = 1
 
const TYPE_PIE = 2
 
const TYPE_SPIDER = 3
 

Protected Member Functions

 __construct (string $a_id)
 
 isValidDataType (ilChartData $a_series)
 Validate data series. More...
 
 isValid ()
 Basic validation. More...
 
 initJS ()
 Init JS script files. More...
 
 addCustomJS ()
 Add type-specific JS script. More...
 

Protected Attributes

ilGlobalTemplateInterface $tpl
 
string $id = ""
 
string $width = ""
 
string $height = ""
 
array $data = []
 
ilChartLegend $legend = null
 
int $shadow = 0
 
array $colors = []
 
bool $auto_resize = false
 
bool $stacked = false
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Abstract Chart generator base class

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 23 of file class.ilChart.php.

Constructor & Destructor Documentation

◆ __construct()

ilChart::__construct ( string  $a_id)
protected

Reimplemented in ilChartGrid.

Definition at line 40 of file class.ilChart.php.

41 {
42 global $DIC;
43
44 $this->tpl = $DIC["tpl"];
45 $this->id = $a_id;
46 $this->data = array();
47
48 $this->setShadow(2);
49 }
setShadow(int $a_value)
global $DIC
Definition: shib_login.php:26

References $DIC, and setShadow().

+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomJS()

ilChart::addCustomJS ( )
protected

Add type-specific JS script.

Reimplemented in ilChartPie, and ilChartSpider.

Definition at line 219 of file class.ilChart.php.

219 : void
220 {
221 }

◆ addData()

ilChart::addData ( ilChartData  $a_series,
?int  $a_idx = null 
)

Add data series.

Definition at line 101 of file class.ilChart.php.

104 : ?int {
105 if ($this->isValidDataType($a_series)) {
106 if ($a_idx === null) {
107 $a_idx = sizeof($this->data);
108 }
109 $this->data[$a_idx] = $a_series;
110 return $a_idx;
111 }
112 return null;
113 }
isValidDataType(ilChartData $a_series)
Validate data series.
array $data

References $data.

◆ getColors()

ilChart::getColors ( )

Definition at line 129 of file class.ilChart.php.

129 : array
130 {
131 return $this->colors;
132 }
array $colors

◆ getDataInstance()

ilChart::getDataInstance ( ?int  $a_type = null)
abstract

Get data series instance.

Reimplemented in ilChartGrid, ilChartPie, and ilChartSpider.

◆ getHTML()

ilChart::getHTML ( )

Render.

Definition at line 233 of file class.ilChart.php.

233 : string
234 {
235 if (!$this->isValid()) {
236 return "";
237 }
238
239 $this->initJS();
240
241 $chart = new ilTemplate("tpl.grid.html", true, true, "components/ILIAS/Chart");
242 $chart->setVariable("ID", $this->id);
243
244 if ($this->width) {
245 if (is_numeric($this->width)) {
246 $chart->setVariable("WIDTH", "width:" . $this->width . "px;");
247 } else {
248 $chart->setVariable("WIDTH", "width:" . $this->width . ";");
249 }
250 }
251 if ($this->height) {
252 if (is_numeric($this->height)) {
253 $chart->setVariable("HEIGHT", "height:" . $this->height . "px;");
254 } else {
255 $chart->setVariable("HEIGHT", "height:" . $this->height . ";");
256 }
257 }
258
259
260 // (series) data
261
262 $json_series = array();
263 foreach ($this->data as $series) {
264 $series->parseData($json_series);
265 }
266 $series_str = json_encode($json_series);
267
268
269 // global options
270
271 $json_options = new stdClass();
272 $json_options->series = new stdClass();
273 $json_options->series->shadowSize = $this->getShadow();
274 $json_options->series->lines = new stdClass();
275 $json_options->series->lines->show = false;
276 $json_options->series->stack = $this->stacked;
277
278 foreach ($this->data as $series) {
279 $series->parseGlobalOptions($json_options, $this);
280 }
281
282 $this->parseGlobalOptions($json_options);
283
284 $colors = $this->getColors();
285 if ($colors) {
286 $json_options->colors = array();
287 foreach ($colors as $color) {
288 $json_options->colors[] = self::renderColor($color);
289 }
290 }
291
292 // legend
293 $json_options->legend = new stdClass();
294 if (!$this->legend) {
295 $json_options->legend->show = false;
296 } else {
297 $this->legend->parseOptions($json_options->legend);
298 }
299
300 $options = json_encode($json_options);
301
302 $this->tpl->addOnLoadCode('$.plot($("#ilChart' . $this->id . '"), ' . $series_str . ', ' . $options . ');');
303
304 $ret = $chart->get();
305 return $ret;
306 }
initJS()
Init JS script files.
static renderColor(string $a_value, float $a_opacity=1)
Render html color code.
isValid()
Basic validation.
bool $stacked
parseGlobalOptions(stdClass $a_options)
Convert (global) properties to flot config.
special template class to simplify handling of ITX/PEAR

◆ getInstanceByType()

static ilChart::getInstanceByType ( int  $a_type,
string  $a_id 
)
static

Definition at line 51 of file class.ilChart.php.

54 : ilChart {
55 switch ($a_type) {
56 case self::TYPE_GRID:
57 return new ilChartGrid($a_id);
58
59 case self::TYPE_PIE:
60 return new ilChartPie($a_id);
61
63 return new ilChartSpider($a_id);
64 }
65 throw new ilException("Unknown chart type.");
66 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const TYPE_SPIDER
const TYPE_PIE
const TYPE_GRID
Base class for ILIAS Exception handling.

References TYPE_GRID, TYPE_PIE, and TYPE_SPIDER.

Referenced by SurveyMatrixQuestionEvaluation\getChart(), SurveyMetricQuestionEvaluation\getChart(), SurveyQuestionEvaluation\getChart(), ilLPObjectStatisticsDailyTableGUI\getGraph(), ilLPObjectStatisticsLPTableGUI\getGraph(), ilLPObjectStatisticsTableGUI\getGraph(), and ilLPObjectStatisticsTypesTableGUI\getGraph().

+ Here is the caller graph for this function:

◆ getShadow()

ilChart::getShadow ( )

Definition at line 173 of file class.ilChart.php.

173 : int
174 {
175 return $this->shadow;
176 }

◆ initJS()

ilChart::initJS ( )
protected

Init JS script files.

Definition at line 195 of file class.ilChart.php.

195 : void
196 {
198
200
201 $tpl->addJavaScript("assets/js/excanvas.min.js");
202 $tpl->addJavaScript("assets/js/jquery.flot.min.js");
203
204 if ($this->auto_resize) {
205 // #13108
206 $tpl->addJavaScript("assets/js/jquery.flot.resize.min.js");
207 }
208
209 if ($this->stacked) {
210 $tpl->addJavaScript("assets/js/jquery.flot.stack.min.js");
211 }
212
213 $this->addCustomJS();
214 }
ilGlobalTemplateInterface $tpl
addCustomJS()
Add type-specific JS script.
static initjQuery(?ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.

References iljQueryUtil\initjQuery(), and ILIAS\UI\examples\Chart\Bar\Horizontal\stacked().

+ Here is the call graph for this function:

◆ isValid()

ilChart::isValid ( )
protected

Basic validation.

Definition at line 81 of file class.ilChart.php.

81 : bool
82 {
83 if (sizeof($this->data)) {
84 return true;
85 }
86 return false;
87 }

◆ isValidColor()

static ilChart::isValidColor ( string  $a_value)
static

Validate html color code.

Definition at line 137 of file class.ilChart.php.

137 : bool
138 {
139 if (preg_match("/^#[0-9a-f]{3}$/i", $a_value, $match)) {
140 return true;
141 } elseif (preg_match("/^#[0-9a-f]{6}$/i", $a_value, $match)) {
142 return true;
143 }
144 return false;
145 }

Referenced by ilChartLegend\setBackground(), and ilChartLegend\setLabelBorder().

+ Here is the caller graph for this function:

◆ isValidDataType()

ilChart::isValidDataType ( ilChartData  $a_series)
abstractprotected

Validate data series.

Reimplemented in ilChartGrid, ilChartPie, and ilChartSpider.

◆ parseGlobalOptions()

ilChart::parseGlobalOptions ( stdClass  $a_options)

Convert (global) properties to flot config.

Reimplemented in ilChartGrid, ilChartPie, and ilChartSpider.

Definition at line 226 of file class.ilChart.php.

226 : void
227 {
228 }

◆ renderColor()

static ilChart::renderColor ( string  $a_value,
float  $a_opacity = 1 
)
static

Render html color code.

Definition at line 150 of file class.ilChart.php.

153 : string {
154 if (self::isValidColor($a_value)) {
155 if (strlen($a_value) == 4) {
156 return "rgba(" . hexdec($a_value[1] . $a_value[1]) . ", " .
157 hexdec($a_value[2] . $a_value[2]) . ", " .
158 hexdec($a_value[3] . $a_value[3]) . ", " . $a_opacity . ")";
159 } else {
160 return "rgba(" . hexdec($a_value[1] . $a_value[2]) . ", " .
161 hexdec($a_value[3] . $a_value[4]) . ", " .
162 hexdec($a_value[5] . $a_value[6]) . ", " . $a_opacity . ")";
163 }
164 }
165 return "";
166 }

Referenced by ilChartData\parseData(), ilChartDataSpider\parseData(), ilChartSpider\parseGlobalOptions(), ilChartDataPie\parseGlobalOptions(), ilChartDataSpider\parseGlobalOptions(), and ilChartLegend\parseOptions().

+ Here is the caller graph for this function:

◆ setAutoResize()

ilChart::setAutoResize ( bool  $a_value)

Toggle auto-resizing on window resize/redraw.

Definition at line 181 of file class.ilChart.php.

183 : void {
184 $this->auto_resize = $a_value;
185 }

◆ setColors()

ilChart::setColors ( array  $a_values)

Definition at line 120 of file class.ilChart.php.

120 : void
121 {
122 foreach ($a_values as $color) {
123 if (self::isValidColor($color)) {
124 $this->colors[] = $color;
125 }
126 }
127 }

◆ setLegend()

ilChart::setLegend ( ilChartLegend  $a_legend)

Definition at line 115 of file class.ilChart.php.

115 : void
116 {
117 $this->legend = $a_legend;
118 }

Referenced by ilChartPie\parseGlobalOptions().

+ Here is the caller graph for this function:

◆ setShadow()

ilChart::setShadow ( int  $a_value)

Definition at line 168 of file class.ilChart.php.

168 : void
169 {
170 $this->shadow = $a_value;
171 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setSize()

ilChart::setSize ( string  $a_x,
string  $a_y 
)

Set chart size.

Definition at line 92 of file class.ilChart.php.

92 : void
93 {
94 $this->width = $a_x;
95 $this->height = $a_y;
96 }

◆ setStacked()

ilChart::setStacked ( bool  $a_value)

Definition at line 187 of file class.ilChart.php.

187 : void
188 {
189 $this->stacked = $a_value;
190 }

References ILIAS\UI\examples\Chart\Bar\Horizontal\stacked().

+ Here is the call graph for this function:

Field Documentation

◆ $auto_resize

bool ilChart::$auto_resize = false
protected

Definition at line 37 of file class.ilChart.php.

◆ $colors

array ilChart::$colors = []
protected

Definition at line 36 of file class.ilChart.php.

◆ $data

array ilChart::$data = []
protected

Definition at line 33 of file class.ilChart.php.

◆ $height

string ilChart::$height = ""
protected

Definition at line 32 of file class.ilChart.php.

◆ $id

string ilChart::$id = ""
protected

Definition at line 30 of file class.ilChart.php.

◆ $legend

ilChartLegend ilChart::$legend = null
protected

Definition at line 34 of file class.ilChart.php.

Referenced by ilChartPie\parseGlobalOptions().

◆ $shadow

int ilChart::$shadow = 0
protected

Definition at line 35 of file class.ilChart.php.

◆ $stacked

bool ilChart::$stacked = false
protected

Definition at line 38 of file class.ilChart.php.

◆ $tpl

ilGlobalTemplateInterface ilChart::$tpl
protected

Definition at line 29 of file class.ilChart.php.

Referenced by ilChartPie\addCustomJS(), and ilChartSpider\addCustomJS().

◆ $width

string ilChart::$width = ""
protected

Definition at line 31 of file class.ilChart.php.

◆ TYPE_GRID

◆ TYPE_PIE

const ilChart::TYPE_PIE = 2

Definition at line 26 of file class.ilChart.php.

Referenced by getInstanceByType().

◆ TYPE_SPIDER

const ilChart::TYPE_SPIDER = 3

Definition at line 27 of file class.ilChart.php.

Referenced by getInstanceByType().


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