ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilChartDataPie.php
Go to the documentation of this file.
1 <?php
2 
21 {
22  protected int $line_width = 0;
23  protected float $label_radius = 0;
24 
25  protected function getTypeString(): string
26  {
27  return "pie";
28  }
29 
30  public function setLineWidth(int $a_value): void
31  {
32  $this->line_width = $a_value;
33  }
34 
35  public function getLineWidth(): int
36  {
37  return $this->line_width;
38  }
39 
45  public function setLabelRadius(float $a_value): void
46  {
47  $this->label_radius = $a_value;
48  }
49 
50  public function getLabelRadius(): float
51  {
52  return $this->label_radius;
53  }
54 
55  public function addPiePoint(int $a_value, string $a_caption = null): void
56  {
57  $this->data[] = array($a_value, $a_caption);
58  }
59 
60  public function parseData(array &$a_data): void
61  {
62  foreach ($this->data as $slice) {
63  $series = new stdClass();
64  $series->label = str_replace("\"", "\\\"", $slice[1]);
65 
66  // add percentage to legend
67  if (!$this->getLabelRadius()) {
68  $series->label .= " (" . $slice[0] . "%)";
69  }
70 
71  $series->data = $slice[0];
72 
73  $options = array("show" => !$this->isHidden());
74 
75  $series->{$this->getTypeString()} = $options;
76 
77  $a_data[] = $series;
78  }
79  }
80 
81  public function parseGlobalOptions(stdClass $a_options, ilChart $a_chart): void
82  {
83  $a_options->series->pie = new stdClass();
84  $a_options->series->pie->show = true;
85 
86  // fill vs. stroke - trying to normalize data attributes
87 
88  $fill = $this->getFill();
89  $width = $this->getLineWidth();
90  if ($fill["fill"] || $width) {
91  $a_options->series->pie->stroke = new stdClass();
92  if ($width) {
93  $a_options->series->pie->stroke->width = $width;
94  }
95  if ($fill["color"]) {
96  $a_options->series->pie->stroke->color = ilChart::renderColor($fill["color"], $fill["fill"]);
97  }
98  }
99 
100  $radius = $this->getLabelRadius();
101  if ($radius) {
102  $a_options->series->pie->label = new stdClass();
103  $a_options->series->pie->label->background = new stdClass();
104  $a_options->series->pie->radius = 1;
105  $a_options->series->pie->label->radius = $radius;
106  $a_options->series->pie->label->show = true;
107  $a_options->series->pie->label->background->color = "#444";
108  $a_options->series->pie->label->background->opacity = 0.8;
109  }
110  }
111 }
setLabelRadius(float $a_value)
Sets the radius at which to place the labels.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addPiePoint(int $a_value, string $a_caption=null)
setLineWidth(int $a_value)
parseData(array &$a_data)
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...
static renderColor(string $a_value, float $a_opacity=1)
Render html color code.
parseGlobalOptions(stdClass $a_options, ilChart $a_chart)