Skip to content

fix(core): chart compare-to shifts {current_iso_week} to the compared week - #36416

Merged
objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-35395-compare-iso-week
Nov 22, 2026
Merged

objectstack-fleet[bot] merged 1 commit into
mainfrom
claude/issue-35395-compare-iso-week

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Steedos · project thread
Fixes #35395

Clause-②: no
Metadata-protocol: none

维护者速读

  • 仪表盘作者在图表筛选里用「本 ISO 周」并开启环比时,对比曲线从「同一周」改为「上一周」(同比则为去年同一天所在周),趋势标签显示「较上周」。
  • 修复图表环比/同比功能里的一处遗漏,替用周主数据做报表的作者解决对比失真。
  • 出错时只影响同时用到这个周占位符和对比功能的图表,对比数值不对;可直接撤回本改动。
  • 无

What changes

shiftFilterByCompareTo (ui/packages/core/src/utils/compare-to.ts) renamed date macros but left the {current_iso_week} period key as written, so the server resolved it to the current week and the comparison series filtered the same week as the main one.

  • previousPeriod: {current_iso_week} / ${current_iso_week} is replaced by the literal previous ISO week key (2026-W22 becomes 2026-W21). Week 1 steps back to the previous ISO year's last week: W53 when that year starts on a Thursday (or a Wednesday in a leap year), else W52. The literal key passes through every resolver unchanged. No new public token is added.
  • previousYear: the period key is resolved against the same shifted day the date macros already use (resolvePeriodKeyTokens), so it is the ISO week of the same day one year earlier.
  • compareToTrendLabelKey: a filter on {current_iso_week} now reads vsLastWeek instead of falling through to vsPreviousPeriod.

Other period-key placeholders that share the gap: none. PERIOD_KEY_TOKENS in @objectstack/spec/data has one member, current_iso_week.

Tests

New block compare-to on the {current_iso_week} period key in ui/packages/core/src/utils/__tests__/compare-to.test.ts: previousPeriod mid-year (W22 to W21, both spellings), week 1 to 2026-W53 and to 2025-W52, previousYear (2025-W21; Fri 2027-01-01 = 2026-W53 becomes 2026-W01), and the label.

Run on a2b9aa6
  • pnpm exec vitest run packages/core/src/utils/ --maxWorkers=1 (from ui/, under the verify lock): Test Files 124 passed (124), Tests 2214 passed (2214). pnpm --filter @object-ui/core type-check: exit 0. Lock: VERDICT command-exit 0.
  • Ablation, one-off (fix committed first): deleted the current_iso_week substitution line with scripts/ablation-replace.mjs, grep -c of the anchor = 0 on disk. compare-to.test.ts: Tests 2 failed / 33 passed. Both previousPeriod pins went red, and the received value was '{current_iso_week}', which is the bug. The test imports the source by relative path, so there is no dist leg. Restored with git checkout HEAD --: git diff HEAD is empty and the blob hash matches HEAD (d276c311).

Acceptance notes

  • ADR-0021 D3 dataset path: service-analytics dataset-executor.ts shifts only the chosen time dimension's dateRange (shiftRange). A selection filter is held constant across the compare pass, whether it holds a date macro or a period key. That is the executor's existing design, not a period-key regression. Noted here, not filed: read from code, no public-door measurement.

Verification

Read first: compare-to.ts previousIsoWeekKey (the year-edge arithmetic is the risky hunk), then its call in shiftFilterByCompareTo.
Two-minute check: cd ui && pnpm exec vitest run packages/core/src/utils/__tests__/compare-to.test.ts. Expect 35 passed.


Generated by Claude Code

🤖 Generated with Claude Code

https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg

@github-actions github-actions Bot added size/s documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 22, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · zhuangjianguo · session_01QsR2jREBdDtYvSLn38xUCg

Final head: a2b9aa62c2b8086da12bf1bf39e906daeb0c02ea — CI 45 success / 13 skipped / 0 failed; mergeable clean. Report on #35395. +64/-4, 3 files (ui/packages/core source + test + changeset), Clause-②: no, Metadata-protocol: none, no governed path.
Review route: over 50 lines with a source change ⇒ not area self-review; L1 requested from the L1-e thread via the seat.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · zhuangjianguo · session_01QsR2jSpi3g1dQNTvN6zEuH

