Skip to content

Commit 9ffbb7f

Browse files
committed
Refactor gis file export tests
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
1 parent 545a8a3 commit 9ffbb7f

42 files changed

Lines changed: 289 additions & 1203 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Controllers/GisDataEditorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __invoke(ServerRequest $request): Response
8181
$result = "'" . $wkt . "'," . $srid;
8282

8383
// Generate SVG based visualization
84-
$visualizationSettings = new GisVisualizationSettings(450, 300, 'wkt');
84+
$visualizationSettings = new GisVisualizationSettings(width: 450, height: 300, spatialColumn: 'wkt');
8585
$data = [['wkt' => $wktWithZero, 'srid' => $srid]];
8686

8787
$visualization = GisVisualization::getByData($data, $visualizationSettings);

src/Controllers/Table/GisVisualizationController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private function getVisualizationSettings(
195195
mixed $settingsIn,
196196
): GisVisualizationSettings {
197197
if (! is_array($settingsIn)) {
198-
return new GisVisualizationSettings(600, 450, $spatialCandidates[0]);
198+
return new GisVisualizationSettings(width: 600, height: 450, spatialColumn: $spatialCandidates[0]);
199199
}
200200

201201
$labelColumn = '';
@@ -213,7 +213,12 @@ private function getVisualizationSettings(
213213
true,
214214
)];
215215

216-
return new GisVisualizationSettings(600, 450, $spatialColumn, $labelColumn);
216+
return new GisVisualizationSettings(
217+
width: 600,
218+
height: 450,
219+
spatialColumn: $spatialColumn,
220+
labelColumn: $labelColumn,
221+
);
217222
}
218223

219224
private function getPos(): int

src/Gis/GisVisualization.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class GisVisualization
6464
/** The height of the GIS visualization. */
6565
private int $height;
6666

67+
private int $border;
68+
6769
private string $spatialColumn;
6870

6971
private string $labelColumn;
@@ -153,11 +155,11 @@ private function __construct(
153155
private int $pos = 0,
154156
) {
155157
$this->width = $options->width;
156-
157158
$this->height = $options->height;
158159

159-
$this->spatialColumn = $options->spatialColumn;
160+
$this->border = $options->border;
160161

162+
$this->spatialColumn = $options->spatialColumn;
161163
$this->labelColumn = $options->labelColumn;
162164

163165
$this->data = is_string($sqlOrData)
@@ -378,24 +380,29 @@ public function asOl(): array
378380
*/
379381
public function toFileAsPdf(string $fileName): void
380382
{
381-
// create pdf
382-
$pdf = new TCPDF('', 'pt', Config::getInstance()->config->PDFDefaultPageSize, true, 'UTF-8', false);
383+
$fileName = $this->sanitizeName($fileName, 'pdf');
384+
$pdf = $this->createPdf(Config::getInstance()->config->PDFDefaultPageSize ?? 'A4');
385+
$this->prepareDataSet($this->data, 'pdf', $pdf);
386+
387+
$pdf->Output($fileName, 'D');
388+
}
383389

384-
// disable header and footer
390+
private function createPdf(string $format): TCPDF
391+
{
392+
$pdf = new TCPDF(
393+
orientation: 'P',
394+
unit: 'mm',
395+
format: $format,
396+
unicode: true,
397+
encoding: 'UTF-8',
398+
diskcache: false,
399+
);
385400
$pdf->setPrintHeader(false);
386401
$pdf->setPrintFooter(false);
387-
388-
//set auto page breaks
389402
$pdf->setAutoPageBreak(false);
390-
391-
// add a page
392403
$pdf->AddPage();
393404

394-
$this->prepareDataSet($this->data, 'pdf', $pdf);
395-
396-
// sanitize file name
397-
$fileName = $this->sanitizeName($fileName, 'pdf');
398-
$pdf->Output($fileName, 'D');
405+
return $pdf;
399406
}
400407

401408
/**
@@ -444,11 +451,9 @@ private function scaleDataSet(array $data): ScaleData|null
444451
return null;
445452
}
446453

447-
$border = 15;
448-
449454
// effective width and height of the plot
450-
$plotWidth = $this->width - 2 * $border;
451-
$plotHeight = $this->height - 2 * $border;
455+
$plotWidth = $this->width - 2 * $this->border;
456+
$plotHeight = $this->height - 2 * $this->border;
452457

453458
// scale the visualization
454459
$xRatio = ($extent->maxX - $extent->minX) / $plotWidth;
@@ -460,10 +465,10 @@ private function scaleDataSet(array $data): ScaleData|null
460465
// Center plot
461466
$x = $ratio === 0.0 || $xRatio < $yRatio
462467
? ($extent->maxX + $extent->minX - $this->width / $scale) / 2
463-
: $extent->minX - ($border / $scale);
468+
: $extent->minX - ($this->border / $scale);
464469
$y = $ratio === 0.0 || $xRatio >= $yRatio
465470
? ($extent->maxY + $extent->minY - $this->height / $scale) / 2
466-
: $extent->minY - ($border / $scale);
471+
: $extent->minY - ($this->border / $scale);
467472

468473
return new ScaleData(scale: $scale, offsetX: $x, offsetY: $y, height: $this->height);
469474
}

src/Gis/GisVisualizationSettings.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function __construct(
1515
public int $height,
1616
public string $spatialColumn,
1717
public string $labelColumn = '',
18+
public int $border = 15,
1819
) {
1920
}
2021
}
7.29 KB
Binary file not shown.
364 Bytes
Loading
Lines changed: 2 additions & 0 deletions
Loading
10.9 KB
Binary file not shown.
1.49 KB
Loading
Lines changed: 2 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)