ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilChartData.php
Go to the documentation of this file.
1 <?php
2 
23 abstract class ilChartData
24 {
25  protected string $type = "";
26  protected string $label = "";
27  protected array $data = [];
28  protected float $fill = 0;
29  protected string $fill_color = "";
30  protected bool $hidden = false;
31 
32  abstract protected function getTypeString(): string;
33 
34  public function setHidden(bool $a_value): void
35  {
36  $this->hidden = $a_value;
37  }
38 
39  public function isHidden(): bool
40  {
41  return $this->hidden;
42  }
43 
44  public function setLabel(string $a_value): void
45  {
46  $this->label = $a_value;
47  }
48 
49  public function getLabel(): string
50  {
51  return $this->label;
52  }
53 
60  public function addPoint(
61  float $a_x,
62  ?float $a_y = null
63  ): void {
64  if ($a_y !== null) {
65  $this->data[] = array($a_x, $a_y);
66  } else {
67  $this->data[] = $a_x;
68  }
69  }
70 
76  public function getData(): array
77  {
78  return $this->data;
79  }
80 
81  public function setFill(
82  float $a_value,
83  string $a_color = ""
84  ): void {
85  $this->fill = $a_value;
86  if (ilChart::isValidColor($a_color)) {
87  $this->fill_color = $a_color;
88  }
89  }
90 
91  public function getFill(): array
92  {
93  return array("fill" => $this->fill, "color" => $this->fill_color);
94  }
95 
99  protected function parseDataOptions(array &$a_options): void
100  {
101  }
102 
106  public function parseData(array &$a_data): void
107  {
108  $series = new stdClass();
109  $series->label = str_replace("\"", "\\\"", $this->getLabel());
110 
111  $series->data = array();
112  foreach ($this->getData() as $point) {
113  if (is_array($point)) {
114  $series->data[] = array($point[0], $point[1]);
115  } else {
116  $series->data[] = $point;
117  }
118  }
119 
120  $options = array("show" => !$this->isHidden());
121 
122  $fill = $this->getFill();
123  if ($fill["fill"]) {
124  $options["fill"] = $fill["fill"];
125  if ($fill["color"]) {
126  $options["fillColor"] = ilChart::renderColor($fill["color"], $fill["fill"]);
127  }
128  }
129 
130  $this->parseDataOptions($options);
131 
132  $series->{$this->getTypeString()} = $options;
133 
134  $a_data[] = $series;
135  }
136 
140  public function parseGlobalOptions(stdClass $a_options, ilChart $a_chart): void
141  {
142  }
143 }
addPoint(float $a_x, ?float $a_y=null)
Set data.
setHidden(bool $a_value)
parseGlobalOptions(stdClass $a_options, ilChart $a_chart)
Convert (global) properties to flot config.
static isValidColor(string $a_value)
Validate html color code.
getData()
Get data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFill(float $a_value, string $a_color="")
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
parseData(array &$a_data)
Convert data to flot config.
parseDataOptions(array &$a_options)
Convert data options to flot config.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLabel(string $a_value)
static renderColor(string $a_value, float $a_opacity=1)
Render html color code.