Explorar el Código

Add logic to go to next slide if there are too many rows to fit

Alan Lam hace 1 año
padre
commit
75a5070d93
Se han modificado 2 ficheros con 28 adiciones y 8 borrados
  1. 3 3
      controllers/reports_presentation.php
  2. 25 5
      engine/chart.php

+ 3 - 3
controllers/reports_presentation.php

@@ -166,7 +166,7 @@ $create_summary_slide = static function(array $options) use ($presentation, $cha
 			if(stripos($chart->getTitle(), "Tests by Stage") === false) {
 				continue;
 			}
-			$chart->addDataTable($slide, 30, $y);
+			$chart->addDataTable($presentation, $slide, 30, $y);
 			break;
 		}
 
@@ -178,7 +178,7 @@ $create_summary_slide = static function(array $options) use ($presentation, $cha
 	/** @var Chart $chart */
 	foreach($charts as $chart) {
 		if(stripos($chart->getTitle(), $chart_prefix) !== false) {
-			$chart->addDataTable($slide, 30, $y);
+			$chart->addDataTable($presentation, $slide, 30, $y);
 			break;
 		}
 	}
@@ -237,7 +237,7 @@ foreach($charts_b64 as $index => $b64) {
 	if($chart->print) {
 		$slide = $presentation->createSlide();
 
-		$chart->addDataTable($slide, 30, 30);
+		$chart->addDataTable($presentation, $slide, 30, 30);
 	}
 }
 

+ 25 - 5
engine/chart.php

@@ -3,6 +3,8 @@
 /** @noinspection PhpUndefinedMethodInspection */
 /** @noinspection PhpUnusedLocalVariableInspection */
 
+use PhpOffice\PhpPresentation\PhpPresentation;
+use PhpOffice\PhpPresentation\Shape\Table;
 use PhpOffice\PhpPresentation\Slide;
 use PhpOffice\PhpPresentation\Style\Alignment;
 
@@ -505,12 +507,13 @@ class Chart {
 	}
 
 	/**
+	 * @param PhpPresentation $presentation
 	 * @param Slide $slide
 	 * @param int $offset_x
 	 * @param int $offset_y
 	 * @throws Exception
 	 */
-	public function addDataTable(Slide $slide, int $offset_x = 30, int $offset_y = 540): void {
+	public function addDataTable(PhpPresentation $presentation, Slide $slide, int $offset_x = 30, int $offset_y = 540): void {
 		$data = $this->getDataTableData();
 
 		$header_row = $data["headerRow"];
@@ -519,10 +522,17 @@ class Chart {
 
 		$column_count = count($header_row);
 
-		$table = $slide->createTableShape($column_count)
-			->setWidth(900)
-			->setOffsetX($offset_x)
-			->setOffsetY($offset_y);
+		$y = $offset_y;
+		$rows_per_page = 31;
+
+		$create_table = static function(Slide $slide, int $y) use($column_count, $offset_x): Table {
+			return $slide->createTableShape($column_count)
+				->setWidth(900)
+				->setOffsetX($offset_x)
+				->setOffsetY($y);
+		};
+
+		$table = $create_table($slide, $offset_y);
 
 		// Create header row
 		$row = $table->createRow();
@@ -541,8 +551,16 @@ class Chart {
 
 		$suffixes = $this->getPrintSuffixes() ?? $this->getDatalabelSuffixes();
 
+		$y += 20;
+
 		// Rows
 		foreach($rows as $row) {
+			if($y >= 650) {
+				$y = 30;
+				$slide = $presentation->createSlide();
+				$table = $create_table($slide, $y);
+			}
+
 			$table_row = $table->createRow();
 			$table_row->setHeight(20);
 
@@ -559,6 +577,8 @@ class Chart {
 					->setMarginTop(4);
 				$cell->createTextRun($text)->getFont()->setBold($bold);
 			}
+
+			$y += 20;
 		}
 
 		// Footer