Published
Edited
Dec 23, 2019
1 fork
1 star
Insert cell
Insert cell
Insert cell
html`<svg height="300" viewBox="0 0 10 10">
${data.map(x => g(...x))}
</svg>`
Insert cell
viewof t = Scrubber(numbers, {delay: 70})
Insert cell
Insert cell
g = function(x,y,col,t) {
const dStep = [
'',
`M 0 ${y} L ${x} ${y} L ${x} 10`,
`M 0 ${y} L ${x} ${y} L 10 ${x}`,
`M 0 ${y} L ${x} ${x*(x-y)/10 + y} L 10 ${x}`,
`M 0 ${y} L ${x} ${x*(x-y)/10 + y} L 10 ${x}`,
'',
].map((a,i,array) => d3.interpolate(array[i-1],a))
const circStep = [
{cx:x, cy:y, r: .2, fill: col,},
{cx:x, cy:y, r: .2, fill: col,},
{cx:x, cy:y, r: .2, fill: col,},
{cx:x, cy:x*(x-y)/10 + y, r: .2, fill: col,},
{cx:x, cy:x*(x-y)/10 + y, r: 0, fill: col,},
{},
].map(JSON.stringify) //stringify and then parse feels ugly, but it was the fastest solution when I got here.
.map((a,i,array) => d3.interpolate(array[i-1],a))
return html`<svg viewport="0 0 10 10">
<g>
<circle ${JSON.parse(circStep[Math.floor(t)](t - Math.floor(t)))}/>
<path
d=${dStep[Math.floor(t)](t - Math.floor(t))}
fill="none"
stroke-width="0.15"
stroke-linejoin="round"
stroke="${col}"
/>
</g></svg>`
}
Insert cell
data = [
[6,9,colors[3]],
[1,7,colors[0]],
[6,4,colors[1]],
[3,3,colors[2]],
].map(x => x.concat([t]))
Insert cell
colors = ["#d43536", "#852df1", "#f2b0f6", "#6153a0", "#70a5c1"]
Insert cell
title = ['Scatterplot','Perpendicular coordinates?', 'crooked slope chart', 'almost there...', 'slope chart!!!', 'Nothing'][[Math.floor(t)]]
Insert cell
import {html, svg} from "@observablehq/htl"
Insert cell
import {Scrubber} from "@mbostock/scrubber"
Insert cell
d3 = require("d3-interpolate@1")
Insert cell
interp = (x,y) => d3.interpolate(`M 0 ${y} L ${x} ${y} L ${x} 10`,
`M 0 ${y} L ${x} ${y} L 10 ${x}`, `M 0 ${y} L ${x} ${y} L 0 ${x}`)
Insert cell
interp(4,5)(.3)
Insert cell
md`interpolate through an array of strings`

Insert cell
interpolations = (x,y) => [
'',
`M 0 ${y} L ${x} ${y} L ${x} 10`,
`M 0 ${y} L ${x} ${y} L 10 ${x}`,
`M 0 ${y} L ${x} ${x*(x-y)/10 + y} L 10 ${x}`,
`M 0 ${y} L ${x} ${x*(x-y)/10 + y} L 10 ${x}`,
'',
].map((a,i,array) => d3.interpolate(array[i-1],a))
Insert cell
interpolations(3,4)[3](.3)
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