Skip to content

fix(echarts): render Plain Timeseries legends as HTML, not canvas - #43314

Merged
sadpandajoe merged 22 commits into
masterfrom
fix-plain-legend-overlap-timeseries
Sep 4, 2026
Merged

sadpandajoe merged 22 commits into
masterfrom
fix-plain-legend-overlap-timeseries

Conversation

@sadpandajoe

@sadpandajoe sadpandajoe commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

When a Time-Series chart's Legend Type is set to Plain (List) with Legend Orientation
Top or Bottom, and enough grouped dimensions are combined to produce many legend
entries, the legend could render on top of the chart's plot area instead of the
chart displaying properly. A Plain legend never paginates or hides entries, so any
legend taller than the space ECharts reserved for it painted directly over the plot.

An earlier iteration of this fix tried to address this by having the chart's
legend-layout estimator reserve more of ECharts' own grid margin for the legend, but
the legend and the plot still shared a single ECharts canvas/coordinate system, so a
legend taller than even the "full" computed margin could still overlap the plot.

This PR replaces that approach for the common case (Plain legend, Top/Bottom
orientation) with a custom HTML legend (TimeseriesLegend) rendered outside the
ECharts canvas, in its own flexbox row via WithLegend. Because the legend and the
chart are now separate DOM elements instead of sharing ECharts' coordinate system,
the legend can no longer paint over the plot: it renders in a bounded, independently
scrollable box (getTimeseriesLegendMaxHeight), and the ECharts canvas always gets
whatever space remains, down to a small fixed minimum plot height. The custom legend
preserves the existing legend interactions (item toggle, "All"/"Inverse" selectors)
by dispatching the same ECharts legend actions the native legend used, and renders
real <button> elements, which are more accessible than ECharts' canvas-drawn legend.

It does not change how the legend type itself is resolved — an explicit Plain/List
selection is still always honored, never silently switched to a scrolling legend.
Plain legends with Left/Right orientation, and every other legend type/orientation
combination, are unaffected — they continue to use the pre-existing margin-reservation
approach (resolveLegendLayout / getHorizontalPlainLegendLayout /
getVerticalPlainLegendLayout). The change is scoped to the Timeseries chart plugin;
the shared legend-layout helper's behavior for other chart types (Mixed Timeseries,
Gantt, Pie, Funnel, Radar, Bubble, Graph) is unchanged.

ROOT CAUSE

getHorizontalPlainLegendLayout in plugins/plugin-chart-echarts/src/utils/series.ts
estimates the number of horizontal legend rows and the margin needed to fit them, but
that margin is still consumed from inside ECharts' own grid — the legend and the plot
are laid out by the same coordinate system, so no margin calculation, however
accurate, can fully decouple the two. The Timeseries plugin now sidesteps that
coupling for Plain + Top/Bottom legends by rendering the legend as ordinary HTML next
to (not inside) the ECharts canvas, so the plot's height is simply "whatever's left"
after the legend takes its bounded, scrollable share — there's no margin the legend
can grow past.

LATENT ISSUES FOUND (not fixed here, noted for future work)

  • getVerticalPlainLegendLayout sizes left/right margins from the longest label and
    selector width but does not account for the number of vertically stacked items — a
    tall vertical Plain legend (still native-ECharts-rendered) can extend beyond the
    plot. Separate, orientation-specific defect from this fix.
  • Mixed Timeseries, Gantt, Pie, Funnel, Radar, Bubble, and Graph share the
    legend-layout resolver but don't render a custom HTML legend, so they retain the
    legacy margin-reservation behavior rather than the structural fix added here.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

Screenshot 2026-08-27 at 10 26 12 PM

After:

Screen.Recording.2026-08-27.at.10.22.00.PM.mov

