ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilChart Class Reference

Abstract Chart generator base class. More...

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

Public Member Functions

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

Static Public Member Functions

static getInstanceByType ($a_type, $a_id)
 Get type instance. More...
 
static isValidColor ($a_value)
 Validate html color code. More...
 
static renderColor ($a_value, $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 ($a_id)
 Constructor. More...
 
 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

 $id
 
 $width
 
 $height
 
 $data
 
 $legend
 
 $shadow
 
 $colors
 
 $auto_resize
 

Detailed Description

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
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilChart::__construct (   $a_id)
protected

Constructor.

Parameters
string$a_id

Reimplemented in ilChartGrid.

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

34 {
35 $this->id = $a_id;
36 $this->data = array();
37
38 $this->setShadow(2);
39 }
setShadow($a_value)
Set shadow.

References 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 261 of file class.ilChart.php.

262 {
263
264 }

Referenced by initJS().

+ Here is the caller graph for this function:

◆ addData()

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

Add data series.

Parameters
ilChartData$a_series
mixed$a_id
Returns
mixed index

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

114 {
115 if($this->isValidDataType($a_series))
116 {
117 if($a_idx === null)
118 {
119 $a_idx = sizeof($this->data);
120 }
121 $this->data[$a_idx] = $a_series;
122 return $a_idx;
123 }
124 }
isValidDataType(ilChartData $a_series)
Validate data series.

References $data, and isValidDataType().

+ Here is the call graph for this function:

◆ getColors()

ilChart::getColors ( )

Get colors.

Returns
array

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

158 {
159 return $this->colors;
160 }

References $colors.

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ getDataInstance()

ilChart::getDataInstance (   $a_type = null)
abstract

Get data series instance.

Returns
ilChartData

Reimplemented in ilChartGrid, ilChartPie, and ilChartSpider.

◆ getHTML()

ilChart::getHTML ( )

Render.

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

280 {
281 if(!$this->isValid())
282 {
283 return;
284 }
285
286 $this->initJS();
287
288 $chart = new ilTemplate("tpl.grid.html", true, true, "Services/Chart");
289 $chart->setVariable("ID", $this->id);
290
291 if($this->width)
292 {
293 if(is_numeric($this->width))
294 {
295 $chart->setVariable("WIDTH", "width:".$this->width."px;");
296 }
297 else
298 {
299 $chart->setVariable("WIDTH", "width:".$this->width.";");
300 }
301 }
302 if($this->height)
303 {
304 if(is_numeric($this->height))
305 {
306 $chart->setVariable("HEIGHT", "height:".$this->height."px;");
307 }
308 else
309 {
310 $chart->setVariable("HEIGHT", "height:".$this->height.";");
311 }
312 }
313
314
315 // (series) data
316
317 $json_series = array();
318 foreach($this->data as $series)
319 {
320 $series->parseData($json_series);
321 }
322 $chart->setVariable("SERIES", json_encode($json_series));
323
324
325 // global options
326
327 $json_options = new stdClass();
328 $json_options->series = new stdClass();
329 $json_options->series->shadowSize = (int)$this->getShadow();
330 $json_options->series->lines = new stdClass();
331 $json_options->series->lines->show = false;
332
333 foreach($this->data as $series)
334 {
335 $series->parseGlobalOptions($json_options, $this);
336 }
337
338 $this->parseGlobalOptions($json_options);
339
340 $colors = $this->getColors();
341 if($colors)
342 {
343 $json_options->colors = array();
344 foreach($colors as $color)
345 {
346 $json_options->colors[] = self::renderColor($color);
347 }
348 }
349
350 // legend
351 $json_options->legend = new stdClass();
352 if(!$this->legend)
353 {
354 $json_options->legend->show = false;
355 }
356 else
357 {
358 $this->legend->parseOptions($json_options->legend);
359 }
360
361 $chart->setVariable("OPTIONS", json_encode($json_options));
362
363 $ret = $chart->get();
364 return $ret;
365 }
initJS()
Init JS script files.
static renderColor($a_value, $a_opacity=1)
Render html color code.
getColors()
Get colors.
isValid()
Basic validation.
getShadow()
Get shadow.
parseGlobalOptions(stdClass $a_options)
Convert (global) properties to flot config.
special template class to simplify handling of ITX/PEAR

References $colors, $ret, getColors(), getShadow(), initJS(), isValid(), parseGlobalOptions(), and renderColor().

+ Here is the call graph for this function:

◆ getInstanceByType()

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

Get type instance.

Parameters
int$a_type
string$a_id
Returns
ilChart

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

49 {
50 switch($a_type)
51 {
52 case self::TYPE_GRID:
53 include_once "Services/Chart/classes/class.ilChartGrid.php";
54 return new ilChartGrid($a_id);
55
56 case self::TYPE_PIE:
57 include_once "Services/Chart/classes/class.ilChartPie.php";
58 return new ilChartPie($a_id);
59
61 include_once "Services/Chart/classes/class.ilChartSpider.php";
62 return new ilChartSpider($a_id);
63 }
64 }
Generator for grid-based charts.
Generator for pie charts.
Generator for spider charts.
const TYPE_SPIDER
const TYPE_PIE
const TYPE_GRID

References TYPE_GRID, TYPE_PIE, and TYPE_SPIDER.

Referenced by ilPollBlockGUI\fillRow(), ilSessionStatisticsGUI\getChart(), ilPersonalSkillsGUI\getGapAnalysisHTML(), ilLPObjectStatisticsDailyTableGUI\getGraph(), ilLPObjectStatisticsLPTableGUI\getGraph(), ilLPObjectStatisticsTableGUI\getGraph(), ilLPObjectStatisticsTypesTableGUI\getGraph(), SurveyMetricQuestionGUI\renderChart(), SurveyQuestionGUI\renderChart(), and ilWikiStatGUI\renderGraph().

+ Here is the caller graph for this function:

◆ getShadow()

ilChart::getShadow ( )

Get shadow.

Returns
int

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

222 {
223 return $this->shadow;
224 }

References $shadow.

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ initJS()

ilChart::initJS ( )
protected

Init JS script files.

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

240 {
241 global $tpl;
242
243 include_once "Services/jQuery/classes/class.iljQueryUtil.php";
245
246 $tpl->addJavascript("Services/Chart/js/flot/excanvas.min.js");
247 $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.min.js");
248
249 if((bool)$this->auto_resize)
250 {
251 // #13108
252 $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.resize.min.js");
253 }
254
255 $this->addCustomJS();
256 }
global $tpl
Definition: ilias.php:8
addCustomJS()
Add type-specific JS script.
static initjQuery($a_tpl=null)
Init jQuery.

References $tpl, addCustomJS(), and iljQueryUtil\initjQuery().

Referenced by getHTML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValid()

ilChart::isValid ( )
protected

Basic validation.

Returns
bool

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

86 {
87 if(sizeof($this->data))
88 {
89 return true;
90 }
91 return false;
92 }

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ isValidColor()

static ilChart::isValidColor (   $a_value)
static

Validate html color code.

Parameters
string$a_value
Returns
bool

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

169 {
170 if(preg_match("/^#[0-9a-f]{3}$/i", $a_value, $match))
171 {
172 return true;
173 }
174 else if(preg_match("/^#[0-9a-f]{6}$/i", $a_value, $match))
175 {
176 return true;
177 }
178 }

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

+ Here is the caller graph for this function:

◆ isValidDataType()

ilChart::isValidDataType ( ilChartData  $a_series)
abstractprotected

Validate data series.

Returns
bool

Reimplemented in ilChartGrid, ilChartPie, and ilChartSpider.

Referenced by addData().

+ Here is the caller graph for this function:

◆ parseGlobalOptions()

ilChart::parseGlobalOptions ( stdClass  $a_options)

Convert (global) properties to flot config.

Parameters
object$a_options

Reimplemented in ilChartGrid, ilChartPie, and ilChartSpider.

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

272 {
273
274 }

Referenced by getHTML().

+ Here is the caller graph for this function:

◆ renderColor()

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

Render html color code.

Parameters
string$a_value
float$a_opacity
Returns
string

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

188 {
189 if(self::isValidColor($a_value))
190 {
191 if(strlen($a_value) == 4)
192 {
193 return "rgba(".hexdec($a_value[1].$a_value[1]).", ".
194 hexdec($a_value[2].$a_value[2]).", ".
195 hexdec($a_value[3].$a_value[3]).", ".$a_opacity.")";
196 }
197 else
198 {
199 return "rgba(".hexdec($a_value[1].$a_value[2]).", ".
200 hexdec($a_value[3].$a_value[4]).", ".
201 hexdec($a_value[5].$a_value[6]).", ".$a_opacity.")";
202 }
203 }
204 }

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

+ Here is the caller graph for this function:

◆ setAutoResize()

ilChart::setAutoResize (   $a_value)

Toggle auto-resizing on window resize/redraw.

Parameters
bool$a_value

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

232 {
233 $this->auto_resize = (bool)$a_value;
234 }

◆ setColors()

ilChart::setColors (   $a_values)

Set colors.

Parameters
array$a_values

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

142 {
143 foreach($a_values as $color)
144 {
145 if(self::isValidColor($color))
146 {
147 $this->colors[] = $color;
148 }
149 }
150 }

◆ setLegend()

ilChart::setLegend ( ilChartLegend  $a_legend)

Set chart legend.

Parameters
ilChartLegend$a_legend

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

132 {
133 $this->legend = $a_legend;
134 }

Referenced by ilChartPie\parseGlobalOptions().

+ Here is the caller graph for this function:

◆ setShadow()

ilChart::setShadow (   $a_value)

Set shadow.

Parameters
int$a_value

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

212 {
213 $this->shadow = (int)$a_value;
214 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setSize()

ilChart::setSize (   $a_x,
  $a_y 
)

Set chart size.

Parameters
int$a_x
int$a_y

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

101 {
102 $this->width = $a_x;
103 $this->height = $a_y;
104 }

Field Documentation

◆ $auto_resize

ilChart::$auto_resize
protected

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

◆ $colors

ilChart::$colors
protected

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

Referenced by getColors(), and getHTML().

◆ $data

ilChart::$data
protected

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

Referenced by addData().

◆ $height

ilChart::$height
protected

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

◆ $id

ilChart::$id
protected

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

◆ $legend

ilChart::$legend
protected

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

Referenced by ilChartPie\parseGlobalOptions().

◆ $shadow

ilChart::$shadow
protected

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

Referenced by getShadow().

◆ $width

ilChart::$width
protected

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

◆ TYPE_GRID

◆ TYPE_PIE

const ilChart::TYPE_PIE = 2

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

Referenced by getInstanceByType().

◆ TYPE_SPIDER

const ilChart::TYPE_SPIDER = 3

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

Referenced by ilPersonalSkillsGUI\getGapAnalysisHTML(), and getInstanceByType().


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