席位核对

L1 (L1-e) on head a2b9aa62c2b8086da12bf1bf39e906daeb0c02ea, card #35395: ACCEPT. No contract face is touched, so no L2 is owed.

  • Shape (l1-face.mjs --pr 36416, CLEAN): open, draft, base main, Fixes #35395, Clause-②: no, Metadata-protocol: none. One changeset, @object-ui/core patch. Gates at this head: 45 success, 13 expected skip, 0 failed. Lint & Repo Gates and TypeScript Type Check are success. The two derived families left to CI through lock starvation (ui scripts vitest, check:type-check-debt) are answered by the check-runs at this head, so I count no local reading for them.
  • Fixes is right. The card's done-when is "a pin shows the compare series does not silently repeat the current week". It is met by compare-to.test.ts (previousPeriod → 2026-W21 from W22, never W22). The body's ablation is a positive control: with the substitution removed, 2 tests go red receiving {current_iso_week}. The card's constraint "no new public tokens" holds, because the key is written as the literal it resolves to.
  • Correctness:
    • previousIsoWeekKey: week 1 steps back to W53 when the previous ISO year starts on a Thursday, or on a Wednesday in a leap year, otherwise W52. That is the ISO 8601 rule, and the pins cover both arms (2027-W01 → 2026-W53, 2026-W01 → 2025-W52).
    • previousYear resolves the key on the same shifted day the date macros use, the same rule as every other token.
    • Both series resolve the key in the same timezone. The main series goes through resolveFilterPlaceholders (client, filter-tokens → resolvePeriodKeyTokens, display timezone), and the compare key now comes from the same resolvePeriodKeyTokens. Week-boundary hours cannot make the two series disagree.
    • Substitution is whole-token only (wholeToken / ^\$?\{…\}$), the same as every other token in this shift.
  • Changeset, checked sentence by sentence: previousPeriod → last week's key with the week-1 step-back, previousYear → the key of the same day a year earlier, the trend label "vs last week" (compareToTrendLabelKey regex gains current_iso_week). All true of the diff.
  • Out-of-scope note (the ADR-0021 dataset path holds selection.filter constant across the compare pass): that is existing design and read from code, and it is recorded in the PR. No card is owed from this PR.
  • SQL push-down: not applicable (a filter rewrite, no new read).

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#7 · zhuangjianguo · session_01QsR2jREBdDtYvSLn38xUCg

