ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChartGrid.php
Go to the documentation of this file.
1<?php
2
23class ilChartGrid extends ilChart
24{
25 public const DATA_LINES = 1;
26 public const DATA_BARS = 2;
27 public const DATA_POINTS = 3;
28
29 protected array $ticks;
30 protected array $integer_axis;
31
32 protected function __construct(string $a_id)
33 {
35
36 $this->setXAxisToInteger(false);
37 $this->setYAxisToInteger(false);
38 }
39
40 public function getDataInstance(?int $a_type = null): ilChartData
41 {
42 switch ($a_type) {
43 case self::DATA_BARS:
44 return new ilChartDataBars();
45
47 return new ilChartDataPoints();
48
49 default:
51 return new ilChartDataLines();
52 }
53 }
54
55 protected function isValidDataType(ilChartData $a_series): bool
56 {
57 if ($a_series instanceof ilChartDataLines
58 || $a_series instanceof ilChartDataBars
59 || $a_series instanceof ilChartDataPoints) {
60 return true;
61 }
62 return false;
63 }
64
71 public function setTicks($a_x, $a_y, bool $a_labeled = false): void
72 {
73 $this->ticks = array("x" => $a_x, "y" => $a_y, "labeled" => $a_labeled);
74 }
75
80 public function getTicks(): array
81 {
82 return $this->ticks;
83 }
84
88 public function setYAxisToInteger(bool $a_status): void
89 {
90 $this->integer_axis["y"] = $a_status;
91 }
92
96 public function setXAxisToInteger(bool $a_status): void
97 {
98 $this->integer_axis["x"] = $a_status;
99 }
100
101 public function parseGlobalOptions(stdClass $a_options): void
102 {
103 // axis/ticks
104 $tmp = array();
105 $ticks = $this->getTicks();
106 if ($ticks) {
107 $labeled = (bool) $ticks["labeled"];
108 unset($ticks["labeled"]);
109 foreach ($ticks as $axis => $def) {
110 if (is_numeric($def) || is_array($def)) {
111 $a_options->{$axis . "axis"} = new stdClass();
112 }
113 if (is_numeric($def)) {
114 $a_options->{$axis . "axis"}->ticks = $def;
115 } elseif (is_array($def)) {
116 $a_options->{$axis . "axis"}->ticks = array();
117 foreach ($def as $idx => $value) {
118 if ($labeled) {
119 $a_options->{$axis . "axis"}->ticks[] = array($idx, $value);
120 } else {
121 $a_options->{$axis . "axis"}->ticks[] = $value;
122 }
123 }
124 }
125 }
126 }
127
128 // optional: remove decimals
129 if ($this->integer_axis["x"] && !isset($a_options->xaxis)) {
130 $a_options->{"xaxis"} = new stdClass();
131 $a_options->{"xaxis"}->tickDecimals = 0;
132 }
133 if ($this->integer_axis["y"] && !isset($a_options->yaxis)) {
134 $a_options->{"yaxis"} = new stdClass();
135 $a_options->{"yaxis"}->tickDecimals = 0;
136 }
137 }
138}
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