Published
Edited
Feb 29, 2020
4 stars
Insert cell
Insert cell
md `## waves`
Insert cell
waves = {
const svg = d3.select(DOM.svg(1000, 1000));
var dict = [];
for (var i = 0; i < 38; i++) {
for (var j = 0; j < 38; j++) {
dict.push({"x": 25+i*25 + (j%2)*12.5,
"y": 25+j*25
});
}
}
svg.selectAll("circle")
.data(dict)
.enter()
.append("circle")
.attr("r", 4)
.attr("cx", function(d, i) {
return d["x"];
})
.attr("cy", function(d, i) {
return d["y"];
})
d3.timer(animateThings);
function animateThings(time) {
var sineVal = 500*(Math.sin(time*0.001) + 1);
svg.selectAll("circle").attr("r", function(d) {
if (Math.abs(d["x"] - sineVal) < 50) {
return 4 + (5-Math.abs(d["x"] - sineVal)/10)
return 10;
}
return 4
})
.attr("fill", function(d) {
return d3.interpolateViridis(1-(Math.abs(d["x"] - sineVal)/1000));
});
}

return svg.node()
}
Insert cell
md `## interesting circles`
Insert cell
circles = {
const svg = d3.select(DOM.svg(1000, 1000));
var dict = [];
for (var i = 0; i < 38; i++) {
for (var j = 0; j < 38; j++) {
dict.push({"x": 25+i*25 + (j%2)*12.5,
"y": 25+j*25
});
}
}
svg.selectAll("circle")
.data(dict)
.enter()
.append("circle")
.attr("r", 4)
.attr("cx", function(d, i) {
return d["x"];
})
.attr("cy", function(d, i) {
return d["y"];
})
svg.on('mousemove', onMouseover);
return svg.node();
}
Insert cell
function onMouseover(d, i) {
var coordinates = d3.mouse(this);
var x = coordinates[0];
var y = coordinates[1];
d3.selectAll("circle")
.attr("fill", function(d, i) {
var distance = Math.sqrt(((x-d["x"])*(x-d["x"])) + ((y-d["y"])*(y-d["y"])))
return d3.interpolateViridis(distance/1000);
})
.attr("r", function(d, i) {
var distance = Math.sqrt(((x-d["x"])*(x-d["x"])) + ((y-d["y"])*(y-d["y"])))
return 5+ distance/75;
})
}
Insert cell
d3 = require("d3@5");
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