19declare(strict_types=1);
70 int $presentation_mode
72 if ($presentation_mode ===
ilObjPoll::SHOW_RESULTS_AS_STACKED_CHART) {
83 $votes_label = $this->
lng->txt(
'poll_chart_votes');
84 $c_dimension = $this->data_factory->dimension()->cardinal();
92 $label = $this->htmlSpecialCharsAsEntities(
$results->getAnswerText(
$id));
94 $tooltip = $total_votes .
' (' . round(
$results->getAnswerPercentage(
$id)) .
'%)';
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]);
138 $label = $this->htmlSpecialCharsAsEntities(
$results->getAnswerText(
$id));
140 $tooltip = $total_votes .
' (' . round(
$results->getAnswerPercentage(
$id)) .
'%)';
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));
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
setVariable($variable, $value='')
Sets a variable value.
Builds a Color from either hex- or rgb values.
renderBarChart(ilTemplate $tpl, ilPollResultsHandler $results)
const float STACKED_BAR_WIDTH
const array STACKED_BAR_COLORS
const float SINGLE_BAR_WIDTH
renderStackedChart(ilTemplate $tpl, ilPollResultsHandler $results)
const string SINGLE_BAR_COLOR
htmlSpecialCharsAsEntities(string $string)
render(ilTemplate $tpl, ilPollResultsHandler $results, int $presentation_mode)
DataFactory $data_factory
__construct(int $ref_id, Refinery $refinery, DataFactory $data_factory, UIFactory $ui_factory, UIRenderer $ui_renderer, ilLanguage $lng)
special template class to simplify handling of ITX/PEAR
An entity that renders components to a string output.
if(!file_exists('../ilias.ini.php'))