Add reusable BarChart component and chart utilities to fidesui#7699
Add reusable BarChart component and chart utilities to fidesui#7699
Conversation
Adds BarChart component, XAxisTick renderer, and time-series utility functions (pickInterval, formatTimestamp, deriveInterval, tooltipLabelFormatter) to support upcoming access control dashboard visualizations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds the summary tab for the access control feature (behind feature flag): - Time-series violations chart, violation rate donut, data consumers table - Paginated findings table with policy violation aggregates - RTK Query endpoints for summary data - Mock data and MSW handlers for local development Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Guard formatTimestamp/tooltipLabelFormatter against invalid dates - Add defensive defaults to XAxisTick props and document deriveInterval contract - Use useChartAnimation in BarChart (consistent with Sparkline, DonutChart, etc.) - Memoize useTooltipContentStyle to avoid unnecessary re-renders - Fix lint: merge duplicate react imports, sort imports Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Categorical labels were rendered by Recharts' default tick (browser sans-serif) while time-series labels went through ChartText (Bazier Mono). Now both paths use ChartText so the font is always consistent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@greptile |
Greptile SummaryThis PR adds a reusable Key observations:
Confidence Score: 3/5
Important Files Changed
Last reviewed commit: "update barchart" |
| export const deriveInterval = (data: { timestamp: string }[]): number => { | ||
| if (data.length < 2) { | ||
| return HOUR_MS; | ||
| } | ||
| const gap = | ||
| new Date(data[1].timestamp).getTime() - | ||
| new Date(data[0].timestamp).getTime(); | ||
| return gap > 0 ? gap : HOUR_MS; | ||
| }; |
There was a problem hiding this comment.
deriveInterval expects timestamp but BarChart uses label
The deriveInterval utility takes data: { timestamp: string }[], but BarChartDataPoint declares the field as label: string. A caller who tries to pass BarChart's data array directly to deriveInterval will find zero matching properties — the derived gap will be NaN, gap > 0 will be false, and the function will fall back to HOUR_MS silently regardless of the actual data.
Since this utility is intended to auto-detect the interval from BarChart data, the field name should either match label:
| export const deriveInterval = (data: { timestamp: string }[]): number => { | |
| if (data.length < 2) { | |
| return HOUR_MS; | |
| } | |
| const gap = | |
| new Date(data[1].timestamp).getTime() - | |
| new Date(data[0].timestamp).getTime(); | |
| return gap > 0 ? gap : HOUR_MS; | |
| }; | |
| export const deriveInterval = (data: { label: string }[]): number => { | |
| if (data.length < 2) { | |
| return HOUR_MS; | |
| } | |
| const gap = | |
| new Date(data[1].label).getTime() - | |
| new Date(data[0].label).getTime(); | |
| return gap > 0 ? gap : HOUR_MS; | |
| }; |
Or, if deriveInterval is intentionally designed for a different, more general-purpose shape, document that clearly and provide a separate helper that accepts BarChartDataPoint[].
- Fix tickFormatter being silently ignored when intervalMs is set by unifying both tick paths into a single ChartText-based renderer - Rename i → index in story generator - Replace div with Flex in story decorator Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ticket: N/A part of PBAC work
Description Of Changes
Add generic, reusable chart components and time-series utilities to fidesui in preparation for the access control dashboard feature. These components are domain-agnostic and can be used by any feature requiring bar charts or time-series visualizations.
Components added:
BarChart— responsive bar chart with Ant Design theme integration, supports both categorical and time-series dataXAxisTick— custom X-axis tick renderer with smart timestamp formatting based on intervalUtilities added to
chart-utils.ts:pickInterval(startMs, endMs)— selects appropriate chart granularity (hourly/6h/daily) based on date rangeformatTimestamp(timestamp, intervalMs)— formats ISO timestamps for tick labels with invalid-date fallbackderiveInterval(data)— auto-detects interval from consecutive data pointstooltipLabelFormatter(label, intervalMs)— formats tooltip labels with full date/time infouseTooltipContentStyle()— memoized hook returning Ant Design-themed tooltip stylesQuality improvements to existing utilities:
formatTimestampandtooltipLabelFormatteruseChartAnimationin BarChart for consistency with Sparkline, DonutChart, RadarChart, StackedBarChartXAxisTickpropsuseTooltipContentStyleto prevent unnecessary re-rendersCode Changes
clients/fidesui/src/components/charts/BarChart.tsx- New reusable bar chart componentclients/fidesui/src/components/charts/BarChart.stories.tsx- Storybook stories covering categorical, time-series, colored, and custom formatter variantsclients/fidesui/src/components/charts/XAxisTick.tsx- New custom X-axis tick rendererclients/fidesui/src/components/charts/chart-utils.ts- New time-series utilities + hardening of date formattingclients/fidesui/src/index.ts- Export new components and utilitiesSteps to Confirm
cd clients/fidesui && npm run storybookPre-Merge Checklist
CHANGELOG.mdupdated