Repository navigation
Commit b317942
fix(plugin-charts): a dataset object-chart draws a select dimension in declared option order (objectui#13403) (#13426)
Closes #13403
Clause-②: no
## What changed
A page-level `object-chart` bound to a `dataset` now draws a select
dimension in its field's declared option order, as the dashboard's
`DatasetWidget` already does for the same dataset (objectui#11809). The
showcase command center's priority panel read 高, 低, 中, 紧急 (the GROUP BY
order of `high, low, medium, urgent`) and now reads 低 → 中 → 高 → 紧急.
`packages/plugin-charts/src/ObjectChart.tsx` is the only source file
touched:
- The memo that already derives the option colours and dimension labels
from the first dimension's localized options now also derives
`categoryOrder` with `@object-ui/core`'s `buildCategoryOrder`. This
applies on the dataset path only, and only when the chart names a
dimension. A field with no options gives `null`, so nothing changes for
it.
- The rows are sorted by that order before `buildChartSeries`: declared
options first, then values the options do not declare, then the empty
bucket. The sort is stable. The order is put on the rows because
`AdvancedChartImpl` reads `categoryOrder` only in its funnel branch. A
bar, line or pie draws its rows in the order it receives them, which is
also why the dashboard sorts its `plotRows` itself.
- The schema handed to `ChartRenderer` carries `categoryOrder`, the same
key the dashboard hands it, which the funnel orders its stages by.
## Judgment calls (premise check)
- **No helper move.** `buildCategoryOrder` and `buildCategoryRank`
already live in `@object-ui/core`, which `plugin-charts` depends on.
`DatasetWidget.tsx` is untouched.
- **Passing `categoryOrder` alone would not have fixed the card.** The
card's mechanism is that "`AdvancedChartImpl` honours it through
`buildCategoryRank(categoryOrder)`". On `main` that holds only for the
funnel. The card's own panels are bars, so the rows had to be ordered as
well. `AdvancedChartImpl.tsx` is untouched (another agent is editing
it).
- **One local helper, `declaredOptionPosition`.** It applies the same
rule as the private function of the same name in `DatasetWidget`.
`DatasetReportRenderer` has a third private copy. Moving it to
`@object-ui/core` would add a core file to this card's declared surface,
so this PR does not do it. It is recorded below as a possible follow-up.
- **Gate is "the field declares options", not "the field type is
select".** This matches the dashboard: `DimensionFieldMeta` carries no
field type, and `buildCategoryOrder` returns `null` for a field without
options.
## Tests
New file
`packages/plugin-charts/src/ObjectChart.categoryOrder-13403.test.tsx`, 3
tests:
- The card's shape. Answered rows `high, low, medium, urgent` reach the
renderer as 低, 中, 高, 紧急, with their measures `[2, 7, 5, 1]`, and
`categoryOrder` equals `buildCategoryOrder(options)`, which is
`['low','低','medium','中','high','高','urgent','紧急']`.
- A value the options do not declare (`blocked`) comes after the
declared ones, and the null bucket comes last.
- Control: a dimension whose field declares no options gets no
`categoryOrder` key and keeps the dataset's answered order.
Results at head `2fa5702bc3`:
- New file: 3/3 passed.
- `pnpm exec vitest run --maxWorkers=2 packages/plugin-charts/`: 98
files, 1268 passed, 9 skipped.
- Dashboard #11809 controls, unchanged:
`DatasetWidget.selectOptionOrder-11809.test.tsx` and
`DatasetWidget.optionLabelI18n.test.tsx`, 2 files, 15/15 passed.
- `turbo run type-check --filter=@object-ui/plugin-charts...`: 19/19
tasks successful. `plugin-dashboard` was not touched.
- `eslint` on the two touched files: 0 errors and 35 warnings. The same
file at base also gives 35 warnings, so none are new.
- `node scripts/check-changeset-presence.mjs`: passes (one patch
changeset for `@object-ui/plugin-charts`).
- `pnpm check:new-line-citations`: 0 new.
Ablation was run on the committed fix, restored with `git checkout
HEAD`, and the restored blob hash matches HEAD:
- Leg A, row sort disabled: 2 failed, 1 passed (the two ordering tests
fail; the control passes).
- Leg B, `categoryOrder` hand-off removed: 2 failed, 1 passed.
## Acceptance notes
- The second dimension's series order is not applied on this path. The
dashboard also orders a pivoted second select dimension's legend
(`seriesOrder`, objectui#11809). The card names the category axis only,
so this PR leaves the series as they are.
- `ChartRenderer`'s doc comment on `categoryOrder` still says it is "Set
by DatasetWidget". `ObjectChart` now sets it too. `ChartRenderer.tsx` is
outside this card's surface.
- `declaredOptionPosition` now has three private copies:
`DatasetWidget`, `DatasetReportRenderer` and `ObjectChart`. A single
home in `@object-ui/core` is a possible follow-up.
- [x] Adds no product-specific widget, dialog, hook or string (see
AGENTS.md › Product-neutral renderer)
Session: `https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj`
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01WJozybDmRH8z2c5SD7vJkj
Co-authored-by: Claude <noreply@anthropic.com>1 parent 2c3dc72 commit b317942
3 files changed
Lines changed: 277 additions & 6 deletions
File tree
- .changeset
- packages/plugin-charts/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
171 | 190 | | |
172 | 191 | | |
173 | 192 | | |
| |||
704 | 723 | | |
705 | 724 | | |
706 | 725 | | |
707 | | - | |
708 | | - | |
| 726 | + | |
| 727 | + | |
709 | 728 | | |
710 | 729 | | |
711 | 730 | | |
| |||
730 | 749 | | |
731 | 750 | | |
732 | 751 | | |
733 | | - | |
734 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
735 | 765 | | |
736 | 766 | | |
737 | 767 | | |
| |||
1273 | 1303 | | |
1274 | 1304 | | |
1275 | 1305 | | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
1276 | 1325 | | |
1277 | 1326 | | |
1278 | | - | |
| 1327 | + | |
1279 | 1328 | | |
1280 | 1329 | | |
1281 | 1330 | | |
| |||
1369 | 1418 | | |
1370 | 1419 | | |
1371 | 1420 | | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
1372 | 1425 | | |
1373 | 1426 | | |
1374 | 1427 | | |
| |||
0 commit comments