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-pack throws error at extendBasis for the given data #150

Closed
aarthi0808 opened this issue Sep 20, 2019 · 4 comments
Closed

d3-pack throws error at extendBasis for the given data #150

aarthi0808 opened this issue Sep 20, 2019 · 4 comments

Comments

@aarthi0808
Copy link

aarthi0808 commented Sep 20, 2019

Facing same kind of issue in using d3-hierarchy for pack layout. Please check the data i am using,
["a",5.473061352023348e+21], ["b", 1.1729457180068344e+21], ["c", 1023]

Checkout the error stack messages

at extendBasis (d3-hierarchy.v1.js:353)
at enclose (d3-hierarchy.v1.js:321)
at packEnclose (d3-hierarchy.v1.js:536)
at d3-hierarchy.v1.js:626
at Node.node_eachAfter [as eachAfter] (d3-hierarchy.v1.js:140)
at pack (d3-hierarchy.v1.js:586)

Need a fix for this issue @mbostock

Originally posted by @aarthi0808 in #100 (comment)

@aarthi0808
Copy link
Author

@mbostock Please respond to this issue!

@mbostock
Copy link
Member

This is an issue of non-robust arithmetic. There’s no simple fix for this.

@mbostock
Copy link
Member

Here is some code that reproduces the error:

d3.packSiblings([
  {r: 5.473061352023348e+12},
  {r: 1.1729457180068344e+12},
  {r: 1023}
])

@robinhouston and I spent some time looking at this before, and perhaps this is my fault for tweaking the enclosure tests. I’d like to fix this, but I’m not entirely sure how to do it. And even if we wanted to adopt robust-predicates, I’m not entirely sure how we’d apply the incircle test here (and also, adding that as a dependency would be significant and likely make this layout slower where a fast approximate solution would suffice).

@theiliad
Copy link

theiliad commented Jun 24, 2021

This is an issue of non-robust arithmetic. There’s no simple fix for this.

Hey @mbostock, @aarthi0808. I found a fix for this issue in https://github.com/carbon-design-system/carbon-charts

Going through https://observablehq.com/@mourner/non-robust-arithmetic-as-art

I realized that if the chart dimensions [width, height] are smaller than 1px, that could fully throw off the math...

Now you might not intend to have a chart at <1px width & height, I didn't either, but for some reason in 1 of the frames in Firefox the chart is actually much smaller than that, almost (9e-9)px.

So I just wait in my renders until the chart dimensions are larger than 1px
image

and voila! it works

Also to add some context, this issue usually shows up when you add .padding() to the d3 pack

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