Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few suggestions for the tree layout #843

Closed
wants to merge 24 commits into from
Closed

A few suggestions for the tree layout #843

wants to merge 24 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Apr 11, 2022

TODO:

  • ideally the suggested defaults could depend on the orientation
  • the suggested defaults could be hints considered by Plot.plot()

@Fil Fil requested a review from mbostock April 11, 2022 11:05
@Fil Fil changed the base branch from main to mbostock/tree April 11, 2022 11:06
@Fil Fil marked this pull request as draft April 11, 2022 11:10
Copy link
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions! I think I’ll manually incorporate a couple of these ideas into the branch. Here are my thoughts.

Comment on lines +165 to +167
function pathJoin(p) {
return Array.isArray(p) ? p.map(str => `${str}`.replace(/\//g, '\\/')).join("/") : p;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we should accept arrays. I think limiting the path to strings is simpler.

@@ -217,7 +221,7 @@ function nodePath(node) {
}

function nodeName(node) {
return node.id.split("/").pop();
return node.id.replace(/\\\//g, "\0").split("/").pop().replace(/\0/g, "/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me realize that we should handle escaped backslashes like we do in d3-hierarchy:

https://github.com/d3/d3-hierarchy/blob/7bea49efdc1093b28a8d60d2f8717d8a17803564/src/stratify.js#L125-L133

We shouldn’t use \0 and hope that it doesn’t exist in the path. 😄

@@ -4,7 +4,7 @@ import {channel, isObject, one, valueof} from "../options.js";
import {basic} from "./basic.js";

export function treeNode({
path, // the delimited path
path = d => d, // the delimited path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use identity from ../options.js here.

Comment on lines +40 to +42
m.plot = function({x = {axis: null}, y = {axis: null}, inset = undefined, insetLeft = inset != null ? inset : 10, insetTop = 20, insetBottom = 20, insetRight = 120, ...options} = {}) {
return plot.call(this, {x, y, insetLeft, insetRight, insetTop, insetBottom, ...options});
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this, too, but I don’t think the mark.plot shorthand should have different defaults from Plot.plot. If we want these hints we should figure out how to do them as channel hints.

@@ -38,7 +38,7 @@ export function treeNode({
for (const o of outputs) o[output_values] = o[output_setValues]([]);
for (const facet of facets) {
const treeFacet = [];
const root = rootof(facet).each(node => node.data = data[node.data]);
const root = rootof(facet.filter(i => P[i] != null)).each(node => node.data = data[node.data]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mbostock
Copy link
Member

accept arrays as inputs (following the work in d3/d3-hierarchy#185 (comment))

Not added, but I added string coercion and you can use a comma as a delimiter to approximate this. (But that kind of defeats the reason to use an array, which is that you don’t have to escape separators, so I’d still recommend escaping separators and passing strings.)

ignore null paths

Added.

default path = identity

Added, using Plot.identity.

useful defaults for the Plot.tree().plot() shorthand

Not added; I think these need to be channel hints rather than _mark.plot shorthand, but I don‘t feel like it’s worth the trouble to implement these yet.

and a test

Added.

Base automatically changed from mbostock/tree to main April 11, 2022 21:40
@Fil Fil closed this Apr 12, 2022
@Fil Fil deleted the fil/tree branch April 12, 2022 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants