Skip to content

feat: Add lline chart color selector - #708

Merged
dmitriy-kostianetskiy merged 11 commits into
mainfrom
feat/line-chart-colors
Jun 11, 2026
Merged

dmitriy-kostianetskiy merged 11 commits into
mainfrom
feat/line-chart-colors

Conversation

@dmitriy-kostianetskiy

@dmitriy-kostianetskiy dmitriy-kostianetskiy commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator
image

Summary by CodeRabbit

  • New Features

    • Histogram bars can be assigned a custom color via a color selector; histogram settings now include an optional color.
    • Line charts support per-series color selection for Y fields and use those colors in rendering and legend labels.
  • Refactor

    • Line chart field configuration reorganized into dedicated X-axis and Y-axis selector components.
    • Multi-field selector now accepts a render-prop for per-field customization.
  • UI Components

    • Added a reusable color selector and a shared default chart color palette; selectors accept optional styling hooks.
  • Style

    • Minor combobox icon spacing adjustment.
  • Tests

    • Added tests for color-assignment utility used by line charts.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Color selection and chart settings refactor

Layer / File(s) Summary
Palette and utility
packages/mosaic/src/constants/chart-colors.ts, packages/mosaic/src/charts/chart-types/line-chart/utils.ts, packages/mosaic/__tests__/chart-types/line-chart-utils.test.ts
Exports DEFAULT_CHART_COLORS and DEFAULT_CHART_FALLBACK_COLOR; adds getUnusedColor(colors, usedColors) with tests.
Combobox and ColorSelector UI
packages/mosaic/src/components/Combobox.tsx
Adjusts ComboboxItem Check icon classes to remove right margin and supports the new ColorSelector usage elsewhere.
Selector primitives & MultiFieldSelector API
packages/mosaic/src/components/ColumnSelector.tsx, packages/mosaic/src/components/FieldSelectorInput.tsx, packages/mosaic/src/components/MultiFieldSelector.tsx
Forwards className through selectors, merges container classes via cn, replaces showAggregation with renderItem render-prop, fixes three-column row layout, and delegates add-field wiring to callers.
Line-chart selectors & spec
packages/mosaic/src/charts/chart-types/line-chart/LineChartXFieldSelector.tsx, .../LineChartYFieldsSelector.tsx, .../LineChartSettings.tsx, .../spec.ts
Adds LineChartXFieldSelector and LineChartYFieldsSelector (per-field color and conditional aggregation), refactors LineChartSettings to use them, and updates spec to use per-field yColumn.color with fallback.
Histogram color support
packages/mosaic/src/charts/chart-types/histogram/schema.ts, .../HistogramSettings.tsx, .../spec.ts
Adds optional color to histogram schema, renders a ColorSelector in histogram settings (wires onChangeConfig('color', ...)), and applies settings.color ?? DEFAULT_CHART_FALLBACK_COLOR in the histogram spec fill.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#591: Related line-chart multi–Y-fields refactor and per-field color/aggregation model.

Suggested reviewers

  • ilyabo

Poem

🐇 I nibble at palettes, hex by hex,
I hop through selectors, clever little tricks,
Bars don new coats, lines pick their hue,
Each field gets a swatch, fresh and true,
Hooray — charts dressed up, bright and new!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title contains a typo ('lline' instead of 'line') and is only partially related to the main change; the PR adds color selectors to both histogram and line charts, not just line charts. Correct the typo to 'feat: Add line chart color selector' and consider whether the title should also mention histogram color support, or clarify if line chart is the primary focus.
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/line-chart-colors

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread packages/mosaic/src/charts/chart-types/line-chart/schema.ts Outdated
@dmitriy-kostianetskiy dmitriy-kostianetskiy changed the title feat: Add Lline chart color selector feat: Add lline chart color selector Jun 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa35765 and a730461.

📒 Files selected for processing (12)
  • packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx
  • packages/mosaic/src/charts/chart-types/histogram/schema.ts
  • packages/mosaic/src/charts/chart-types/histogram/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartXFieldSelector.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/utils.ts
  • packages/mosaic/src/components/ColorSelector.tsx
  • packages/mosaic/src/components/Combobox.tsx
  • packages/mosaic/src/components/MultiFieldSelector.tsx
  • packages/mosaic/src/constants/chart-colors.ts

Comment thread packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx Outdated
Comment thread packages/mosaic/src/charts/chart-types/line-chart/spec.ts Outdated
Comment thread packages/mosaic/src/components/ColorSelector.tsx Outdated
Comment thread packages/mosaic/src/components/MultiFieldSelector.tsx Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread packages/mosaic/src/components/MultiFieldSelector.tsx
@@ -0,0 +1,13 @@
// Chart color palette (default palette colors)
export const CHART_COLORS = [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd suggest to use categoricalSchemeColors.Observable10 from @sqlrooms/color-scales here

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 lift

Component still coupled to line-chart schema.

Line 11 imports YFieldConfig from the line-chart schema, and this type appears throughout the component's public API (lines 14, 21). This violates the coding guideline: "Public exports in packages/ should be kept generic, composable, documented, and free of app/example-specific assumptions."

While the refactoring correctly delegates behavior via onAdd and renderItem (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 win

Consider moving getChartItemColor to a shared utilities location.

getChartItemColor is a generic chart utility but is currently located in line-chart/utils.ts. Since it's being reused across multiple chart types (line chart and histogram), it should live in a shared location such as constants/chart-colors.ts or a dedicated utils/chart-utils.ts file. 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

📥 Commits

Reviewing files that changed from the base of the PR and between a730461 and a79d8f1.

📒 Files selected for processing (8)
  • packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/utils.ts
  • packages/mosaic/src/components/ColorSelector.tsx
  • packages/mosaic/src/components/ColumnSelector.tsx
  • packages/mosaic/src/components/FieldSelectorInput.tsx
  • packages/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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between a79d8f1 and f183297.

📒 Files selected for processing (7)
  • packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx
  • packages/mosaic/src/charts/chart-types/histogram/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/utils.ts
  • packages/mosaic/src/components/ColorSelector.tsx
  • packages/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

Comment thread packages/mosaic/src/charts/chart-types/line-chart/utils.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f183297 and ea80e27.

📒 Files selected for processing (7)
  • packages/mosaic/__tests__/chart-types/line-chart-utils.test.ts
  • packages/mosaic/src/charts/chart-types/histogram/HistogramSettings.tsx
  • packages/mosaic/src/charts/chart-types/histogram/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartYFieldsSelector.tsx
  • packages/mosaic/src/charts/chart-types/line-chart/spec.ts
  • packages/mosaic/src/charts/chart-types/line-chart/utils.ts
  • packages/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

Comment thread packages/mosaic/src/charts/chart-types/line-chart/utils.ts
Comment thread packages/mosaic/src/constants/chart-colors.ts
@dmitriy-kostianetskiy
dmitriy-kostianetskiy merged commit b790206 into main Jun 11, 2026
4 checks passed
@dmitriy-kostianetskiy
dmitriy-kostianetskiy deleted the feat/line-chart-colors branch June 11, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants