From f6eeea4f3f6cc00d5ca8d6995db40e6a75fd89d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 19 Jan 2025 14:04:33 +0100 Subject: [PATCH 1/2] test --- test/plots/index.ts | 1 + test/plots/window.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 test/plots/window.ts diff --git a/test/plots/index.ts b/test/plots/index.ts index f54398dca7..723501089f 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -356,4 +356,5 @@ export * from "./yearly-requests-dot.js"; export * from "./yearly-requests-line.js"; export * from "./yearly-requests.js"; export * from "./young-adults.js"; +export * from "./window.js"; export * from "./zero.js"; diff --git a/test/plots/window.ts b/test/plots/window.ts new file mode 100644 index 0000000000..a0351ae5f5 --- /dev/null +++ b/test/plots/window.ts @@ -0,0 +1,40 @@ +import * as Plot from "@observablehq/plot"; +import * as d3 from "d3"; + +export async function windowZ() { + const random = d3.randomLcg(42); + const data = d3.sort( + ["a", "b", "c"].flatMap((type, i) => + d3.utcDay.range(new Date("2024-01-01"), new Date("2025-01-01"), [1, 7, 30][i]).map((date) => ({ + type, + date, + value: ((random() * 1000) | 0) + i * 1500 + })) + ), + (d) => d.date + ); + + return Plot.plot({ + y: {grid: true}, + marks: [ + Plot.dot(data, { + x: "date", + y: "value", + fill: "type", + r: 1.5 + }), + Plot.lineY( + data, + Plot.windowY({ + x: "date", + y: "value", + anchor: "end", + stroke: {value: "type"}, + k: 10, + reduce: "mean", + tip: true + }) + ) + ] + }); +} From efa8d4b7a0f5056567ec219883cea6ac5d6e5f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 19 Jan 2025 14:41:37 +0100 Subject: [PATCH 2/2] temporary fix --- src/transforms/map.js | 2 +- test/output/windowZ.svg | 514 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 515 insertions(+), 1 deletion(-) create mode 100644 test/output/windowZ.svg diff --git a/src/transforms/map.js b/src/transforms/map.js index 5b0e5a270c..eaa422d6ba 100644 --- a/src/transforms/map.js +++ b/src/transforms/map.js @@ -32,7 +32,7 @@ export function map(outputs = {}, options = {}) { }); return { ...basic(options, (data, facets) => { - const Z = valueof(data, z); + const Z = valueof(data, isObject(z) ? z.value : z); const X = channels.map(({input}) => valueof(data, input)); const MX = channels.map(({setOutput}) => setOutput(new Array(data.length))); for (const facet of facets) { diff --git a/test/output/windowZ.svg b/test/output/windowZ.svg new file mode 100644 index 0000000000..1170428534 --- /dev/null +++ b/test/output/windowZ.svg @@ -0,0 +1,514 @@ + + + + + + 500 + 1,000 + 1,500 + 2,000 + 2,500 + 3,000 + 3,500 + + + ↑ value + + + + Jan2024 + Feb + Mar + Apr + May + Jun + Jul + Aug + Sep + Oct + Nov + Dec + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file