Public
Edited
May 23, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataset = [
{
mip: "AMIP1",
models: 29,
experiments: 1,
institutions: 28,
countries: 9,
forcings: 2,
release_year: "1990-01-01T00:00:00Z"
},
{
mip: "AMIP2",
models: 32,
experiments: 1,
institutions: 25,
countries: 9,
forcings: 2,
release_year: "1995-01-01T00:00:00Z"
},
{
mip: "CMIP1",
models: 20,
experiments: 1,
institutions: 16,
countries: 8,
forcings: 1,
release_year: "1996-01-01T00:00:00Z"
},
{
mip: "CMIP2",
models: 17,
experiments: 2,
institutions: 15,
countries: 8,
forcings: 1,
release_year: "1997-01-01T00:00:00Z"
},
{
mip: "CMIP3",
models: 24,
experiments: 12,
institutions: 16,
countries: 11,
forcings: 15,
release_year: "2005-01-01T00:00:00Z"
},
{
mip: "CMIP5",
models: 59,
experiments: 34,
institutions: 26,
countries: 12,
forcings: 24,
release_year: "2011-01-01T00:00:00Z"
},
{
mip: "CMIP6",
models: 131,
experiments: 322,
institutions: 49,
countries: 26,
forcings: 63,
release_year: "2016-01-01T00:00:00Z"
}
] //.map((d,i)=>{d.color = '#1c5169';d.created_at= d.release_year; return d})
Insert cell
stackGen = d3.stack()
.keys(["models", "experiments", "institutions", "countries", "forcings"]);

Insert cell
stack = stackGen(dataset)
Insert cell
newdata = {
var d = [];
dataset.forEach((e, i) => {
["models", "experiments", "institutions", "countries", "forcings"].forEach(
(f, k) => {
d.push({
created_at: e.release_year, //`201${i}-01-01T01:01:01Z`,
platform: e.mip,
distribution: f, //e.mip,
version: `${i}.{i}.0`,
download_count: +e[f],
color: colors[k]
});
}
);
});
d.sort(function (a, b) {
return a.created_at - b.created_at;
});
return d;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
df = aq.from(newdata)
Insert cell
Insert cell
Insert cell
stackplot = (table, params) => {
const height = sizeScale(params.height)
const scaleOptions = {
grid: true,
tickSize: 0,
label: null
}
const yearMarkOptions = {
x: d => d,
text: d => d3.timeFormat('%Y')(d),
fontSize: sizeScale(12, 7),
fontWeight: 'bold',
fill: frameColors.regular,
stroke: frameColors.background
}
return Plot.plot({
width: width,
height: height,
marginRight: 0,
marginLeft: 0,
marginTop: 0,
marginBottom: 0,
style: {
color: frameColors.light,
background: "#faf8f5",
// background: frameColors.background
},
color: {
legend: true
},
x: {
...scaleOptions,
ticks: 50
},
y: {
...scaleOptions,
ticks: 5,
tickFormat: d => ''
// tickFormat: d => [0,1].includes(d) ? '' : params.tickFormatter(d)
},
marks: [
Plot.areaY(table, Plot.stackY({
x: 'created_at',
y: 'download_count',
z: params.z,
fill: params.color ? params.color : 'color',
fillOpacity: .85,
curve: 'basis',
offset: params.offset,
stroke: frameColors.background,
strokeWidth: .9,
title: d => `${d.platform}\n${'d.distribution'}`,
order: 'sum'
})),
Plot.ruleX(yearMarks, {
stroke: frameColors.background,
strokeWidth: 5,
strokeOpacity: 1
}),
params.maxY ? Plot.text([params.maxYText], {
x: last_release,
y: params.maxY,
lineAnchor: 'top',
text: d => d,
textAnchor: 'end',
fontSize: sizeScale(10, 7),
fontWeight: 'bold',
stroke: frameColors.background,
strokeWidth: 1.8,
fill: frameColors.regular,
dx: -2,
dy: 3,
}) : null,
params.maxY ? Plot.text([0], {
x: first_release,
y: 0,
lineAnchor: 'bottom',
text: d => d,
textAnchor: 'start',
fontSize: sizeScale(10, 7),
fontWeight: 'bold',
stroke: frameColors.background,
strokeWidth: 1.8,
fill: frameColors.regular,
dx: 2,
dy: -3,
}) : null,
params.yearTicks ? Plot.text(yearMarks, {
...yearMarkOptions,
frameAnchor: 'bottom',
dy: (-90 / 500) * height,
}) : null,
params.yearTicks ? Plot.text(yearMarks, {
...yearMarkOptions,
frameAnchor: 'top',
dy: (90 / 500) * height,
}) : null,
]
})
}
Insert cell
Insert cell
// platformColors = ({
// windows: '#eb9b00',
// macOS: '#1c5169',
// linux: '#be413b',
// 'ota updates': '#0c0d05'
// })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
topPlot = stackplot(df, {z:'distribution', height:100, offset:null, yearTicks: false, maxY: max_downloads, maxYText: `${d3.format('.2s')(max_downloads)} downloads`})
Insert cell
midPlot = stackplot(df, {
z: "distribution",
height: 500,
offset: "silhouette",
yearTicks: false
})
Insert cell
bottomPlot = stackplot(df, {z:'distribution', height:100, offset:'normalize', yearTicks: false, maxY: 1, maxYText:'100%'})
Insert cell
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