Published
Edited
Dec 30, 2019
2 stars
Insert cell
Insert cell
chart = {var width = 1000, height = 700;
width/=2
height/=2

var vertices = d3.range(40).map(function(d) {
return [Math.random() * width, Math.random() * height];
});
var delaunay = d3.Delaunay.from(vertices)
var voronoi = d3.voronoi().extent([[0, 0], [width, height]]);
const svg = d3.create("svg").attr("width", width).attr("height", height);

svg.style('filter','hue-rotate(352deg)invert(.0)saturate(1.3)brightness(1.51)')
var path = svg.append("g").selectAll("path");
console.log(window.mapping)
function polygon(d) {
return "M" + d.join("L") + "Z";
}
console.log(voronoi.polygons(vertices)) ;
[...voronoi.polygons(vertices)].forEach(function(d,j){
var p = polygon(d)
var c = d3.polygonCentroid(d)
var max = 33
var pow = 2.73
var marea = Math.sqrt(width*height)/50
var sets = 1.73
d3.range(1,max,sets).forEach(e=>{
var d1 = d.map(t=>t.map(o=>((1-e/max)**pow)*o))
var p1 = polygon(d1)
var c1 = d3.polygonCentroid(d1)
var a = d3.polygonArea(d1)
console.log(a,marea,'dsfds')

if (a>marea)
svg.append("path")
.attr("d",p1).attr('stroke','#222').attr('fill','none').attr('transform',`scale(${1})translate(${( c[0] - c1[0] )} ${( c[1] - c1[1])})`)
})
//svg.node().appendChild(q )
});
//let node = rc.rectangle(10, 10, 200, 200); // x, y, width, height
//svg.node().appendChild(node);
return svg.node()
}
Insert cell
Insert cell
DOM.download(() => serialize(chart), undefined, "Save as SVG")
Insert cell
d3 = require("d3@5", "d3-delaunay")
Insert cell
rough = require('roughjs@3.0.0/dist/rough.js').catch(() => window.rough)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more