Skip to content

Commit

Permalink
Keep single point path for markers
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Mar 5, 2021
1 parent de4fd79 commit 21c04e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
26 changes: 18 additions & 8 deletions plugins/removeHiddenElems.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

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

exports.type = 'perItem';

Expand All @@ -27,8 +28,6 @@ exports.params = {
polygonEmptyPoints: true,
};

var regValidPath = /M\s*(?:[-+]?(?:\d*\.\d+|\d+(?:\.|(?!\.)))([eE][-+]?\d+)?(?!\d)\s*,?\s*){2}\D*\d/i;

/**
* Remove hidden elements with disabled rendering:
* - display="none"
Expand Down Expand Up @@ -229,12 +228,23 @@ exports.fn = function (item, params) {
// https://www.w3.org/TR/SVG11/paths.html#DAttribute
//
// <path d=""/>
if (
params.pathEmptyD &&
item.isElem('path') &&
(!item.hasAttr('d') || !regValidPath.test(item.attr('d').value))
) {
return false;
if (params.pathEmptyD && item.isElem('path')) {
if (item.hasAttr('d') === false) {
return false;
}
const pathData = parsePathData(item.attr('d').value);
if (pathData.length === 0) {
return false;
}
// keep single point paths for markers
if (
pathData.length === 1 &&
computedStyle['marker-start'] == null &&
computedStyle['marker-end'] == null
) {
return false;
}
return true;
}

// Polyline with empty points
Expand Down
7 changes: 7 additions & 0 deletions test/plugins/removeHiddenElems.08.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 21c04e4

Please sign in to comment.