TESTING INSTRUCTIONS

  1. Create a Time-Series Line Chart using a dataset with two grouped dimensions
    whose combination produces many series (dozens or more) — e.g. two categorical
    columns with a handful of distinct values each.
  2. Under the Customize tab, set Legend Type to Plain and Legend Orientation to Top
    (repeat with Bottom).
  3. Create/update the chart.
  4. Verify the legend renders as its own scrollable panel above/below the chart
    instead of overlapping the plot area — the plot area shrinks to make room for
    the legend instead of being painted over.
  5. Verify a chart with only a few legend entries is unaffected — the legend still
    reserves only the minimal space it needs and isn't scrollable.
  6. Click a legend item to toggle a series, and use the "All"/"Inverse" buttons —
    verify they still drive the chart the same way the native ECharts legend did.
  7. Verify Plain legend with Left/Right orientation is unaffected (still uses the
    previous margin-reservation behavior).

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.88957% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.08%. Comparing base (22027ec) to head (f60e348).
⚠️ Report is 197 commits behind head on master.

Files with missing lines Patch % Lines
...lugin-chart-echarts/src/Timeseries/transformers.ts 76.31% 9 Missing ⚠️
...gin-chart-echarts/src/Timeseries/transformProps.ts 89.06% 7 Missing ⚠️
...-chart-echarts/src/Timeseries/TimeseriesLegend.tsx 87.09% 4 Missing ⚠️
...chart-echarts/src/Timeseries/EchartsTimeseries.tsx 90.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43314      +/-   ##
==========================================
- Coverage   79.16%   79.08%   -0.08%     
==========================================
  Files        2879     2878       -1     
  Lines      165765   165298     -467     
  Branches    38322    38259      -63     
==========================================
- Hits       131224   130734     -490     
- Misses      32064    32111      +47     
+ Partials     2477     2453      -24     
Flag Coverage Δ
javascript 74.65% <85.88%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sadpandajoe sadpandajoe added review:draft 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Aug 20, 2026
@github-actions github-actions Bot added 🎪 f0f7e12 🚦 building 🎪 ⌛ 48h Environment expires after 48 hours (default) and removed 🎪 ⚡ showtime-trigger-start Create new ephemeral environment for this PR labels Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for f0f7e12

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 5c0717f

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 7ad3202

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 9b8da16

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 9b8da16

• Environment: http://44.243.198.58:8080 (admin/admin)
• Lifetime: 48h auto-cleanup
• Updates: New commits create fresh environments automatically

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for f56c10f

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for f56c10f

• Environment: http://35.94.59.81:8080 (admin/admin)
• Lifetime: 48h auto-cleanup
• Updates: New commits create fresh environments automatically

@bito-code-review

bito-code-review Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8c6534

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts - 1
    • Stale comment after refactor · Line 1506-1506
      The comment "Hide legend on compact charts — not enough vertical space" is now inaccurate. Legend visibility is controlled by `isLegendVisible` (which already encodes the compact-chart guard), not by the `isSmallChart` flag passed to `getLegendProps`. This could mislead future maintainers.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - 1
    • CWE-134: Wrong boolean param causes wrong constants · Line 390-390
Review Details
  • Files reviewed - 11 · Commit Range: 506424d..f56c10f
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.test.tsx
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.tsx
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/utils/legendLayout.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/Bar/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/EchartsTimeseries.test.tsx
    • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

…erlap-timeseries

# Conflicts:
#	superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 6965baf

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 6965baf

• Environment: http://54.213.84.123:8080 (admin/admin)
• Lifetime: 48h auto-cleanup
• Updates: New commits create fresh environments automatically

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 5f195cf

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 5f195cf

• Environment: http://16.146.79.93:8080 (admin/admin)
• Lifetime: 48h auto-cleanup
• Updates: New commits create fresh environments automatically

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 560e5bf

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime is building environment on GHA for 2f0d78d

@github-actions

Copy link
Copy Markdown
Contributor

🎪 Showtime deployed environment on GHA for 2f0d78d

• Environment: http://44.243.247.238:8080 (admin/admin)
• Lifetime: 48h auto-cleanup
• Updates: New commits create fresh environments automatically

