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

Weighted Voronoi? Different distance algorithms? #5

Open
mbostock opened this Issue Oct 21, 2015 · 32 comments

Comments

@mbostock
Member

mbostock commented Oct 21, 2015

Related mbostock/d3#2401. For example: Manhattan, Chebychev, and Minovsky.

@BBischof

This comment has been minimized.

BBischof commented May 22, 2016

I'd also like to echo the request for support for Weighted(additive and multiplicative) Vornoi.

@Fil

This comment has been minimized.

Member

Fil commented Jun 5, 2016

Seems that the reference algorithm can handle weights
https://en.wikipedia.org/wiki/Fortune%27s_algorithm#Weighted_sites_and_disks

@jarmstrong2

This comment has been minimized.

jarmstrong2 commented Aug 26, 2016

Would also like weighted support if possible! Thanks!

@mbostock mbostock changed the title from Different distance algorithms? to Weighted Voronoi? Different distance algorithms? Sep 6, 2016

@Fil

This comment has been minimized.

Member

Fil commented Sep 21, 2016

If we could include geoDistance() in the pack then it would help solve Fil/d3-geo-voronoi#1 too!

@nitaku

This comment has been minimized.

nitaku commented Sep 22, 2016

@mbostock Any pointers on which parts of the code are involved? I'm also interested in having custom distance functions.

@mbostock

This comment has been minimized.

Member

mbostock commented Sep 22, 2016

@nitaku No pointers, sorry. If I knew how to do this I would have done it already.

@jarmstrong2

This comment has been minimized.

jarmstrong2 commented Sep 22, 2016

Mike, what is the original algorithm for d3's voronoi based on? If it is in fact Fortune's algo, there is a weighted variant available.

@mbostock

This comment has been minimized.

Member

mbostock commented Sep 22, 2016

Yes, as @Fil mentioned. This library is an adaptation of gorhill/Javascript-Voronoi, which is an implementation of Fortune’s algorithm.

@aubergene

This comment has been minimized.

aubergene commented Sep 26, 2016

I'd love to see these additions. A while ago @jasondavies made an example weighted voronoi power diagram, he's since replaced it with an image. I think it was written with an older version of d3 which I didn't use Fortune's algorithm

@nitaku

This comment has been minimized.

nitaku commented Sep 27, 2016

Maybe @gorhill could help us to understand which parts of the implemented algorithm are involved. I had a look at his github, but I was unable to identify the code about distance metrics.

@Kcnarf

This comment has been minimized.

Kcnarf commented Jan 25, 2017

I've found an interesting bl.ock implementing a Weighted Voronoï algorithm in order to produce a Voronoï Treemap : https://bl.ocks.org/mkedwards/759e719eefe36cf9c8ab.

I guess the algorithm uses a 'power distance' as the tessellation uses straight lines. Also, I've not yet been able to identify the underlying algorithm, nor if it is a port from another language.

Nevertheless, it could be a good starting point.

@jarmstrong2

This comment has been minimized.

jarmstrong2 commented Jan 25, 2017

@mbostock

This comment has been minimized.

Member

mbostock commented Jan 25, 2017

@mhebrard

This comment has been minimized.

mhebrard commented Mar 12, 2017

I am not sure about the relation between the previous citations, but found another article (with algorithmic)
Balzer et al

@Kcnarf

This comment has been minimized.

Kcnarf commented Mar 14, 2017

Also, I found an interesting article called An efficient algorithm for construction of the power diagram from the Voronoi diagram in the plane presenting an alternative approach. Instead of computing a new power diagram from sites, it reuses an existing basic Voronoï diagram and modifies the cells' borders regarding the weights of each site.

@zbryikt

This comment has been minimized.

zbryikt commented Mar 17, 2017

hey, a year ago I implemented the weighted voronoi treemap, with MIT License:
https://github.com/zbryikt/voronoijs

it's adopted in PlotDB with d3js for quick customization, which is also my project:
https://plotdb.com/chart/1017/

voronoijs is in vanillajs, but not sure if it's possible to be integrated.

the algorithm is based on following papers:

  • "An efficient algorithm for construction of the power diagram from the Voronoi diagram in the plane" ( Marina Gavrilova and Jon Rokne, the one @Kcnarf mentioned. )
  • "Voronoi Treemaps" ( Michael Balzer and Oliver Deussen )
  • "Applications of Random Sampling in Computational Geometry, II" ( Kenneth L. Clarkson and Peter W. Shor )
@SSCodeChamp

This comment has been minimized.

SSCodeChamp commented Jul 22, 2017

Hey ,how can I draw voronoi by size/area of each cell instead of sites ?

@Fil

This comment has been minimized.

Member

Fil commented Jul 23, 2017

@zbryikt very impressive! Do you need help integrating it as a d3 plugin? It would certainly be very enjoyable, and useful.

Ideally d3-voronoi-weighted or d3-power-diagram would share the same API as d3-voronoi, with defaults of equal weights so that maybe it could be used as a drop-in replacement, and compared for performance, features etc.

