ILIAS  release_8 Revision v8.24
class.ilChartGrid.php
Go to the documentation of this file.
1<?php
2
20class ilChartGrid extends ilChart
21{
22 public const DATA_LINES = 1;
23 public const DATA_BARS = 2;
24 public const DATA_POINTS = 3;
25
26 protected array $ticks;
27 protected array $integer_axis;
28
29 protected function __construct(string $a_id)
30 {
32
33 $this->setXAxisToInteger(false);
34 $this->setYAxisToInteger(false);
35 }
36
37 public function getDataInstance(int $a_type = null): ilChartData
38 {
39 switch ($a_type) {
40 case self::DATA_BARS:
41 return new ilChartDataBars();
42
44 return new ilChartDataPoints();
45
46 default:
48 return new ilChartDataLines();
49 }
50 }
51
52 protected function isValidDataType(ilChartData $a_series): bool
53 {
54 if ($a_series instanceof ilChartDataLines
55 || $a_series instanceof ilChartDataBars
56 || $a_series instanceof ilChartDataPoints) {
57 return true;
58 }
59 return false;
60 }
61
68 public function setTicks($a_x, $a_y, bool $a_labeled = false): void
69 {
70 $this->ticks = array("x" => $a_x, "y" => $a_y, "labeled" => $a_labeled);
71 }
72
77 public function getTicks(): array
78 {
79 return $this->ticks;
80 }
81
85 public function setYAxisToInteger(bool $a_status): void
86 {
87 $this->integer_axis["y"] = $a_status;
88 }
89
93 public function setXAxisToInteger(bool $a_status): void
94 {
95 $this->integer_axis["x"] = $a_status;
96 }
97
98 public function parseGlobalOptions(stdClass $a_options): void
99 {
100 // axis/ticks
101 $tmp = array();
102 $ticks = $this->getTicks();
103 if ($ticks) {
104 $labeled = (bool) $ticks["labeled"];
105 unset($ticks["labeled"]);
106 foreach ($ticks as $axis => $def) {
107 if (is_numeric($def) || is_array($def)) {
108 $a_options->{$axis . "axis"} = new stdClass();
109 }
110 if (is_numeric($def)) {
111 $a_options->{$axis . "axis"}->ticks = $def;
112 } elseif (is_array($def)) {
113 $a_options->{$axis . "axis"}->ticks = array();
114 foreach ($def as $idx => $value) {
115 if ($labeled) {
116 $a_options->{$axis . "axis"}->ticks[] = array($idx, $value);
117 } else {
118 $a_options->{$axis . "axis"}->ticks[] = $value;
119 }
120 }
121 }
122 }
123 }
124
125 // optional: remove decimals
126 if ($this->integer_axis["x"] && !isset($a_options->xaxis)) {
127 $a_options->{"xaxis"} = new stdClass();
128 $a_options->{"xaxis"}->tickDecimals = 0;
129 }
130 if ($this->integer_axis["y"] && !isset($a_options->yaxis)) {
131 $a_options->{"yaxis"} = new stdClass();
132 $a_options->{"yaxis"}->tickDecimals = 0;
133 }
134 }
135}
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isValidDataType(ilChartData $a_series)
Validate data series.
getTicks()
Get ticks.
__construct(string $a_id)
setYAxisToInteger(bool $a_status)
Restrict y-axis to integer values.
setXAxisToInteger(bool $a_status)
Restrict x-axis to integer values.
setTicks($a_x, $a_y, bool $a_labeled=false)
Set ticks.
parseGlobalOptions(stdClass $a_options)
Convert (global) properties to flot config.
getDataInstance(int $a_type=null)
Get data series instance.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc