Skip to content

Commit b25b6eb

Browse files
committed
wip(ui): adapt month-axis pins to the bucket label face
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibzKuj2HUUN2wUhZ9Go
1 parent e56af92 commit b25b6eb

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ describe('month bucket keys on the category axis (row 15)', () => {
8282

8383
describe('legend swatches (row 15)', () => {
8484
const compared = [
85-
{ dataKey: 'n', label: 'Count', variant: 'current' },
86-
{ dataKey: 'n__compare', label: 'Count · vs last quarter', variant: 'comparison' },
85+
{ dataKey: 'n', label: 'Count', variant: 'current' as const },
86+
{ dataKey: 'n__compare', label: 'Count · vs last quarter', variant: 'comparison' as const },
8787
];
8888
const rows = [{ stage: 'Prospecting', n: 3, n__compare: 2 }, { stage: 'Proposal', n: 5, n__compare: 4 }];
8989

@@ -101,7 +101,7 @@ describe('legend swatches (row 15)', () => {
101101
}
102102
});
103103

104-
it.each(['bar', 'line', 'area'])('%s: the comparison swatch is hollow and the primary one solid, in the same colour', async (chartType) => {
104+
it.each(['bar', 'line', 'area'] as const)('%s: the comparison swatch is hollow and the primary one solid, in the same colour', async (chartType) => {
105105
const { container } = render(
106106
<AdvancedChartImpl chartType={chartType} data={rows} xAxisKey="stage" series={compared} isAnimationActive={false} />,
107107
);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ describe('AdvancedChartImpl — unreadable-data guard (framework#4033)', () => {
100100

101101
expect(container.querySelector('[data-chart-error="missing-category-key"]')).toBeNull();
102102
expect(container.querySelector('svg')).not.toBeNull();
103-
expect(container.textContent).toContain('2026-01');
103+
// The month bucket key draws its display face (objectstack#27520).
104+
expect(container.textContent).toContain('Jan 2026');
104105
expect(warn).not.toHaveBeenCalled();
105106
warn.mockRestore();
106107
});

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*
88
* objectui#13390 — a line or area chart cut its last x-axis label at the
9-
* chart's right edge: "2026-10" was painted as "2026".
9+
* chart's right edge: "2026-10" was painted as "2026". The month buckets now
10+
* draw as "Oct 2026" (objectstack#27520), and the same inset holds them.
1011
*
1112
* recharts lays a line or area chart's categorical x axis out as a POINT
1213
* scale, so the first and last categories sit ON the plot edges and each label
@@ -70,6 +71,8 @@ const MONTHS = [
7071
{ month: '2026-09', tasks: 18 },
7172
{ month: '2026-10', tasks: 9 },
7273
];
74+
/** The labels the axis draws for them: a month bucket key's face (objectstack#27520). */
75+
const MONTH_LABELS = ['Aug 2026', 'Sep 2026', 'Oct 2026'];
7376

7477
/** Upper estimate of half a tick label's painted width at the 12px tick font. */
7578
const halfLabelPx = (label: string) => ([...label].length * 0.65 * 12) / 2;
@@ -105,9 +108,7 @@ function plotOf(container: HTMLElement) {
105108
/** Each x-axis tick label: its text, the x it is centred on, and whether it is rotated. */
106109
function xTicksOf(container: HTMLElement) {
107110
const ticks = [...container.querySelectorAll('.recharts-xAxis-tick-labels .recharts-cartesian-axis-tick-value')];
108-
expect(ticks.map((t) => (t.textContent ?? '').trim()), 'the x axis did not draw every month').toEqual(
109-
MONTHS.map((r) => r.month),
110-
);
111+
expect(ticks.map((t) => (t.textContent ?? '').trim()), 'the x axis did not draw every month').toEqual(MONTH_LABELS);
111112
return ticks.map((t) => ({
112113
label: (t.textContent ?? '').trim(),
113114
x: Number(t.getAttribute('x')),

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,15 @@ const CATEGORY_LABEL_LINE_EM = 1.1;
545545
* characters, which left a bar named only by its first letters ("In Progr…").
546546
*/
547547
function WrappedCategoryTick(props: any) {
548-
const { x, y, payload, textAnchor, maxWidthPx, formatLabel } = props;
548+
const { x, y, payload, textAnchor, orientation, maxWidthPx, formatLabel } = props;
549549
const full = String(formatLabel(payload?.value) ?? '');
550550
const { lines, truncated } = wrapCategoryLabel(full, maxWidthPx);
551551
// Centre the block on the tick: the first line rises half the extra lines,
552552
// and 0.355em puts a line's middle (not its baseline) on `y`.
553553
const firstDy = `${0.355 - ((lines.length - 1) * CATEGORY_LABEL_LINE_EM) / 2}em`;
554554
return (
555-
<text x={x} y={y} textAnchor={textAnchor ?? 'end'} fill={AXIS_TICK_STYLE.fill} className="recharts-text recharts-cartesian-axis-tick-value">
555+
// `orientation` as recharts' own tick text carries it: the side the axis is drawn on.
556+
<text x={x} y={y} textAnchor={textAnchor ?? 'end'} fill={AXIS_TICK_STYLE.fill} orientation={orientation} className="recharts-text recharts-cartesian-axis-tick-value">
556557
{truncated ? <title>{full}</title> : null}
557558
{lines.map((line, i) => (
558559
<tspan key={i} x={x} dy={i === 0 ? firstDy : `${CATEGORY_LABEL_LINE_EM}em`}>{line}</tspan>
@@ -621,8 +622,8 @@ const DATA_LABEL_CHART_MARGIN = {
621622
*
622623
* ## Why this size
623624
*
624-
* Half of a `YYYY-MM` label, the bucket a monthly trend chart draws, at the
625-
* tick font, by the same upper estimate the rotated band is sized from
625+
* Half of a month bucket's label (`Oct 2026`, the face a `YYYY-MM` key draws,
626+
* objectstack#27520), the bucket a monthly trend chart draws, at the tick font, by the same upper estimate the rotated band is sized from
626627
* ({@link estimateLabelWidthPx}), less the chart margin already on that side.
627628
* A fixed figure, not one sized from each chart's labels, so every line and
628629
* area chart lays out the same way. It is not a bound on every label: a long
@@ -633,7 +634,7 @@ const DATA_LABEL_CHART_MARGIN = {
633634
* derived from recharts' layout, not measured in a browser.
634635
*/
635636
const POINT_X_AXIS_EDGE_PADDING_PX =
636-
Math.ceil(estimateLabelWidthPx('0000-00') / 2) - CHART_MARGIN_X_PX / 2;
637+
Math.ceil(estimateLabelWidthPx('Mmm 0000') / 2) - CHART_MARGIN_X_PX / 2;
637638
/** A module constant so recharts' axis settings memo is not defeated per render. */
638639
const POINT_X_AXIS_PADDING = {
639640
left: POINT_X_AXIS_EDGE_PADDING_PX,

‎ui/packages/plugin-dashboard/src/__tests__/metricTileLayout-12623.test.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ function expectTileContainer(inner: Element) {
8282
describe('dataset-bound metric tile — the layout rule (objectui#12623)', () => {
8383
const source = () => ({
8484
queryDataset: vi.fn(async () => ({
85-
rows: [{ total_amount: 1964500 }],
85+
// A short value: a longer one takes the dataset tile's ladder, pinned in
86+
// `metricTileDatasetValueScale-27520.test.tsx`.
87+
rows: [{ total_amount: 196450 }],
8688
fields: [{ name: 'total_amount', label: 'Total Amount', type: 'number' }],
8789
})),
8890
});
@@ -105,7 +107,7 @@ describe('dataset-bound metric tile — the layout rule (objectui#12623)', () =>
105107

106108
it('gives the title the first line alone, up to two lines', async () => {
107109
renderTile();
108-
await screen.findByText('1964500');
110+
await screen.findByText('196450');
109111
const title = screen.getByTestId('dataset-metric-title');
110112
expectTitleRule(title);
111113
// Alone on its line: the heading row holds the title and nothing else.
@@ -114,12 +116,12 @@ describe('dataset-bound metric tile — the layout rule (objectui#12623)', () =>
114116

115117
it('draws the value unwrapped, one step smaller below a 160 px tile', async () => {
116118
renderTile();
117-
expectValueRule(await screen.findByText('1964500'));
119+
expectValueRule(await screen.findByText('196450'));
118120
});
119121

120122
it('draws the measure label under the value, 11 px, hidden below a 160 px tile, and keeps it in the tooltip', async () => {
121123
renderTile();
122-
const value = await screen.findByText('1964500');
124+
const value = await screen.findByText('196450');
123125
const label = screen.getByTestId('dataset-metric-label');
124126

125127
expect(value.nextElementSibling).toBe(label);
@@ -134,7 +136,7 @@ describe('dataset-bound metric tile — the layout rule (objectui#12623)', () =>
134136

135137
it('measures every width rule against the tile, which holds the title, the value and the label', async () => {
136138
renderTile();
137-
const value = await screen.findByText('1964500');
139+
const value = await screen.findByText('196450');
138140
const box = expectTileContainer(value);
139141
expect(box).toContainElement(screen.getByTestId('dataset-metric-title'));
140142
expect(box).toContainElement(screen.getByTestId('dataset-metric-label'));

0 commit comments

Comments
 (0)