From 73b1a45ddb2cc133dca8b78702180eca1e5e0168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 14 Jun 2023 14:24:55 +0200 Subject: [PATCH] variable name conflict between s and v --- src/transforms/window.js | 16 ++--- test/output/sfTemperatureWindow.svg | 98 +++++++++++++++++++++++++++++ test/plots/index.ts | 1 + test/plots/sf-temperature-window.ts | 18 ++++++ 4 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 test/output/sfTemperatureWindow.svg create mode 100644 test/plots/sf-temperature-window.ts 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 38 + 40 + 42 + 44 + 46 + 48 + 50 + 52 + 54 + 56 + 58 + 60 + 62 + + + ↑ Temperature (°F) + + + + + + + + + + + + + + October + 2011 + April + July + October + 2012 + April + July + October + + + + + + + + + + + + + + \ 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"})) + ] + }); +}