Skip to content

feat: Line chart legend - #706

Merged
dmitriy-kostianetskiy merged 4 commits into
mainfrom
feat/line-chart-legend
Jun 10, 2026
Merged

dmitriy-kostianetskiy merged 4 commits into
mainfrom
feat/line-chart-legend

Conversation

@dmitriy-kostianetskiy

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

Copy link
Copy Markdown
Collaborator
image

Summary by CodeRabbit

  • New Features

    • Added a "Show Legend" toggle to line chart settings to control legend visibility.
  • Improvements

    • Enhanced chart container styling and layout for more consistent display.
    • More resilient chart rendering to handle edge cases when embedding plots.
  • Tests

    • Added comprehensive tests covering line chart legend behavior.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a configurable showLegend boolean to line charts (default true), toggled from settings, updates spec generation to conditionally emit a legend panel, adds tests for legend scenarios, improves plot-instance discovery and layout styling, and refactors the Switch component used by ThemeSwitch.

Changes

Line Chart Legend Feature and Supporting Updates

Layer / File(s) Summary
Legend schema and settings UI
packages/mosaic/src/charts/chart-types/line-chart/schema.ts, packages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsx
LineChartSettings adds optional showLegend?: boolean (default true). Settings UI adds a Switch-backed “Show Legend” toggle wired to onChangeConfig('showLegend', ...).
Conditional legend spec generation
packages/mosaic/src/charts/chart-types/line-chart/spec.ts
Introduces getLegendLabel, computes colorDomain/colorRange, emits only lineY marks, and conditionally returns either a standalone plotSpec (no legend) or a vconcat with a color legend when showLegend is true.
Legend behavior test coverage
packages/mosaic/__tests__/chart-types/line-chart-spec.test.ts
New tests assert legend is omitted when showLegend is false, present and configured in a vconcat when true, and included by default when unset.
Plot instance discovery and layout styling
packages/mosaic/src/useVgPlotChartRender.ts, packages/mosaic/src/VgPlotChart.tsx
getPlotInstance locates a .plot element on the container or its descendants before reading the plot instance; VgPlotChart uses cn() to apply nested Tailwind selectors for plot and legend layout.
Switch component refactor and ThemeSwitch update
packages/ui/src/components/switch.tsx, packages/ui/src/components/theme-switch.tsx
Switch is split into a root that accepts optional children and a Switch.Thumb wrapper; ThemeSwitch now uses the local Switch component and updated classNames.
Histogram spec cleanup
packages/mosaic/src/charts/chart-types/histogram/spec.ts
Removes explicit height and width from the returned histogram spec.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • sqlrooms/sqlrooms#591: Related prior refactor of line-chart support (multiple yFields/aggregation) that touches the same spec generation area.
  • sqlrooms/sqlrooms#638: Overlaps with improvements to useVgPlotChartRender and plot-instance mounting logic.

Suggested reviewers

  • ilyabo

Poem

🐰 A tiny rabbit taps the key,
A legend wakes for all to see.
Toggle soft, toggle bold,
Colors prance in lines of gold—
Hop, chart, hop into glee!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Line chart legend' directly describes the main feature added across the changeset—a legend feature for line charts.
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-legend

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: 0664ffb0f3

ℹ️ 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/spec.ts

@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: 1

🤖 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/LineChartSettings.tsx`:
- Around line 57-65: The "Show Legend" label is not associated with the Switch,
making the control inaccessible; update the Switch in LineChartSettings so it
has an accessible name tied to the label (e.g., give the Switch an id like
"show-legend-switch" and set the label's htmlFor to that id, or add a clear
aria-label/aria-labelledby) and ensure the onCheckedChange still calls
onChangeConfig('showLegend', showLegend) and the component still reads initial
state from config.settings.showLegend.
🪄 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: f7f630a7-e57b-47e9-9b89-1a8ffe2dc265

📥 Commits

Reviewing files that changed from the base of the PR and between 48c1edb and 0664ffb.

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

Comment thread packages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsx Outdated
@ilyabo

ilyabo commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

I think the Show legend switch is a bit too large, I'd make it smaller, also I would place it on the left of the label and maybe change the background to not use the primary color? It feels a bit too visually intense.

e.g. here it doesn't look that large:
https://ui.shadcn.com/docs/components/radix/switch
image

@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: 88bfe4b4a7

ℹ️ 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/ui/src/components/switch.tsx

@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/ui/src/components/switch.tsx (1)

8-25: ⚠️ Potential issue | 🟠 Major

Fix SwitchRoot default to use the styled Thumb
SwitchRoot falls back to {children ?? <SwitchPrimitives.Thumb />}, so a self-closing <Switch /> renders Radix’s unstyled thumb (no SwitchThumb classes). packages/kepler/src/components/CustomInteractionManager.tsx uses <Switch ... /> with no children, so it will miss the styled thumb; by contrast packages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsx correctly renders <Switch.Thumb />. Use <SwitchThumb /> as the fallback (or document that callers must provide <Switch.Thumb />).

🤖 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/ui/src/components/switch.tsx` around lines 8 - 25, SwitchRoot
currently falls back to Radix’s unstyled SwitchPrimitives.Thumb when no children
are provided, causing unstyled thumbs for plain <Switch /> usages; update the
fallback inside the SwitchRoot forwardRef (where SwitchPrimitives.Root is
rendered) to use the styled SwitchThumb component instead of
SwitchPrimitives.Thumb so a self-closing <Switch /> renders the correct styled
thumb. Ensure the ref/props behavior remains unchanged and keep
SwitchRoot.displayName as-is.
🧹 Nitpick comments (1)
packages/ui/src/components/switch.tsx (1)

