19 declare(strict_types=1);
70 int $presentation_mode
83 $votes_label = $this->
lng->txt(
'poll_chart_votes');
84 $c_dimension = $this->data_factory->dimension()->cardinal();
97 $dimensions[$label] = $c_dimension;
98 $data_values[$label] = $total_votes;
99 $bar_configs[$label] = $bar_config->withColor(
100 $this->data_factory->color(self::STACKED_BAR_COLORS[$color_index])
101 )->withRelativeWidth(self::STACKED_BAR_WIDTH);
102 $tooltips[$label] = $tooltip;
104 $color_index = ($color_index + 1) >= count(self::STACKED_BAR_COLORS) ? 0 : ($color_index + 1);
107 $dimension_group = $this->data_factory->dimension()->group();
108 $dataset = $this->data_factory->dataset(
110 [
'stacked' => $this->data_factory->dimension()->group(...array_keys($dimensions))]
114 )->withAlternativeInformation(
120 $group_config = $group_config->withStacked(
true);
121 $chart = $this->ui_factory->chart()->bar()->horizontal(
'', $dataset)
122 ->withTitleVisible(
false)
123 ->withLegendVisible(
true)
124 ->withBarConfigs($bar_configs)
125 ->withGroupConfigs([
'stacked' => $group_config]);
126 $tpl->
setVariable(
'CHART', $this->ui_renderer->render($chart));
133 $votes_label = $this->
lng->txt(
'poll_chart_votes');
134 $c_dimension = $this->data_factory->dimension()->cardinal();
135 $dataset = $this->data_factory->dataset([$votes_label => $c_dimension]);
141 $dataset = $dataset->withPoint($label, [$votes_label => $total_votes])
142 ->withAlternativeInformation($label, [$votes_label => $tooltip]);
146 $bar_config = $bar_config->withColor($this->data_factory->color(self::SINGLE_BAR_COLOR))
147 ->withRelativeWidth(self::SINGLE_BAR_WIDTH);
148 $chart = $this->ui_factory->chart()->bar()->horizontal(
'', $dataset)
149 ->withTitleVisible(
false)
150 ->withLegendVisible(
false)
151 ->withBarConfigs([$votes_label => $bar_config]);
152 $tpl->
setVariable(
'CHART', $this->ui_renderer->render($chart));
157 return $this->
refinery->encode()->htmlSpecialCharsAsEntities()->transform(nl2br($string));
const string SINGLE_BAR_COLOR
const int SHOW_RESULTS_AS_STACKED_CHART
const float SINGLE_BAR_WIDTH
setVariable($variable, $value='')
Sets a variable value.
renderStackedChart(ilTemplate $tpl, ilPollResultsHandler $results)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderBarChart(ilTemplate $tpl, ilPollResultsHandler $results)
__construct(int $ref_id, Refinery $refinery, DataFactory $data_factory, UIFactory $ui_factory, UIRenderer $ui_renderer, ilLanguage $lng)
DataFactory $data_factory
render(ilTemplate $tpl, ilPollResultsHandler $results, int $presentation_mode)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
getAnswerPercentage(int $id)
htmlSpecialCharsAsEntities(string $string)
const float STACKED_BAR_WIDTH
const array STACKED_BAR_COLORS