Преглед изворни кода

Add datalabels to the periodic totals charts

Alan Lam пре 1 година
родитељ
комит
9f048347dc
2 измењених фајлова са 13 додато и 15 уклоњено
  1. 8 3
      engine/chart.php
  2. 5 12
      engine/chart_generator.php

+ 8 - 3
engine/chart.php

@@ -8,12 +8,17 @@ use PhpOffice\PhpPresentation\Style\Alignment;
 
 class Chart {
 
-	const DATALABELS_BOX = [
-		"backgroundColor" => "rgba(0, 0, 0, 0.75)",
+	public const DATALABELS_BOX = [
+		"backgroundColor" => "rgba(0, 0, 0, 0.5)",
 		"borderRadius" => "2",
 	];
 
-	const COLOURS = [
+	public const DATALABELS_STROKE = [
+		"textStrokeColor" => "black",
+		"textStrokeWidth" => 2,
+	];
+
+	public const COLOURS = [
 		"#f44336",
 		"#673ab7",
 		"#03a9f4",

+ 5 - 12
engine/chart_generator.php

@@ -591,36 +591,29 @@ class ChartGenerator {
 			"background_colours" => "transparent",
 			"type" => "line",
 			"y_axis_id" => "y-axis-2",
-			"datalabels" => [
-				"display" => false
-			],
+			"datalabels" => Chart::DATALABELS_BOX,
 			"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
-			],
+			"datalabels" => Chart::DATALABELS_STROKE,
 		]);
 		$chart->addDataset("Pass", $pass_counts, [
 			"background_colours" => self::COLOUR_GREEN,
 			"type" => "bar",
 			"y_axis_id" => "y-axis-1",
-			"datalabels" => [
-				"display" => false
-			],
+			"datalabels" => Chart::DATALABELS_STROKE
 		]);
 		$chart->addDataset("Fail", $fail_counts, [
 			"background_colours" => self::COLOUR_RED,
 			"type" => "bar",
 			"y_axis_id" => "y-axis-1",
-			"datalabels" => [
-				"display" => false
-			],
+			"datalabels" => Chart::DATALABELS_STROKE
 		]);
 		$chart->setDatalabelSuffixes("%", "", "", "");
+
 		$chart->print = true;
 		return $chart;
 	}