ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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

 $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 34 of file class.ilChart.php.

References array, data, and setShadow().

35  {
36  $this->id = $a_id;
37  $this->data = array();
38 
39  $this->setShadow(2);
40  }
Add some data
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 277 of file class.ilChart.php.

Referenced by initJS().

278  {
279 
280  }
+ 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 114 of file class.ilChart.php.

References $data, data, and isValidDataType().

115  {
116  if($this->isValidDataType($a_series))
117  {
118  if($a_idx === null)
119  {
120  $a_idx = sizeof($this->data);
121  }
122  $this->data[$a_idx] = $a_series;
123  return $a_idx;
124  }
125  }
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 158 of file class.ilChart.php.

References $colors.

Referenced by getHTML().

159  {
160  return $this->colors;
161  }
+ 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 295 of file class.ilChart.php.

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

296  {
297  if(!$this->isValid())
298  {
299  return;
300  }
301 
302  $this->initJS();
303 
304  $chart = new ilTemplate("tpl.grid.html", true, true, "Services/Chart");
305  $chart->setVariable("ID", $this->id);
306 
307  if($this->width)
308  {
309  if(is_numeric($this->width))
310  {
311  $chart->setVariable("WIDTH", "width:".$this->width."px;");
312  }
313  else
314  {
315  $chart->setVariable("WIDTH", "width:".$this->width.";");
316  }
317  }
318  if($this->height)
319  {
320  if(is_numeric($this->height))
321  {
322  $chart->setVariable("HEIGHT", "height:".$this->height."px;");
323  }
324  else
325  {
326  $chart->setVariable("HEIGHT", "height:".$this->height.";");
327  }
328  }
329 
330 
331  // (series) data
332 
333  $json_series = array();
334  foreach($this->data as $series)
335  {
336  $series->parseData($json_series);
337  }
338  $chart->setVariable("SERIES", json_encode($json_series));
339 
340 
341  // global options
342 
343  $json_options = new stdClass();
344  $json_options->series = new stdClass();
345  $json_options->series->shadowSize = (int)$this->getShadow();
346  $json_options->series->lines = new stdClass();
347  $json_options->series->lines->show = false;
348  $json_options->series->stack = (bool)$this->stacked;
349 
350  foreach($this->data as $series)
351  {
352  $series->parseGlobalOptions($json_options, $this);
353  }
354 
355  $this->parseGlobalOptions($json_options);
356 
357  $colors = $this->getColors();
358  if($colors)
359  {
360  $json_options->colors = array();
361  foreach($colors as $color)
362  {
363  $json_options->colors[] = self::renderColor($color);
364  }
365  }
366 
367  // legend
368  $json_options->legend = new stdClass();
369  if(!$this->legend)
370  {
371  $json_options->legend->show = false;
372  }
373  else
374  {
375  $this->legend->parseOptions($json_options->legend);
376  }
377 
378  $chart->setVariable("OPTIONS", json_encode($json_options));
379 
380  $ret = $chart->get();
381  return $ret;
382  }
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 49 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().

50  {
51  switch($a_type)
52  {
53  case self::TYPE_GRID:
54  include_once "Services/Chart/classes/class.ilChartGrid.php";
55  return new ilChartGrid($a_id);
56 
57  case self::TYPE_PIE:
58  include_once "Services/Chart/classes/class.ilChartPie.php";
59  return new ilChartPie($a_id);
60 
61  case self::TYPE_SPIDER:
62  include_once "Services/Chart/classes/class.ilChartSpider.php";
63  return new ilChartSpider($a_id);
64  }
65  }
Generator for spider charts.
$a_type
Definition: workflow.php:93
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 222 of file class.ilChart.php.

References $shadow.

Referenced by getHTML().

223  {
224  return $this->shadow;
225  }
+ Here is the caller graph for this function:

◆ initJS()

ilChart::initJS ( )
protected

Init JS script files.

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

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

Referenced by getHTML().

251  {
252  global $tpl;
253 
254  include_once "Services/jQuery/classes/class.iljQueryUtil.php";
256 
257  $tpl->addJavascript("Services/Chart/js/flot/excanvas.min.js");
258  $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.min.js");
259 
260  if((bool)$this->auto_resize)
261  {
262  // #13108
263  $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.resize.min.js");
264  }
265 
266  if((bool)$this->stacked)
267  {
268  $tpl->addJavascript("Services/Chart/js/flot/jquery.flot.stack.min.js");
269  }
270 
271  $this->addCustomJS();
272  }
addCustomJS()
Add type-specific JS script.
global $tpl
Definition: ilias.php:8
static initjQuery($a_tpl=null)
Init jQuery.
+ 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 86 of file class.ilChart.php.

References data.

Referenced by getHTML().

87  {
88  if(sizeof($this->data))
89  {
90  return true;
91  }
92  return false;
93  }
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 169 of file class.ilChart.php.

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

170  {
171  if(preg_match("/^#[0-9a-f]{3}$/i", $a_value, $match))
172  {
173  return true;
174  }
175  else if(preg_match("/^#[0-9a-f]{6}$/i", $a_value, $match))
176  {
177  return true;
178  }
179  }
+ 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 287 of file class.ilChart.php.

Referenced by getHTML().

288  {
289 
290  }
+ 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 188 of file class.ilChart.php.

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

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

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

◆ setColors()

ilChart::setColors (   $a_values)

Set colors.

Parameters
array$a_values

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

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

◆ setLegend()

ilChart::setLegend ( ilChartLegend  $a_legend)

Set chart legend.

Parameters
ilChartLegend$a_legend

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

Referenced by ilChartPie\parseGlobalOptions().

133  {
134  $this->legend = $a_legend;
135  }
+ Here is the caller graph for this function:

◆ setShadow()

ilChart::setShadow (   $a_value)

Set shadow.

Parameters
int$a_value

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

Referenced by __construct().

213  {
214  $this->shadow = (int)$a_value;
215  }
+ 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 101 of file class.ilChart.php.

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

◆ setStacked()

ilChart::setStacked (   $a_value)

Toggle stacking.

Parameters
bool$a_value

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

243  {
244  $this->stacked = (bool)$a_value;
245  }

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().

◆ $stacked

ilChart::$stacked
protected

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

◆ $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 26 of file class.ilChart.php.

◆ TYPE_SPIDER

const ilChart::TYPE_SPIDER = 3

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

Referenced by ilPersonalSkillsGUI\getGapAnalysisHTML().


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