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

d3.treemap should treat negative values as zero. #134

Closed
mbostock opened this issue Jan 29, 2019 · 4 comments
Closed

d3.treemap should treat negative values as zero. #134

mbostock opened this issue Jan 29, 2019 · 4 comments
Milestone

Comments

@mbostock
Copy link
Member

Except there’s not an obvious way to do this because hierarchy.sum gets called before it’s passed to d3.treemap. If layouts didn’t mutate data #62, then it’d be easier to move the summation into the treemap algorithm and ignore negative values.

@mbostock mbostock added this to the 2 milestone Jan 29, 2019
@mbostock mbostock mentioned this issue Jul 30, 2019
29 tasks
@Fil
Copy link
Member

Fil commented Jul 21, 2020

Is this not simply a documentation / example issue?

treemap = data => d3.treemap()
    .tile(tile)
    .size([width, height])
    .padding(1)
    .round(true)
  (d3.hierarchy(data)
      .sum(d => d.value) //  🥺  replace with Math.max(0, d.value) ?
      .sort((a, b) => b.value - a.value))

@mbostock
Copy link
Member Author

It’s just that people will forget to do that, or not realize they have negative values, and when that happens the treemap algorithm behaves badly.

@mbostock
Copy link
Member Author

mbostock commented Dec 4, 2021

I think the way to do this is node.sumPositive as a variant of node.sum that treats negative values are zero.

@mbostock
Copy link
Member Author

mbostock commented Dec 9, 2021

I’ve updated the treemap chart (and related charts) to wrap the specified value accessor to treat negative values as zero. I think short of folding the value (and sort) operations directly into the treemap layouts, this is basically done.

@mbostock mbostock closed this as completed Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants