ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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

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

References setShadow().

34  {
35  $this->id = $a_id;
36  $this->data = array();
37 
38  $this->setShadow(2);
39  }
setShadow($a_value)
Set shadow.
+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomJS()

ilChart::addCustomJS ( )
protected

Add type-specific JS script.

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

Referenced by initJS().

262  {
263 
264  }
+ 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.

References $data, and isValidDataType().

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.
+ Here is the call graph for this function:

◆ getColors()

ilChart::getColors ( )

Get colors.

Returns
array

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

References $colors.

Referenced by getHTML().

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

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

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  }
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.
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 48 of file class.ilChart.php.

References getDataInstance(), and isValidDataType().

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

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 
60  case self::TYPE_SPIDER:
61  include_once "Services/Chart/classes/class.ilChartSpider.php";
62  return new ilChartSpider($a_id);
63  }
64  }
Generator for spider charts.
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 221 of file class.ilChart.php.

References $shadow.

Referenced by getHTML().

222  {
223  return $this->shadow;
224  }
+ 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.

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

Referenced by getHTML().

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  }
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 85 of file class.ilChart.php.

Referenced by getHTML().

86  {
87  if(sizeof($this->data))
88  {
89  return true;
90  }
91  return false;
92  }
+ 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.

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

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

Referenced by getHTML().

272  {
273 
274  }
+ 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  {
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  }
+ 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.

Referenced by ilChartPie\parseGlobalOptions().

132  {
133  $this->legend = $a_legend;
134  }
+ 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.

Referenced by __construct().

212  {
213  $this->shadow = (int)$a_value;
214  }
+ 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.

◆ TYPE_SPIDER

const ilChart::TYPE_SPIDER = 3

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

Referenced by ilPersonalSkillsGUI\getGapAnalysisHTML().


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