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

Treemap layout (treemapBinary strategy) outputs NaN co-ordinates #157

Closed
peterrcook opened this issue Jan 27, 2020 · 3 comments
Closed

Treemap layout (treemapBinary strategy) outputs NaN co-ordinates #157

peterrcook opened this issue Jan 27, 2020 · 3 comments

Comments

@peterrcook
Copy link

I'm seeing x0 and x1 NaN values when data contains zeroes e.g.

var data = [
  {id: 'A', val1: 0, val2: 125},
  {id: 'B', val1: 0, val2: 150},
  {id: 'C', val1: 1, val2: 100}
];

If I sum by val2 or use the default tiling strategy, I don't see NaNs.

Example here:

https://bl.ocks.org/peterrcook/21c0582665261a5f9d270b01d1a12d76

Maybe related to #35

@mbostock
Copy link
Member

As a notebook for easier inspection and editing:

https://observablehq.com/d/d69b436a2fcc4ed6

It’s almost certainly a divide by zero here:

var xk = (x0 * valueRight + x1 * valueLeft) / value;

var yk = (y0 * valueRight + y1 * valueLeft) / value;

@mbostock
Copy link
Member

There’s a similar bug in d3.treemapResquarify, most likely a divide by zero here:

if (row.dice) treemapDice(row, x0, y0, x1, y0 += (y1 - y0) * row.value / value);
else treemapSlice(row, x0, y0, x0 += (x1 - x0) * row.value / value, y1);

Fil added a commit that referenced this issue Aug 12, 2020
@Fil
Copy link
Member

Fil commented Aug 23, 2020

fixed by 39f420c

@Fil Fil closed this as completed Aug 23, 2020
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

3 participants