Public
Edited
Feb 17, 2023
1 fork
2 stars
Insert cell
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width",500);

const linebox = svg.append("g");
// let counter = 0;
const lines = linebox.selectAll(".lines")
.data(data)
.join("line")
.attr("x1",d => d.x1)
.attr("y1",d => d.y1)
.attr("x2",d => d.x2)
.attr("y2",d => d.y2)
.attr("class","lines")
.attr("stroke","#0789ad")
.attr("stroke-opacity",0)

function transition() {
// counter++;
lines.attr("transform", d => {
return `rotate(${0},${d.x1},${d.y1 + lineLength/2})`
})
lines.transition()
.duration(duration)
.delay(d => d.y1 * d.x1*0.008 + delay)
.attr("transform", d => {
return `rotate(${angle},${d.x1},${d.y1 + lineLength/2})`
})
.attrTween("stroke-opacity", function() {
return function(t) {
return Math.sin(t*Math.PI)
};
})
.call(endall, function() {
transition();
});
}
return svg.call(transition).node();
}
Insert cell
Insert cell
function endall(transition, callback) {
if (transition.size() === 0) { callback() }
var n = 0;
transition
.each(function() { ++n; })
.on("end", function() { if (!--n) callback.apply(this, arguments); });
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@5") // Use the latest Version
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