19 declare(strict_types=1);
50 $tpl = $this->
getTemplate(
"tpl.bar_horizontal.html",
true,
true);
55 $tpl->setVariable(
"LIST", $default_renderer->render($a11y_list));
59 $dimensions = $component->getDataset()->getDimensions();
60 $x_labels = json_encode($this->
reformatValueLabels($dimensions[key($dimensions)]->getLabels()));
61 $tooltips = json_encode($component->getDataset()->getAlternativeInformation());
63 $component = $component->withAdditionalOnLoadCode(
64 function (
$id) use ($options,
$data, $x_labels, $tooltips) {
65 return "il.UI.chart.bar.horizontal.init( 75 $tpl->setVariable(
"ID",
$id);
84 $tpl = $this->
getTemplate(
"tpl.bar_vertical.html",
true,
true);
90 $dimensions = $component->getDataset()->getDimensions();
91 $y_labels = json_encode($this->
reformatValueLabels($dimensions[key($dimensions)]->getLabels()));
92 $tooltips = json_encode($component->getDataset()->getAlternativeInformation());
95 $tpl->setVariable(
"LIST", $default_renderer->render($a11y_list));
97 $component = $component->withAdditionalOnLoadCode(
98 function (
$id) use ($options,
$data, $y_labels, $tooltips) {
99 return "il.UI.chart.bar.vertical.init( 109 $tpl->setVariable(
"ID",
$id);
116 $tpl->
setVariable(
"TITLE", $component->getTitle());
130 $item_count = count($component->getDataset()->getPoints());
131 $height = $min_height + ($item_count - 2) * 50;
132 if ($height < $min_height) {
133 $height = $min_height;
135 if ($height > $max_height) {
136 $height = $max_height;
139 return $height .
"px";
147 $height = $min_height + ($data_max / 10) * 50;
148 if ($height > $max_height) {
149 $height = $max_height;
152 return $height .
"px";
160 $points_per_dimension = $component->getDataset()->getPointsPerDimension();
161 $tooltips_per_dimension = $component->getDataset()->getAlternativeInformationPerDimension();
162 $dimensions = $component->getDataset()->getDimensions();
163 $value_labels = $dimensions[key($dimensions)]->getLabels();
167 foreach ($points_per_dimension as $dimension_name => $item_points) {
169 foreach ($item_points as $messeaurement_item_label => $point) {
170 if (isset($tooltips_per_dimension[$dimension_name][$messeaurement_item_label])) {
172 $entries[] = $messeaurement_item_label .
": " . $tooltips_per_dimension[$dimension_name][$messeaurement_item_label];
173 } elseif (is_array($point)) {
176 foreach ($point as $p) {
180 $entries[] = $messeaurement_item_label .
": " .
$range;
181 } elseif (is_null($point)) {
183 $entries[] = $messeaurement_item_label .
": -";
184 } elseif (!empty($value_labels) && is_int($point) && !empty($value_labels[$point - $lowest])) {
186 $entries[] = $messeaurement_item_label .
": " . $value_labels[$point - $lowest];
189 $entries[] = $messeaurement_item_label .
": " . $point;
192 $list_items[$dimension_name] = $ui_fac->listing()->unordered($entries);
195 $list = $ui_fac->listing()->descriptive($list_items);
204 foreach ($component->getDataset()->getDimensions() as $dimension_name => $dimension) {
205 $new_min = floor($component->getDataset()->getMinValueForDimension($dimension_name));
206 if (is_null($min) || $new_min < $min) {
212 $min = $component->getXAxis()->getMinValue() ?? $min;
214 $min = $component->getYAxis()->getMinValue() ?? $min;
224 foreach ($component->getDataset()->getDimensions() as $dimension_name => $dimension) {
225 $new_max = ceil($component->getDataset()->getMaxValueForDimension($dimension_name));
226 if (is_null($max) || $new_max > $max) {
232 $max = $component->getXAxis()->getMaxValue() ?? $max;
234 $max = $component->getYAxis()->getMaxValue() ?? $max;
244 foreach ($labels as $label) {
245 $new_labels[$index] = $label;
255 $options->indexAxis = $component->getIndexAxis();
256 $options->responsive =
true;
257 $options->maintainAspectRatio =
false;
259 $options->plugins->legend =
new stdClass();
260 $options->plugins->legend->display = $component->isLegendVisible();
261 $options->plugins->legend->position = $component->getLegendPosition();
262 $options->plugins->tooltip =
new stdClass();
263 $options->plugins->tooltip->enabled = $component->isTooltipsVisible();
264 $options->plugins->tooltip->callbacks =
new stdClass();
265 $options->plugins->title =
new stdClass();
266 $options->plugins->title->display = $component->isTitleVisible();
267 $options->plugins->title->text = $component->getTitle();
282 $x_axis = $component->getXAxis();
284 $scales->x->axis = $x_axis->getAbbreviation();
285 $scales->x->type = $x_axis->getType();
286 $scales->x->display = $x_axis->isDisplayed();
287 $scales->x->position = $x_axis->getPosition();
288 $scales->x->beginAtZero = $x_axis->isBeginAtZero();
290 $scales->x->ticks->callback =
null;
291 $scales->x->ticks->stepSize = $x_axis->getStepSize();
292 if ($x_axis->getMinValue()) {
293 $scales->x->min = $x_axis->getMinValue();
295 if ($x_axis->getMaxValue()) {
296 $scales->x->max = $x_axis->getMaxValue();
298 $dimension_groups = $component->getDataset()->getDimensionGroups();
299 foreach ($component->getGroupConfigs() as $group_name => $config) {
300 if (!isset($dimension_groups[$group_name]) || !$config->isStacked()) {
303 $scales->y->stacked =
true;
304 $scales->x->stacked =
true;
309 $dimension_scales = $component->getDataset()->getDimensions();
310 foreach ($dimension_scales as $scale_id) {
311 $scales->{get_class($scale_id)} =
new stdClass();
312 $scales->{get_class($scale_id)}->axis =
"y";
313 $scales->{get_class($scale_id)}->display =
false;
323 $y_axis = $component->getYAxis();
325 $scales->y->axis = $y_axis->getAbbreviation();
326 $scales->y->type = $y_axis->getType();
327 $scales->y->display = $y_axis->isDisplayed();
328 $scales->y->position = $y_axis->getPosition();
329 $scales->y->beginAtZero = $y_axis->isBeginAtZero();
331 $scales->y->ticks->callback =
null;
332 $scales->y->ticks->stepSize = $y_axis->getStepSize();
333 if ($y_axis->getMinValue()) {
334 $scales->y->min = $y_axis->getMinValue();
336 if ($y_axis->getMaxValue()) {
337 $scales->y->max = $y_axis->getMaxValue();
339 $dimension_groups = $component->getDataset()->getDimensionGroups();
340 foreach ($component->getGroupConfigs() as $group_name => $config) {
341 if (!isset($dimension_groups[$group_name]) || !$config->isStacked()) {
344 $scales->x->stacked =
true;
345 $scales->y->stacked =
true;
350 $dimension_scales = $component->getDataset()->getDimensions();
351 foreach ($dimension_scales as $scale_id) {
352 $scales->{get_class($scale_id)} =
new stdClass();
353 $scales->{get_class($scale_id)}->axis =
"x";
354 $scales->{get_class($scale_id)}->display =
false;
367 foreach ($user_data as $set) {
369 $datasets[] = $dataset;
371 $data->datasets = $datasets;
372 $data->labels = array_keys($component->getDataset()->getPoints());
379 $points_per_dimension = $component->getDataset()->getPointsPerDimension();
380 $dimensions = $component->getDataset()->getDimensions();
381 $dimension_groups = $component->getDataset()->getDimensionGroups();
382 $bar_configs = $component->getBarConfigs();
383 $group_configs = $component->getGroupConfigs();
385 $stacking_groups = [];
387 foreach ($group_configs as $group_name => $config) {
388 if (!isset($dimension_groups[$group_name]) || !$config->isStacked()) {
391 foreach ($dimension_groups[$group_name]->getDimensionKeys() as $dimension_name) {
392 $stacking_groups[$dimension_name] = $group_name;
396 foreach ($points_per_dimension as $dimension_name => $item_points) {
397 $data[$dimension_name][
"label"] = $dimension_name;
398 if (isset($bar_configs[$dimension_name]) && $bar_configs[$dimension_name]->getColor()) {
399 $data[$dimension_name][
"backgroundColor"] = $bar_configs[$dimension_name]->getColor()->asHex();
401 if (isset($bar_configs[$dimension_name]) && $bar_configs[$dimension_name]->getRelativeWidth()) {
402 $data[$dimension_name][
"barPercentage"] = $bar_configs[$dimension_name]->getRelativeWidth();
404 if (isset($stacking_groups[$dimension_name])) {
405 $data[$dimension_name][
"stack"] = $stacking_groups[$dimension_name];
408 $points_as_objects = [];
410 foreach ($item_points as $y_point => $x_point) {
413 $datasets->data->y = $y_point;
414 $datasets->data->x = $x_point;
415 $points_as_objects[] = $datasets->data;
417 $data[$dimension_name][
"data"] = $points_as_objects;
418 $data[$dimension_name][
"yAxisID"] = get_class($dimensions[$dimension_name]);
420 foreach ($item_points as $x_point => $y_point) {
423 $datasets->data->x = $x_point;
424 $datasets->data->y = $y_point;
425 $points_as_objects[] = $datasets->data;
427 $data[$dimension_name][
"data"] = $points_as_objects;
428 $data[$dimension_name][
"xAxisID"] = get_class($dimensions[$dimension_name]);
440 parent::registerResources($registry);
441 $registry->
register(
'assets/js/chart.umd.js');
442 $registry->
register(
'assets/js/bar.js');
Registry for resources required by rendered output like Javascript or CSS.
renderHorizontal(Bar\Horizontal $component, RendererInterface $default_renderer)
getHighestValueOfChart(Bar\Bar $component)
getLowestValueOfChart(Bar\Bar $component)
getParsedOptionsForHorizontal(Bar\Bar $component)
reformatValueLabels(array $labels)
renderVertical(Bar\Vertical $component, RendererInterface $default_renderer)
determineHeightForVertical(Bar\Bar $component)
setVariable(string $name, $value)
Set a variable in the current block.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
renderBasics(Bar\Bar $component, Template $tpl)
getParsedOptions(Bar\Bar $component)
getTemplate(string $name, bool $purge_unfilled_vars, bool $purge_unused_blocks)
Get template of component this renderer is made for.
registerResources(ResourceRegistry $registry)
Announce resources this renderer requires.
cannotHandleComponent(Component $component)
This method MUST be called by derived component renderers, if.
getAccessibilityList(Bar\Bar $component)
register(string $name)
Add a dependency.
getParsedData(Bar\Bar $component)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getUserData(Bar\Bar $component)
render(Component\Component $component, RendererInterface $default_renderer)
getUIFactory()
Get a UI factory.
getParsedOptionsForVertical(Bar\Bar $component)
determineHeightForHorizontal(Bar\Bar $component)
Base class for all component renderers.
bindJavaScript(JavaScriptBindable $component)
Bind the component to JavaScript.