If I'm understanding this correctly, your script offers both the computation of the power diagram (which would be the equivalent of d3-voronoi's Diagram) and of a treemap layout based on it (which looks like "voronoi relaxation"). One of them (I'm not sure which?) is based on an extent defined by an ellipsoid (n-polygon), where d3-voronoi has a rectangle extent. So even with equal weights it would add an interesting feature. (Is it possible to use other types of polygons for the extent?)

@Kcnarf

This comment has been minimized.

Kcnarf commented Jul 24, 2017

@Fil
I'm working on the subject too when I found time to do so, cf. block which works with D3v4. Perhaps it's a good starting point because it already works with d3v4.

I reuse a code from here (https://bl.ocks.org/mkedwards/759e719eefe36cf9c8ab), which computes a treemap and seems to use the same algorithm than the one used by @zbryikt (@zbryikt, can you confirm?).

The code now focuses on computing the power diagram. I remove treemap generation 'cause I think it is another subject. It contains 3 files :

  • PowerDiagram.js, which is main API computing the weighted voronoi
  • ConvexHull.js, which computes 3D-convexHull
  • d3-polygon-clip.js (feature in d3v3 no longer in d3v4)

@Fil, regarding your question with the extent, I guess it could be any convex, hole-free polygon. furthermore, this feature may be added to the current d3-voronoi: once computed, each cell have to be clipped by the desired polygon (by using the d3-polygon-clip).

@Kcnarf

This comment has been minimized.

Kcnarf commented Jul 28, 2017

I've continued to put some effort in creating a dedicated d3 plugin for weighted Voronoi, and the result is here : d3-weighted-voronoi.

@zbryikt

This comment has been minimized.

zbryikt commented Jul 28, 2017

@Fil I think it will be great if we make a d3-plugin for voronoijs, but I don't have time to do this currently. Yet I think it won't take too much time to do this...

Voronoijs contains power digram calculation and treemap building by recursively buliding power diagram. the boundary could be arbitrary convex polygon.

@Kcnarf I'm not sure but it looks like we use different algorithms; this is the algorithm I used.

@Kcnarf

This comment has been minimized.

Kcnarf commented Jul 28, 2017

@zbryikt
power diagram is computed in the same way (projection of a 3D convex hull)
I don't know if the relaxation part is the same.

@SSCodeChamp

This comment has been minimized.

SSCodeChamp commented Aug 17, 2017

@Kcnarf
https://bl.ocks.org/mkedwards/759e719eefe36cf9c8ab - this guy does not compute diagram correctly. If you use this , you will find that not all shapes sizes match with his weight.

@Kcnarf

This comment has been minimized.

Kcnarf commented Aug 17, 2017

@Svmali84
this is bad news ... but I've guessed things were not going very well in this block. Hence ...

When I ported this block to d3v4, I've actually found some bugs. Some were fixed, and others not (cf. Weighted Voronoi Treemap in D3v4).

And when I've reuse part of this code for the d3-weighted-voronoi plugin (which focuses only on weighted voronoi diagram computation, and leaves out treemap/relaxation computation), I put some effort on automated (but simple) tests. I can not prove the code works fine, but I do my best to do so.

Finally, if you have some repeatable failing tests or can point out some bugs in the code, I will put some effort to investigate it.

@SSCodeChamp

This comment has been minimized.

SSCodeChamp commented Aug 17, 2017

@Kcnarf - Thanks for the reply. I did one small test with the code by writing weight of each cell into it. Through this you can clearly see the issue.

This is what I observed , if you have say 3 cells with weightes as 3,4,5 . Sometimes you see cell 3 bigger than cell 4 etc..

@SSCodeChamp

This comment has been minimized.

SSCodeChamp commented Jan 5, 2018

@Kcnarf - I tried with different data. Sometimes if we have large data we gets twin is NULL exception. Any idea what is it ?

@Kcnarf

This comment has been minimized.

Kcnarf commented Jan 6, 2018

@Svmali84 - go to https://bl.ocks.org/Kcnarf/15d54f4ccae6a3710cd3029546664eec : it is a port of @mkedward's block to d3V4, with some reworks and fixes (difs are listed in the readme); notably, it drastically reduces the arising of the Cannot set property 'twin' of null error

Furthermore, perhaps that you can use the d3-voronoi-treemap plugin, which provide a packaged solution, and may be simpler to use.

@SSCodeChamp

This comment has been minimized.

SSCodeChamp commented Jan 7, 2018

Thanks @Kcnarf . This one is working fine with most of the data sets.

So can I make use of it on my website free ? I see it is under GPL-3 license. So putting copyright is sufficient ?

@SSCodeChamp

This comment has been minimized.

SSCodeChamp commented Jan 11, 2018

Hi,

Can someone let me know if I can use this on the website ? I have very less idea of GPL license

@micahstubbs

This comment has been minimized.

micahstubbs commented Jan 11, 2018

@Svmali84 I imagine that you can use it so long as you do not distribute it. this stackoverflow answer may help 😄 https://stackoverflow.com/a/2281266/1732222

@micahstubbs

This comment has been minimized.

micahstubbs commented Jan 11, 2018

we could also ask @Kcnarf if he would be willing to release d3-voronoi under a more liberal license, like for example the BSD-3-Clause license that d3 itself is released under or the popular MIT license

@Kcnarf

This comment has been minimized.

Kcnarf commented Jan 11, 2018

@Svmali84 - I propose to continue this license-related discussion into the dedicated d3-voronoi-treemap's issue#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment