ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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...
 
 setStacked ($a_value)
 Toggle stacking. 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

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

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

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

References $DIC, array, data, and setShadow().

40  {
41  global $DIC;
42 
43  $this->tpl = $DIC["tpl"];
44  $this->id = $a_id;
45  $this->data = array();
46 
47  $this->setShadow(2);
48  }
Add some data
global $DIC
Definition: saml.php:7
setShadow($a_value)
Set shadow.
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomJS()

ilChart::addCustomJS ( )
protected

Add type-specific JS script.

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

Referenced by initJS().

271  {
272  }
+ 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 120 of file class.ilChart.php.

References $data, data, and isValidDataType().

121  {
122  if ($this->isValidDataType($a_series)) {
123  if ($a_idx === null) {
124  $a_idx = sizeof($this->data);
125  }
126  $this->data[$a_idx] = $a_series;
127  return $a_idx;
128  }
129  }
Add some data
isValidDataType(ilChartData $a_series)
Validate data series.
+ Here is the call graph for this function:

◆ getColors()

ilChart::getColors ( )

Get colors.

Returns
array

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

References $colors.

Referenced by getHTML().

161  {
162  return $this->colors;
163  }
+ Here is the caller graph for this function:

◆ getDataInstance()

ilChart::getDataInstance (   $a_type = null)
abstract

Get data series instance.

Returns
ilChartData

Referenced by getInstanceByType().

+ Here is the caller graph for this function:

◆ getHTML()

ilChart::getHTML ( )

Render.

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

References $chart, $colors, $ret, $series, array, data, getColors(), getShadow(), initJS(), isValid(), and parseGlobalOptions().

287  {
288  if (!$this->isValid()) {
289  return;
290  }
291 
292  $this->initJS();
293 
294  $chart = new ilTemplate("tpl.grid.html", true, true, "Services/Chart");
295  $chart->setVariable("ID", $this->id);
296 
297  if ($this->width) {
298  if (is_numeric($this->width)) {
299  $chart->setVariable("WIDTH", "width:" . $this->width . "px;");
300  } else {
301  $chart->setVariable("WIDTH", "width:" . $this->width . ";");
302  }
303  }
304  if ($this->height) {
305  if (is_numeric($this->height)) {
306  $chart->setVariable("HEIGHT", "height:" . $this->height . "px;");
307  } else {
308  $chart->setVariable("HEIGHT", "height:" . $this->height . ";");
309  }
310  }
311 
312 
313  // (series) data
314 
315  $json_series = array();
316  foreach ($this->data as $series) {
317  $series->parseData($json_series);
318  }
319  $chart->setVariable("SERIES", json_encode($json_series));
320 
321 
322  // global options
323 
324  $json_options = new stdClass();
325  $json_options->series = new stdClass();
326  $json_options->series->shadowSize = (int) $this->getShadow();
327  $json_options->series->lines = new stdClass();
328  $json_options->series->lines->show = false;
329  $json_options->series->stack = (bool) $this->stacked;
330 
331  foreach ($this->data as $series) {
332  $series->parseGlobalOptions($json_options, $this);
333  }
334 
335  $this->parseGlobalOptions($json_options);
336 
337  $colors = $this->getColors();
338  if ($colors) {
339  $json_options->colors = array();
340  foreach ($colors as $color) {
341  $json_options->colors[] = self::renderColor($color);
342  }
343  }
344 
345  // legend
346  $json_options->legend = new stdClass();
347  if (!$this->legend) {
348  $json_options->legend->show = false;
349  } else {
350  $this->legend->parseOptions($json_options->legend);
351  }
352 
353  $chart->setVariable("OPTIONS", json_encode($json_options));
354 
355  $ret = $chart->get();
356  return $ret;
357  }
Add some data
parseGlobalOptions(stdClass $a_options)
Convert (global) properties to flot config.
initJS()
Init JS script files.
isValid()
Basic validation.
special template class to simplify handling of ITX/PEAR
getColors()
Get colors.
Create styles array
The data for the language used.
$ret
Definition: parser.php:6
getShadow()
Get shadow.
+ 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 57 of file class.ilChart.php.

References $a_type, getDataInstance(), and isValidDataType().

Referenced by ilPollBlockGUI\fillRow(), SurveyMetricQuestionEvaluation\getChart(), SurveyMatrixQuestionEvaluation\getChart(), SurveyQuestionEvaluation\getChart(), ilSessionStatisticsGUI\getChart(), ilPersonalSkillsGUI\getGapAnalysisHTML(), ilLPObjectStatisticsTypesTableGUI\getGraph(), ilLPObjectStatisticsDailyTableGUI\getGraph(), ilLPObjectStatisticsTableGUI\getGraph(), ilLPObjectStatisticsLPTableGUI\getGraph(), and ilWikiStatGUI\renderGraph().

