Răsfoiți Sursa

Add pass rate to tests by period chart

Alan Lam 2 ani în urmă
părinte
comite
2e80840353
2 a modificat fișierele cu 32 adăugiri și 0 ștergeri
  1. 2 0
      engine/chart.php
  2. 30 0
      engine/chart_generator.php

+ 2 - 0
engine/chart.php

@@ -165,6 +165,7 @@ class Chart {
 		$type = $options["type"] ?? false;
 		$datalabels = $options["datalabels"] ?? false;
 		$line_tension = $options["line_tension"] ?? null;
+		$point_background_colour = ["point_background_colour"] ?? null;
 
 		$dataset = [
 			"label" => $label,
@@ -178,6 +179,7 @@ class Chart {
 		if($type) $dataset["type"] = $type;
 		if($datalabels) $dataset["datalabels"] = $datalabels;
 		if(isset($line_tension)) $dataset["lineTension"] = $line_tension;
+		if(isset($point_background_colour)) $dataset["pointBackgroundColor"] = $point_background_colour;
 
 		$this->datasets[] = (object) $dataset;
 

+ 30 - 0
engine/chart_generator.php

@@ -18,6 +18,8 @@ class ChartGenerator {
 	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;
@@ -593,18 +595,46 @@ class ChartGenerator {
 
 	public function getPeriodicTestCountChart(): Chart {
 		$test_counts = $this->getPeriodicTestCounts();
+		$pass_rates = $this->getPeriodicPassRates();
+		$pass_rate_max = ceil(max($pass_rates) / 10) * 10;
 
 		$chart = new Chart;
 		$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("Tests by {$this->resolutionName}");
 		$chart->setLabels($this->xDataLabels);
 		$chart->addDataset("Tests", $test_counts, [
 			"background_colours" => self::COLOUR_BLUE
 		]);
+		$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->setDatalabelSuffixes("", "%");
 		return $chart;
 	}