{
const tempWithGaps = temp.slice(0,100)
.map((d, i) => ({...d, valueOrGap: [22, 53, 60, 87].includes(i) ? NaN : d.middle}));
const customWindowY = ({ anchor, k, reduce = d3.mean, ...options }) =>
Plot.map(
{
y: (v) => {
const R = Array.from(v, () => null);
const a =
anchor === "start" ? 0 : anchor === "end" ? k - 1 : (k - 1) >> 1;
for (let i = -a; i + k -a < v.length; i++) {
R[a + i] = reduce(v.slice(Math.max(0, i), i + k + 1));
}
return R;
}
},
options
);
return Plot.plot({
caption: `Custom map, ignoring gaps`,
marks: [
Plot.dot(
tempWithGaps,
{
x: "date",
y: d => d.valueOrGap || 43.5,
fill: d => !!d.valueOrGap,
r: 2.5
}
),
Plot.line(
tempWithGaps,
customWindowY({
k : 5,
x: "date",
y: "valueOrGap",
stroke: "orange",
strokeWidth: 4
})
),
Plot.line(
tempWithGaps,
Plot.windowY({
k : 5,
x: "date",
y: "valueOrGap",
stroke: "brown",
strokeWidth: 3
})
),
],
color: { domain: [false, true], range: ["brown", "grey"] },
height: 250
});
}