Skip to content

Easier tree label positioning? #1589

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

Closed
Fil opened this issue May 19, 2023 · 3 comments · Fixed by #1610
Closed

Easier tree label positioning? #1589

Fil opened this issue May 19, 2023 · 3 comments · Fixed by #1610
Labels
enhancement New feature or request question Further information is needed

Comments

@Fil
Copy link
Contributor

Fil commented May 19, 2023

In https://observablehq.com/@observablehq/plot-tree-tidy if you want to vary the orientation of node labels (so that leaves point to the right and parent nodes to the left, as in https://observablehq.com/@d3/tree), you can do:

Plot.plot({
  axis: null,
  margin: 10,
  marginLeft: 40,
  marginRight: 160,
  width: 928,
  height: 1800,
  marks: [
    Plot.tree(flare, {
      path: "name",
      delimiter: ".",
      dx: -6,
      textAnchor: "end",
      fontSize: { node: (d) => (d.children ? 10 : NaN) }
    }),
    Plot.text(flare, Plot.treeNode({
      path: "name",
      delimiter: ".",
      dx: 6,
      text: "node:name",
      fontSize: { node: (d) => (d.children ? NaN : 10) }
    }))
  ]
})

This could be easier if dx and textAnchor were channels (#1528, #909), or maybe we need a specific option to Plot.tree.

@Fil Fil added enhancement New feature or request question Further information is needed labels May 19, 2023
@mbostock
Copy link
Member

The tree mark could do this automatically by generating separate text marks for internal vs. leaf nodes with appropriate filters. I don’t think we should make dx and textAnchor into channels; I appreciate that there is desire for it but making everything a channel makes it harder to implement marks and is not practical. It is better to focus our efforts on channels that are intended to encode data rather than allow bespoke formatting.

@Fil
Copy link
Contributor Author

Fil commented May 20, 2023

Would this be a new option (say, balancedLabels), or are you suggesting that we modify Plot.tree to do it by default? In that case would we just use dx and -dx?

@mbostock
Copy link
Member

I think we would just modify tree to do this. Not configurable.

Fil added a commit that referenced this issue May 22, 2023
@Fil Fil mentioned this issue May 22, 2023
3 tasks
mbostock pushed a commit that referenced this issue Jun 15, 2023
@Fil Fil closed this as completed in #1610 Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants