Alan Lam 8 лет назад
Родитель
Сommit
cb90d01e0b
2 измененных файлов с 70 добавлено и 7 удалено
  1. 38 0
      controllers/performance.php
  2. 32 7
      engine/chart.php

+ 38 - 0
controllers/performance.php

@@ -58,6 +58,8 @@ $colours = [
 	"#9e9e9e",
 ];
 
+$project_ids = [];
+
 $submit = http::value("submit");
 if($submit) {
 	try {
@@ -472,6 +474,42 @@ if($submit) {
 		]);
 		$charts[] = $chart;
 
+		// Monthly Totals by Period
+
+		$test_counts = array_column($data, "testCount");
+		$pass_counts = array_column($data, "passCount");
+		$fail_counts = array_column($data, "failCount");
+
+		$chart = new Chart;
+		$chart->setType("bar");
+		$chart->setTitle("Monthly Totals by $resolution_name");
+		$chart->setLabels($x_data_labels);
+		$chart->addYAxis("linear", "left", "y-axis-1");
+		$chart->addYAxis("linear", "right", "y-axis-2", false);
+
+		$chart->addDataset("Test Count", $test_counts, [
+			"background_colours" => "#2196F3",
+			"type" => "bar",
+			"y_axis_id" => "y-axis-1",
+		]);
+		$chart->addDataset("Pass", $pass_counts, [
+			"background_colours" => "#4CAF50",
+			"type" => "bar",
+			"y_axis_id" => "y-axis-1",
+		]);
+		$chart->addDataset("Fail", $fail_counts, [
+			"background_colours" => "#F44336",
+			"type" => "bar",
+			"y_axis_id" => "y-axis-1",
+		]);
+		$chart->addDataset("Performance (%)", $performance, [
+			"border_colours" => "#FFEB3B",
+			"background_colours" => "transparent",
+			"type" => "line",
+			"y_axis_id" => "y-axis-2",
+		]);
+		$charts[] = $chart;
+
 		// Point of Challenge (Each Period)
 
 		foreach($keys as $index => $key) {

+ 32 - 7
engine/chart.php

@@ -7,11 +7,24 @@ class Chart {
 	private $type = "bar";
 	private $datasets = [];
 	private $labels = [];
+	private $yAxes = [];
 
 	public function __construct() {
 		$this->id = bin2hex(random_bytes(8));
 	}
 
+	public function addYAxis($type, $position, $id, $grid_lines = true) {
+		$this->yAxes[] = [
+			"type" => $type,
+			"display" => true,
+			"position" => $position,
+			"id" => $id,
+			"gridLines" => [
+				"drawOnChartArea" => $grid_lines
+			],
+		];
+	}
+
 	public function getID() {
 		return $this->id;
 	}
@@ -33,6 +46,8 @@ class Chart {
 		$background_colours = $options["background_colours"] ?? false;
 		$border_colours = $options["border_colours"] ?? false;
 		$border_width = $options["border_width"] ?? false;
+		$y_axis_id = $options["y_axis_id"] ?? false;
+		$type = $options["type"] ?? false;
 
 		$dataset = [
 			"label" => $label,
@@ -42,6 +57,8 @@ class Chart {
 		if($background_colours) $dataset["backgroundColor"] = $background_colours;
 		if($border_colours) $dataset["borderColor"] = $border_colours;
 		if($border_width) $dataset["borderWidth"] = (int) $border_width;
+		if($y_axis_id) $dataset["yAxisID"] = $y_axis_id;
+		if($type) $dataset["type"] = $type;
 
 		$this->datasets[] = $dataset;
 
@@ -53,30 +70,38 @@ class Chart {
 
 	public function getJSON() {
 
-		return json_encode([
+		$object = (object) [
 			"type" => $this->type,
-			"data" => [
+			"data" => (object) [
 				"labels" => $this->labels,
 				"datasets" => $this->datasets
 			],
-			"options" => [
-				"title" => [
+			"options" => (object) [
+				"title" => (object) [
 					"display" => true,
 					"fontSize" => 32,
 					"fontFamily" => "Roboto",
 					"fontStyle" => "300",
 					"text" => $this->title
 				],
-				"legend" => [
+				"legend" => (object) [
 					"position" => "top",
 				],
-				"plugins" => [
+				"plugins" => (object) [
 					"datalabels" => [
 						"color" => "white",
 					],
 				],
 			],
-		]);
+		];
+
+		if($this->yAxes) {
+			$object->options->scales = new stdClass;
+			$object->options->scales->yAxes = $this->yAxes;
+		}
+
+
+		return json_encode($object);
 
 	}