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