diff --git a/src/transforms/window.js b/src/transforms/window.js
index be733dd8bc..7e4c7096a3 100644
--- a/src/transforms/window.js
+++ b/src/transforms/window.js
@@ -96,24 +96,24 @@ function reduceAccessor(f) {
strict
? {
mapIndex(I, S, T) {
- const s = (i) => (S[i] == null ? NaN : +S[i]);
+ const v = (i) => (S[i] == null ? NaN : +S[i]);
let nans = 0;
- for (let i = 0; i < k - 1; ++i) if (isNaN(s(i))) ++nans;
+ for (let i = 0; i < k - 1; ++i) if (isNaN(v(i))) ++nans;
for (let i = 0, n = I.length - k + 1; i < n; ++i) {
- if (isNaN(s(i + k - 1))) ++nans;
- T[I[i + s]] = nans === 0 ? f(slice(I, i, i + k), s) : NaN;
- if (isNaN(s(i))) --nans;
+ if (isNaN(v(i + k - 1))) ++nans;
+ T[I[i + s]] = nans === 0 ? f(slice(I, i, i + k), v) : NaN;
+ if (isNaN(v(i))) --nans;
}
}
}
: {
mapIndex(I, S, T) {
- const s = (i) => (S[i] == null ? NaN : +S[i]);
+ const v = (i) => (S[i] == null ? NaN : +S[i]);
for (let i = -s; i < 0; ++i) {
- T[I[i + s]] = f(slice(I, 0, i + k), s);
+ T[I[i + s]] = f(slice(I, 0, i + k), v);
}
for (let i = 0, n = I.length - s; i < n; ++i) {
- T[I[i + s]] = f(slice(I, i, i + k), s);
+ T[I[i + s]] = f(slice(I, i, i + k), v);
}
}
};
diff --git a/test/output/sfTemperatureWindow.svg b/test/output/sfTemperatureWindow.svg
new file mode 100644
index 0000000000..9ba17a2d0e
--- /dev/null
+++ b/test/output/sfTemperatureWindow.svg
@@ -0,0 +1,98 @@
+
\ No newline at end of file
diff --git a/test/plots/index.ts b/test/plots/index.ts
index 15ade2348a..93bc831398 100644
--- a/test/plots/index.ts
+++ b/test/plots/index.ts
@@ -245,6 +245,7 @@ export * from "./seattle-temperature-cell.js";
export * from "./sf-covid-deaths.js";
export * from "./sf-temperature-band-area.js";
export * from "./sf-temperature-band.js";
+export * from "./sf-temperature-window.js";
export * from "./shorthand-area.js";
export * from "./shorthand-areaY.js";
export * from "./shorthand-barY.js";
diff --git a/test/plots/sf-temperature-window.ts b/test/plots/sf-temperature-window.ts
new file mode 100644
index 0000000000..23d175d488
--- /dev/null
+++ b/test/plots/sf-temperature-window.ts
@@ -0,0 +1,18 @@
+import * as Plot from "@observablehq/plot";
+import * as d3 from "d3";
+
+export async function sfTemperatureWindow() {
+ const sftemp = await d3.csv("data/sf-temperatures.csv", d3.autoType);
+ return Plot.plot({
+ y: {
+ grid: true,
+ label: "Temperature (°F)"
+ },
+ marks: [
+ Plot.lineY(sftemp, {x: "date", y: "low", strokeOpacity: 0.3}),
+ Plot.lineY(sftemp, Plot.windowY({k: 28, reduce: "min"}, {x: "date", y: "low", stroke: "blue"})),
+ Plot.lineY(sftemp, Plot.windowY({k: 28, reduce: "max"}, {x: "date", y: "low", stroke: "red"})),
+ Plot.lineY(sftemp, Plot.windowY({k: 28, reduce: "median"}, {x: "date", y: "low"}))
+ ]
+ });
+}