Skip to content

Commit 21c04e4

Browse files
committed
Keep single point path for markers
1 parent de4fd79 commit 21c04e4

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

plugins/removeHiddenElems.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const { computeStyle } = require('../lib/style.js');
4+
const { parsePathData } = require('../lib/path.js');
45

56
exports.type = 'perItem';
67

@@ -27,8 +28,6 @@ exports.params = {
2728
polygonEmptyPoints: true,
2829
};
2930

30-
var regValidPath = /M\s*(?:[-+]?(?:\d*\.\d+|\d+(?:\.|(?!\.)))([eE][-+]?\d+)?(?!\d)\s*,?\s*){2}\D*\d/i;
31-
3231
/**
3332
* Remove hidden elements with disabled rendering:
3433
* - display="none"
@@ -229,12 +228,23 @@ exports.fn = function (item, params) {
229228
// https://www.w3.org/TR/SVG11/paths.html#DAttribute
230229
//
231230
// <path d=""/>
232-
if (
233-
params.pathEmptyD &&
234-
item.isElem('path') &&
235-
(!item.hasAttr('d') || !regValidPath.test(item.attr('d').value))
236-
) {
237-
return false;
231+
if (params.pathEmptyD && item.isElem('path')) {
232+
if (item.hasAttr('d') === false) {
233+
return false;
234+
}
235+
const pathData = parsePathData(item.attr('d').value);
236+
if (pathData.length === 0) {
237+
return false;
238+
}
239+
// keep single point paths for markers
240+
if (
241+
pathData.length === 1 &&
242+
computedStyle['marker-start'] == null &&
243+
computedStyle['marker-end'] == null
244+
) {
245+
return false;
246+
}
247+
return true;
238248
}
239249

240250
// Polyline with empty points

test/plugins/removeHiddenElems.08.svg

Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)