Landing: L1-e ACCEPT 7078530466 at a2b9aa62c2b8086da12bf1bf39e906daeb0c02ea, no L2 owed. check-governed-merges --pr 36416: NOT governed, 68 lines. K = 10 (git rev-list --first-parent --count 4e55e4eb..origin/main; landing-k.mjs cannot answer on a ui-only PR, no Test Core shard ran) < 15 ⇒ no merge of main. CI at this head 45 success / 13 skipped / 0 failed. Ready + auto-merge.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 22, 2026 11:36
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 285ad8d Nov 22, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-35395-compare-iso-week branch November 22, 2026 11:57
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…od chip (objectstack-ai#36767)

<!-- claude-projects-attribution: {"github_login":"os-warren"} -->
_Requested by **Warren** · [project
thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8Hx43jgsjNPA5ohr5yAhkBL)_

Fixes objectstack-ai#36645 — item 3 (「和上一期对比」). Item 1 shipped in objectstack-ai#36705; item 2 moved
to its own card, objectstack-ai#36722; so this closes the card.
Clause-②: yes (widening)
Metadata-protocol: none

## 维护者速读

-
用户能看到什么变化:报表上方的时间范围旁边多了一个「和上一期对比」开关,和「之前同样长的一段时间」比。打开后,按类别分组的柱状图、折线图(比如按状态)每组旁边多一根浅色柱,就是上一期的数;「数字」图在数字下面写「较上期
3(+133.3%)」。横轴本身就是按月/按周的日期时,不提供这个开关,因为两段时间的月份数可能不一样,柱子会对错月份。报表页和搭建页的预览都有。
- 为什么做:仪表盘和报表专题里搭建页的最后一项,是维护者看过的效果图三第 6 项的后半句;挡它的引擎缺陷 objectstack-ai#35395 已于 11-22
修好。
-
出错会怎样:开关只是看的人自己的选择,不存进报表,关掉就和以前一样;服务器拒绝对比时,图的位置会写明原因,不会悄悄消失。选「全部时间」时没有可对比的上一期,开关变灰。可以直接撤回本次合并。
- 要你做什么:无。(两件事没做、需要的话另开功能卡:「默认就打开对比」随报表保存;按「上一个自然月/季度」对比,好让日期横轴也能用。)

## What changes

**The switch** (`ui/packages/plugin-report/src/ReportDateRange.tsx`)
- `ReportCompareToggle`: 「Compare with previous period」 beside the
period chip. Like the chip's own pick it is the viewer's state, keyed on
the report's `dateRange` declaration, never written into the report.
Off, and disabled, while the period names no window (All time, or a
custom range missing an end).
- `reportChartComparable(chart, windowDimension)`: offered only where
the chart can draw a clean comparison — `bar`, `column`,
`horizontal-bar`, `line`, `area` over an x axis that is NOT the window's
own date dimension, or a single number (`metric`, `kpi`) — and not on a
`seriesBy` split (its series are values of the split dimension, so no
series pairs with the measure's earlier window). Pie / donut / funnel /
treemap / sankey / table are not offered it. Nothing is offered until
the window's dimension is known.
- `reportCompareTo`: the selection's `compareTo` only while on AND a
window exists.

**The chart**
(`ui/packages/plugin-report/src/DatasetReportRenderer.tsx`)
- `useDatasetRows` takes an optional `compareTo` and sends it beside the
window it shifts (`compareTo: { kind: 'previousPeriod', dimension: <the
window's dimension> }`, the existing `DatasetSelection.compareTo`
contract); it is part of the query signature, so toggling re-queries.
Only the embedded chart passes it; the table beside the chart is not
asked for a comparison.
- Series charts get one more series, `<measure>__compare` (the
executor's column), labelled `<measure> ·
<dashboard.trend.vsPreviousPeriod>` with `variant: 'comparison'`, the
chart's existing muted / dashed styling — the dashboard's overlay shape.
The chart is compared with the same-length window just before the
current one (the contract's `previousPeriod`). On a category axis the
rows merge by key, so each category's earlier total sits beside its
current one.
- A single number shows the previous value and the signed percent change
under it (`formatPeriodChange`, module-local; no percent when the
previous value is 0).
- A click on an earlier-window mark opens no record list (the
dashboard's `chartDrillMeasure` rule for the same series); a current
mark drills as before.
- A refused comparison is drawn as the error where the chart was.
Before, any chart error fell back silently to the table; with the switch
on that would leave it on over a vanished chart.

**Strings, docs, changeset**
- `@object-ui/i18n`: one key, `report.dateRange.comparePrevious`, in all
11 locales. The series caption reuses the dashboard's
`dashboard.trend.vsPreviousPeriod`.
- `content/docs/ui/reports.mdx` › *Period and export*: one bullet on the
switch, and the stale 「Declared, not drawn yet」 callout replaced (see
Acceptance notes).
- `.changeset/36645-report-compare-previous-period.md` (patch;
plugin-report, i18n).

No spec key, schema, export or server change.

Read first (by risk): `DatasetReportChart` in
`DatasetReportRenderer.tsx` (the series and the drill guard) ·
`reportChartComparable` (where the switch is offered).

## Why

objectstack-ai#36374 item 6 (board 49, figure 3): the time switch offers 「和上一期对比」 and
the chart draws both periods. It waited on objectstack-ai#35395 (`{current_iso_week}`
left unshifted by compare-to), closed 2026-11-22 by objectstack-ai#36416. On base
`460af0e4` the report renderer never sent `compareTo`, although the
analytics executor answers it.

## Verification

- New `DatasetReportRenderer.comparePrevious-36645.test.tsx`: `pnpm
--dir ui exec vitest run
packages/plugin-report/src/__tests__/DatasetReportRenderer.comparePrevious-36645.test.tsx`
→ 15 passed at `fd8a9260`. Ablation at the first head:
`DatasetReportRenderer.tsx` checked out from `origin/main` (the new
`ReportDateRange.tsx` exports left in place) → 8 failed | 4 passed; the
4 green by design are the "not offered" cases (donut, table, `seriesBy`,
no period), which hold on base because base offers no switch at all.
Ablation of the date-axis rule at `fd8a9260`: `ReportDateRange.tsx` and
`DatasetReportRenderer.tsx` checked out from `ccb43920` (before the
rule) → 2 failed | 13 passed, the two red being the new bar / line "not
offered on the window's own date axis" pins. Both restored; `git status`
clean before each commit.
- `pnpm --dir ui exec vitest run --maxWorkers=3 packages/plugin-report/`
at `fd8a9260` → 38 files, 377 passed | 7 skipped. `packages/i18n/`
(first head) → 107 files, 2006 passed | 13 skipped (key parity across
the 11 locales included).
- ESLint on the three touched plugin-report files: 0 errors (warnings
only, the file's existing `react-refresh` / test `any` kinds). `pnpm
check:new-line-citations` → 0 new.
- Not measured locally: the plugin-report type-check (it needs the built
`@object-ui/*` declarations this container did not build); covered by CI
Type Check UI.
- Executor, live (showcase, `showcase_invoice_metrics`, `last_90_days`,
grouped by `issued_on`):
`{"issued_on":"2026-09","invoice_count":2,"invoice_count__compare":1}`,
`2026-10` 2/1, `2026-11` 3/1 — the executor answers `compareTo`. (That
date-axis shape is the one the switch no longer offers; see Acceptance
notes.)
- Browser (showcase on a local server, console from this branch's `ui/`
source, zh-CN, admin). Frames in the project folder `issue-36645/`:
- `item3-1-switch-beside-period.png` (first head) — the switch beside
「今年」 on a number, off.
- `item3-6-date-axis-bar-not-offered.png` (`fd8a9260`) — new report →
Invoice Metrics → group by Issued → 近 90 天, bar: the period chip and no
switch.
- `item3-4-number-previous-and-change.png` (`fd8a9260`) — the same
report as 数字: switch on, 7, 「较上期 3 (+133.3%)」.
- `item3-7-category-axis-two-periods.png` (`fd8a9260`) — report page
「按状态统计工时(图表)」, its list response intercepted in the browser to add
`dateRange: { dimension: 'created_at', defaultRange: 'this_month' }`
(showcase ships no report with a period): 本月 + switch on, a lighter
earlier-window bar beside each status; the request carried
`"dimensions":["status"],…,"timeDimensions":[{"dimension":"created_at","dateRange":"this_month"}],"compareTo":{"kind":"previousPeriod","dimension":"created_at"}`.
- `item3-5-all-time-switch-off.png` (first head) — 全部时间: switch off and
disabled, one series.

## Acceptance notes

- Not done, by design: saving "compare on" as the report's default. That
is a new report spec key (a widening of `ReportSchema.dateRange`), a
separate Feature if wanted.
- Not done: a comparison column in the report's table / 「计算值」 grid; the
card asks the chart to draw both periods.
- Contract review S1 (comment 7109766175), resolved by the seat's
ruling: `ccb43920` first documented the position pairing; `fd8a9260`
then stops offering the switch on a chart whose x axis is the window's
own date dimension (the bars could pair with the wrong period where the
two windows split into different bucket counts), and words docs,
changeset and this body as "the same-length window just before it". A
calendar-aligned comparison would be a new `compareTo` kind (a spec
widening) and the seat files it as a separate Feature card. The
`runCompare` unaligned-bucket overwrite the review escalated is an
executor defect outside this diff, filed as objectstack-ai#36770.
- Fixed here on the seat's word (same file):
`content/docs/ui/reports.mdx` › *Period and export* carried the callout
「Declared, not drawn yet … there is no period chip」, false since the
renderer draws the chip and the Export control (both `live` in the spec
liveness ledger, so `os validate` no longer warns). Replaced with one
paragraph saying what the page draws.

## Human Minimum

- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; lint passes on the touched files.
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: n/a.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English (the maintainer
quick-read above is the allowed Chinese channel).
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01JQwxbYCxqr63HW2KJGpmAq

<!-- signed: repo:objectstack#1 · os-warren ·
session_01JQwxbYCxqr63HW2KJGpmAq -->

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/s tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chart compare-to (previous period) leaves {current_iso_week} unshifted, so the comparison series filters the same week

2 participants