42-46: ⚡ Quick win

Document the compound component API for public consumers.

The Switch.Thumb compound component API is exported from packages/ui but lacks JSDoc documentation. As per coding guidelines, public exports should be documented. Consider adding JSDoc that explains:

  • How to use <Switch /> with the default thumb versus <Switch><Switch.Thumb /></Switch> for custom styling
  • The props accepted by both Switch and Switch.Thumb
  • Example usage patterns (basic toggle vs custom content like icons)
📝 Example documentation structure
+/**
+ * A flexible switch component built on Radix UI primitives.
+ * 
+ * `@example`
+ * // Basic switch with default thumb
+ * <Switch checked={isEnabled} onCheckedChange={setIsEnabled} />
+ * 
+ * `@example`
+ * // Switch with custom styled thumb
+ * <Switch checked={isEnabled} onCheckedChange={setIsEnabled}>
+ *   <Switch.Thumb className="custom-styles" />
+ * </Switch>
+ * 
+ * `@example`
+ * // Switch with custom content
+ * <Switch checked={isDark} onCheckedChange={setIsDark}>
+ *   <Switch.Thumb>
+ *     <SunIcon />
+ *   </Switch.Thumb>
+ * </Switch>
+ */
 const Switch = Object.assign(SwitchRoot, {
+  /** Styled thumb component for use within Switch */
   Thumb: SwitchThumb,
 });
🤖 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/ui/src/components/switch.tsx` around lines 42 - 46, Add JSDoc for
the public compound component export where Switch is composed from SwitchRoot
and SwitchThumb (the Object.assign block that creates Switch from SwitchRoot and
Thumb: SwitchThumb). Document usage patterns: default thumb via <Switch /> and
custom thumb via <Switch><Switch.Thumb /></Switch>, list accepted props for
Switch (e.g., checked, onChange, disabled, className) and for Switch.Thumb
(e.g., className, children) and include two short examples (basic toggle and
custom content like an icon). Place the comment immediately above the const
Switch = Object.assign(...) export so it appears in the generated docs for both
Switch and Switch.Thumb.

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/ui/src/components/switch.tsx`:
- Around line 8-25: SwitchRoot currently falls back to Radix’s unstyled
SwitchPrimitives.Thumb when no children are provided, causing unstyled thumbs
for plain <Switch /> usages; update the fallback inside the SwitchRoot
forwardRef (where SwitchPrimitives.Root is rendered) to use the styled
SwitchThumb component instead of SwitchPrimitives.Thumb so a self-closing
<Switch /> renders the correct styled thumb. Ensure the ref/props behavior
remains unchanged and keep SwitchRoot.displayName as-is.

---

Nitpick comments:
In `@packages/ui/src/components/switch.tsx`:
- Around line 42-46: Add JSDoc for the public compound component export where
Switch is composed from SwitchRoot and SwitchThumb (the Object.assign block that
creates Switch from SwitchRoot and Thumb: SwitchThumb). Document usage patterns:
default thumb via <Switch /> and custom thumb via <Switch><Switch.Thumb
/></Switch>, list accepted props for Switch (e.g., checked, onChange, disabled,
className) and for Switch.Thumb (e.g., className, children) and include two
short examples (basic toggle and custom content like an icon). Place the comment
immediately above the const Switch = Object.assign(...) export so it appears in
the generated docs for both Switch and Switch.Thumb.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7d1451e7-82b0-4a24-9421-1c2a5f9eaa85

📥 Commits

Reviewing files that changed from the base of the PR and between 0664ffb and 88bfe4b.

📒 Files selected for processing (3)
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsx
  • packages/ui/src/components/switch.tsx
  • packages/ui/src/components/theme-switch.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/mosaic/src/charts/chart-types/line-chart/LineChartSettings.tsx

@dmitriy-kostianetskiy
dmitriy-kostianetskiy merged commit c1bba26 into main Jun 10, 2026
4 checks passed
@dmitriy-kostianetskiy
dmitriy-kostianetskiy deleted the feat/line-chart-legend branch June 10, 2026 13:07
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