|
|
@@ -46,6 +46,9 @@ class ChartGenerator {
|
|
|
/** @var array $areaManagerData */
|
|
|
private $areaManagerData;
|
|
|
|
|
|
+ /** @var Template $template */
|
|
|
+ private $template;
|
|
|
+
|
|
|
public static function getVenueTypePassFailChart(array $venue_type_data): Chart {
|
|
|
$chart = new Chart();
|
|
|
$chart->addXAxis([
|
|
|
@@ -78,6 +81,93 @@ class ChartGenerator {
|
|
|
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);
|
|
|
+ }, $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("Stage % 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
@@ -1120,4 +1210,11 @@ class ChartGenerator {
|
|
|
return $chart;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param Template $template
|
|
|
+ */
|
|
|
+ public function setTemplate(Template $template): void {
|
|
|
+ $this->template = $template;
|
|
|
+ }
|
|
|
+
|
|
|
}
|