@bito-code-review

bito-code-review Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #010b9e

Actionable Suggestions - 0
Additional Suggestions - 4
  • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - 2
    • Behavior change in margin calc · Line 260-275
      The new margin calculation replaces the deleted `estimateEchartsHorizontalLegendAdditionalMargin` with a simpler row-count-based formula. This changes behavior for charts that previously used `reserveFullHorizontalPlainLegendMargin` with `horizontalPlainLegendItemLayouts`. Verify visual output matches expectations, especially for charts with complex legend layouts.
    • API signature breaking change · Line 457-461
      The function signature removes `horizontalPlainLegendItemLayouts` and `reserveFullHorizontalPlainLegendMargin` parameters. Verify all callers are updated and consider if this is a breaking API change.
  • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.tsx - 1
    • Redundant grid transformation call · Line 828-836
      `getViableTimeseriesEchartOptions` is already called in `transformProps.ts` (line 1676) with `height`. Calling it again here with `chartBodyHeight` is redundant and can produce different grid values when `extraControlHeight > 0` (since `chartBodyHeight = Math.max(height - extraControlHeight, 0)`). The old code only applied this logic when `customLegend` was defined and `!shouldRenderCustomLegend`; the new code applies it unconditionally, changing behavior for charts without custom legends. Remove the redundant call or use `height` to keep it idempotent.
  • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/EchartsTimeseries.test.tsx - 1
    • Duplicate querySelectorAll call · Line 60-61
      The mock calls `legend.querySelectorAll('[aria-pressed]').length` twice on consecutive lines. Reuse the `itemCount` variable: `const selectorHeight = itemCount ? 20 : 0;`. This avoids a redundant DOM query in the test mock.
Review Details
  • Files reviewed - 13 · Commit Range: f56c10f..2f0d78d
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.test.tsx
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.tsx
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/TimeseriesLegend.tsx
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/types.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/utils/legendLayout.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/Bar/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/EchartsTimeseries.test.tsx
    • superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/test/utils/series.test.ts
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas

rusackas commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

Heya @sadpandajoe, the title and description here are still describing the original margin-cap approach in getHorizontalPlainLegendLayout. That file hasn't been touched since bf16b511 swapped it for the new TimeseriesLegend component. Might be worth updating both, since right now they undersell what's actually being proposed: a custom HTML legend replacing ECharts' native one for Plain+Top/Bottom, not a margin tweak.

Otherwise this looks good to me. Capping the legend height instead of letting margin grow unbounded is the right call, and real <button>s beat ECharts' canvas legend on accessibility. Once the description catches up and the review:draft label comes off, LGTM from me.

@sadpandajoe

Copy link
Copy Markdown
Member Author

Good catch — the description was stale from before the swap to the custom TimeseriesLegend component. Updated the title and description to describe the current HTML-legend approach (rendered via WithLegend outside the ECharts canvas for Plain+Top/Bottom) rather than the original margin-cap. Thanks for the review!

@gabotorresruiz gabotorresruiz 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.

LGTM, thanks Joe, and thanks for the description rewrite, it now matches the implementation exactly. I verified this end to end: 24 of the new tests fail on master so they genuinely pin the fix, the full Timeseries and collateral echarts suites pass locally (636 tests), and the branch merges cleanly with current master. The SSR grid-geometry assertions are a level of rigor we rarely get in this plugin. Two small non-blockers inline.

The custom Plain-legend renders as HTML, so it lost the native ECharts
legend behavior of highlighting the hovered series. Wire onMouseEnter/
onMouseLeave to dispatch highlight/downplay actions by series name.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@bito-code-review

bito-code-review Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #66fddb

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 2f0d78d..f60e348
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/EchartsTimeseries.tsx
    • superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/TimeseriesLegend.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

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

Labels

change:frontend Requires changing the frontend plugins size/XXL viz:charts:echarts Related to Echarts viz:charts:timeseries Related to Timeseries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants