Skip to content

Commit 39b0908

Browse files
committed
Only add label to gis svg when it is non-empty
Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
1 parent 5d5d28c commit 39b0908

14 files changed

Lines changed: 56 additions & 45 deletions

resources/js/table/gis_visualization.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ class SvgVisualization extends GisVisualization {
396396
$('#tooltip').remove();
397397

398398
const target = event.target as SVGElement;
399-
const contents = target.getAttribute('data-label').trim();
400-
if (contents === '') {
399+
const contents = target.getAttribute('data-label');
400+
if (!contents) {
401401
return;
402402
}
403403

src/Gis/GisLineString.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,15 @@ public function prepareRowAsPdf(
166166
*/
167167
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
168168
{
169-
$lineOptions = [
170-
'data-label' => $label,
169+
$options = [
171170
'class' => 'linestring vector',
172171
'fill' => 'none',
173172
'stroke' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
174173
'stroke-width' => 2,
175174
];
175+
if ($label !== '') {
176+
$options['data-label'] = $label;
177+
}
176178

177179
// Trim to remove leading 'LINESTRING(' and trailing ')'
178180
$linestring = mb_substr($spatial, 11, -1);
@@ -184,7 +186,7 @@ public function prepareRowAsSvg(string $spatial, string $label, array $color, Sc
184186
}
185187

186188
$row .= '"';
187-
foreach ($lineOptions as $option => $val) {
189+
foreach ($options as $option => $val) {
188190
$row .= ' ' . $option . '="' . $val . '"';
189191
}
190192

src/Gis/GisMultiLineString.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ public function prepareRowAsPdf(
187187
*/
188188
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
189189
{
190-
$lineOptions = [
191-
'data-label' => $label,
190+
$options = [
192191
'class' => 'linestring vector',
193192
'fill' => 'none',
194193
'stroke' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
195194
'stroke-width' => 2,
196195
];
196+
if ($label !== '') {
197+
$options['data-label'] = $label;
198+
}
197199

198200
// Trim to remove leading 'MULTILINESTRING((' and trailing '))'
199201
$multilineString = mb_substr($spatial, 17, -2);
@@ -210,7 +212,7 @@ public function prepareRowAsSvg(string $spatial, string $label, array $color, Sc
210212
}
211213

212214
$row .= '"';
213-
foreach ($lineOptions as $option => $val) {
215+
foreach ($options as $option => $val) {
214216
$row .= ' ' . $option . '="' . $val . '"';
215217
}
216218

src/Gis/GisMultiPoint.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,15 @@ public function prepareRowAsPdf(
160160
*/
161161
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
162162
{
163-
$pointOptions = [
164-
'data-label' => $label,
163+
$options = [
165164
'class' => 'multipoint vector',
166165
'fill' => 'white',
167166
'stroke' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
168167
'stroke-width' => 2,
169168
];
169+
if ($label !== '') {
170+
$options['data-label'] = $label;
171+
}
170172

171173
// Trim to remove leading 'MULTIPOINT(' and trailing ')'
172174
$multipoint = mb_substr($spatial, 11, -1);
@@ -179,7 +181,7 @@ public function prepareRowAsSvg(string $spatial, string $label, array $color, Sc
179181
}
180182

181183
$row .= '<circle cx="' . $point[0] . '" cy="' . $point[1] . '" r="3"';
182-
foreach ($pointOptions as $option => $val) {
184+
foreach ($options as $option => $val) {
183185
$row .= ' ' . $option . '="' . $val . '"';
184186
}
185187

src/Gis/GisMultiPolygon.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,17 @@ public function prepareRowAsPdf(
193193
*/
194194
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
195195
{
196-
$polygonOptions = [
197-
'data-label' => $label,
196+
$options = [
198197
'class' => 'multipolygon vector',
199198
'stroke' => 'black',
200199
'stroke-width' => 0.5,
201200
'fill' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
202201
'fill-rule' => 'evenodd',
203202
'fill-opacity' => 0.8,
204203
];
204+
if ($label !== '') {
205+
$options['data-label'] = $label;
206+
}
205207

206208
$row = '';
207209

@@ -219,7 +221,7 @@ public function prepareRowAsSvg(string $spatial, string $label, array $color, Sc
219221
}
220222

221223
$row .= '"';
222-
foreach ($polygonOptions as $option => $val) {
224+
foreach ($options as $option => $val) {
223225
$row .= ' ' . $option . '="' . $val . '"';
224226
}
225227

src/Gis/GisPoint.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ public function prepareRowAsPdf(
159159
*/
160160
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
161161
{
162-
$pointOptions = [
163-
'data-label' => $label,
162+
$options = [
164163
'class' => 'point vector',
165164
'fill' => 'white',
166165
'stroke' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
167166
'stroke-width' => 2,
168167
];
168+
if ($label !== '') {
169+
$options['data-label'] = $label;
170+
}
169171

170172
// Trim to remove leading 'POINT(' and trailing ')'
171173
$point = mb_substr($spatial, 6, -1);
@@ -174,7 +176,7 @@ public function prepareRowAsSvg(string $spatial, string $label, array $color, Sc
174176
$row = '';
175177
if ($pointsArr[0] !== 0.0 && $pointsArr[1] !== 0.0) {
176178
$row .= '<circle cx="' . $pointsArr[0] . '" cy="' . $pointsArr[1] . '" r="3"';
177-
foreach ($pointOptions as $option => $val) {
179+
foreach ($options as $option => $val) {
178180
$row .= ' ' . $option . '="' . $val . '"';
179181
}
180182

src/Gis/GisPolygon.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,17 @@ public function prepareRowAsPdf(
162162
*/
163163
public function prepareRowAsSvg(string $spatial, string $label, array $color, ScaleData $scaleData): string
164164
{
165-
$polygonOptions = [
166-
'data-label' => $label,
165+
$options = [
167166
'class' => 'polygon vector',
168167
'stroke' => 'black',
169168
'stroke-width' => 0.5,
170169
'fill' => sprintf('#%02x%02x%02x', $color[0], $color[1], $color[2]),
171170
'fill-rule' => 'evenodd',
172171
'fill-opacity' => 0.8,
173172
];
173+
if ($label !== '') {
174+
$options['data-label'] = $label;
175+
}
174176

175177
// Trim to remove leading 'POLYGON((' and trailing '))'
176178
$polygon = mb_substr($spatial, 9, -2);
@@ -183,7 +185,7 @@ public function prepareRowAsSvg(string $spatial, string $label, array $color, Sc
183185
}
184186

185187
$row .= '"';
186-
foreach ($polygonOptions as $option => $val) {
188+
foreach ($options as $option => $val) {
187189
$row .= ' ' . $option . '="' . $val . '"';
188190
}
189191

tests/unit/Controllers/Table/GisVisualizationControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testGisVisualizationController(): void
9595
],
9696
'visualization' => '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n"
9797
. '<svg version="1.1" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"'
98-
. ' width="600" height="450"><g><circle cx="300" cy="225" r="3" data-label=""'
98+
. ' width="600" height="450"><g><circle cx="300" cy="225" r="3"'
9999
. ' class="point vector" fill="white" stroke="#b02ee0" stroke-width="2"/></g></svg>',
100100
'open_layers_data' => [
101101
[

tests/unit/Gis/GisGeometryCollectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ public static function providerForPrepareRowAsSvg(): array
379379
'svg',
380380
[176, 46, 224],
381381
new ScaleData(offsetX: 12, offsetY: 69, scale: 2, height: 150),
382-
'<path d="M46,268L-4,248L6,208L66,198ZM16,228L46,224L36,248Z" data-label="svg"'
382+
'<path d="M46,268L-4,248L6,208L66,198ZM16,228L46,224L36,248Z"'
383383
. ' class="polygon vector" stroke="black" stroke-width="0.5"'
384-
. ' fill="#b02ee0" fill-rule="evenodd" fill-opacity="0.8"/>',
384+
. ' fill="#b02ee0" fill-rule="evenodd" fill-opacity="0.8" data-label="svg"/>',
385385
],
386386
];
387387
}

tests/unit/Gis/GisLineStringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ public static function providerForPrepareRowAsSvg(): array
251251
[176, 46, 224],
252252
new ScaleData(offsetX: 12, offsetY: 69, scale: 2, height: 150),
253253
'<polyline points="0,218 72,138 114,242 26,198 4,182 46,132 " '
254-
. 'data-label="svg" class="linestring vector" fill="none" '
255-
. 'stroke="#b02ee0" stroke-width="2"/>',
254+
. 'class="linestring vector" fill="none" '
255+
. 'stroke="#b02ee0" stroke-width="2" data-label="svg"/>',
256256
],
257257
];
258258
}

0 commit comments

Comments
 (0)