Skip to content

Commit 6e7373d

Browse files
Copilothotlong
andcommitted
refactor(plugin-charts): memoize hasLongLabels check in AdvancedChartImpl
Address code review feedback: memoize the data.some() long label check using useMemo to avoid O(n) recalculation on every render. Agent-Logs-Url: https://github.com/objectstack-ai/objectui/sessions/eae827ef-e746-4d58-8b55-9f9e8fcd1dd0 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 1860732 commit 6e7373d

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- **Charts groupBy value→label resolution** (`@object-ui/plugin-charts`): Chart X-axis labels now display human-readable labels instead of raw values. Select/picklist fields resolve value→label via field metadata options, lookup/master_detail fields batch-fetch referenced record names, and all other fields fall back to `humanizeLabel()` (snake_case → Title Case). Removed hardcoded `value.slice(0, 3)` truncation from `AdvancedChartImpl.tsx` XAxis tick formatters — desktop now shows full labels with angle rotation for long text, mobile truncates at 8 characters with "…".
13+
1214
- **Analytics aggregate measures format** (`@object-ui/data-objectstack`): Fixed `aggregate()` method to send `measures` as string array (`['amount_sum']`, `['count']`) instead of object array (`[{ field, function }]`). The backend `MemoryAnalyticsService.resolveMeasure()` expects strings and calls `.split('.')`, causing `TypeError: t.split is not a function` when receiving objects. Also fixed `dimensions` to send an empty array when `groupBy` is `'_all'` (single-bucket aggregation), and added response mapping to rename measure keys (e.g. `amount_sum`) back to the original field name (`amount`) for consumer compatibility. Additionally fixed chart rendering blank issue: the `rawRows` extraction now handles the `{ rows: [...] }` envelope (when the SDK unwraps the outer `{ success, data }` wrapper) and the `{ data: { rows: [...] } }` envelope (when the SDK returns the full response), matching the actual shape returned by the analytics API (`/api/v1/analytics/query`).
1315
- **Fields SSR build** (`@object-ui/fields`): Added `@object-ui/i18n` to Vite `external` in `vite.config.ts` and converted to regex-based externalization pattern (consistent with `@object-ui/components`) to prevent `react-i18next` CJS code from being bundled. Fixes `"dynamic usage of require is not supported"` error during Next.js SSR prerendering of `/docs/components/basic/text`.
1416
- **Console build** (`@object-ui/console`): Added missing `@object-ui/plugin-chatbot` devDependency that caused `TS2307: Cannot find module '@object-ui/plugin-chatbot'` during build.

packages/plugin-charts/src/AdvancedChartImpl.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ export default function AdvancedChartImpl({
112112

113113
console.log('📈 Rendering Chart:', { chartType, dataLength: data.length, config, series, xAxisKey });
114114

115+
// Memoize whether any X-axis label is long enough to warrant angle rotation
116+
const hasLongLabels = React.useMemo(
117+
() => data.some((d: any) => String(d[xAxisKey] || '').length > 5),
118+
[data, xAxisKey],
119+
);
120+
115121
// Helper function to get color palette
116122
const getPalette = () => [
117123
'hsl(var(--chart-1))',
@@ -250,7 +256,7 @@ export default function AdvancedChartImpl({
250256
if (isMobile && value.length > 8) return value.slice(0, 8) + '…';
251257
return value;
252258
}}
253-
{...(!isMobile && data.some((d: any) => String(d[xAxisKey] || '').length > 5) && { angle: -35, textAnchor: 'end', height: 60 })}
259+
{...(!isMobile && hasLongLabels && { angle: -35, textAnchor: 'end', height: 60 })}
254260
/>
255261
<YAxis yAxisId="left" tickLine={false} axisLine={false} />
256262
<YAxis yAxisId="right" orientation="right" tickLine={false} axisLine={false} />
@@ -292,7 +298,7 @@ export default function AdvancedChartImpl({
292298
if (isMobile && value.length > 8) return value.slice(0, 8) + '…';
293299
return value;
294300
}}
295-
{...(!isMobile && data.some((d: any) => String(d[xAxisKey] || '').length > 5) && { angle: -35, textAnchor: 'end', height: 60 })}
301+
{...(!isMobile && hasLongLabels && { angle: -35, textAnchor: 'end', height: 60 })}
296302
/>
297303
<ChartTooltip content={<ChartTooltipContent />} />
298304
<ChartLegend

0 commit comments

Comments
 (0)