Skip to content

Commit 5ab2a30

Browse files
committed
ignore / if the delimiter is something else
(note: I don't think this is the correct fix! But at least it gives a unit test) closes #1849
1 parent 30d6c90 commit 5ab2a30

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

src/transforms/tree.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function nodeData(field) {
169169
function normalizer(delimiter = "/") {
170170
return `${delimiter}` === "/"
171171
? (P) => P // paths are already slash-separated
172-
: (P) => P.map(replaceAll(delimiter, "/")); // TODO string.replaceAll when supported
172+
: (P) => P.map(replaceAll("/", "\\/")).map(replaceAll(delimiter, "/")); // TODO string.replaceAll when supported
173173
}
174174

175175
function replaceAll(search, replace) {
@@ -272,7 +272,7 @@ function parentValue(evaluate) {
272272
function nameof(path) {
273273
let i = path.length;
274274
while (--i > 0) if (slash(path, i)) break;
275-
return path.slice(i + 1);
275+
return path.slice(i + 1).replaceAll("\\/", "/");
276276
}
277277

278278
// Slashes can be escaped; to determine whether a slash is a path delimiter, we

test/output/treeDelimiter.svg

Lines changed: 41 additions & 0 deletions
Loading

test/plots/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export * from "./title.js";
298298
export * from "./traffic-horizon.js";
299299
export * from "./travelers-covid-drop.js";
300300
export * from "./travelers-year-over-year.js";
301+
export * from "./tree-delimiter.js";
301302
export * from "./uniform-random-difference.js";
302303
export * from "./untyped-date-bin.js";
303304
export * from "./us-congress-age-color-explicit.js";

test/plots/tree-delimiter.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export async function treeDelimiter() {
4+
return Plot.plot({
5+
axis: null,
6+
height: 100,
7+
margin: 10,
8+
marginLeft: 40,
9+
marginRight: 190,
10+
marks: [
11+
Plot.tree(
12+
[
13+
"foo;bar;http://www.example.com",
14+
"foo;bar;https://www.example.com/posts/1",
15+
"foo;baz;https://www.example.com/posts/2"
16+
],
17+
{delimiter: ";"}
18+
)
19+
]
20+
});
21+
}

0 commit comments

Comments
 (0)