ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Bar.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
29 
30 class 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;
46  protected array $group_configs;
47  protected bool $title_visible = true;
48  protected bool $legend_visible = true;
49  protected string $legend_position = "top";
50  protected bool $tooltips_visible = true;
51 
52  public function __construct(string $title, Dataset $dataset, array $bar_configs = [], array $group_configs = [])
53  {
54  $this->title = $title;
55  if ($dataset->isEmpty()) {
56  throw new \LogicException(
57  "Dataset must not be empty."
58  );
59  } else {
60  foreach ($dataset->getDimensions() as $dimension) {
61  if (!$dimension instanceof CardinalDimension &&
62  !$dimension instanceof RangeDimension
63  ) {
64  throw new \InvalidArgumentException(
65  "Expected parameter to be a CardinalDimension or RangeDimension."
66  );
67  }
68  }
69  $this->dataset = $dataset;
70  }
71  $this->bar_configs = $bar_configs;
72  $this->group_configs = $group_configs;
73  }
74 
75  public function withTitle(string $title): self
76  {
77  $clone = clone $this;
78  $clone->title = $title;
79  return $clone;
80  }
81 
82  public function getTitle(): string
83  {
84  return $this->title;
85  }
86 
87  public function withDataset(Dataset $dataset): self
88  {
89  $clone = clone $this;
90  $clone->dataset = $dataset;
91  return $clone;
92  }
93 
94  public function getDataset(): Dataset
95  {
96  return $this->dataset;
97  }
98 
99  public function withBarConfigs(array $bar_configs): self
100  {
101  $clone = clone $this;
102  $clone->bar_configs = $bar_configs;
103  return $clone;
104  }
105 
106  public function getBarConfigs(): array
107  {
108  return $this->bar_configs;
109  }
110 
111  public function withGroupConfigs(array $group_configs): self
112  {
113  $clone = clone $this;
114  $clone->group_configs = $group_configs;
115  return $clone;
116  }
117 
118  public function getGroupConfigs(): array
119  {
120  return $this->group_configs;
121  }
122 
123  public function withTitleVisible(bool $title_visible): self
124  {
125  $clone = clone $this;
126  $clone->title_visible = $title_visible;
127  return $clone;
128  }
129 
130  public function isTitleVisible(): bool
131  {
132  return $this->title_visible;
133  }
134 
135  public function withLegendVisible(bool $legend_visible): self
136  {
137  $clone = clone $this;
138  $clone->legend_visible = $legend_visible;
139  return $clone;
140  }
141 
142  public function isLegendVisible(): bool
143  {
144  return $this->legend_visible;
145  }
146 
147  public function withLegendPosition(string $legend_position): self
148  {
149  if (!in_array($legend_position, self::ALLOWED_POSITIONS)) {
150  throw new \InvalidArgumentException(
151  "Position must be 'bottom', 'top', 'left' or 'right'."
152  );
153  }
154  $clone = clone $this;
155  $clone->legend_position = $legend_position;
156  return $clone;
157  }
158 
159  public function getLegendPosition(): string
160  {
161  return $this->legend_position;
162  }
163 
164  public function withTooltipsVisible(bool $tooltips_visible): self
165  {
166  $clone = clone $this;
167  $clone->tooltips_visible = $tooltips_visible;
168  return $clone;
169  }
170 
171  public function isTooltipsVisible(): bool
172  {
174  }
175 }
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
withGroupConfigs(array $group_configs)
Definition: Bar.php:111
withLegendVisible(bool $legend_visible)
Definition: Bar.php:135
__construct(string $title, Dataset $dataset, array $bar_configs=[], array $group_configs=[])
Definition: Bar.php:52
withLegendPosition(string $legend_position)
Definition: Bar.php:147
withTooltipsVisible(bool $tooltips_visible)
Definition: Bar.php:164