58  {
59  switch ($a_type) {
60  case self::TYPE_GRID:
61  include_once "Services/Chart/classes/class.ilChartGrid.php";
62  return new ilChartGrid($a_id);
63 
64  case self::TYPE_PIE:
65  include_once "Services/Chart/classes/class.ilChartPie.php";
66  return new ilChartPie($a_id);
67 
68  case self::TYPE_SPIDER:
69  include_once "Services/Chart/classes/class.ilChartSpider.php";
70  return new ilChartSpider($a_id);
71  }
72  }
Generator for spider charts.
$a_type
Definition: workflow.php:92
Generator for pie charts.
Generator for grid-based charts.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getShadow()

ilChart::getShadow ( )

Get shadow.

Returns
int

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

References $shadow.

Referenced by getHTML().

218  {
219  return $this->shadow;
220  }
+ Here is the caller graph for this function:

◆ initJS()

ilChart::initJS ( )
protected

Init JS script files.

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

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

Referenced by getHTML().

246  {
247  $tpl = $this->tpl;
248 
249  include_once "Services/jQuery/classes/class.iljQueryUtil.php";
251 
252  $tpl->addJavascript("Services/Chart/js/flot/excanvas.min.js");
253  $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.min.js");
254 
255  if ((bool) $this->auto_resize) {
256  // #13108
257  $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.resize.min.js");
258  }
259 
260  if ((bool) $this->stacked) {
261  $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.stack.min.js");
262  }
263 
264  $this->addCustomJS();
265  }
addCustomJS()
Add type-specific JS script.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
+ 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 93 of file class.ilChart.php.

References data.

Referenced by getHTML().

94  {
95  if (sizeof($this->data)) {
96  return true;
97  }
98  return false;
99  }
Add some data
+ 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 171 of file class.ilChart.php.

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

172  {
173  if (preg_match("/^#[0-9a-f]{3}$/i", $a_value, $match)) {
174  return true;
175  } elseif (preg_match("/^#[0-9a-f]{6}$/i", $a_value, $match)) {
176  return true;
177  }
178  }
+ Here is the caller graph for this function:

◆ isValidDataType()

ilChart::isValidDataType ( ilChartData  $a_series)
abstractprotected

Validate data series.

Returns
bool

Referenced by addData(), and getInstanceByType().

+ Here is the caller graph for this function:

◆ parseGlobalOptions()

ilChart::parseGlobalOptions ( stdClass  $a_options)

Convert (global) properties to flot config.

Parameters
object$a_options

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

Referenced by getHTML().

280  {
281  }
+ 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.

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

188  {
189  if (self::isValidColor($a_value)) {
190  if (strlen($a_value) == 4) {
191  return "rgba(" . hexdec($a_value[1] . $a_value[1]) . ", " .
192  hexdec($a_value[2] . $a_value[2]) . ", " .
193  hexdec($a_value[3] . $a_value[3]) . ", " . $a_opacity . ")";
194  } else {
195  return "rgba(" . hexdec($a_value[1] . $a_value[2]) . ", " .
196  hexdec($a_value[3] . $a_value[4]) . ", " .
197  hexdec($a_value[5] . $a_value[6]) . ", " . $a_opacity . ")";
198  }
199  }
200  }
+ 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 227 of file class.ilChart.php.

228  {
229  $this->auto_resize = (bool) $a_value;
230  }

◆ setColors()

ilChart::setColors (   $a_values)

Set colors.

Parameters
array$a_values

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

147  {
148  foreach ($a_values as $color) {
149  if (self::isValidColor($color)) {
150  $this->colors[] = $color;
151  }
152  }
153  }

◆ setLegend()

ilChart::setLegend ( ilChartLegend  $a_legend)

Set chart legend.

Parameters
ilChartLegend$a_legend

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

Referenced by ilChartPie\parseGlobalOptions().

137  {
138  $this->legend = $a_legend;
139  }
+ Here is the caller graph for this function:

◆ setShadow()

ilChart::setShadow (   $a_value)

Set shadow.

Parameters
int$a_value

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

Referenced by __construct().

208  {
209  $this->shadow = (int) $a_value;
210  }
+ 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 107 of file class.ilChart.php.

108  {
109  $this->width = $a_x;
110  $this->height = $a_y;
111  }

◆ setStacked()

ilChart::setStacked (   $a_value)

Toggle stacking.

Parameters
bool$a_value

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

238  {
239  $this->stacked = (bool) $a_value;
240  }

Field Documentation

◆ $auto_resize

ilChart::$auto_resize
protected

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

◆ $colors

ilChart::$colors
protected

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

Referenced by getColors(), and getHTML().

◆ $data

ilChart::$data
protected

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

Referenced by addData().

◆ $height

ilChart::$height
protected

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

◆ $id

ilChart::$id
protected

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

◆ $legend

ilChart::$legend
protected

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

Referenced by ilChartPie\parseGlobalOptions().

◆ $shadow

ilChart::$shadow
protected

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

Referenced by getShadow().

◆ $stacked

ilChart::$stacked
protected

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

◆ $tpl

ilChart::$tpl
protected

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

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

◆ $width

ilChart::$width
protected

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

◆ TYPE_GRID

◆ TYPE_PIE

const ilChart::TYPE_PIE = 2

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

◆ TYPE_SPIDER

const ilChart::TYPE_SPIDER = 3

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

Referenced by ilPersonalSkillsGUI\getGapAnalysisHTML().


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