Skip to content

refactor(charts): describe bar series as objects, not parallel maps - #8470

Draft
talissoncosta wants to merge 2 commits into
feat/experiment-conversion-chartfrom
refactor/barchart-series-descriptors
Draft

refactor(charts): describe bar series as objects, not parallel maps#8470
talissoncosta wants to merge 2 commits into
feat/experiment-conversion-chartfrom
refactor/barchart-series-descriptors

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Contributes to #8463, targeting that branch so the diff is only my part. A suggestion, not a blocker.

BarChart gained seven props in #8463, five with a single caller and two with none. This changes the shape rather than trimming the list:

  • One BarSeries (key, label, colour, stackId?, opacity?) replaces colorMap, seriesLabels, stackMap and opacityMap, so the legend reads the same array the bars do.
  • grouped goes, since side by side is just distinct stack ids. yAxis goes until something passes it.
  • The two tooltip props become one object, where formatValue hides the non-additive total by default.

15 props down to 8, and the conversion card's call site from six to two. ColorSwatch gains an optional opacity so the faded legend swatch is the shared component, and toBarSeries bridges callers still holding maps, which LineChart continues to read. Existing charts keep their default shared stack, so nothing moves visually.

Left out on purpose: REST_SUFFIX and the card's key parsing, which depend on whether buildConversionRateChartData stays.

How did you test this code?

  • npm run test:unit: 43 suites, 614 tests pass.
  • npm run typecheck: 938 errors, same as the base branch. Zero delta.
  • New PartOfWholeStacks (BarChart) and Faded (ColorSwatch) stories, so the stacks, the fade and the legend can be checked in Storybook.
  • The five migrated charts should be unchanged: usage over time, organisation usage, SDK labels, and both feature analytics charts.

talissoncosta and others added 2 commits September 4, 2026 14:34
Series drawn with an SVG fill-opacity had no matching swatch: colours are
CSS var() strings, so a className can't carry a per-series alpha. Adds an
optional opacity, and a story alongside the other prop variants.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
BarChart took four maps keyed by dataKey (colours, labels, stack ids, fill
opacities) with nothing tying the keys together, so a missing entry silently
dropped a bar's colour or stack. One BarSeries per series replaces all four,
and the legend now reads the same array the bars do, so a faded swatch can't
drift from its faded bar.

Two props go with it. `grouped` was unreachable: side by side is distinct
stack ids, which is what the conversion chart's daily mode already did. The
tooltip's formatter and its total flag become one object, with a formatted
value hiding the non-additive total by default rather than asking every
caller to remember.

Existing charts keep their shared default stack, so nothing moves visually.
toBarSeries bridges callers still holding maps from buildChartColorMap or
useEnvChartProps, which LineChart continues to read.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flagsmith-frontend-preview Ready Ready Preview Sep 4, 2026 5:36pm UTC
flagsmith-frontend-staging Ready Ready Preview Sep 4, 2026 5:36pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
docs Ignored Ignored Sep 4, 2026 5:36pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

BarChart now accepts structured BarSeries objects and consolidated tooltip options. Series metadata controls labels, colours, stacking, and opacity. ColorSwatch supports opacity for faded legends. Conversion charts now return structured series data. Existing chart consumers and documentation stories use the new API. Tests validate conversion series metadata.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: 🔵 Low · up to 669a2

Bar charts now use structured series metadata for labels, colours, stacking, opacity, and tooltips. The functional migration appears ready, with a low-risk cleanup needed to align new chart-module imports with frontend conventions.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 8ca7d968-5853-430a-bfcc-d0108efd587b

📥 Commits

Reviewing files that changed from the base of the PR and between 9811252 and 669a208.

📒 Files selected for processing (14)
  • frontend/documentation/components/BarChart.stories.tsx
  • frontend/documentation/components/ColorSwatch.stories.tsx
  • frontend/web/components/ColorSwatch.tsx
  • frontend/web/components/charts/BarChart.tsx
  • frontend/web/components/charts/index.ts
  • frontend/web/components/charts/toBarSeries.ts
  • frontend/web/components/charts/types.ts
  • frontend/web/components/experiments/results/ExperimentConversionRateCard/ExperimentConversionRateCard.tsx
  • frontend/web/components/experiments/results/__tests__/deriveConversionRate.test.ts
  • frontend/web/components/experiments/results/deriveConversionRate.ts
  • frontend/web/components/feature-page/FeatureNavTab/FeatureAnalytics.tsx
  • frontend/web/components/organisation-settings/usage/OrganisationUsage.container.tsx
  • frontend/web/components/organisation-settings/usage/components/SingleSDKLabelsChart.tsx
  • frontend/web/components/pages/usage/components/UsageOverTime/UsageOverTime.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment on lines 14 to +15
import ChartTooltip from './ChartTooltip'
import { ChartDataPoint } from './types'
import { BarSeries, ChartDataPoint } from './types'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace the relative chart-module imports.

Lines 14-15 use relative paths. Use components/charts/ChartTooltip and components/charts/types instead.

As per coding guidelines, “Use only common/, components/, and project/ import paths; do not use relative imports.”

Proposed fix
-import ChartTooltip from './ChartTooltip'
-import { BarSeries, ChartDataPoint } from './types'
+import ChartTooltip from 'components/charts/ChartTooltip'
+import { BarSeries, ChartDataPoint } from 'components/charts/types'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import ChartTooltip from './ChartTooltip'
import { ChartDataPoint } from './types'
import { BarSeries, ChartDataPoint } from './types'
import ChartTooltip from 'components/charts/ChartTooltip'
import { BarSeries, ChartDataPoint } from 'components/charts/types'

Source: Coding guidelines

@@ -0,0 +1,17 @@
import { BarSeries } from './types'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use frontend aliases for the new chart module paths.

The changed chart modules introduce relative paths, which violates the frontend import-path rule.

  • frontend/web/components/charts/toBarSeries.ts#L1-L1: use components/charts/types instead of ./types.
  • frontend/web/components/charts/index.ts#L7-L8: use components/charts/toBarSeries and components/charts/types instead of relative paths.

As per coding guidelines, frontend/**/*.{js,jsx,ts,tsx} must use only common/, components/, and project/ import paths. Do not use relative imports.

📍 Affects 2 files
  • frontend/web/components/charts/toBarSeries.ts#L1-L1 (this comment)
  • frontend/web/components/charts/index.ts#L7-L8

Source: Coding guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant