Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Cannot read property '0' of null in clipCells() #16

Closed
brianwebb11 opened this issue Aug 24, 2016 · 13 comments
Closed

Cannot read property '0' of null in clipCells() #16

brianwebb11 opened this issue Aug 24, 2016 · 13 comments

Comments

@brianwebb11
Copy link

I'm using d3 4.2.2. I'm getting an exception in clipCells().

angular.js:13920 TypeError: Cannot read property '0' of null
    at clipCells (d3.js:11482)
    at new Diagram (d3.js:11849)
    at voronoi (d3.js:11918)
    at Function.voronoi.polygons (d3.js:11927)
    ...

Looking at the code it appears that the variable end is referenced end[0] before it is populated with a value.

https://github.com/d3/d3-voronoi/blob/master/src/Cell.js#L75

I don't have a simple test case right now since I'm seeing this exception buried under several other layers of 3rd party code that ends up calling d3.

Thanks for having a look.

@mbostock
Copy link
Member

I’d like to look into this, but without a test case that reproduces the error, I’m not sure where to start.

@brianwebb11
Copy link
Author

I discovered there was a problem in an intermediate library which calls into d3. The problem was that the other library defined a callBack() function in d3.voronoi().y(callBack). The callBack() function would sometime return data that was incorrect.

Sorry for the confusion.

@mbostock
Copy link
Member

Thanks for letting me know.

@micahstubbs
Copy link

also experiencing just this issue. it's also hard for me to reproduce the error with the same data in a single page example.

screen shot 2016-09-29 at 5 03 18 pm

@micahstubbs
Copy link

micahstubbs commented Sep 30, 2016

@brwebb do you remember how your data was sometimes incorrect?

@micahstubbs
Copy link

here's a working example with the exact data that fails in my larger project http://bl.ocks.org/micahstubbs/2e7c882e69aa10d9dc317b59baf64692

now to go figure out if something is transforming the data in the middle of the larger project before it gets to d3.voronoi() 💭

@brianwebb11
Copy link
Author

Unfortunately I don't remember the details. However, I think it had something to do with processing data points where the x or y value did not exist, maybe 0 or null.

@micahstubbs
Copy link

@brwebb, thanks all the same! it looks like sparse data with lots of 0 values is the issue for me

@micahstubbs
Copy link

@mbostock managed to make a minimal example that reproduces the issue
Voronoi clipCells() end[1] null Example II
preview

this second example, though less minimal, logs out internal values from d3 to the console to perhaps shed some light on the error message
Voronoi clipCells() end[1] null Example III

preview

@micahstubbs
Copy link

it looks like this could be the cause #12

thanks to @Fil for the answer over on slack

@micahstubbs
Copy link

for voronoi you're not allowed to have two points at the same coords

@AlexanderBollbach
Copy link

i'm also seeing this error in the same clipCells function. have spent many hours on this and made no progress

@micahstubbs
Copy link

micahstubbs commented Jul 25, 2018

@AlexanderBollbach is there a minimal example of the place you experience the error that you can share?

(nice to see others encounter this same specific issue as I did 😄 )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants