Published
Edited
May 5, 2019
Insert cell
md`# Drop viz`
Insert cell
drawRain()
Insert cell
height = 500
Insert cell
width = 500
Insert cell
svg = d3.select(DOM.svg(width, height))
Insert cell
d3 = require("d3@5")
Insert cell
data = d3.csv('https://gist.githubusercontent.com/daranzolin/5f80cdd35c12409c1ed9b475c3f4342f/raw/8ae6c82a6d8b4d39545f50d6eb835cf996ac0fc8/d3rain.csv')
Insert cell

function drawRain() {
svg.append("g")
.call(xAxis);

svg.append("g")
.call(yAxis)
.selectAll("text")
.attr("x", width / 2)
.attr('transform', 'translate(0, 10)')
.style("font", "18px times");
let circles = svg.selectAll('circle')
.data(data)
.enter().append('circle')
.attr('cx', (d, i) => x(i))
.attr('cy', margin.top)
.attr('r', 5)
.attr('fill', 'firebrick')

/*
for (let i = 0; i <= levels.length; i++) {
circles.transition()
.filter(d => d.group == levels[i])
.duration(d => d.group === 'l3' ? 5000 : 1000) */
/*
sleep(2000).then(() => {
setTimeout(function (){
circles.filter(d => d.group == levels[i])
.transition()
.duration(1000)
.ease(d3.easeBounce)
.attr('cy', d => y(d.group) + y.bandwidth() / 2)
}, 1500)
})
} */
circles.transition()
.delay((d, i) => 100 * i)
.duration(1000)
.ease(d3.easeBounce)
.attr('cy', d => y(d.group) + y.bandwidth() / 2)
return svg.node();
}

Insert cell
x = d3.scaleLinear()
.domain([0, data.length])
.range([margin.left, width - margin.right])
Insert cell
xAxis = g => g
.call(d3.axisTop(x))
.call(g => g.select(".domain").remove())
Insert cell
y = d3.scaleBand()
.domain(['l1', 'l2', 'l3'])
.range([margin.top, height - margin.bottom])
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y))
.call(g => g.selectAll(".tick line").clone()
.attr("stroke-opacity", 0.2)
.attr("x2", width - margin.right))
.attr('transform', 'translate(0, 10)')
.call(g => g.select(".domain").remove())
Insert cell
margin = ({top: 20, right: 10, bottom: 20, left: 25});
Insert cell
[y('l0'), y('l1'), y('l2'), y("l3")]
Insert cell
millisecondsToWait = 2000

Insert cell
setTimeout(function() {
}, millisecondsToWait);
Insert cell
levels = ['l1', 'l2', 'l3']
Insert cell
levels
Insert cell
duration_waits = [1000, 2000, 3000, 4000, 5000, 6000]
Insert cell
sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
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