| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436 |
- <?php
- /**
- * Class ChartGenerator
- */
- class ChartGenerator {
- public const COLOUR_GREEN = "#4CAF50";
- public const COLOUR_RED = "#F44336";
- public const COLOUR_YELLOW = "#FFEB3B";
- public const COLOUR_LIGHT_GREY = "#CCCCCC";
- public const COLOUR_LIGHT_RED = "#FFAB91";
- public const COLOUR_ORANGE = "#FBC02D";
- public const COLOUR_BLUE = "#2196F3";
- public const COLOUR_MAGENTA = "#E91E63";
- public const COLOUR_DARK_BLUE = "#3F51B5";
- public const COLOUR_PURPLE = "#9C27B0";
- public const COLOUR_GREY = "#9E9E9E";
- public const COLOUR_CYAN = "#00BCD4";
- public const COLOUR_BLACK = "#000000";
- public const COLOUR_DARK_GREY = "#333333";
- /** @var object $totalData */
- private $totalData;
- /** @var array $periodicData */
- private $periodicData;
- /** @var string $dateRangeLabel */
- private $dateRangeLabel;
- /** @var string $resolutionName */
- private $resolutionName;
- /** @var string[] $xDataLabels */
- private $xDataLabels;
- /** @var string[] $periodKeys */
- private $periodKeys;
- /** @var string[] $periodLabels */
- private $periodLabels;
- /** @var array $regionData */
- private $regionData;
- /** @var array $areaManagerData */
- private $areaManagerData;
- /** @var array */
- private $operationsManagerData;
- /** @var array */
- private $brandData;
- /** @var Template $template */
- private $template;
- private ?Customer $customer = null;
- public static function getVenueTypePassFailChart(array $venue_type_data): Chart {
- $chart = new Chart();
- $chart->addXAxis([
- "type" => "category",
- "stacked" => true,
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100],
- "stacked" => true,
- ]);
- $get_rates = static function(string $column) use ($venue_type_data) {
- return array_values(array_map(static function($d) use ($column) {
- if($d["testCount"] === 0) return 0;
- return round(($d[$column] / $d["testCount"]) * 100);
- }, $venue_type_data));
- };
- $pass_rates = $get_rates("passCount");
- $fail_rates = $get_rates("failCount");
- $chart->setType("bar");
- $chart->setTitle("Pass / Fail by Venue Type");
- $chart->setLabels(array_keys($venue_type_data));
- $chart->addDataset("Pass Rate (%)", $pass_rates, ["background_colours" => self::COLOUR_GREEN]);
- $chart->addDataset("Fail Rate (%)", $fail_rates, ["background_colours" => self::COLOUR_RED]);
- $chart->setDatalabelSuffixes("%", "%");
- return $chart;
- }
- public function getVenueTypeChallengeStageStackedBarChart(array $venue_type_data): ?Chart {
- $field = $this->template->getChallengeStageField();
- if(!$field) {
- return null;
- }
- $x_labels = $field->displayStrings;
- array_shift($x_labels); // Remove placeholder string
- $chart = new Chart();
- $chart->addXAxis([
- "type" => "category",
- "stacked" => true,
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100],
- "stacked" => true,
- ]);
- $get_rates = static function(string $stage_index) use ($venue_type_data) {
- return array_values(array_map(static function($d) use ($stage_index) {
- $total_count = array_sum($d["stageCounts"]);
- if($total_count === 0) return 0;
- return round(($d["stageCounts"][$stage_index] / $total_count) * 100, 1);
- }, $venue_type_data));
- };
- $bg_colours = [
- self::COLOUR_GREEN,
- self::COLOUR_YELLOW,
- self::COLOUR_ORANGE,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_RED,
- ];
- $chart->setType("bar");
- $chart->setTitle("Stages by Venue Type");
- $chart->setLabels(array_keys($venue_type_data));
- foreach($x_labels as $stage_index => $label) {
- $chart->addDataset("$label (%)", $get_rates($stage_index), ["background_colours" => $bg_colours[$stage_index]]);
- }
- $suffixes = array_fill(0, count($x_labels), "%");
- $chart->setDatalabelSuffixes(...$suffixes);
- return $chart;
- }
- /**
- * @param array $venue_type_data
- * @return Chart[]
- */
- public function getVenueTypeChallengeStagePieCharts(array $venue_type_data): array {
- $field = $this->template->getChallengeStageField();
- if(!$field) {
- return [];
- }
- $x_labels = $field->displayStrings;
- array_shift($x_labels); // Remove placeholder string
- $charts = [];
- foreach($venue_type_data as $venue_type => $data) {
- $values = $data["stageCounts"];
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("Tests by Stage - $venue_type ({$this->dateRangeLabel})");
- $chart->setLabels($x_labels);
- $chart->addDataset("Counts", $values, [
- "background_colours" => [
- self::COLOUR_GREEN,
- self::COLOUR_YELLOW,
- self::COLOUR_ORANGE,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_RED,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $charts[] = $chart;
- }
- return $charts;
- }
- public function __construct(object $total_data, array $periodic_data) {
- $this->totalData = $total_data;
- $this->periodicData = $periodic_data;
- $this->xDataLabels = array_values(array_map(static function($d) {
- return $d->label;
- }, $this->periodicData));
- }
- public function setDateRangeLabel(string $label): void {
- $this->dateRangeLabel = $label;
- }
- public function setResolutionName(string $name): void {
- $this->resolutionName = $name;
- }
- public function setPeriodKeysAndLabels(array $keys, array $labels): void {
- $this->periodKeys = $keys;
- $this->periodLabels = $labels;
- }
- public function setRegionData(array $data): void {
- ksort($data, SORT_NATURAL);
- $this->regionData = $data;
- }
- public function setAreaManagerData(array $data): void {
- ksort($data, SORT_NATURAL);
- $this->areaManagerData = $data;
- }
- public function setOperationsManagerData(array $data): void {
- ksort($data, SORT_NATURAL);
- $this->operationsManagerData = $data;
- }
- public function setBrandData(array $data): void {
- $this->brandData = $data;
- }
- // Charts
- public function getTestsByStageChart(array $labels, string $title = "Tests by Stage"): Chart {
- $chart = new Chart();
- $chart->setType("doughnut");
- $chart->setTitle("$title ({$this->dateRangeLabel})");
- $chart->setLabels($labels);
- $chart->addDataset("Tests", [
- $this->totalData->stage1Count,
- $this->totalData->stage2Count,
- $this->totalData->stage3Count,
- $this->totalData->stage4Count,
- $this->totalData->stage5Count,
- ], [
- "background_colours" => [
- self::COLOUR_GREEN,
- self::COLOUR_YELLOW,
- self::COLOUR_ORANGE,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_RED,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $chart->setPrintSuffixes("");
- $chart->print = true;
- $chart->printPercentages = true;
- $chart->printTotalColumn = true;
- $chart->setPrintLabels(["Stage 1", "Stage 2", "Stage 3", "Stage 4", "Stage 5"]);
- return $chart;
- }
- public function getChallengerGenderChart(): Chart {
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("Staff Gender ({$this->dateRangeLabel})");
- $chart->setLabels(["Male", "Female", "Unspecified"]);
- $chart->addDataset("Counts", [
- $this->totalData->maleChallengerCount,
- $this->totalData->femaleChallengerCount,
- $this->totalData->unspecifiedChallengerCount,
- ], [
- "background_colours" => [
- self::COLOUR_BLUE,
- self::COLOUR_MAGENTA,
- self::COLOUR_GREY,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- return $chart;
- }
- public function getTesterGenderChart(): Chart {
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("Tester Gender ({$this->dateRangeLabel})");
- $chart->setLabels(["Male", "Female"]);
- $chart->addDataset("Counts", [
- $this->totalData->maleTesterCount,
- $this->totalData->femaleTesterCount,
- ], [
- "background_colours" => [
- self::COLOUR_BLUE,
- self::COLOUR_MAGENTA,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- return $chart;
- }
- public function getPassFailCountChart(string $title = "Pass / Fail"): Chart {
- $data = $this->totalData;
- $dataset = [$data->passCount, $data->failCount];
- $labels = ["Pass", "Fail"];
- $colours = [self::COLOUR_GREEN, self::COLOUR_RED];
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("{$title} ({$this->dateRangeLabel})");
- $chart->setLabels($labels);
- $chart->addDataset("Counts", $dataset, [
- "background_colours" => $colours,
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- return $chart;
- }
- public function getPassFailCountChartByKey(string $title, string $object_key): Chart {
- $data = $this->totalData;
- $counts = $data->$object_key;
- $pass_count = $counts["pass"] ?? 0;
- $fail_count = $counts["fail"] ?? 0;
- $dataset = [$pass_count, $fail_count];
- $labels = ["Pass", "Fail"];
- $colours = [self::COLOUR_GREEN, self::COLOUR_RED];
- $title = sprintf("%s (%s)", $title, $this->dateRangeLabel);
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle($title);
- $chart->setLabels($labels);
- $chart->addDataset("Counts", $dataset, [
- "background_colours" => $colours,
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- return $chart;
- }
- public function getPeriodicPassFailRateChart(array $options = []): Chart {
- $title = $options["title"] ?? "Pass / Fail";
- $array_key = $options["array_key"] ?? null;
- $pass_rates = [];
- $fail_rates = [];
- foreach($this->periodicData as $period) {
- if($array_key) {
- $pass_count = $period->$array_key["pass"];
- $fail_count = $period->$array_key["fail"];
- }
- else {
- $pass_count = $period->passCount;
- $fail_count = $period->failCount;
- }
- $test_count = $pass_count + $fail_count;
- if($test_count === 0) {
- $pass_rates[] = 0;
- $fail_rates[] = 0;
- }
- else {
- $pass_rate = round(($pass_count / $test_count) * 100);
- $pass_rates[] = $pass_rate;
- $fail_rates[] = 100 - $pass_rate;
- }
- }
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addXAxis([
- "type" => "category",
- "stacked" => true,
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100],
- "stacked" => true,
- ]);
- $chart->setType("bar");
- $chart->setTitle("{$title} by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("Pass Rate (%)", $pass_rates, [
- "background_colours" => self::COLOUR_GREEN
- ]);
- $chart->addDataset("Fail Rate (%)", $fail_rates, [
- "background_colours" => self::COLOUR_RED
- ]);
- $chart->setDatalabelSuffixes("%", "%");
- return $chart;
- }
- public function getPeriodicDoorSensorAlertPassRateChart(): Chart {
- return $this->getPeriodicPassRateChart(
- "Pass Rate by Door Sensor Alert",
- $this->getPeriodicPassRateByDoorSensorAlert(1),
- $this->getPeriodicPassRateByDoorSensorAlert(0),
- $this->getPeriodicPassRateByDoorSensorAlert(2)
- );
- }
- public function getPeriodicMachinePowerChart(): Chart {
- return $this->getPeriodicBooleanChart(
- "Machines Powered",
- $this->getMachinePowerRates()
- );
- }
- public function getPeriodicMachineSeatChart(): Chart {
- return $this->getPeriodicBooleanChart(
- "Machine Seating",
- $this->getMachineSeatRates()
- );
- }
- public function getPeriodicMachineTableChart(): Chart {
- return $this->getPeriodicBooleanChart(
- "Machine Table/Shelf",
- $this->getMachineTableRates()
- );
- }
- public function getPeriodicMachineAccessibleChart(): Chart {
- return $this->getPeriodicBooleanChart(
- "Machines Accessible",
- $this->getMachineAccessibleRates()
- );
- }
- public function getPeriodicEyeContactPassRateChart(): Chart {
- return $this->getPeriodicPassRateChart(
- "Pass Rate by Eye Contact",
- $this->getPeriodicPassRateByEyeContact(1),
- $this->getPeriodicPassRateByEyeContact(0),
- $this->getPeriodicPassRateByEyeContact(2)
- );
- }
- public function getPeriodicLineOfSightPassRateChart(array $options = []): Chart {
- $title = $options["title"] ?? __("Pass Rate by Line of Sight");
- $include_no_challenge = $options["include_no_challenge"] ?? true;
- $pass_counts = $this->getPeriodicPassRateByLineOfSight(1);
- $fail_counts = $this->getPeriodicPassRateByLineOfSight(0);
- $no_challenge_counts = $this->getPeriodicPassRateByLineOfSight(2);
- return $this->getPeriodicPassRateChart(
- $title,
- $pass_counts,
- $fail_counts,
- $include_no_challenge ? $no_challenge_counts : null
- );
- }
- public function getPeriodicBarPurchasePassRateChart(): Chart {
- return $this->getPeriodicPassRateChart(
- "Pass Rate by Bar Purchase",
- $this->getPeriodicPassRateByBarPurchase(1),
- $this->getPeriodicPassRateByBarPurchase(0),
- $this->getPeriodicPassRateByBarPurchase(2)
- );
- }
- public function getPeriodicPassRateChartByKey(string $title, string $object_key): Chart {
- $pass_rates = [];
- $fail_rates = [];
- foreach($this->periodicData as $index => $data) {
- $counts = $data->$object_key;
- $pass_count = $counts["pass"];
- $fail_count = $counts["fail"];
- $test_count = $pass_count + $fail_count;
- if($test_count === 0) {
- $pass_rate = 0;
- $fail_rate = 0;
- }
- else {
- $pass_rate = round(($pass_count / $test_count) * 100);
- $fail_rate = 100 - $pass_rate;
- }
- $pass_rates[] = $pass_rate;
- $fail_rates[] = $fail_rate;
- }
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addXAxis([
- "type" => "category",
- "stacked" => true,
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100],
- "stacked" => true,
- ]);
- $chart->setType("bar");
- $chart->setTitle("$title by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("Pass (%)", $pass_rates, ["background_colours" => self::COLOUR_GREEN]);
- $chart->addDataset("Fail (%)", $fail_rates, ["background_colours" => self::COLOUR_RED]);
- $chart->setDatalabelSuffixes("%", "%");
- return $chart;
- }
- public function getPeriodicBooleanPassRateChart(array $rates, string $title): Chart {
- $chart = new Chart();
- $chart->addXAxis([
- "type" => "category",
- "stacked" => true,
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100],
- "stacked" => true,
- ]);
- $chart->setType("bar");
- $chart->setTitle($title);
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("Yes (%)", array_column($rates, "pass"), [
- "background_colours" => self::COLOUR_GREEN
- ]);
- $chart->addDataset("No (%)", array_column($rates, "fail"), [
- "background_colours" => self::COLOUR_RED
- ]);
- $chart->setDatalabelSuffixes("%", "%");
- return $chart;
- }
- public function getPeriodicEyeContactChart(): Chart {
- return $this->getPeriodicBooleanChart(
- "Eye Contact",
- $this->getEyeContactRates()
- );
- }
- public function getPeriodicTotalsChart(array $options = []): Chart {
- $title = $options["title"] ?? "Totals";
- // Test counts are in "pass" and "fail" keys
- $array_key = $options["array_key"] ?? null;
- if($array_key) {
- $test_counts = [];
- $pass_rates = [];
- $pass_counts = [];
- $fail_counts = [];
- foreach($this->periodicData as $index => $period) {
- $pass_count = $period->$array_key["pass"];
- $fail_count = $period->$array_key["fail"];
- $test_count = $pass_count + $fail_count;
- $test_counts[] = $test_count;
- $pass_rates[] = $test_count > 0 ? round(($pass_count / $test_count) * 100) : 0;
- $pass_counts[] = $pass_count;
- $fail_counts[] = $fail_count;
- }
- }
- else {
- $test_counts = $this->getPeriodicTestCounts();
- $pass_rates = $this->getPeriodicPassRates();
- $pass_counts = $this->getPeriodicPassCounts();
- $fail_counts = $this->getPeriodicFailCounts();
- }
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->setType("bar");
- $chart->setTitle("{$title} by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]
- ]);
- $chart->addYAxis([
- "position" => "right",
- "id" => "y-axis-2",
- "grid_lines" => false,
- "tick_config" => ["min" => 0, "max" => 100]
- ]);
- $chart->addDataset("Pass Rate (%)", $pass_rates, [
- "border_colours" => self::COLOUR_YELLOW,
- "background_colours" => "transparent",
- "type" => "line",
- "y_axis_id" => "y-axis-2",
- "datalabels" => [
- "display" => false
- ],
- "line_tension" => 0,
- ]);
- $chart->addDataset("Test Count", $test_counts, [
- "background_colours" => self::COLOUR_BLUE,
- "type" => "bar",
- "y_axis_id" => "y-axis-1",
- "datalabels" => [
- "display" => false
- ],
- ]);
- $chart->addDataset("Pass", $pass_counts, [
- "background_colours" => self::COLOUR_GREEN,
- "type" => "bar",
- "y_axis_id" => "y-axis-1",
- "datalabels" => [
- "display" => false
- ],
- ]);
- $chart->addDataset("Fail", $fail_counts, [
- "background_colours" => self::COLOUR_RED,
- "type" => "bar",
- "y_axis_id" => "y-axis-1",
- "datalabels" => [
- "display" => false
- ],
- ]);
- $chart->setDatalabelSuffixes("%", "", "", "");
- $chart->print = true;
- return $chart;
- }
- /**
- * @return Chart[]
- * @throws Exception
- */
- public function getPointOfChallengeCharts(string $title_format, array $labels = []): array {
- $charts = [];
- foreach($this->periodKeys as $index => $key) {
- $key_label = $this->periodLabels[$index];
- $period_data = $this->periodicData[$key];
- if($period_data->testCount === 0) continue;
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle(sprintf($title_format, $key_label));
- $chart->setLabels($labels);
- $chart->addDataset("Counts", [
- $period_data->stage1Count,
- $period_data->stage2Count,
- $period_data->stage3Count,
- $period_data->stage4Count,
- $period_data->stage5Count,
- ], [
- "background_colours" => [
- self::COLOUR_GREEN,
- self::COLOUR_YELLOW,
- self::COLOUR_ORANGE,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_RED,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $charts[] = $chart;
- }
- return $charts;
- }
- public function getPeriodicTesterGenderChart(): Chart {
- $male_counts = $this->getPeriodicMaleTesterCount();
- $female_counts = $this->getPeriodicFemaleTesterCount();
- $counts = array_merge($male_counts, $female_counts);
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => ceil(max($counts) / 10) * 10]
- ]);
- $chart->setType("bar");
- $chart->setTitle("Tester Gender by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("Male", $male_counts, [
- "background_colours" => self::COLOUR_BLUE
- ]);
- $chart->addDataset("Female", $female_counts, [
- "background_colours" => self::COLOUR_MAGENTA
- ]);
- return $chart;
- }
- public function getPeriodicTestCountChart(string $title = "Tests"): Chart {
- $test_counts = $this->getPeriodicTestCounts();
- $pass_rates = $this->getPeriodicPassRates();
- $pass_rate_max = ceil(max($pass_rates) / 10) * 10;
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]
- ]);
- $chart->addYAxis([
- "id" => "y-axis-2",
- "tick_config" => ["min" => 0, "max" => $pass_rate_max],
- "position" => "right"
- ]);
- $chart->setType("bar");
- $chart->setTitle("{$title} by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("Pass Rate", $pass_rates, [
- "type" => "line",
- "y_axis_id" => "y-axis-2",
- "border_colours" => self::COLOUR_RED,
- "background_colours" => "transparent",
- "line_tension" => 0,
- "datalabels" => [
- "align" => "top",
- "color" => self::COLOUR_DARK_GREY,
- "borderColor" => self::COLOUR_GREY,
- "borderWidth" => 1,
- "borderRadius" => 4,
- "backgroundColor" => "white",
- "font" => [
- "weight" => "bold"
- ],
- ],
- "point_background_colour" => self::COLOUR_RED,
- ]);
- $chart->addDataset("Tests", $test_counts, [
- "background_colours" => self::COLOUR_BLUE
- ]);
- $chart->setDatalabelSuffixes("%", "");
- return $chart;
- }
- public function getGenderComparisonCharts(): array {
- $charts = [];
- $gender_keys = [
- "maleChallengeMale" => [
- "title" => "Male Challenge Male",
- "label" => "M Cha. M",
- ],
- "maleChallengeFemale" => [
- "title" => "Male Challenge Female",
- "label" => "M Cha. F",
- ],
- "femaleChallengeMale" => [
- "title" => "Female Challenge Male",
- "label" => "F Cha. M",
- ],
- "femaleChallengeFemale" => [
- "title" => "Female Challenge Female",
- "label" => "F Cha. F",
- ],
- "unknownChallenge" => [
- "title" => "Gender Not Specified",
- "label" => "Gender Not Specified",
- ],
- ];
- $gender_test_counts = [];
- foreach($gender_keys as $gk => $gv) {
- $gender_test_counts[] = array_sum(array_column($this->periodicData, "{$gk}Count"));
- }
- // Gender Comparison by Date Range
- $chart = new Chart();
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => ceil(max($gender_test_counts) / 10) * 10]
- ]);
- $chart->setType("bar");
- $chart->setTitle("Gender Comparison ({$this->dateRangeLabel})");
- $chart->setLabels(array_column($gender_keys, "label"));
- $chart->addDataset("Tests", $gender_test_counts, [
- "background_colours" => self::COLOUR_BLUE
- ]);
- $charts[] = $chart;
- // Gender Comparison by Resolution
- $mcm_counts = array_column($this->periodicData, "maleChallengeMaleCount");
- $mcf_counts = array_column($this->periodicData, "maleChallengeFemaleCount");
- $fcm_counts = array_column($this->periodicData, "femaleChallengeMaleCount");
- $fcf_counts = array_column($this->periodicData, "femaleChallengeFemaleCount");
- $ns_counts = array_column($this->periodicData, "unknownChallengeCount");
- $counts = array_merge($mcm_counts, $mcf_counts, $fcm_counts, $fcf_counts);
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => ceil(max($counts) / 10) * 10]
- ]);
- $chart->setType("bar");
- $chart->setTitle("Gender Comparison by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("M Cha. M", $mcm_counts, ["background_colours" => self::COLOUR_BLUE]);
- $chart->addDataset("M Cha. F", $mcf_counts, ["background_colours" => self::COLOUR_DARK_BLUE]);
- $chart->addDataset("F Cha. M", $fcm_counts, ["background_colours" => self::COLOUR_PURPLE]);
- $chart->addDataset("F Cha. F", $fcf_counts, ["background_colours" => self::COLOUR_MAGENTA]);
- $chart->addDataset("Not Specified", $ns_counts, ["background_colours" => self::COLOUR_GREY]);
- $chart->print = true;
- $charts[] = $chart;
- // Gender Comparison Pass Rate by Resolution
- /** @noinspection PhpUnusedLocalVariableInspection */
- {
- $mcm_pass_counts = array_column($this->periodicData, "maleChallengeMalePassCount");
- $mcf_pass_counts = array_column($this->periodicData, "maleChallengeFemalePassCount");
- $fcm_pass_counts = array_column($this->periodicData, "femaleChallengeMalePassCount");
- $fcf_pass_counts = array_column($this->periodicData, "femaleChallengeFemalePassCount");
- $ns_pass_counts = array_column($this->periodicData, "unknownChallengePassCount");
- }
- /**
- * @var float $mcm_pass_rates
- * @var float $mcf_pass_rates
- * @var float $fcm_pass_rates
- * @var float $fcf_pass_rates
- * @var float $ns_pass_rates
- */
- foreach(["mcm", "mcf", "fcm", "fcf", "ns"] as $prefix) {
- $pass_rates = [];
- $pass_counts = ${$prefix . "_pass_counts"};
- $test_counts = ${$prefix . "_counts"};
- foreach($test_counts as $index => $test_count) {
- if($test_count === 0) {
- $pass_rates[] = 0;
- continue;
- }
- $pass_rates[] = number_format(($pass_counts[$index] * 100) / $test_count, 2);
- }
- ${$prefix . "_pass_rates"} = $pass_rates;
- }
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100],
- ]);
- $chart->setType("bar");
- $chart->setTitle("Gender Comparison Pass Rate by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("M Cha. M", $mcm_pass_rates, ["background_colours" => self::COLOUR_BLUE, "datalabels" => ["display" => false], "line_tension" => 0]);
- $chart->addDataset("M Cha. F", $mcf_pass_rates, ["background_colours" => self::COLOUR_DARK_BLUE, "datalabels" => ["display" => false], "line_tension" => 0]);
- $chart->addDataset("F Cha. M", $fcm_pass_rates, ["background_colours" => self::COLOUR_PURPLE, "datalabels" => ["display" => false], "line_tension" => 0]);
- $chart->addDataset("F Cha. F", $fcf_pass_rates, ["background_colours" => self::COLOUR_MAGENTA, "datalabels" => ["display" => false], "line_tension" => 0]);
- $chart->addDataset("Not Specified", $ns_pass_rates, ["background_colours" => self::COLOUR_GREY, "datalabels" => ["display" => false], "line_tension" => 0]);
- $chart->print = true;
- $chart->setDatalabelSuffixes("%", "%", "%", "%", "%");
- $charts[] = $chart;
- // Gender Comparison Point of Challenge
- foreach($this->periodKeys as $index => $key) {
- $key_label = $this->periodLabels[$index];
- $period_data = $this->periodicData[$key];
- foreach($gender_keys as $prefix => $gv) {
- $title = $gv["label"];
- $test_count = $period_data->{$prefix . "Count"};
- $stage_data = $period_data->{$prefix . "Stages"};
- if($test_count === 0) continue;
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("$key_label $title Point of Challenge");
- $chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
- $chart->addDataset("Counts", $stage_data, [
- "background_colours" => [
- self::COLOUR_GREEN,
- self::COLOUR_YELLOW,
- self::COLOUR_ORANGE,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_RED,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $charts[] = $chart;
- }
- }
- return $charts;
- }
- private function getDataPassRateChart(array $data, string $entity_name): Chart {
- $data_values = [];
- $test_counts = [];
- $pass_counts = [];
- $fail_counts = [];
- uasort($data, static function(array $a, array $b) {
- $a_test_count = array_sum(array_column($a, "testCount"));
- $a_pass_count = array_sum(array_column($a, "passCount"));
- $a_pass_rate = ($a_test_count === 0) ? 0 : round(($a_pass_count * 100) / $a_test_count);
- $b_test_count = array_sum(array_column($b, "testCount"));
- $b_pass_count = array_sum(array_column($b, "passCount"));
- $b_pass_rate = ($b_test_count === 0) ? 0 : round(($b_pass_count * 100) / $b_test_count);
- return $b_pass_rate <=> $a_pass_rate;
- });
- foreach($data as $datum) {
- $total_test_count = array_sum(array_column($datum, "testCount"));
- $total_pass_count = array_sum(array_column($datum, "passCount"));
- $test_counts[] = $total_test_count;
- $pass_counts[] = $total_pass_count;
- $fail_counts[] = $total_test_count - $total_pass_count;
- $data_values[] = ($total_test_count === 0) ? 0 : round(($total_pass_count * 100) / $total_test_count);
- }
- $chart = new Chart();
- $chart->addXAxis([
- "type" => "category",
- "scale_label_config" => [
- "display" => true,
- "labelString" => $entity_name,
- ]
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100]
- ]);
- $chart->setType("bar");
- $chart->setTitle("{$entity_name} Pass Rate ({$this->dateRangeLabel})");
- $chart->setLabels(array_keys($data));
- $chart->addDataset("Pass %", $data_values , [
- "background_colours" => self::COLOUR_BLUE
- ]);
- $chart->addPrintDataset("Tests", $test_counts);
- $chart->addPrintDataset("Pass", $pass_counts);
- $chart->addPrintDataset("Fail", $fail_counts);
- $chart->setDatalabelSuffixes("%");
- $chart->print = true;
- $chart->printTotalColumn = true;
- $chart->numeratorColumnIndex = 2;
- $chart->denominatorColumnIndex = 1;
- return $chart;
- }
- public function getPeriodicDataPassRateChart(string $entity): Chart {
- switch($entity) {
- case "region":
- $data = $this->regionData;
- $entity_name = $this->customer->getRegionLabel(1);
- $entity_keys = $this->getRegionKeys();
- $x_labels = $this->getRegionXDataLabels();
- break;
- case "areaManager":
- $data = $this->areaManagerData;
- $entity_name = $this->customer->getAreaManagerLabel(1);
- $entity_keys = $this->getAreaManagerKeys();
- $x_labels = $this->getAreaManagerKeys();
- break;
- case "brand":
- $data = $this->brandData;
- $entity_name = $this->customer->getBrandLabel(1);
- $entity_keys = $this->getBrandKeys();
- $x_labels = $this->getBrandKeys();
- break;
- case "operationsManager":
- $data = $this->operationsManagerData;
- $entity_name = $this->customer->getOperationsManagerLabel(1);
- $entity_keys = $x_labels = $this->getOperationsManagerKeys();
- break;
- default:
- throw new RuntimeException("Invalid entity passed to getPeriodicDataPassRateChart: $entity");
- }
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addXAxis([
- "type" => "category",
- "scale_label_config" => [
- "display" => true,
- "labelString" => $entity_name,
- ]
- ]);
- $chart->addYAxis([
- "id" => "y-axis-1",
- "tick_config" => ["min" => 0, "max" => 100]
- ]);
- $chart->setType("bar");
- $chart->setTitle("{$entity_name} Pass Rate by {$this->resolutionName}");
- $chart->setLabels($x_labels);
- foreach($this->periodKeys as $index => $key) {
- $data_values = [];
- foreach($entity_keys as $entity_key) {
- $datum = $data[$entity_key][$key];
- $data_values[] = ($datum->testCount === 0) ? 0 : round(($datum->passCount * 100) / $datum->testCount);
- }
- $chart->addDataset($this->periodLabels[$index], $data_values, [
- "background_colours" => Chart::getColourByIndex($index),
- "datalabels" => [
- "display" => false
- ]
- ]);
- }
- $chart->setDatalabelSuffixes(...array_fill(0, count($this->periodKeys), "%"));
- $chart->print = true;
- return $chart;
- }
- public function hasRegionData(): bool {
- return $this->regionData !== null;
- }
- public function getRegionPassRateChart(): Chart {
- return $this->getDataPassRateChart($this->regionData, $this->customer->getRegionLabel(1));
- }
- public function getPeriodicRegionPassRateChart(): Chart {
- return $this->getPeriodicDataPassRateChart("region");
- }
- public function hasAreaManagerData(): bool {
- return $this->areaManagerData !== null;
- }
- public function getAreaManagerPassRateChart(): Chart {
- return $this->getDataPassRateChart($this->areaManagerData, $this->customer->getAreaManagerLabel(1));
- }
- public function getPeriodicAreaManagerPassRateChart(): Chart {
- return $this->getPeriodicDataPassRateChart("areaManager");
- }
- public function hasBrandData(): bool {
- return $this->brandData !== null;
- }
- public function getBrandPassRateChart(): Chart {
- return $this->getDataPassRateChart($this->brandData, $this->customer->getBrandLabel(1));
- }
- public function getPeriodicBrandPassRateChart(): Chart {
- return $this->getPeriodicDataPassRateChart("brand");
- }
- public function hasOperationsManagerData(): bool {
- return $this->operationsManagerData !== null;
- }
- public function getOperationsManagerPassRateChart(): Chart {
- return $this->getDataPassRateChart($this->operationsManagerData, $this->customer->getOperationsManagerLabel(1));
- }
- public function getPeriodicOperationsManagerPassRateChart(): Chart {
- return $this->getPeriodicDataPassRateChart("operationsManager");
- }
- public function getCleanlinessChart(): Chart {
- $chart = new Chart();
- $chart->setType("doughnut");
- $chart->setTitle("Tests by Cleanliness ({$this->dateRangeLabel})");
- $chart->setLabels(["Very dirty", "Dirty", "Adequate", "Clean", "Very Clean"]);
- $chart->addDataset("Tests", [
- $this->totalData->cleanlinessCounts[0],
- $this->totalData->cleanlinessCounts[1],
- $this->totalData->cleanlinessCounts[2],
- $this->totalData->cleanlinessCounts[3],
- $this->totalData->cleanlinessCounts[4],
- ], [
- "background_colours" => [
- self::COLOUR_RED,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_ORANGE,
- self::COLOUR_YELLOW,
- self::COLOUR_GREEN,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $chart->setPrintSuffixes("");
- $chart->print = true;
- $chart->printTotalColumn = true;
- $chart->printPercentages = true;
- return $chart;
- }
- /**
- * @return Chart[]
- * @throws Exception
- */
- public function getPeriodicCleanlinessCharts(): array {
- $charts = [];
- foreach($this->periodKeys as $index => $key) {
- $key_label = $this->periodLabels[$index];
- $period_data = $this->periodicData[$key];
- if($period_data->testCount === 0) continue;
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("$key_label Cleanliness");
- $chart->setLabels(["Very dirty", "Dirty", "Adequate", "Clean", "Very Clean"]);
- $chart->addDataset("Counts", [
- $period_data->cleanlinessCounts[0],
- $period_data->cleanlinessCounts[1],
- $period_data->cleanlinessCounts[2],
- $period_data->cleanlinessCounts[3],
- $period_data->cleanlinessCounts[4],
- ], [
- "background_colours" => [
- self::COLOUR_RED,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_ORANGE,
- self::COLOUR_YELLOW,
- self::COLOUR_GREEN,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $charts[] = $chart;
- }
- return $charts;
- }
- public function getPeriodicStaffBadgeWornChart(): Chart {
- $staff_badge_worn_counts = array_column($this->periodicData, "staffBadgeWornCounts");
- $unknown_counts = array_column($staff_badge_worn_counts, 0);
- $no_counts = array_column($staff_badge_worn_counts, 1);
- $yes_counts = array_column($staff_badge_worn_counts, 2);
- $chart = new Chart();
- $chart->setType("bar");
- $chart->setTitle("Staff Badge Worn by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("No challenge", $unknown_counts, [
- "background_colours" => self::COLOUR_LIGHT_GREY
- ]);
- $chart->addDataset("No", $no_counts, [
- "background_colours" => self::COLOUR_RED
- ]);
- $chart->addDataset("Yes", $yes_counts, [
- "background_colours" => self::COLOUR_GREEN
- ]);
- return $chart;
- }
- public function getPeriodicStaffOfferedDrinkChart(): Chart {
- $counts = array_column($this->periodicData, "staffOfferedDrinkCounts");
- return $this->getPeriodicBooleanChart("Staff Offered Drink", $counts);
- }
- public function getPeriodicStaffOfferedPromotionChart(): Chart {
- $counts = array_column($this->periodicData, "staffOfferedPromotionCounts");
- return $this->getPeriodicBooleanChart("Staff Offered Promotion", $counts);
- }
- public function getPeriodicStaffOfferedHelpChart(): Chart {
- $counts = array_column($this->periodicData, "staffOfferedHelpCounts");
- return $this->getPeriodicBooleanChart("Staff Offered Help", $counts);
- }
- public function getPeriodicStaffBehaviourCharts(): array {
- $charts = [];
- foreach($this->periodKeys as $index => $key) {
- $key_label = $this->periodLabels[$index];
- $period_data = $this->periodicData[$key];
- if($period_data->testCount === 0) continue;
- $chart = new Chart();
- $chart->setType("pie");
- $chart->setTitle("$key_label Staff Behaviour");
- $chart->setLabels(["N/A", "Rude", "Slightly rude", "Neither rude or polite", "Polite", "Very polite"]);
- $chart->addDataset("Counts", [
- $period_data->staffBehaviourCounts[0],
- $period_data->staffBehaviourCounts[1],
- $period_data->staffBehaviourCounts[2],
- $period_data->staffBehaviourCounts[3],
- $period_data->staffBehaviourCounts[4],
- $period_data->staffBehaviourCounts[5],
- ], [
- "background_colours" => [
- self::COLOUR_LIGHT_GREY,
- self::COLOUR_RED,
- self::COLOUR_LIGHT_RED,
- self::COLOUR_ORANGE,
- self::COLOUR_YELLOW,
- self::COLOUR_GREEN,
- ],
- "datalabels" => Chart::DATALABELS_BOX,
- ]);
- $charts[] = $chart;
- }
- return $charts;
- }
- public function getPeriodicStaffUniformChart(): Chart {
- $counts = array_column($this->periodicData, "staffUniformCounts");
- return $this->getPeriodicBooleanChart("Staff Uniform", $counts);
- }
- // Private methods
- private function getPeriodicPassRates(): array {
- return array_values(array_map(static function($period) {
- if($period->testCount === 0) return 0;
- return round(($period->passCount / $period->testCount) * 100);
- }, $this->periodicData));
- }
- private function getPeriodicFailRates(): array {
- return array_values(array_map(static function($period) {
- if($period->testCount === 0) return 0;
- $pass_rate = round(($period->passCount / $period->testCount) * 100);
- return 100 - $pass_rate;
- }, $this->periodicData));
- }
- private function getPeriodicPassRate(string $prefix, int $index): array {
- $pass_field = $prefix . "PassCounts";
- $fail_field = $prefix . "FailCounts";
- return array_values(array_map(static function($data) use ($pass_field, $fail_field, $index) {
- if(!$data) return null;
- if(!isset($data->$pass_field)) return null;
- if(!isset($data->$fail_field)) return null;
- $pass_count = $data->$pass_field[$index];
- $fail_count = $data->$fail_field[$index];
- $test_count = $pass_count + $fail_count;
- if($test_count === 0) {
- return null;
- }
- return round(($pass_count / $test_count) * 100);
- }, $this->periodicData));
- }
- private function getPeriodicPassRateByDoorSensorAlert(int $index): array {
- return $this->getPeriodicPassRate("doorSensorAlert", $index);
- }
- private function getPeriodicPassRateByEyeContact(int $index): array {
- return $this->getPeriodicPassRate("eyeContact", $index);
- }
- private function getPeriodicPassRateByLineOfSight(int $index): array {
- return $this->getPeriodicPassRate("lineOfSight", $index);
- }
- private function getPeriodicPassRateByBarPurchase(int $index): array {
- return $this->getPeriodicPassRate("barPurchase", $index);
- }
- private function getMachinePowerRates(): array {
- return $this->getBooleanRates("machinePowerCounts");
- }
- private function getMachineSeatRates(): array {
- return $this->getBooleanRates("machineSeatCounts");
- }
- private function getMachineTableRates(): array {
- return $this->getBooleanRates("machineTableCounts");
- }
- private function getMachineAccessibleRates(): array {
- return $this->getBooleanRates("machineAccessibleCounts");
- }
- private function getBooleanRates(string $field): array {
- return array_values(array_map(static function($period) use ($field) {
- if($period->testCount === 0) {
- return [0, 0, 0];
- }
- $yes = round(($period->$field[0] / $period->testCount) * 100);
- $no = 100 - $yes;
- $na = 0;
- return [$yes, $no, $na];
- }, $this->periodicData));
- }
- private function getEyeContactRates(): array {
- return $this->getBooleanRates("eyeContactCounts");
- }
- private function getPeriodicTestCounts(): array {
- return array_column($this->periodicData, "testCount");
- }
- private function getPeriodicPassCounts(): array {
- return array_column($this->periodicData, "passCount");
- }
- private function getPeriodicFailCounts(): array {
- return array_column($this->periodicData, "failCount");
- }
- private function getPeriodicMaleTesterCount(): array {
- return array_values(array_map(static function($d) {
- return $d->maleTesterCount;
- }, $this->periodicData));
- }
- private function getPeriodicFemaleTesterCount(): array {
- return array_values(array_map(static function($d) {
- return $d->femaleTesterCount;
- }, $this->periodicData));
- }
- private function getRegionKeys(): array {
- if(!$this->regionData) return [];
- return array_keys($this->regionData);
- }
- private function getRegionXDataLabels(): array {
- return array_map(static function($key) {
- return "Region $key";
- }, $this->getRegionKeys());
- }
- private function getAreaManagerKeys(): array {
- if(!$this->areaManagerData) return [];
- return array_keys($this->areaManagerData);
- }
- private function getBrandKeys(): array {
- if(!$this->brandData) return [];
- return array_keys($this->brandData);
- }
- private function getOperationsManagerKeys(): array {
- return $this->operationsManagerData ? array_keys($this->operationsManagerData) : [];
- }
- private function getAreaManagerXDataLabels(): array {
- return $this->getAreaManagerKeys();
- }
- private function getPeriodicBooleanChart(string $title, array $values): Chart {
- $no_counts = array_column($values, 0);
- $yes_counts = array_column($values, 1);
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->setType("bar");
- $chart->setTitle("{$title} by {$this->resolutionName}");
- $chart->setLabels($this->xDataLabels);
- $chart->addDataset("Yes", $yes_counts, [
- "background_colours" => self::COLOUR_GREEN
- ]);
- $chart->addDataset("No", $no_counts, [
- "background_colours" => self::COLOUR_RED
- ]);
- $chart->setDatalabelSuffixes("%", "%");
- return $chart;
- }
- private function getPeriodicPassRateChart(string $title, array $yes_rates, array $no_rates, ?array $null_rates = null): Chart {
- $chart = new Chart();
- $chart->setIsPeriodic(true);
- $chart->addYAxis([
- "tick_config" => ["min" => 0, "max" => 100],
- ]);
- $chart->setType("bar");
- $chart->setTitle($title);
- $chart->setLabels($this->xDataLabels);
- $chart->setDatalabelSuffixes("%", "%");
- $chart->addDataset("Yes (%)", $yes_rates, [
- "background_colours" => self::COLOUR_GREEN,
- "border_colours" => self::COLOUR_GREEN,
- "line_tension" => 0,
- "datalabels" => ["display" => false],
- ]);
- $chart->addDataset("No (%)", $no_rates, [
- "background_colours" => self::COLOUR_RED,
- "border_colours" => self::COLOUR_RED,
- "line_tension" => 0,
- "datalabels" => ["display" => false],
- ]);
- if($null_rates !== null) {
- $chart->addDataset("No challenge", $null_rates, [
- "background_colours" => self::COLOUR_CYAN,
- "border_colours" => self::COLOUR_CYAN,
- "line_tension" => 0,
- "datalabels" => ["display" => false],
- ]);
- $chart->setDatalabelSuffixes("%", "%", "%");
- }
- $chart->print = true;
- return $chart;
- }
- /**
- * @param Template $template
- */
- public function setTemplate(Template $template): void {
- $this->template = $template;
- }
- public function setCustomer(?Customer $customer): void {
- $this->customer = $customer;
- }
- }
|