Repository navigation
Commit 285ad8d
fix(core): chart compare-to shifts {current_iso_week} to the compared week (#36416)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbD5gxSWeWGswbZYVzNvtqNM)_
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.
<details><summary>Run on a2b9aa6</summary>
- `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`).
</details>
## 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](https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jREBdDtYvSLn38xUCg
Co-authored-by: Claude <noreply@anthropic.com>1 parent 5345905 commit 285ad8d
3 files changed
Lines changed: 64 additions & 4 deletions
File tree
- .changeset
- ui/packages/core/src/utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
136 | 154 | | |
137 | 155 | | |
138 | 156 | | |
| |||
246 | 264 | | |
247 | 265 | | |
248 | 266 | | |
249 | | - | |
| 267 | + | |
| 268 | + | |
250 | 269 | | |
251 | 270 | | |
252 | 271 | | |
| |||
266 | 285 | | |
267 | 286 | | |
268 | 287 | | |
269 | | - | |
| 288 | + | |
| 289 | + | |
270 | 290 | | |
271 | 291 | | |
272 | 292 | | |
| |||
278 | 298 | | |
279 | 299 | | |
280 | 300 | | |
| 301 | + | |
281 | 302 | | |
282 | 303 | | |
283 | 304 | | |
| |||
313 | 334 | | |
314 | 335 | | |
315 | 336 | | |
316 | | - | |
| 337 | + | |
317 | 338 | | |
318 | 339 | | |
319 | 340 | | |
| |||
0 commit comments