{
const filter = d => filter_date(d.orderDate, ins.interval) && filter_dow(d.day_of_week, ins.dow);
const x = 'orderDate';
const y = ins.data;
const z = ins.z == 'none' ? undefined : ins.z;
const color = ins.z == 'none' ? d => '#AAA' : ins.z;
const agg = 'sum';
const tooltip = d => `${format_date(d[0].orderDate)} ${d3.sum(d, v => v[ins.data])}`;
const pizzaByDay = ins.show.includes('mean') && ins.facet == 'no facet' && z == 'day_of_week' ?
d3.rollups(pizzaOrders.filter(filter), d => aggregate(d, ['orderDate', 'day_of_week']), d => d.orderDate) :
[];
return Plot.plot({
facet: ins.facet == 'no facet' ? undefined : {
data: pizzaOrders,
y: ins.facet
},
marks: [
Plot.frame({anchor: "bottom"}),
Plot.ruleY(pizzaByDay, Plot.groupZ({y: 'mean'},
{y: d => d[1][y], z: d => d[1].day_of_week, stroke: d => d[1].day_of_week})),
Plot.dot(pizzaOrders,
Plot.groupX({y: agg, title: tooltip},
{x, y, fill: color, filter, r: ins.radius})),
Plot.line(ins.show.includes('line') ? pizzaOrders : [],
Plot.groupX({y: agg},
{x, y, stroke: color, filter, curve: ins.curve, strokeWidth: ins.line_width}))
],
y: {
tickFormat: ins.data == 'total' ? d3.format('$,') : null,
grid: true
},
color: {
legend: ins.z == 'none' ? false : true,
domain: z == 'day_of_week' ? d3.range(7) : undefined,
tickFormat: z == 'day_of_week' ? d => dow_legend[d] : undefined
},
width
});
}