lineDotsLabel = (data, aggregator, color, label = '', rightLabelYOffset = 3, startDate = new Date(0)) => [
Plot.line(
data,
Plot.binX(
{ y: aggregator },
{ x: 'month', stroke: d => label, strokeWidth: 6, filter: d => +d.month > +startDate, thresholds: d3.timeMonth }
)
),
Plot.dot(
data,
Plot.binX(
{ y: aggregator },
{ x: 'month', fill: '#FFF', opacity: 0.5, filter: d => +d.month > +startDate, thresholds: d3.timeMonth, r: 3 }
)
),
Plot.text(
data,
Plot.selectLast(Plot.binX(
{ y: aggregator, text: g => d3.format('.0%')(aggregator(g)) + ' ' + label },
{
x: 'month',
dx: 5,
dy: rightLabelYOffset,
textAnchor: 'start',
stroke: '#FFF',
strokeWidth: 4,
fill: d => label,
fontWeight: 600,
fontSize: 12,
filter: d => +d.month > +startDate,
thresholds: d3.timeMonth
}
))
),
Plot.text(
data,
Plot.selectFirst(Plot.binX(
{ y: aggregator, text: g => d3.format('.0%')(aggregator(g)) },
{
x: 'month',
dx: -5,
dy: 3,
textAnchor: 'end',
fill: d => label,
stroke: '#FFF',
strokeWidth: 4,
fontWeight: 400,
filter: d => +d.month > +startDate,
thresholds: d3.timeMonth
}
))
)
]