Repository navigation
feat: Add lline chart color selector - #708
Conversation
Design for adding color selection UI to MultiFieldSelector component. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
📝 WalkthroughWalkthroughAdds a default chart color palette and an unused-color utility, a Combobox-based ColorSelector, refactors selector primitives and MultiFieldSelector to support per-item rendering, introduces LineChart X/Y selector components with per-field color/aggregation, and exposes histogram bar color in schema, settings UI, and spec. ChangesColor selection and chart settings refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9abcf9037
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a730461d38
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx`:
- Line 24: The code uses a non-null assertion on CHART_COLORS[0] (seen in
HistogramSettings.tsx value={config.settings.color ?? CHART_COLORS[0]!}) which
can crash if CHART_COLORS is empty; update places that use CHART_COLORS[0]
(including spec.ts) to defensively handle an empty palette by either using
nullish coalescing to a hard-coded fallback color (e.g., config.settings.color
?? CHART_COLORS[0] ?? '`#000000`') or add an explicit validation early (validate
CHART_COLORS.length > 0 and throw a clear error) so the UI and module loading
cannot fail silently.
In `@packages/mosaic/src/charts/chart-types/line-chart/spec.ts`:
- Line 23: The legend string uses locale-sensitive casing; replace the call to
toLocaleUpperCase() on yColumn.aggregate with the locale-invariant toUpperCase()
so the legend for aggregate tokens (yColumn.aggregate) is deterministic across
locales—update the expression that currently returns `${yColumn.field}
(${yColumn.aggregate.toLocaleUpperCase()})` to use toUpperCase() instead.
In `@packages/mosaic/src/components/ColorSelector.tsx`:
- Around line 27-33: The color swatches in ColorSelector.tsx (inside the
CHART_COLORS.map and Combobox.Item) are purely decorative and not announced to
screen readers; update each Combobox.Item to include an accessible label
containing the color value (e.g., the hex string from CHART_COLORS) by either
adding an aria-label on the Combobox.Item (aria-label={color}) or by rendering a
visually-hidden text node (span with sr-only class or role="status" as
appropriate) next to the swatch so non-visual users can identify the color
choice; keep the visual swatch markup the same but ensure the Combobox.Item
exposes the hex value for assistive tech.
In `@packages/mosaic/src/components/MultiFieldSelector.tsx`:
- Line 12: MultiFieldSelector currently hardcodes line-chart behavior by
importing getLineColor and defaulting to the 'sum' aggregation inside its
internal item creation; make it chart-agnostic by removing the getLineColor
import and the 'sum' default and instead accept a prop like
createFieldConfig(fieldName: string, index: number) => FieldConfig (or similar)
that returns the initial config for each item. Update MultiFieldSelector to call
props.createFieldConfig when adding or initializing items (replace uses of
getLineColor and the 'sum' literal), provide a sensible fallback no-op factory
if none is passed, and document the new prop so callers (e.g., the line-chart)
can inject their color/aggregation defaults.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: daa896aa-ccde-49be-81a1-507b9acb2478
📒 Files selected for processing (12)
packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsxpackages/mosaic/src/charts/chart-types/histogram/schema.tspackages/mosaic/src/charts/chart-types/histogram/spec.tspackages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsxpackages/mosaic/src/charts/chart-types/line-chart/LineChartXFieldSelector.tsxpackages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsxpackages/mosaic/src/charts/chart-types/line-chart/spec.tspackages/mosaic/src/charts/chart-types/line-chart/utils.tspackages/mosaic/src/components/ColorSelector.tsxpackages/mosaic/src/components/Combobox.tsxpackages/mosaic/src/components/MultiFieldSelector.tsxpackages/mosaic/src/constants/chart-colors.ts
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a79d8f1459
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| @@ -0,0 +1,13 @@ | |||
| // Chart color palette (default palette colors) | |||
| export const CHART_COLORS = [ | |||
There was a problem hiding this comment.
I'd suggest to use categoricalSchemeColors.Observable10 from @sqlrooms/color-scales here
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/mosaic/src/components/MultiFieldSelector.tsx (1)
11-25:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftComponent still coupled to line-chart schema.
Line 11 imports
YFieldConfigfrom the line-chart schema, and this type appears throughout the component's public API (lines 14, 21). This violates the coding guideline: "Public exports inpackages/should be kept generic, composable, documented, and free of app/example-specific assumptions."While the refactoring correctly delegates behavior via
onAddandrenderItem(addressing the past review's concerns about hardcoded defaults), the type-level coupling prevents reuse by other chart types.Consider making the component generic:
export interface MultiFieldSelectorProps<T extends { field: string }> { types?: string[]; value: T[]; onChange: (value: T[]) => void; onAdd: (fieldName: string) => void; renderItem?: ( fieldConfig: T, index: number, handleUpdate: (index: number, updates: Partial<T>) => void ) => React.ReactNode; }Or define a minimal base type in the components folder that line-chart extends.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/mosaic/src/components/MultiFieldSelector.tsx` around lines 11 - 25, The component is typed to the line-chart-specific YFieldConfig; change MultiFieldSelectorProps to be generic so the component is reusable: replace YFieldConfig usage in the public API (the MultiFieldSelectorProps interface, value, onChange, onAdd, and renderItem signatures) with a generic type parameter T (e.g., T extends { field: string } or a small shared BaseField type defined in the components package) and update renderItem and handleUpdate to use Partial<T>; remove the direct import of YFieldConfig and, if needed, have the line-chart package pass its YFieldConfig as the concrete T when using the component.Source: Coding guidelines
🧹 Nitpick comments (1)
packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx (1)
9-9: ⚡ Quick winConsider moving
getChartItemColorto a shared utilities location.
getChartItemColoris a generic chart utility but is currently located inline-chart/utils.ts. Since it's being reused across multiple chart types (line chart and histogram), it should live in a shared location such asconstants/chart-colors.tsor a dedicatedutils/chart-utils.tsfile. This would improve discoverability and better reflect that it's not line-chart-specific.As per coding guidelines: "Public exports in
packages/should be kept generic, composable, documented, and free of app/example-specific assumptions" — while the function itself is appropriately generic, its current location in a chart-type-specific directory implies narrower scope than its actual usage.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx` at line 9, getChartItemColor is a generic color utility currently imported from a line-chart-specific module (line-chart/utils) but used by multiple chart types; move the function to a shared module (e.g., constants/chart-colors.ts or utils/chart-utils.ts), export it there, update imports in HistogramSettings.tsx and other callers to import getChartItemColor from the new shared path, and remove the original export from line-chart/utils to avoid duplicate exports; ensure the relocated function keeps its original name and behavior and update any relevant docs/comments.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/mosaic/src/components/MultiFieldSelector.tsx`:
- Around line 11-25: The component is typed to the line-chart-specific
YFieldConfig; change MultiFieldSelectorProps to be generic so the component is
reusable: replace YFieldConfig usage in the public API (the
MultiFieldSelectorProps interface, value, onChange, onAdd, and renderItem
signatures) with a generic type parameter T (e.g., T extends { field: string }
or a small shared BaseField type defined in the components package) and update
renderItem and handleUpdate to use Partial<T>; remove the direct import of
YFieldConfig and, if needed, have the line-chart package pass its YFieldConfig
as the concrete T when using the component.
---
Nitpick comments:
In `@packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx`:
- Line 9: getChartItemColor is a generic color utility currently imported from a
line-chart-specific module (line-chart/utils) but used by multiple chart types;
move the function to a shared module (e.g., constants/chart-colors.ts or
utils/chart-utils.ts), export it there, update imports in HistogramSettings.tsx
and other callers to import getChartItemColor from the new shared path, and
remove the original export from line-chart/utils to avoid duplicate exports;
ensure the relocated function keeps its original name and behavior and update
any relevant docs/comments.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2a1adaa5-2a92-47c6-b124-d7879b965e4c
📒 Files selected for processing (8)
packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsxpackages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsxpackages/mosaic/src/charts/chart-types/line-chart/spec.tspackages/mosaic/src/charts/chart-types/line-chart/utils.tspackages/mosaic/src/components/ColorSelector.tsxpackages/mosaic/src/components/ColumnSelector.tsxpackages/mosaic/src/components/FieldSelectorInput.tsxpackages/mosaic/src/components/MultiFieldSelector.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
- packages/mosaic/src/charts/chart-types/line-chart/utils.ts
- packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
- packages/mosaic/src/charts/chart-types/line-chart/spec.ts
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f183297de8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/mosaic/src/charts/chart-types/line-chart/utils.ts`:
- Around line 1-11: Add a JSDoc block to the public function getChartItemColor
describing its behavior (returns the provided color or a fallback from the
colors array based on index), document parameters (colors: readonly string[] -
must be non-empty, color: string | undefined, index: number default 0), the
return type (string), and any preconditions/notes (colors should contain at
least one entry; index is modulo-length). Include `@param` and `@returns` tags and
mark it as part of the public API (e.g., `@public`) so callers know expected
inputs and behavior.
- Around line 1-11: The getChartItemColor function currently assumes the colors
array is non-empty; validate that colors.length > 0 (or explicitly document the
precondition) and handle the empty case to guarantee a string return. Update
getChartItemColor to check colors is non-empty and either throw a clear Error,
return a safe default color string, or fallback to the provided color parameter
when colors is empty, ensuring the function never returns undefined; reference
the function name getChartItemColor and the parameters colors, color, and index
to locate where to add the guard and error/default behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ee41bf2f-95d5-4dc6-a79d-1b912b40d47c
📒 Files selected for processing (7)
packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsxpackages/mosaic/src/charts/chart-types/histogram/spec.tspackages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsxpackages/mosaic/src/charts/chart-types/line-chart/spec.tspackages/mosaic/src/charts/chart-types/line-chart/utils.tspackages/mosaic/src/components/ColorSelector.tsxpackages/mosaic/src/constants/chart-colors.ts
🚧 Files skipped from review as they are similar to previous changes (5)
- packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx
- packages/mosaic/src/charts/chart-types/line-chart/spec.ts
- packages/mosaic/src/components/ColorSelector.tsx
- packages/mosaic/src/charts/chart-types/histogram/spec.ts
- packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea80e27688
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const color = getLineColor(yColumn.color, index); | ||
| const aggregate = yColumn.aggregate || 'sum'; | ||
| yColumns.forEach((yColumn) => { | ||
| const color = yColumn.color ?? DEFAULT_CHART_FALLBACK_COLOR; |
There was a problem hiding this comment.
Keep per-series fallback colors
When a saved/configured line chart has multiple yFields without stored color values, this now assigns DEFAULT_CHART_FALLBACK_COLOR to every series, so previously valid multi-line charts render indistinguishable lines and a duplicate-color legend. The schema still allows color to be omitted, and the previous code varied the fallback by series index, so the fallback here should remain index-based for configs/tool calls that do not persist colors.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/mosaic/src/charts/chart-types/line-chart/utils.ts`:
- Around line 6-21: getUnusedColor assumes the input array colors is non-empty
which can lead to returning undefined; add a guard at the start of
getUnusedColor that validates colors.length > 0 and throws a clear Error (e.g.
"getUnusedColor: colors must contain at least one color") if empty, and update
the function JSDoc to document the precondition that colors must be non-empty;
keep the existing logic (usedSet loop and fallback to colors[0]) intact after
the validation.
In `@packages/mosaic/src/constants/chart-colors.ts`:
- Line 5: DEFAULT_CHART_FALLBACK_COLOR currently uses a non-null assertion on
DEFAULT_CHART_COLORS[0], which can break if categoricalSchemeColors.Observable10
is empty; update the initialization of DEFAULT_CHART_FALLBACK_COLOR to
defensively handle an empty array by checking DEFAULT_CHART_COLORS (or the
source categoricalSchemeColors.Observable10) and either (a) use a hard-coded
safe color string as a fallback via nullish coalescing, or (b) validate and
throw a clear error at module load if the palette is invalid; refer to
DEFAULT_CHART_FALLBACK_COLOR and DEFAULT_CHART_COLORS when making the change so
consumers always receive a valid color or a clear failure message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 985e963c-21dc-4d6e-a671-58483558d6ef
📒 Files selected for processing (7)
packages/mosaic/__tests__/chart-types/line-chart-utils.test.tspackages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsxpackages/mosaic/src/charts/chart-types/histogram/spec.tspackages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsxpackages/mosaic/src/charts/chart-types/line-chart/spec.tspackages/mosaic/src/charts/chart-types/line-chart/utils.tspackages/mosaic/src/constants/chart-colors.ts
✅ Files skipped from review due to trivial changes (1)
- packages/mosaic/tests/chart-types/line-chart-utils.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/mosaic/src/charts/chart-types/histogram/spec.ts
- packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
Summary by CodeRabbit
New Features
Refactor
UI Components
Style
Tests