Skip to content

Commit 02735c4

Browse files
committed
reindexIri
1 parent 3d8fb02 commit 02735c4

7 files changed

Lines changed: 20 additions & 53 deletions

test/output/opacityLegendCSS4.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/opacityLegendColor.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/opacityLegendLinear.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/opacityLegendLog.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/opacityLegendRange.svg

Lines changed: 2 additions & 2 deletions
Loading

test/output/opacityLegendSqrt.svg

Lines changed: 2 additions & 2 deletions
Loading

test/plot-snapshot.js

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export function test(plot) {
1717
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
1818
}
1919
reindexStyle(root);
20-
reindexMarker(root);
21-
reindexClip(root);
22-
reindexPattern(root);
20+
reindexIri(root, "clip", ["clip-path"]);
21+
reindexIri(root, "filter", ["filter"]);
22+
reindexIri(root, "marker", ["marker-start", "marker-mid", "marker-end"])
23+
reindexIri(root, "pattern", ["fill", "stroke"]);
2324
const actual = normalizeHtml(root.outerHTML);
2425
const outfile = join("test", "output", `${name}.${ext}`);
2526
const diffile = join("test", "output", `${name}-changed.${ext}`);
@@ -63,50 +64,16 @@ function reindexStyle(root) {
6364
}
6465
}
6566

66-
function reindexMarker(root) {
67+
function reindexIri(root, name, attributes) {
6768
let index = 0;
6869
const map = new Map();
69-
for (const node of root.querySelectorAll("[id^=plot-marker-]")) {
70+
for (const node of root.querySelectorAll(`[id^=plot-${name}-]`)) {
7071
let id = node.getAttribute("id");
7172
if (map.has(id)) id = map.get(id);
72-
else map.set(id, (id = `plot-marker-${++index}`));
73+
else map.set(id, (id = `plot-${name}-${++index}`));
7374
node.setAttribute("id", id);
7475
}
75-
for (const key of ["marker-start", "marker-mid", "marker-end"]) {
76-
for (const node of root.querySelectorAll(`[${key}]`)) {
77-
let id = node.getAttribute(key).slice(5, -1);
78-
if (map.has(id)) node.setAttribute(key, `url(#${map.get(id)})`);
79-
}
80-
}
81-
}
82-
83-
function reindexClip(root) {
84-
let index = 0;
85-
const map = new Map();
86-
for (const node of root.querySelectorAll("[id^=plot-clip-]")) {
87-
let id = node.getAttribute("id");
88-
if (map.has(id)) id = map.get(id);
89-
else map.set(id, (id = `plot-clip-${++index}`));
90-
node.setAttribute("id", id);
91-
}
92-
for (const key of ["clip-path"]) {
93-
for (const node of root.querySelectorAll(`[${key}]`)) {
94-
let id = node.getAttribute(key).slice(5, -1);
95-
if (map.has(id)) node.setAttribute(key, `url(#${map.get(id)})`);
96-
}
97-
}
98-
}
99-
100-
function reindexPattern(root) {
101-
let index = 0;
102-
const map = new Map();
103-
for (const node of root.querySelectorAll("[id^=plot-pattern-]")) {
104-
let id = node.getAttribute("id");
105-
if (map.has(id)) id = map.get(id);
106-
else map.set(id, (id = `plot-pattern-${++index}`));
107-
node.setAttribute("id", id);
108-
}
109-
for (const key of ["fill", "stroke"]) {
76+
for (const key of attributes) {
11077
for (const node of root.querySelectorAll(`[${key}]`)) {
11178
let id = node.getAttribute(key).slice(5, -1);
11279
if (map.has(id)) node.setAttribute(key, `url(#${map.get(id)})`);

0 commit comments

Comments
 (0)