Skip to content

Commit 51890d9

Browse files
Merge pull request #20156 from MoonE/svg-visualization
Refactor GIS export-as-file tests
2 parents 5df8f55 + 58a67e8 commit 51890d9

42 files changed

Lines changed: 2355 additions & 1426 deletions

Some content is hidden

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

‎psalm-baseline.xml‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,16 +4360,12 @@
43604360
<MixedArgument>
43614361
<code><![CDATA[$dataRow[$i] ?? null]]></code>
43624362
<code><![CDATA[$tempPoint[0]]]></code>
4363-
<code><![CDATA[$tempPoint[0]]]></code>
4364-
<code><![CDATA[$tempPoint[1]]]></code>
43654363
<code><![CDATA[$tempPoint[1]]]></code>
43664364
</MixedArgument>
43674365
<MixedArrayAccess>
43684366
<code><![CDATA[$dataRow[$i]]]></code>
43694367
<code><![CDATA[$dataRow['data_length']]]></code>
43704368
<code><![CDATA[$tempPoint[0]]]></code>
4371-
<code><![CDATA[$tempPoint[0]]]></code>
4372-
<code><![CDATA[$tempPoint[1]]]></code>
43734369
<code><![CDATA[$tempPoint[1]]]></code>
43744370
</MixedArrayAccess>
43754371
<MixedAssignment>
@@ -4394,8 +4390,6 @@
43944390
<MixedArgument>
43954391
<code><![CDATA[$dataRow[$i][$j] ?? null]]></code>
43964392
<code><![CDATA[$tempPoint[0]]]></code>
4397-
<code><![CDATA[$tempPoint[0]]]></code>
4398-
<code><![CDATA[$tempPoint[1]]]></code>
43994393
<code><![CDATA[$tempPoint[1]]]></code>
44004394
</MixedArgument>
44014395
<MixedArrayAccess>
@@ -4409,8 +4403,6 @@
44094403
<code><![CDATA[$rowData['parts'][$i]]]></code>
44104404
<code><![CDATA[$rowData['parts'][$i]['points']]]></code>
44114405
<code><![CDATA[$tempPoint[0]]]></code>
4412-
<code><![CDATA[$tempPoint[0]]]></code>
4413-
<code><![CDATA[$tempPoint[1]]]></code>
44144406
<code><![CDATA[$tempPoint[1]]]></code>
44154407
</MixedArrayAccess>
44164408
<MixedAssignment>
@@ -10005,8 +9997,6 @@
100059997
<file src="tests/unit/Gis/GisVisualizationTest.php">
100069998
<MixedAssignment>
100079999
<code><![CDATA[$dataSet]]></code>
10008-
<code><![CDATA[$dataSet]]></code>
10009-
<code><![CDATA[$queryString]]></code>
1001010000
</MixedAssignment>
1001110001
</file>
1001210002
<file src="tests/unit/GitTest.php">

‎src/Gis/GisLineString.php‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,19 @@ public function prepareRowAsPdf(
106106
ScaleData $scaleData,
107107
TCPDF $pdf,
108108
): void {
109-
$line = ['width' => 1.5, 'color' => $color];
109+
$lineStyle = ['all' => ['width' => 1.5, 'color' => $color]];
110110

111111
// Trim to remove leading 'LINESTRING(' and trailing ')'
112112
$linestring = mb_substr($spatial, 11, -1);
113-
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
114-
115-
foreach ($pointsArr as $point) {
116-
if (isset($tempPoint)) {
117-
// draw line section
118-
$pdf->Line($tempPoint[0], $tempPoint[1], $point[0], $point[1], $line);
119-
}
120-
121-
$tempPoint = $point;
122-
}
113+
$pointsArr = $this->extractPoints1dLinear($linestring, $scaleData);
114+
$pdf->PolyLine($pointsArr, 'S', $lineStyle);
123115

124116
if ($label === '') {
125117
return;
126118
}
127119

128120
// print label
129-
$pdf->setXY($pointsArr[1][0], $pointsArr[1][1]);
121+
$pdf->setXY($pointsArr[2], $pointsArr[3]);
130122
$pdf->setFontSize(5);
131123
$pdf->Cell(0, 0, $label);
132124
}

‎src/Gis/GisMultiLineString.php‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function prepareRowAsPdf(
121121
ScaleData $scaleData,
122122
TCPDF $pdf,
123123
): void {
124-
$line = ['width' => 1.5, 'color' => $color];
124+
$lineStyle = ['all' => ['width' => 1.5, 'color' => $color]];
125125

126126
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
127127
$multilineString = mb_substr($spatial, 17, -2);
@@ -130,20 +130,12 @@ public function prepareRowAsPdf(
130130

131131
$firstLine = true;
132132
foreach ($linestrings as $linestring) {
133-
$pointsArr = $this->extractPoints1d($linestring, $scaleData);
134-
foreach ($pointsArr as $point) {
135-
if (isset($tempPoint)) {
136-
// draw line section
137-
$pdf->Line($tempPoint[0], $tempPoint[1], $point[0], $point[1], $line);
138-
}
133+
$pointsArr = $this->extractPoints1dLinear($linestring, $scaleData);
134+
$pdf->PolyLine($pointsArr, 'S', $lineStyle);
139135

140-
$tempPoint = $point;
141-
}
142-
143-
unset($tempPoint);
144136
// print label
145137
if ($label !== '' && $firstLine) {
146-
$pdf->setXY($pointsArr[1][0], $pointsArr[1][1]);
138+
$pdf->setXY($pointsArr[2], $pointsArr[3]);
147139
$pdf->setFontSize(5);
148140
$pdf->Cell(0, 0, $label);
149141
}
@@ -165,7 +157,7 @@ public function prepareRowAsPdf(
165157
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
166158
{
167159
$options = [
168-
'class' => 'linestring vector',
160+
'class' => 'multilinestring vector',
169161
'fill' => 'none',
170162
'stroke' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
171163
'stroke-width' => 2,

‎src/Gis/GisVisualization.php‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,24 +378,29 @@ public function asOl(): array
378378
*/
379379
public function toFileAsPdf(string $fileName): void
380380
{
381-
// create pdf
382-
$pdf = new TCPDF('', 'pt', Config::getInstance()->config->PDFDefaultPageSize, true, 'UTF-8', false);
381+
$fileName = $this->sanitizeName($fileName, 'pdf');
382+
$pdf = $this->createEmptyPdf(Config::getInstance()->config->PDFDefaultPageSize ?? 'A4');
383+
$this->prepareDataSet($this->data, 'pdf', $pdf);
383384

384-
// disable header and footer
385+
$pdf->Output($fileName, 'D');
386+
}
387+
388+
private function createEmptyPdf(string $format): TCPDF
389+
{
390+
$pdf = new TCPDF(
391+
orientation: 'P',
392+
unit: 'pt',
393+
format: $format,
394+
unicode: true,
395+
encoding: 'UTF-8',
396+
diskcache: false,
397+
);
385398
$pdf->setPrintHeader(false);
386399
$pdf->setPrintFooter(false);
387-
388-
//set auto page breaks
389400
$pdf->setAutoPageBreak(false);
390-
391-
// add a page
392401
$pdf->AddPage();
393402

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

401406
/**

‎tests/test_data/gis/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
*-actual.json
2+
*-actual.pdf
13
*-actual.png
4+
*-actual.svg
7.29 KB
Binary file not shown.
364 Bytes
Loading
Lines changed: 5 additions & 0 deletions
Loading
7.38 KB
Binary file not shown.
10.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)