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",
},
color: {
legend: true
},
x: {
...scaleOptions,
ticks: 50
},
y: {
...scaleOptions,
ticks: 5,
tickFormat: 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,
]
})
}