ILIAS  release_8 Revision v8.24
class.ilChartData.php
Go to the documentation of this file.
1<?php
2
20abstract class ilChartData
21{
22 protected string $type = "";
23 protected string $label = "";
24 protected array $data = [];
25 protected float $fill = 0;
26 protected string $fill_color = "";
27 protected bool $hidden = false;
28
29 abstract protected function getTypeString(): string;
30
31 public function setHidden(bool $a_value): void
32 {
33 $this->hidden = $a_value;
34 }
35
36 public function isHidden(): bool
37 {
38 return $this->hidden;
39 }
40
41 public function setLabel(string $a_value): void
42 {
43 $this->label = $a_value;
44 }
45
46 public function getLabel(): string
47 {
48 return $this->label;
49 }
50
57 public function addPoint(
58 float $a_x,
59 ?float $a_y = null
60 ): void {
61 if ($a_y !== null) {
62 $this->data[] = array($a_x, $a_y);
63 } else {
64 $this->data[] = $a_x;
65 }
66 }
67
73 public function getData(): array
74 {
75 return $this->data;
76 }
77
78 public function setFill(
79 float $a_value,
80 string $a_color = ""
81 ): void {
82 $this->fill = $a_value;
83 if (ilChart::isValidColor($a_color)) {
84 $this->fill_color = $a_color;
85 }
86 }
87
88 public function getFill(): array
89 {
90 return array("fill" => $this->fill, "color" => $this->fill_color);
91 }
92
96 protected function parseDataOptions(array &$a_options): void
97 {
98 }
99
103 public function parseData(array &$a_data): void
104 {
105 $series = new stdClass();
106 $series->label = str_replace("\"", "\\\"", $this->getLabel());
107
108 $series->data = array();
109 foreach ($this->getData() as $point) {
110 if (is_array($point)) {
111 $series->data[] = array($point[0], $point[1]);
112 } else {
113 $series->data[] = $point;
114 }
115 }
116
117 $options = array("show" => !$this->isHidden());
118
119 $fill = $this->getFill();
120 if ($fill["fill"]) {
121 $options["fill"] = $fill["fill"];
122 if ($fill["color"]) {
123 $options["fillColor"] = ilChart::renderColor($fill["color"], $fill["fill"]);
124 }
125 }
126
127 $this->parseDataOptions($options);
128
129 $series->{$this->getTypeString()} = $options;
130
131 $a_data[] = $series;
132 }
133
137 public function parseGlobalOptions(stdClass $a_options, ilChart $a_chart): void
138 {
139 }
140}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addPoint(float $a_x, ?float $a_y=null)
Set data.
parseData(array &$a_data)
Convert data to flot config.
setLabel(string $a_value)
parseDataOptions(array &$a_options)
Convert data options to flot config.
parseGlobalOptions(stdClass $a_options, ilChart $a_chart)
Convert (global) properties to flot config.
getData()
Get data.
setHidden(bool $a_value)
setFill(float $a_value, string $a_color="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static renderColor(string $a_value, float $a_opacity=1)
Render html color code.
static isValidColor(string $a_value)
Validate html color code.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20