Skip to content

Commit

Permalink
ignore / if the delimiter is something else
Browse files Browse the repository at this point in the history
(note: I don't think this is the correct fix! But at least it gives a unit test)

closes #1849
  • Loading branch information
Fil committed Sep 7, 2023
1 parent 30d6c90 commit 5ab2a30
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transforms/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function nodeData(field) {
function normalizer(delimiter = "/") {
return `${delimiter}` === "/"
? (P) => P // paths are already slash-separated
: (P) => P.map(replaceAll(delimiter, "/")); // TODO string.replaceAll when supported
: (P) => P.map(replaceAll("/", "\\/")).map(replaceAll(delimiter, "/")); // TODO string.replaceAll when supported
}

function replaceAll(search, replace) {
Expand Down Expand Up @@ -272,7 +272,7 @@ function parentValue(evaluate) {
function nameof(path) {
let i = path.length;
while (--i > 0) if (slash(path, i)) break;
return path.slice(i + 1);
return path.slice(i + 1).replaceAll("\\/", "/");
}

// Slashes can be escaped; to determine whether a slash is a path delimiter, we
Expand Down
41 changes: 41 additions & 0 deletions test/output/treeDelimiter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export * from "./title.js";
export * from "./traffic-horizon.js";
export * from "./travelers-covid-drop.js";
export * from "./travelers-year-over-year.js";
export * from "./tree-delimiter.js";
export * from "./uniform-random-difference.js";
export * from "./untyped-date-bin.js";
export * from "./us-congress-age-color-explicit.js";
Expand Down
21 changes: 21 additions & 0 deletions test/plots/tree-delimiter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as Plot from "@observablehq/plot";

export async function treeDelimiter() {
return Plot.plot({
axis: null,
height: 100,
margin: 10,
marginLeft: 40,
marginRight: 190,
marks: [
Plot.tree(
[
"foo;bar;http://www.example.com",
"foo;bar;https://www.example.com/posts/1",
"foo;baz;https://www.example.com/posts/2"
],
{delimiter: ";"}
)
]
});
}

0 comments on commit 5ab2a30

Please sign in to comment.