Comments (5)
I’d recommend subtracting by 0.5 so that the average jitter is still zero, like this example:
var voronoi = d3.voronoi()
.x(function(d) { return d.x + Math.random() - 0.5; })
.y(function(d) { return d.y + Math.random() - 0.5; });
from d3-voronoi.
The problem is that your input is (approximately) collinear:
Unfortunately, this Voronoi implementation doesn’t gracefully handle such input. As Jason wrote in d3/d3#1895 (comment),
This is a specific instance of a more general problem: there is more than one possible Delaunay triangulation for n ≥ 4 cocircular points; otherwise there is always a unique triangulation satisfying the Delaunay property. I think a reasonable fix is to pick an arbitrary Delaunay triangulation in this situtation.
Your input data exhibits a similar error here:
http://www.raymondhill.net/voronoi/rhill-voronoi.html
If you click “Clear all sites”, paste this in, and then click “Parse as sites”:
0.03638187704872731,464.2891731435667
18.726131781749977,447.97448002565795
79.47054617672242,394.9493467555858
126.61481653614429,353.7960778727167
178.5339693099149,308.4747092741625
197.96420712404677,291.51362799902915
266.8323214526062,231.39713866083747
343.10585755513114,164.81629403340833
421.6683900355436,96.23733420146249
497.7763624024437,29.80101379463332
You’ll see a TypeError: Cannot read property 'site' of undefined.
I probably won’t be able to fix this in the near future… Sorry. You can probably work around by adding a tiny amount of random jitter to your points (though that is no guarantee, in the extremely unlikely case your jittered input happens to still be collinear or cocircular).
Related d3/d3#235 d3/d3#1895 gorhill/Javascript-Voronoi#12.
from d3-voronoi.
Yeah, I thought it might be related to that existing issue as those sets of values are highly correlated. I'm building an interface in which I'm allowing users to plot different sets of values, including that rather uninteresting pair. It would be nice if it could fail gracefully so I could plot something else or render a message in its place. Right now the user has the potential to kill the browser window with an indefinite loop if they are an especially boring and/or unlucky individual :P
I would like to take the opportunity Mike to thank you for this library, and the continuing work and support you have put in including the countless examples and high quality tutorials. Taking the time to learn your library helped me get my first job as a developer, and so I'm personally very grateful.
from d3-voronoi.
Thank you. I expect that adding a tiny bit of random jitter would be safe if you don’t mind sacrificing accuracy.
from d3-voronoi.
Yep, adding jitter with Math.random() to the scaled value in the accessors is a good enough trade off for my (and I imagine the majority of) cases.
const voronoiGen = voronoi()
.x(d => x(d.x) + Math.random())
.y(d => y(d.y) + Math.random())
.extent([[0, 0], [w, h]]);
from d3-voronoi.
Related Issues (20)
- New examples for 1.0.1 HOT 4
- Crash in voronoi.triangles? HOT 4
- Suggestion: small optimization by returning the tangent instead of the angle HOT 1
- Cannot read property '0' of null in clipCells() HOT 13
- Voronoi.find(x,y) HOT 5
- polygons() returning [null, null, null] HOT 4
- .find() throws exception when data contains two elements on the same same position
- Missing Triangle? HOT 2
- Inverse Voronoi? HOT 1
- TypeError: Cannot read property 'circle' of null HOT 6
- Feature request; polygon extent HOT 2
- d3.voronoi mutates data HOT 3
- voronoi.findAll(x,y,r) HOT 2
- voronoi.polygons crashes (runs out of memory) HOT 2
- Relation with d3-delaunay HOT 1
- Cell.js:75 Uncaught TypeError: Cannot read property '0' of null HOT 2
- voronoi.polygons will run out of memory or return incorrect polygons for certain data sets. HOT 1
- clipCells causes 'cannot read property 0 of null' HOT 6
- Incremental Voronoi?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-voronoi.