Commit e979b00f authored by Pascal Engélibert's avatar Pascal Engélibert

Add Voronoi for communities

parent 4589f14b
......@@ -20,11 +20,12 @@ Générez le cache JSON à partir de duniter.db (il vous faut un serveur Duniter
python3 gencache.py -d /chemin/vers/duniter.db -e
WorldWotMap nécessite jQuery, Leaflet et jLouvain. Modifiez les chemins dans le HTML en fonction de votre serveur.
WorldWotMap nécessite jQuery, D3, Leaflet et jLouvain. Modifiez les chemins dans le HTML en fonction de votre serveur.
* https://leafletjs.com/
* https://jquery.com/
* https://leafletjs.com
* https://jquery.com
* https://github.com/upphiminn/jLouvain
* https://d3js.org
C'est aussi plus joli avec une belle police, par exemple Proza Libre. https://fontlibrary.org/en/font/proza-libre
......
......@@ -81,6 +81,7 @@ a, a:visited {
}
</style>
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/d3.js"></script>
<script type="text/javascript" src="/js/jLouvain.js"></script>
<script type="text/javascript" src="/js/leaflet/leaflet.js"></script>
<script type="text/javascript" src="utils.js"></script>
......
......@@ -373,7 +373,7 @@ class Community {
}
}
function computeCommunities() {
function computeCommunities(circles=false) {
var colors = ["#ff0000", "#00ff00", "#0000ff", "#c0c000", "#c000c0", "#00c0c0", "#d05000", "#d00050", "#50d000", "#00d050", "#d00050", "#00d050"];
var _nodes = [];
var _edges = [];
......@@ -386,11 +386,14 @@ function computeCommunities() {
}
var _communities = jLouvain().nodes(_nodes).edges(_edges)();
var _points = {};
var _allpoints = [];
var i = 0;
for(a in _communities) {
if(a in accounts) {
if(!(_communities[a] in communities)) {
communities[_communities[a]] = new Community(colors[i % colors.length]);
_points[_communities[a]] = [];
i ++;
}
accounts[a].community = _communities[a];
......@@ -402,8 +405,24 @@ function computeCommunities() {
pubkey: a
}).addTo(map);
point.addTo(l_communities);
if(accounts[a].pos != null) {
_allpoints.push(a);
_points[_communities[a]].push(a);
}
}
}
l_communities.addTo(map);
l_communities.remove(map);
var voronoi = d3.voronoi()
.x(function(a) { return accounts[a].pos[0]; })
.y(function(a) { return accounts[a].pos[1]; });
var _polygons = voronoi(_allpoints).polygons();
for(_poly in _polygons) {
if(_polygons[_poly].indexOf(null) == -1)
L.polygon(_polygons[_poly], {stroke: false, fillOpacity: 0.3, color: communities[accounts[_polygons[_poly].data].community].color}).addTo(l_communities);
else
console.log(_polygons[_poly]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment