Skip to content

Commit a386a1d

Browse files
fix(plugin-charts): a report or dashboard chart's value axis prints a whole-scale percent and a currency measure in the measure's units (#37194)
Fixes #37053 Clause-②: yes Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:报表和仪表盘里的图表,纵轴刻度现在带上指标自己的单位——按百分点存储的百分比指标从「0、9、18、27、36」变成「0.0%、9.0%、18.0%、27.0%、36.0%」,人民币金额指标从「3K、6K」变成「CN¥3K、CN¥6K」(中文界面写作「¥30万」这样的形式);仪表盘组件画按小数存储的百分比指标时,纵轴原来没有百分号(组件不传纵轴格式),现在读作「0.0%…34.0%」,与旁边表格的读法一致。 - 为什么做:接续上一张修复报表图表百分比纵轴的卡,补齐它当时留下的另一半(按百分点存储的百分比和货币金额)。HotCRM「SLA 表现」报表的违约率是按小数存储的百分比,它的报表纵轴上一张卡已修好,本次不变;变化的只是画同一指标的仪表盘组件。 - 出错会怎样:最坏是某张图表的纵轴单位或小数位显示得不如预期,数值和图形本身不变;每行币种不同的金额指标仍显示纯数字;撤回这次改动即可恢复原样。 - 要你做什么:无。 ## What changes Route **B** of the card, as the seat chose it: an internal value-format carrier beside the internal series props. No spec change. The report and dashboard producers fill the carrier; it is not meant to be authored, and #37214 refuses it on static chart nodes. 1. **The carrier.** `series[].measureFormat` carries the measure's `{ format, currency, percentScale }`. It sits on the chart renderer's internal series props, beside `series[].aggregate`, and follows that key's precedent: the report and dashboard producers fill it from the dataset answer, and it is not meant to be authored (#37214 refuses it on static chart nodes). Three places hold it: - `MeasureValueFormat` and `NormalizedSeries.measureFormat` in `normalizeChartSchema.ts`; - `normalizeSeries`, which keeps the carrier's three keys and nothing else; - the internal `dataKey` arm of `ChartRendererProps.schema.series`. 2. **The value axis reads it** at the tick-step place PR #37051 introduced (`valueAxisTickFormatter` in `AdvancedChartImpl.tsx`). The order is a declared axis `format` first (`formatterFor`, unchanged), then the measure's units, then the compact default. An axis uses a carrier only when every series bound to it carries the same one and that carrier names a unit, either a currency or a `%` pattern (`sharedMeasureFormat`). This is the same all-or-nothing rule `plotsWholeNumbers` applies to `aggregate`. Data labels print with their axis' formatter (objectstack#27372), so they carry the units too. - **Percent:** printed through `formatMeasure` from `@object-ui/core`, the function the table uses, at the column's own `percentScale`. The pattern's places are the minimum and grow to the step's place (the `formatterFor` rule), so two ticks never share a label. A `whole` rate of 33.3 now reads `0.0%` … `36.0%`. - **Currency:** printed as the compact default with the currency's symbol (`CN¥3K` … `CN¥12K` in `en`, `¥30万` in `zh-CN`). `compactTickFormatter` gains an optional `currency` argument. If `Intl` refuses the code, the tick falls back to the plain compact number. 3. **The producers fill it.** - `DatasetReportRenderer.tsx` (`measureFormatCarrier`) gives every drawn series the measure's facts. That covers a `seriesBy` split and the earlier-window series too. - `DatasetWidget.tsx` gives each series the facts of the measure it plots. A pivot uses its one measure; any other series uses its own measure or that measure's earlier window. The dimensionless (transposed) series carries a carrier only when every measure formats alike. - Both producers take the currency from `measureCellCurrency(field)` with no row. That is the currency the table prints a cell with when the cell has no row of its own. 4. **The per-row currency carve-out.** A measure with a per-row `currencyField` has no single axis currency. `measureCellCurrency` returns none for it, so its carrier holds no currency and its axis keeps the plain-number default. The pin for this is the control in each test file. 5. **The fraction-scale path from PR #37051 is unchanged.** The report still passes `yAxis[0].format` for a fraction-scale percent, and a declared axis format outranks the carrier. The `percentAxisFormat` docblock now points to the carrier. Responsibility: whose code is it? The platform's own `@object-ui/plugin-charts` value axis, whose `format` key carries only a d3 pattern. Is there an existing platform path? None: the table's `formatMeasure` path never reaches the chart axis. Who reaches it? Every report or dashboard chart over a whole-scale percent or currency measure. ## Tests The pins live in the shared harness of each mechanism, as AGENTS.md's ruling record 6583487846 asks: each is a new top-level `describe` for objectstack#37053 in the file that already holds the neighbouring pin. Each SUBJECT is red with this card's source files at their `main` blobs and green after (see Verification). - `ui/packages/plugin-charts/src/AdvancedChartImpl.axisLabels.test.tsx`, the axis-tick harness that holds the objectstack#36988 pin. It builds a real chart through `normalizeChartSchema`, with the series carrier as a producer hands it. - A whole-scale percent's ticks are `['0.0%', '9.0%', '18.0%', '27.0%', '36.0%']`. Each tick equals `formatMeasure(tick, '0.0%', undefined, 'whole', 'en')`, and the table's `33.3%` is the same function's output. - A `CNY` measure's ticks are `['CN¥0', 'CN¥3K', 'CN¥6K', 'CN¥9K', 'CN¥12K']`, a `USD` measure's are `['$0', '$3K', '$6K', '$9K', '$12K']`, and a `CNY` measure in a `zh-CN` session reads `['¥0', '¥30万', '¥60万', '¥90万', '¥120万']`. - CONTROL: a per-row currency measure (pattern, no currency) keeps distinct plain ticks `['0', '3K', '6K', '9K', '12K']`. - Also pinned: - a fraction-scale percent through the carrier alone (the dashboard's case); - a declared axis `format` wins over the carrier: `yAxis: [{ format: '0,0' }]` over a `CNY` measure reads `0` … `12,000` with no `CN¥`. This pin goes red when the order in `valueAxisTickFormatter` is swapped (see Verification); - the report's fraction-scale `yAxis[0].format` path still reads `0.0%` … `34.0%` beside its carrier (PR #37051); - a `'0%'` pattern on a 0.85-point step reads `0.00%` … `3.40%`; - data labels read `33.3%`; - two differently formatted series on one axis keep the default. - `ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.chartChrome.test.tsx`, the report chart-schema harness that holds the objectstack#36988 pin. It checks the schema the registered chart receives: - the carrier for a whole-scale percent, with the table's `33.3%` beside it and still no `yAxis`; - the carrier for a `CNY` measure; - the per-row currency control, whose carrier has no currency; - every `seriesBy` series carrying the carrier; - a fraction-scale percent keeping its `yAxis[0].format`; - no carrier for a measure that states no facts. `plugin-report` does not depend on `plugin-charts`, so this pin stops at the schema. The chart harness above draws it, the same split the objectstack#36988 pin uses. - `ui/packages/plugin-dashboard/src/__tests__/DatasetWidget.integerMeasureTicks-11681.test.tsx`, the widget value-axis harness that holds the `aggregate` carrier's pins. It renders the real chain (`DatasetWidget` → `SchemaRenderer` → `chart` → `AdvancedChartImpl`, no stub) and pins: - the whole-scale percent widget (`0.0%` … `36.0%`, equal to `formatMeasure`); - the `CNY` widget (`CN¥0` … `CN¥12K`); - the per-row currency control (`0` … `12K`); - the transposed (dimensionless) series over two measures that format alike reads `0.0%` … `36.0%`, and its control, a percent beside a currency, keeps plain numbers; - the comparison overlay (`compareColumn`) carries its measure's format, so the axis keeps `0.0%` … `36.0%` with both windows drawn. - `ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.comparePrevious-36645.test.tsx`, the report compare harness: with 「Compare with previous period」 on, both the current and the `amount__compare` series carry the `CNY` carrier, and a measure with no format facts gives neither series one (the control). - `ui/packages/plugin-report/src/__tests__/DatasetReportRenderer.measureFormatCarrierParity-37053.test.ts` keeps the two copies of `measureFormatCarrier` in step. A shared copy would belong in `@object-ui/core`, which is outside this card's surface, so this pin holds them together instead. The pin has two halves: - **Text:** the dashboard's copy is byte-identical to the report's, read from source. A floor stops a slice that caught nothing from passing. - **Behaviour:** the report's copy, over six field shapes plus no field, answers the carrier the chart reads. Because the text is identical, the same input field gives the same carrier in both producers. No harness exists for a cross-producer pin, so this one has its own file. ## Acceptance notes - **Currency ticks are compact, not the table's full amount (a deviation from route B's "through `formatMeasure`" wording for this one unit, ruled A by the maintainer: 7153146695).** `formatMeasure` has no compact notation. Its amount is the width of a cell (`CN¥12,000.00` in `en`, `CN¥1,200,000.00` for a pipeline total), and every vertical value axis is drawn 48 px wide (`VALUE_AXIS_WIDTH_PX`). The leading symbol is the part that would be cut off. Widening the axis band was not taken because the 48 px figure feeds the plot-width fit (`categoryLabelsFitBand`) and the `X_AXIS_ALL_LABELS_MAX_BUCKETS` derivation. The compact reading with the symbol is the convention the axis already uses for every amount. The maintainer ruled this compact form, with the symbol from the same `Intl` source the table uses (7153146695). The pins are the fixed-ISO currency cases above (`CN¥0` … `CN¥12K`). Routing currency ticks through `formatMeasure` with a `notation` option on `@object-ui/core` is a follow-up card (#37224). - **Only two units travel: a `%` pattern and a single currency.** A measure with a plain numeral pattern (no `%`, no currency, e.g. `'0,0.00'`) keeps the compact default (`1.2M`), as before; its carrier names no unit the axis prints, so `sharedMeasureFormat` passes it by. - **`formatMeasure` prints a pattern's places as a fixed width.** So a percent axis whose step needs more places than the pattern prints trailing zeros (`0.00%` … `3.40%`), where `formatterFor` would print `0%` … `3.4%`. The labels stay distinct and each one is the table's reading of that number. - **The by-name refusal of `series[].measureFormat` in `@object-ui/types` is not in this PR; it is #37214.** Refusing a key that the published loose `ChartDataSeriesSchema` accepts narrows what an author can write. That is `Clause-②: yes (narrowing)` with `Metadata-protocol: narrowed`, and under ADR-0087 it owes a semantic ledger entry under `packages/spec/src/migrations/entries/semantic/`. Seat repo:objectstack#4 ruled to keep this PR non-breaking (widening only), with no spec change. The refusal, its pin and the drafted ledger entry go to #37214, which carries its own L2 and dogfood run. **Until #37214 lands, the carrier is author-writable on a static SDUI chart node:** a hand-written `measureFormat` there is honoured. The spec's strict `ChartSeriesSchema` already refuses the key. - **`measureFormatCarrier` is written twice**, once in each producer. Its shared home (`@object-ui/core`, beside `buildChartSeries`' `aggregateOf`) is outside this card's file surface, so the two copies are exported from their modules (not from either package's entry), cross-referenced in their docblocks, and held identical by the parity pin above. - **The file surface as read.** "The chart renderer's internal props type beside it" was read as the internal series types: `NormalizedSeries` and its reader `normalizeSeries` in `normalizeChartSchema.ts`, and the `dataKey` arm in `ChartRenderer.tsx`. Those are where `series[].aggregate`, the named precedent, lives. The pure formatter helpers (`sharedMeasureFormat`, `measureTickFormatter`, and the `currency` argument of `compactTickFormatter`) sit in the same file, beside `formatterFor` and `compactTickFormatter`. - **Not in this card:** - tooltips keep their own value text; - object-bound charts (`ObjectChart` over `aggregate`) fill no carrier; - a horizontal-bar chart's value axes (drawn across the plot) take the same formatter, but this card does not pin them. ## Verification Two-minute check: `cd ui && pnpm --filter @object-ui/plugin-charts exec vitest run --root ../.. --maxWorkers=2 packages/plugin-charts/src/AdvancedChartImpl.axisLabels.test.tsx packages/plugin-report/src/__tests__/DatasetReportRenderer.chartChrome.test.tsx packages/plugin-report/src/__tests__/DatasetReportRenderer.comparePrevious-36645.test.tsx packages/plugin-report/src/__tests__/DatasetReportRenderer.measureFormatCarrierParity-37053.test.ts packages/plugin-dashboard/src/__tests__/DatasetWidget.integerMeasureTicks-11681.test.tsx`. Expect 5 files and 85 tests to pass, among them the objectstack#37053 describes reading `0.0%` … `36.0%`, `CN¥0` … `CN¥12K`, `$12K` and `¥30万`. Read first, in order of risk: 1. `ui/packages/plugin-charts/src/normalizeChartSchema.ts`: `measureTickFormatter` (the places rule at the displayed scale) and `sharedMeasureFormat` (when an axis takes a carrier). 2. `ui/packages/plugin-dashboard/src/DatasetWidget.tsx`: `seriesMeasureFormat` (which measure a series plots, including the transposed and comparison series). 3. `ui/packages/plugin-charts/src/AdvancedChartImpl.tsx`: the precedence in `valueAxisTickFormatter`. <details><summary>Package suites and type-check at 8816da6 (after merging origin/main)</summary> - `pnpm --filter @object-ui/plugin-charts exec vitest run --root ../.. --maxWorkers=2 packages/plugin-charts/ packages/plugin-report/ packages/plugin-dashboard/ packages/types/`: Test Files 749 passed (749), Tests 14386 passed, 22 skipped. Exit 0, run under the verify lock. - `pnpm --filter @object-ui/types --filter @object-ui/plugin-charts --filter @object-ui/plugin-report --filter @object-ui/plugin-dashboard run type-check` (all four script names echoed): exit 0. </details> <details><summary>Ablations and red on main</summary> Both ablation legs ran under the verify lock at HEAD 8816da6, over the five harness files in the two-minute check (85 tests). Each leg was restored to blob 4811aff == HEAD, with `git diff HEAD` empty. - **Leg A, the carrier read:** `scripts/ablation-replace.mjs` deleted `?? measureTickFormatter(sharedMeasureFormat(plotted), displayLocale, exponent)` from `AdvancedChartImpl.tsx` (anchor 1 → 0, blob 4811aff → 4faad709). Result: 11 failed, 74 passed. - The 7 chart cases that need the carrier failed: whole-scale percent, `CNY`, `USD`, `zh-CN`, fraction through the carrier, the coarse pattern and data labels. - The 4 widget cases failed: percent, `CNY`, the transposed series and the comparison overlay. - The controls stayed green: per-row currency, the mixed series, the mixed transposed series, the declared `0,0` axis and the fraction `yAxis[0].format` path. The report schema pins, the compare pins and the parity pin stayed green too, as producer pins should. - **Leg B, the precedence swapped (the seat's S1):** the replacement made `valueAxisTickFormatter` read the carrier before a declared axis `format` (anchor 1 → 0, blob 4811aff → c948f168). Result: 1 failed, 84 passed. The one failure is "a declared axis `format` wins over the carrier", the pin S1 asked for. - **Red on main**, taken at c8a011b before the harness move, over the same assertions: the five edited source files were set to their `main` (95734fe) blobs, with hashes checked on disk. Result: 12 failed, 5 passed. Each file was restored to its HEAD blob, and both `git diff HEAD` and the porcelain were empty. The round-2 producer pins were not run on main. On main no series carries `measureFormat`, so their carrier expectations fail by construction. </details> <details><summary>Derived gate families (dispatch-gates --commands, 40 families, tree 8816da6)</summary> All 40 exited 0 when re-run on this head, with the exit code captured before any pipe. `pnpm --dir ui exec vitest run --maxWorkers=2 scripts/` (under the lock) reported Test Files 172 passed, 2 skipped, and Tests 5130 passed. `dispatch-gates --ran`: 40 derived, 40 run, 0 NOT-MEASURED, 0 UNRUN. The CI-owned families are read from this PR's check-runs. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D)_ <!-- signed: repo:objectstack#4 · os-justin · session_01QSeKYmRepQK9DkZeU7F53D --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent ad604c1 commit a386a1d

13 files changed

Lines changed: 791 additions & 20 deletions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/plugin-charts': patch
3+
---
4+
5+
fix(plugin-charts): a chart's value axis prints its dataset measure's percent and currency units
6+
7+
Clause-②: yes
8+
Metadata-protocol: none
9+
10+
- **A value axis over a dataset measure reads in the measure's units.** The chart renderer's internal series props carry one more producer-filled key, `series[].measureFormat` (the measure's `format`, `currency` and `percentScale`), beside `series[].aggregate`. The report chart and the dashboard widget fill it from the dataset answer; it is not meant to be authored, and objectstack#37214 refuses it on a static chart node. A value axis whose series all carry the same one prints its ticks, and the data labels that share its format, in that measure's units:
11+
- a percent pattern prints through `formatMeasure`, the function the table uses, at the column's own `percentScale`. A measure stored in percentage points (`percentScale: 'whole'`) reads `0.0%` … `36.0%`, where the axis printed `0` … `36`;
12+
- a measure with one ISO currency prints the compact default with that currency's symbol (`CN¥3K` … `CN¥12K`, `¥30万` in Chinese), where the axis printed `3K` … `12K`.
13+
- A declared axis `format` still wins over the measure's units. A measure with a per-row currency (`currencyField`) has no single currency, so its axis keeps plain numbers. Two series on one axis that are formatted differently also keep the default axis.
14+
15+
Nothing to migrate: no metadata key changes, and the widened series type is the renderer's internal one.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-dashboard': patch
3+
---
4+
5+
fix(plugin-dashboard): a dashboard chart widget's value axis prints its measure's percent and currency units
6+
7+
Clause-②: yes
8+
Metadata-protocol: none
9+
10+
A dataset chart widget's series now carry the format facts of the measure they plot (`format`, `percentScale` and its single currency) as the chart's internal `series[].measureFormat`. The value axis then prints a percent measure as percents (`0.0%` … `36.0%` for a rate in percentage points, which drew `0` … `36` before) and a currency amount with its symbol, as the widget's table prints them. A measure with a per-row currency (`currencyField`) keeps plain numbers. A dimensionless chart that plots several measures carries a format only when they all share it.
11+
12+
Nothing to migrate: no metadata key changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-report': patch
3+
---
4+
5+
fix(plugin-report): a report chart hands its chart the measure's format, so the value axis reads `33.3%` and `¥` beside the table
6+
7+
Clause-②: yes
8+
Metadata-protocol: none
9+
10+
A report chart's series now carry the plotted measure's `format`, `percentScale` and single currency as the chart's internal `series[].measureFormat`. The chart's value axis then prints a measure stored in percentage points (`percentScale: 'whole'`) as percents and a currency amount with its symbol, as the table beside it does. A measure with a per-row currency (`currencyField`) hands no currency, so its axis keeps plain numbers. The fraction-scale percent pattern still travels on the value-axis `format` key as before.
11+
12+
Nothing to migrate: no metadata key changes.

‎ui/packages/plugin-charts/src/AdvancedChartImpl.axisLabels.test.tsx‎

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import React from 'react';
1111
import { describe, it, expect, afterEach, vi } from 'vitest';
1212
import { render, cleanup } from '@testing-library/react';
13+
import { formatMeasure } from '@object-ui/core';
14+
import { LocalizationProvider } from '@object-ui/i18n';
1315

1416
vi.mock('recharts', async () => {
1517
const actual = await vi.importActual<any>('recharts');
@@ -134,3 +136,199 @@ describe('AdvancedChartImpl — value-axis ticks on a small domain (objectstack#
134136
expect(ticks).toEqual(['0%', '0.85%', '1.7%', '2.55%', '3.4%']);
135137
});
136138
});
139+
140+
/**
141+
* objectstack#37053 — a value axis prints its dataset measure's UNITS: a
142+
* whole-scale percent and a currency amount, beside a table that prints them
143+
* through `formatMeasure`.
144+
*
145+
* The chart's value-axis `format` key is a d3-style pattern (`formatterFor`):
146+
* it reads a `%` pattern as a 0–1 fraction and has no slot for an ISO
147+
* currency, so a report or dashboard chart over a `percentScale: 'whole'` rate
148+
* or a `CNY` amount printed bare numbers (`0` … `34`, `0` … `12K`) beside a
149+
* table printing `33.3%` and `¥12,000.00`. The producer now hands each series
150+
* the measure's `{ format, currency, percentScale }` (`series[].measureFormat`,
151+
* renderer-internal like `series[].aggregate`), and an axis whose series all
152+
* carry the same one prints that measure's units:
153+
*
154+
* - a percent pattern through `formatMeasure` itself, at the column's scale;
155+
* - a currency as the compact default carrying the currency's symbol.
156+
*
157+
* A per-row currency column (`currencyField`) has no single currency, so its
158+
* producer hands no `currency` and the axis keeps distinct plain numbers — the
159+
* control. Every chart here is built the way `ChartRenderer` builds it: the
160+
* schema through `normalizeChartSchema`, whose series reader is where the
161+
* carrier is kept or dropped.
162+
*
163+
* A new top-level `describe` in this axis-tick harness, beside the
164+
* objectstack#36988 one above it.
165+
*/
166+
describe('AdvancedChartImpl — a value axis prints its dataset measure’s units (objectstack#37053)', () => {
167+
/** The display locale the chart resolves with no provider mounted. */
168+
const LOCALE = 'en';
169+
170+
const CATEGORIES = new Set(['High', 'Medium', 'Low']);
171+
172+
/** The value tick labels the left axis draws, in order. */
173+
const valueTicks = (c: HTMLElement) =>
174+
[...c.querySelectorAll('text.recharts-cartesian-axis-tick-value')]
175+
.filter((t) => t.getAttribute('orientation') === 'left')
176+
.map((t) => (t.textContent ?? '').trim())
177+
.filter((t) => !CATEGORIES.has(t));
178+
179+
/** The data labels the bars print (`showDataLabels`). */
180+
const dataLabels = (c: HTMLElement) =>
181+
[...c.querySelectorAll('.recharts-label-list text')].map((t) => (t.textContent ?? '').trim());
182+
183+
/**
184+
* Draw one column chart over `rows`, its `value` series carrying `measureFormat`
185+
* exactly as a producer hands it, through the translation `ChartRenderer`
186+
* applies to every schema.
187+
*/
188+
function draw(
189+
rows: Array<{ priority: string; value: number }>,
190+
measureFormat: Record<string, unknown> | undefined,
191+
extra: Record<string, unknown> = {},
192+
locale?: string,
193+
) {
194+
const spec = normalizeChartSchema({
195+
type: 'chart',
196+
chartType: 'column',
197+
xAxisKey: 'priority',
198+
series: [{ dataKey: 'value', label: 'Value', ...(measureFormat ? { measureFormat } : {}) }],
199+
...extra,
200+
});
201+
const { container } = render(
202+
<AdvancedChartImpl
203+
chartType="column"
204+
data={rows}
205+
xAxisKey="priority"
206+
series={spec.series}
207+
yAxes={spec.yAxes}
208+
showDataLabels={spec.showDataLabels}
209+
isAnimationActive={false}
210+
/>,
211+
// The display locale the chart reads (`useDisplayLocale`), when a case names one.
212+
locale
213+
? { wrapper: ({ children }: { children: React.ReactNode }) => <LocalizationProvider value={{ locale }}>{children}</LocalizationProvider> }
214+
: undefined,
215+
);
216+
return container;
217+
}
218+
219+
// A rate stored in percentage points (`percentScale: 'whole'`): one bucket at 33.3%.
220+
const WHOLE_RATE = [
221+
{ priority: 'High', value: 100 / 3 },
222+
{ priority: 'Medium', value: 0 },
223+
{ priority: 'Low', value: 0 },
224+
];
225+
// An amount column, in thousands of yuan.
226+
const AMOUNTS = [
227+
{ priority: 'High', value: 12000 },
228+
{ priority: 'Medium', value: 4500 },
229+
{ priority: 'Low', value: 0 },
230+
];
231+
232+
it('SUBJECT: a whole-scale percent measure’s ticks read percents, in the table’s own format', () => {
233+
const measure = { format: '0.0%', percentScale: 'whole' };
234+
const ticks = valueTicks(draw(WHOLE_RATE, measure));
235+
expect(ticks).toEqual(['0.0%', '9.0%', '18.0%', '27.0%', '36.0%']);
236+
// The table prints the bucket's value through `formatMeasure` at the same
237+
// scale and pattern; each tick is that function's reading of its tick.
238+
expect(formatMeasure(100 / 3, '0.0%', undefined, 'whole', LOCALE)).toBe('33.3%');
239+
expect(ticks).toEqual([0, 9, 18, 27, 36].map((t) => formatMeasure(t, '0.0%', undefined, 'whole', LOCALE)));
240+
});
241+
242+
it('SUBJECT: a fixed-currency measure’s ticks carry its symbol', () => {
243+
const ticks = valueTicks(draw(AMOUNTS, { format: '0,0.00', currency: 'CNY' }));
244+
expect(ticks).toEqual(['CN¥0', 'CN¥3K', 'CN¥6K', 'CN¥9K', 'CN¥12K']);
245+
// The symbol is the one the table prints the amount with.
246+
expect(formatMeasure(12000, '0,0.00', 'CNY', undefined, LOCALE)).toBe('CN¥12,000.00');
247+
});
248+
249+
it('a second currency carries its own symbol (`USD` → `$12K`)', () => {
250+
const ticks = valueTicks(draw(AMOUNTS, { format: '0,0.00', currency: 'USD' }));
251+
expect(ticks).toEqual(['$0', '$3K', '$6K', '$9K', '$12K']);
252+
expect(formatMeasure(12000, '0,0.00', 'USD', undefined, LOCALE)).toBe('$12,000.00');
253+
});
254+
255+
it('a zh-CN session reads the currency in its own compact units (`¥30万`)', () => {
256+
const large = AMOUNTS.map((r) => ({ ...r, value: r.value * 100 }));
257+
const ticks = valueTicks(draw(large, { format: '0,0.00', currency: 'CNY' }, {}, 'zh-CN'));
258+
expect(ticks).toEqual(['¥0', '¥30万', '¥60万', '¥90万', '¥120万']);
259+
expect(formatMeasure(1200000, '0,0.00', 'CNY', undefined, 'zh-CN')).toBe('¥1,200,000.00');
260+
});
261+
262+
it('CONTROL: a per-row currency measure (no single currency) keeps distinct plain-number ticks', () => {
263+
// A `currencyField` column's producer hands its pattern and no currency.
264+
const ticks = valueTicks(draw(AMOUNTS, { format: '0,0.00' }));
265+
expect(ticks).toEqual(['0', '3K', '6K', '9K', '12K']);
266+
expect(new Set(ticks).size).toBe(ticks.length);
267+
expect(ticks.some((t) => /[¥$€£%]/.test(t))).toBe(false);
268+
});
269+
270+
it('a fraction-scale percent measure reads percents through the carrier alone (the dashboard’s case)', () => {
271+
const rate = WHOLE_RATE.map((r) => ({ ...r, value: r.value / 100 }));
272+
expect(valueTicks(draw(rate, { format: '0.0%' }))).toEqual(['0.0%', '8.5%', '17.0%', '25.5%', '34.0%']);
273+
});
274+
275+
it('a declared axis `format` wins over the carrier: a `0,0` axis over a `CNY` measure prints no symbol', () => {
276+
// The two readings differ here, so swapping their order in
277+
// `valueAxisTickFormatter` turns this red.
278+
const ticks = valueTicks(draw(AMOUNTS, { format: '0,0.00', currency: 'CNY' }, { yAxis: [{ format: '0,0' }] }));
279+
expect(ticks).toEqual(['0', '3,000', '6,000', '9,000', '12,000']);
280+
expect(ticks.some((t) => t.includes('CN¥'))).toBe(false);
281+
});
282+
283+
it('the report’s fraction-scale `yAxis[0].format` path still reads percents beside its carrier (objectstack#36988)', () => {
284+
const rate = [
285+
{ priority: 'High', value: 1 / 3 },
286+
{ priority: 'Medium', value: 0 },
287+
{ priority: 'Low', value: 0 },
288+
];
289+
const ticks = valueTicks(draw(rate, { format: '0.0%' }, { yAxis: [{ format: '0.0%' }] }));
290+
expect(ticks).toEqual(['0.0%', '8.5%', '17.0%', '25.5%', '34.0%']);
291+
});
292+
293+
it('a pattern too coarse for the step gains the places the step needs, so no two ticks share a label', () => {
294+
const rate = [
295+
{ priority: 'High', value: 3.4 },
296+
{ priority: 'Medium', value: 0 },
297+
{ priority: 'Low', value: 0 },
298+
];
299+
const ticks = valueTicks(draw(rate, { format: '0%', percentScale: 'whole' }));
300+
// `formatMeasure` prints a pattern's places as a fixed width, so every tick
301+
// carries the two the 0.85-point step needs.
302+
expect(ticks).toEqual(['0.00%', '0.85%', '1.70%', '2.55%', '3.40%']);
303+
expect(new Set(ticks).size).toBe(ticks.length);
304+
});
305+
306+
it('data labels print with the axis’ measure format', () => {
307+
const labels = dataLabels(draw(WHOLE_RATE, { format: '0.0%', percentScale: 'whole' }, { showDataLabels: true }));
308+
expect(labels).toContain('33.3%');
309+
});
310+
311+
it('two series formatted differently on one axis keep the default axis', () => {
312+
const spec = normalizeChartSchema({
313+
type: 'chart',
314+
chartType: 'column',
315+
xAxisKey: 'priority',
316+
series: [
317+
{ dataKey: 'value', measureFormat: { format: '0.0%', percentScale: 'whole' } },
318+
{ dataKey: 'other', measureFormat: { format: '0,0.00', currency: 'CNY' } },
319+
],
320+
});
321+
const { container } = render(
322+
<AdvancedChartImpl
323+
chartType="column"
324+
data={WHOLE_RATE.map((r) => ({ ...r, other: r.value }))}
325+
xAxisKey="priority"
326+
series={spec.series}
327+
isAnimationActive={false}
328+
/>,
329+
);
330+
const ticks = valueTicks(container);
331+
expect(ticks.length).toBeGreaterThanOrEqual(3);
332+
expect(ticks.some((t) => /[¥%]/.test(t))).toBe(false);
333+
});
334+
});

‎ui/packages/plugin-charts/src/AdvancedChartImpl.tsx‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {
5252
ChartContainerConfig
5353
} from './ChartContainerImpl';
5454
import { mapScatterClick, mapTreemapClick, mapSankeyClick } from './chartDrillEvents';
55-
import { formatterFor, compactTickFormatter, valueTickExponent, domainFor, ticksFor, plotsWholeNumbers, wholeNumberTickCount, RENDERABLE, SINGLE_VALUE_CHART_TYPES, TABULAR_CHART_TYPES, effectiveChartFamily, comboBaseFamily, placeYAxes, type DeclaredChartFamily, type NormalizedAxis, type NormalizedSeries, type ValueAxisSlot, type YAxisPlacement } from './normalizeChartSchema';
55+
import { formatterFor, compactTickFormatter, measureTickFormatter, sharedMeasureFormat, valueTickExponent, domainFor, ticksFor, plotsWholeNumbers, wholeNumberTickCount, RENDERABLE, SINGLE_VALUE_CHART_TYPES, TABULAR_CHART_TYPES, effectiveChartFamily, comboBaseFamily, placeYAxes, type DeclaredChartFamily, type NormalizedAxis, type NormalizedSeries, type ValueAxisSlot, type YAxisPlacement } from './normalizeChartSchema';
5656
import { buildCategoryRank, chartRowBucketId, formatMonthBucketLabel, isRealCalendarDate, toDateInputValue, toDisplayDate, type ChartSegmentClickEvent } from '@object-ui/core';
5757
import { createSafeTranslation, useDisplayLocale, useSafeTranslate } from '@object-ui/i18n';
5858

@@ -2593,18 +2593,24 @@ function AdvancedChartImplInner({
25932593

25942594
/**
25952595
* The tick formatter of one value axis: the author's `format` where it
2596-
* declares one, else the compact default (1,200,000 → `1.2M`) — either
2597-
* printed to the decimal place the axis' tick step needs, so two ticks never
2598-
* share a label (objectstack#36988; see `valueTickExponent`). The step is
2599-
* measured over the values plotted in the slot, with the tick count
2600-
* `yAxisSpecProps` hands recharts for it.
2596+
* declares one, else the units of the dataset measure its series plot
2597+
* (objectstack#37053: a percent at its own scale, a currency's symbol — see
2598+
* `measureTickFormatter`), else the compact default (1,200,000 → `1.2M`) —
2599+
* each printed to the decimal place the axis' tick step needs, so two ticks
2600+
* never share a label (objectstack#36988; see `valueTickExponent`). The step
2601+
* is measured over the values plotted in the slot, with the tick count
2602+
* `yAxisSpecProps` hands recharts for it. Data labels print with the same
2603+
* formatter (`valueTickFormatterOf`), so they carry the measure's units too.
26012604
*/
26022605
const valueAxisTickFormatter = React.useCallback(
26032606
(axis: NormalizedAxis | undefined, side: ValueAxisSlot) => {
2607+
const plotted = slotSeries(side);
26042608
const values = axisValues(side);
2605-
const tickCount = plotsWholeNumbers(slotSeries(side)) ? wholeNumberTickCount(axis, values) : undefined;
2609+
const tickCount = plotsWholeNumbers(plotted) ? wholeNumberTickCount(axis, values) : undefined;
26062610
const exponent = valueTickExponent(axis, values, tickCount);
2607-
return formatterFor(axis?.format, displayLocale, exponent) ?? compactTickFormatter(displayLocale, exponent);
2611+
return formatterFor(axis?.format, displayLocale, exponent)
2612+
?? measureTickFormatter(sharedMeasureFormat(plotted), displayLocale, exponent)
2613+
?? compactTickFormatter(displayLocale, exponent);
26082614
},
26092615
[axisValues, slotSeries, displayLocale],
26102616
);

‎ui/packages/plugin-charts/src/ChartRenderer.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Skeleton } from '@object-ui/components';
44
import type { ChartContainerConfig } from './ChartContainerImpl';
55
import type { ChartSegmentClickEvent } from '@object-ui/core';
66
import { useObjectTranslation } from '@object-ui/i18n';
7-
import { normalizeChartSchema } from './normalizeChartSchema';
7+
import { normalizeChartSchema, type MeasureValueFormat } from './normalizeChartSchema';
88

99
// 🚀 Lazy load the implementation files
1010
const LazyChart = React.lazy(() => import('./ChartImpl'));
@@ -76,9 +76,13 @@ export interface ChartRendererProps {
7676
* the measure's aggregate, carried by `buildChartSeries` from the dataset
7777
* answer, so a value axis over counts draws whole-number ticks. The
7878
* authoring face refuses it by name (`ChartDataSeriesSchema.aggregate`).
79+
* `measureFormat` is the same kind of carrier (objectstack#37053): the
80+
* measure's `format` / `currency` / `percentScale`, filled by a
81+
* dataset-bound producer so the value axis prints the measure's units —
82+
* see `NormalizedSeries.measureFormat`.
7983
*/
8084
series?: Array<
81-
| { dataKey: string; label?: string; type?: string; variant?: 'current' | 'comparison'; opacity?: number; dashArray?: string; chartType?: 'bar' | 'line' | 'area'; stack?: string; yAxis?: 'left' | 'right'; color?: string; aggregate?: string }
85+
| { dataKey: string; label?: string; type?: string; variant?: 'current' | 'comparison'; opacity?: number; dashArray?: string; chartType?: 'bar' | 'line' | 'area'; stack?: string; yAxis?: 'left' | 'right'; color?: string; aggregate?: string; measureFormat?: MeasureValueFormat }
8286
| { name: string; label?: unknown; type?: string; variant?: 'current' | 'comparison' | 'primary'; opacity?: number; dashArray?: string; stack?: string; yAxis?: 'left' | 'right'; color?: string }
8387
>;
8488
/** Spec `ChartConfig` shape — honored via `normalizeChartSchema`
@@ -162,7 +166,7 @@ export const ChartRenderer: React.FC<ChartRendererProps> = ({ schema, onChartCli
162166
// `normalizeSeries` is a no-op on a well-formed internal-shaped entry apart
163167
// from `type`: it round-trips every other key the internal arm of
164168
// `ChartRendererProps.series` declares (`dataKey`/`label`/`chartType`/
165-
// `variant`/`opacity`/`dashArray`/`stack`/`yAxis`/`color`/`aggregate`) unchanged, and
169+
// `variant`/`opacity`/`dashArray`/`stack`/`yAxis`/`color`/`aggregate`/`measureFormat`) unchanged, and
166170
// translates `type` to `chartType` — the translation this routing exists
167171
// for. So always taking the normalized array
168172
// is not a second read site for `type` (AGENTS.md #0.1) — it is routing

0 commit comments

Comments
 (0)