ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 20 of file class.ilChart.php.

Constructor & Destructor Documentation

◆ __construct()

ilChart::__construct ( string  $a_id)
protected

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

References $DIC, and setShadow().

38  {
39  global $DIC;
40 
41  $this->tpl = $DIC["tpl"];
42  $this->id = $a_id;
43  $this->data = array();
44 
45  $this->setShadow(2);
46  }
setShadow(int $a_value)
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomJS()

ilChart::addCustomJS ( )
protected

Add type-specific JS script.

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

Referenced by initJS().

216  : void
217  {
218  }
+ Here is the caller graph for this function:

◆ addData()

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

Add data series.

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

References $data, and isValidDataType().

101  : ?int {
102  if ($this->isValidDataType($a_series)) {
103  if ($a_idx === null) {
104  $a_idx = sizeof($this->data);
105  }
106  $this->data[$a_idx] = $a_series;
107  return $a_idx;
108  }
109  return null;
110  }
array $data
isValidDataType(ilChartData $a_series)
Validate data series.
+ Here is the call graph for this function:

◆ getColors()

ilChart::getColors ( )

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

References $colors.

Referenced by getHTML().

126  : array
127  {
128  return $this->colors;
129  }
array $colors
+ Here is the caller graph for this function:

◆ getDataInstance()

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

Get data series instance.

Referenced by getInstanceByType().

+ Here is the caller graph for this function:

◆ getHTML()

ilChart::getHTML ( )

Render.

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

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

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

◆ getInstanceByType()

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

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

References getDataInstance(), and isValidDataType().

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

51  : ilChart {
52  switch ($a_type) {
53  case self::TYPE_GRID:
54  return new ilChartGrid($a_id);
55 
56  case self::TYPE_PIE:
57  return new ilChartPie($a_id);
58 
59  case self::TYPE_SPIDER:
60  return new ilChartSpider($a_id);
61  }
62  throw new ilException("Unknown chart type.");
63  }
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...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getShadow()

ilChart::getShadow ( )

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

References $shadow.

Referenced by getHTML().

170  : int
171  {
172  return $this->shadow;
173  }
+ Here is the caller graph for this function:

◆ initJS()

ilChart::initJS ( )
protected

Init JS script files.

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

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

Referenced by getHTML().

192  : void
193  {
194  $tpl = $this->tpl;
195 
197 
198  $tpl->addJavaScript("Services/Chart/js/flot/excanvas.min.js");
199  $tpl->addJavaScript("Services/Chart/js/flot/jquery.flot.min.js");
200 
201  if ($this->auto_resize) {
202  // #13108
203  $tpl->addJavaScript("Services/Chart/js/flot/jquery.flot.resize.min.js");
204  }
205 
206  if ($this->stacked) {
207  $tpl->addJavaScript("Services/Chart/js/flot/jquery.flot.stack.min.js");
208  }
209 
210  $this->addCustomJS();
211  }
addCustomJS()
Add type-specific JS script.
ilGlobalTemplateInterface $tpl
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.
static initjQuery(ilGlobalTemplateInterface $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.

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

Referenced by getHTML().

78  : bool
79  {
80  if (sizeof($this->data)) {
81  return true;
82  }
83  return false;
84  }
+ Here is the caller graph for this function:

◆ isValidColor()

static ilChart::isValidColor ( string  $a_value)
static

Validate html color code.

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

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

134  : bool
135  {
136  if (preg_match("/^#[0-9a-f]{3}$/i", $a_value, $match)) {
137  return true;
138  } elseif (preg_match("/^#[0-9a-f]{6}$/i", $a_value, $match)) {
139  return true;
140  }
141  return false;
142  }
+ Here is the caller graph for this function:

◆ isValidDataType()

ilChart::isValidDataType ( ilChartData  $a_series)
abstractprotected

Validate data series.

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.

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

Referenced by getHTML().

223  : void
224  {
225  }
+ Here is the caller graph for this function:

◆ renderColor()

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

Render html color code.

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

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

150  : string {
151  if (self::isValidColor($a_value)) {
152  if (strlen($a_value) == 4) {
153  return "rgba(" . hexdec($a_value[1] . $a_value[1]) . ", " .
154  hexdec($a_value[2] . $a_value[2]) . ", " .
155  hexdec($a_value[3] . $a_value[3]) . ", " . $a_opacity . ")";
156  } else {
157  return "rgba(" . hexdec($a_value[1] . $a_value[2]) . ", " .
158  hexdec($a_value[3] . $a_value[4]) . ", " .
159  hexdec($a_value[5] . $a_value[6]) . ", " . $a_opacity . ")";
160  }
161  }
162  return "";
163  }
+ Here is the caller graph for this function:

◆ setAutoResize()

ilChart::setAutoResize ( bool  $a_value)

Toggle auto-resizing on window resize/redraw.

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

180  : void {
181  $this->auto_resize = $a_value;
182  }

◆ setColors()

ilChart::setColors ( array  $a_values)

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

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

◆ setLegend()

ilChart::setLegend ( ilChartLegend  $a_legend)

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

Referenced by ilChartPie\parseGlobalOptions().

112  : void
113  {
114  $this->legend = $a_legend;
115  }
+ Here is the caller graph for this function:

◆ setShadow()

ilChart::setShadow ( int  $a_value)

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

Referenced by __construct().

165  : void
166  {
167  $this->shadow = $a_value;
168  }
+ Here is the caller graph for this function:

◆ setSize()

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

Set chart size.

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

89  : void
90  {
91  $this->width = $a_x;
92  $this->height = $a_y;
93  }

◆ setStacked()

ilChart::setStacked ( bool  $a_value)

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

184  : void
185  {
186  $this->stacked = $a_value;
187  }

Field Documentation

◆ $auto_resize

bool ilChart::$auto_resize = false
protected

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

◆ $colors

array ilChart::$colors = []
protected

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

Referenced by getColors().

◆ $data

array ilChart::$data = []
protected

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

Referenced by addData().

◆ $height

string ilChart::$height = ""
protected

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

◆ $id

string ilChart::$id = ""
protected

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

◆ $legend

ilChartLegend ilChart::$legend = null
protected

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

Referenced by ilChartPie\parseGlobalOptions().

◆ $shadow

int ilChart::$shadow = 0
protected

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

Referenced by getShadow().

◆ $stacked

bool ilChart::$stacked = false
protected

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

Referenced by getHTML().

◆ $tpl

ilGlobalTemplateInterface ilChart::$tpl
protected

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

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

◆ $width

string ilChart::$width = ""
protected

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

◆ TYPE_GRID

◆ TYPE_PIE

const ilChart::TYPE_PIE = 2

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

Referenced by ilPollBlockGUI\fillRow().

◆ TYPE_SPIDER

const ilChart::TYPE_SPIDER = 3

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


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