Comments (4)
@Fil: I see you use the 'pie' initial position, which actually removes the randomness at initilization. It works fine when there is no too much data. In your use case, it doesn't produce the same arrangement because during the iterative process producing the final arrangement, some of your data (the lightest) are completely overweighted (they are too close to other heavier cells, and they are assigned an empty area). In such a case, the algorithm randomly choose a new position where such cell still exists. This is why you get different Voronoï maps when reloading.
The PR from @michaschwab is the solution: re-positioning of overweighted cells will become repeatable. It is orthogonal to the 'pie' initial positioning, and both codes will perfectly work together. Nevertheless, the doc of the 'pie' initial positioning have to be updated.
I will not be able to work on @michaschwab's PR before next week (from 13th aug. 2018).
from d3-voronoi-map.
The new version 1.2.0 of the d3-voronoi-map plugin now provides a new 'prng' API. It allows to define a prng. If this one is seeded, then randomness becomes repeatable, leading to repeatable outputs/arrangements.
You can see it in action in https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps (focus on https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps#voronoiMap). Indeed, the initial 'pie' positioning is no longer required for the sake of repeatability.
from d3-voronoi-map.
See Kcnarf/d3-voronoi-treemap#4.
I'm working on a pull request to fix this.
from d3-voronoi-map.
After some googling, I found another way to make a repeatable Voronoï map with the help of seedrandom.
As the @michaschwab's PR does, it defines a PRNG. It may be used to replace/overwrite Math.random()
. You can see it in action in https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps (focus on https://beta.observablehq.com/@kcnarf/repeatable-voronoi-weighted-maps#voronoiMap). Indeed, the initial 'pie' positioning is no longer required for the sake of repeatability.
Seedrandom can also be used without overwriting Math.random()
, and without introducing any side effect, by defining a new standalone PRNG. Enhancing d3-voronoi-map by providing an API that allows the user to set its preferred random generator (see d3-random) is another implementation that allows repeatable Voronoï map.
from d3-voronoi-map.
Related Issues (9)
- Deterministic Layout HOT 2
- Uncaught TypeError: Cannot set property 'twin' of null HOT 10
- Get rid of console.log in production
- handleOverweighted1 sometimes gets stuck in an infinite loop HOT 1
- remove unused dependencies (d3-array)
- Update to d3 v6 HOT 1
- 'default' is not exported HOT 4
- Large data set is causing "handleOverweighted1 is looping too much" error HOT 1
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-map.