Published unlisted
Edited
Sep 15, 2020
Insert cell
Insert cell
Insert cell
Insert cell
html`<svg id="chart" width="${width}" height="${height}" />`
Insert cell
chart = {
const renderData = [
{
key: 'g',
append: 'g',
// duration: 1000,
children: series.map((d, i) => {
// console.log(d, i);
return {
key: `${d.key}`,
append: 'path',
fill: color(d.key),
opacity: { enter: 1, exit: 0 },
// d: area(d),
d: { enter: area(d), exit: area(d) },
duration: 1000
// children: [
// {
// append: 'text',
// text: d.key
// }
// ]
};
})
},
{
append: 'g',
call: xAxis
},
{
append: 'g',
call: yAxis
}
];

render("#chart", renderData);

return md`### Edit chart code`;
}
Insert cell
data = d3.csvParse(
await FileAttachment(
"Australian Art Exhibition Catalogue Index 1845-1900 2019.11.251 DX Lab - Gender % by year@1.csv"
).text(),
d3.autoType
)
Insert cell
series = d3
.stack()
// .keys(data.columns.slice(1))
.keys(() => {
// console.log(data.columns.slice(1));
// return data.columns.slice(1);
return ['maleTotal', 'femaleTotal', 'unknown'];
// console.log(columns);
// return columns.split(',');
})
.offset(d3.stackOffsetExpand)(
data.map(d => {
if (columns === 'include-unknowns') {
return d;
}

return {
...d,
unknown: 0
};
})
)
Insert cell
area = d3
.area()
.curve(d3.curveStep)
.x(d => x(d.data.year))
.y0(d => y(d[0]))
.y1(d => y(d[1]))
Insert cell
x = d3
.scaleTime()
.domain(
d3.extent(data, d => {
return d.year;
})
)
.range([margin.left, width - margin.right])
Insert cell
y = d3.scaleLinear()
.range([height - margin.bottom, margin.top])
Insert cell
color = d3.scaleOrdinal()
.domain(data.columns.slice(1))
.range(d3.schemeCategory10)
Insert cell
xAxis = g =>
g.attr("transform", `translate(0,${height - margin.bottom})`).call(
d3
.axisBottom(x)
.ticks(width / 80)
.tickSizeOuter(0)
.tickFormat(d3.format("d"))
)
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(10, "%"))
.call(g => g.select(".domain").remove())
Insert cell
height = 500
Insert cell
margin = ({top: 10, right: 20, bottom: 20, left: 40})
Insert cell
d3 = require("d3@5")
Insert cell
d3Render = require('d3-render')
Insert cell
render = d3Render.default
Insert cell
import {swatches} from "@d3/color-legend"
Insert cell
import { radio } from '@jashkenas/inputs'
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