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

balanced tree #1610

Merged
merged 7 commits into from Jun 15, 2023
Merged

balanced tree #1610

merged 7 commits into from Jun 15, 2023

Conversation

Fil
Copy link
Contributor

@Fil Fil commented May 22, 2023

todo:

closes #1589

  • what do we want to expose as data? I decided on an object with the "node:*" values, but that's tbd. (unchanged)
  • we'll probably need to make this configurable (opt-in or out, or smarter anyway, maybe it could be set by the layout), otherwise flare-indent is going sideways.
Capture d’écran 2023-05-22 à 17 51 40

@Fil Fil requested a review from mbostock May 22, 2023 15:56
Comment on lines 46 to 53
treeData[treeIndex] = {
data: node.data,
name: nodeName(node),
path: nodePath(node),
internal: nodeInternal(node),
depth: node.depth, // nodeDepth(node)
height: node.height // nodeHeight(node)
};
Copy link
Member

Choose a reason for hiding this comment

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

This breaks backwards compatibility, and I think we want to preserve the original data (which is why I originally designed it this way).

Can we not use the existing node:internal method because that only works for channels that are visible to the tree transform? I would think that we could pass filter: "node:internal" as an option to the treeNode transform? (And we could have a node:external or node:leaf for the opposite meaning.) But maybe we have to pull out the filter option and do something special; I haven’t tested yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find how to filter inside the transform; the naive approach removes those nodes too early, even before the determination of the tree—basically crashing with a "missing root". There's certainly a better way.

Copy link
Member

Choose a reason for hiding this comment

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

I guess the confusion is whether the filter applies before or after the tree is constructed? I guess the filter operation should run before the tree layout… 🤔 Maybe we could have a treeFilter option that runs after the tree layout, and supports the same node:internal method?

@mbostock mbostock mentioned this pull request May 22, 2023
@Fil Fil marked this pull request as ready for review May 23, 2023 08:24
@Fil Fil requested a review from mbostock May 23, 2023 08:24
@Fil Fil enabled auto-merge (squash) May 23, 2023 08:28
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.

I think I prefer textLayout: "balanced" instead of textBalanced: true, because what if we think of a different text layout strategy in the future? I think I would also prefer mirrored to balanced. What do you think?

...options
} = {}
) {
if (dx === undefined) dx = maybeTreeAnchor(options.treeAnchor).dx;
if (textAnchor !== undefined) throw new Error("textAnchor is not a configurable tree option");
textLayout = keyword(
textLayout === undefined ? (options.treeLayout === undefined ? "mirrored" : "normal") : textLayout,
Copy link
Member

Choose a reason for hiding this comment

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

I think we should check whether treeLayout is Tree or Cluster here. I’ll make this change and then merge. (I was just thinking this would be nice for the D3 documentation!)

@Fil Fil merged commit 36e5bc4 into main Jun 15, 2023
1 check passed
@Fil Fil deleted the fil/balanced-tree branch June 15, 2023 23:21
Fil added a commit that referenced this pull request Aug 21, 2023
Co-authored-by: Mike Bostock <mbostock@gmail.com>
chaichontat pushed a commit to chaichontat/plot that referenced this pull request Jan 14, 2024
Co-authored-by: Mike Bostock <mbostock@gmail.com>
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.

Easier tree label positioning?
2 participants