ILIAS  release_8 Revision v8.24
Bar.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
24use ILIAS\UI\Implementation\Component\ComponentHelper;
29
30class Bar implements C\Chart\Bar\Bar
31{
32 use ComponentHelper;
34
35 protected const ALLOWED_POSITIONS = ["top", "bottom", "left", "right"];
36
37 protected string $title;
38 protected Dataset $dataset;
42 protected array $bar_configs;
43 protected bool $title_visible = true;
44 protected bool $legend_visible = true;
45 protected string $legend_position = "top";
46 protected bool $tooltips_visible = true;
47
48 public function __construct(string $title, Dataset $dataset, array $bar_configs = [])
49 {
50 $this->title = $title;
51 if ($dataset->isEmpty()) {
52 throw new \LogicException(
53 "Dataset must not be empty."
54 );
55 } else {
56 foreach ($dataset->getDimensions() as $dimension) {
57 if (!$dimension instanceof CardinalDimension &&
58 !$dimension instanceof RangeDimension
59 ) {
60 throw new \InvalidArgumentException(
61 "Expected parameter to be a CardinalDimension or RangeDimension."
62 );
63 }
64 }
65 $this->dataset = $dataset;
66 }
67 $this->bar_configs = $bar_configs;
68 }
69
70 public function withTitle(string $title): self
71 {
72 $clone = clone $this;
73 $clone->title = $title;
74 return $clone;
75 }
76
77 public function getTitle(): string
78 {
79 return $this->title;
80 }
81
82 public function withDataset(Dataset $dataset): self
83 {
84 $clone = clone $this;
85 $clone->dataset = $dataset;
86 return $clone;
87 }
88
89 public function getDataset(): Dataset
90 {
91 return $this->dataset;
92 }
93
94 public function withBarConfigs(array $bar_configs): self
95 {
96 $clone = clone $this;
97 $clone->bar_configs = $bar_configs;
98 return $clone;
99 }
100
101 public function getBarConfigs(): array
102 {
103 return $this->bar_configs;
104 }
105
106 public function withTitleVisible(bool $title_visible): self
107 {
108 $clone = clone $this;
109 $clone->title_visible = $title_visible;
110 return $clone;
111 }
112
113 public function isTitleVisible(): bool
114 {
115 return $this->title_visible;
116 }
117
118 public function withLegendVisible(bool $legend_visible): self
119 {
120 $clone = clone $this;
121 $clone->legend_visible = $legend_visible;
122 return $clone;
123 }
124
125 public function isLegendVisible(): bool
126 {
127 return $this->legend_visible;
128 }
129
130 public function withLegendPosition(string $legend_position): self
131 {
132 if (!in_array($legend_position, self::ALLOWED_POSITIONS)) {
133 throw new \InvalidArgumentException(
134 "Position must be 'bottom', 'top', 'left' or 'right'."
135 );
136 }
137 $clone = clone $this;
138 $clone->legend_position = $legend_position;
139 return $clone;
140 }
141
142 public function getLegendPosition(): string
143 {
144 return $this->legend_position;
145 }
146
147 public function withTooltipsVisible(bool $tooltips_visible): self
148 {
149 $clone = clone $this;
150 $clone->tooltips_visible = $tooltips_visible;
151 return $clone;
152 }
153
154 public function isTooltipsVisible(): bool
155 {
156 return $this->tooltips_visible;
157 }
158}
withLegendPosition(string $legend_position)
Definition: Bar.php:130
withTooltipsVisible(bool $tooltips_visible)
Definition: Bar.php:147
__construct(string $title, Dataset $dataset, array $bar_configs=[])
Definition: Bar.php:48
withLegendVisible(bool $legend_visible)
Definition: Bar.php:118
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...
Definition: Bar.php:21
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.