window transform: difference, ratio, first and last drop the trailing outputs of each series

未关闭 适合新手
#2,472 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, node.js

调研方向

阅读 src/transforms/window.js 并检查 reduceDifference、reduceRatio、reduceFirst 和 reduceLast,将它们在 strict 和 non-strict 模式下的循环边界与示例中描述的行为进行比较。为两种模式下的末尾输出添加或更新测试,然后运行相关的 window transform 测试。当这些 reducer 生成预期的完整长度输出(包括 strict 为 false 时被截短的末尾窗口)时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

The difference, ratio, first and last window reducers stop their loops early: with strict: true the last full window is missing, and with strict: false the last k - 1 - s truncated windows are missing. Other reducers such as mean fill these positions.

import * as Plot from "@observablehq/plot";

const run = (w, data) => {
  const o = Plot.windowY(w, {x: "i", y: "v"});
  o.transform(data, [Uint32Array.from(data, (_, i) => i)]);
  return Array.from(o.y.transform());
};
const d = [2, 4, 8, 16].map((v, i) => ({i, v}));

console.log(run({k: 2, reduce: "difference", strict: true, anchor: "end"}, d));
console.log(run({k: 2, reduce: "ratio",      strict: true, anchor: "end"}, d));
console.log(run({k: 1, reduce: "last",       strict: true}, d));
console.log(run({k: 3, reduce: "first",      anchor: "start"}, d));
console.log(run({k: 3, reduce: "difference", anchor: "start"}, d));
console.log(run({k: 3, reduce: "mean",       anchor: "start"}, d));

node t.mjs

Actual:

[ undefined, 2, 4, undefined ]
[ undefined, 2, 2, undefined ]
[ 2, 4, 8, undefined ]
[ 2, 4, undefined, undefined ]
[ 6, 12, undefined, undefined ]
[ 4.666666666666667, 9.333333333333334, 12, 16 ]

Expected:

[ undefined, 2, 4, 8 ]
[ undefined, 2, 2, 2 ]
[ 2, 4, 8, 16 ]
[ 2, 4, 8, 16 ]
[ 6, 12, 8, 0 ]
[ 4.666666666666667, 9.333333333333334, 12, 16 ]

In a chart, Plot.lineY(data, Plot.windowY({k: 7, reduce: "difference"}, ...)) stops short of the right edge.

Tested with @observablehq/plot 0.6.19 and main 2245188, Node.js v26.13.0.

In src/transforms/window.js, reduceDifference, reduceRatio, reduceFirst and reduceLast use n = I.length - k in the strict branch (should be I.length - k + 1) and n = I.length - k + s + 1 in the non-strict branch (should be I.length - s, with the window clipped to I.length).

Credit: https://ucsbplse.github.io/

主要语言
HTML
星标
5.4k
派生
251
平均合并
2 天 1 小时
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

observablehq/plot 的其他 Issue

查看 observablehq/plot 的全部 Issue

相似的 Issue

更多 Data Visualization Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。