Skip to content

fix(plugin-chart-echarts): limit the grain-based bar width cap to sub-daily grains - #45519

Open
Anikesh0001 wants to merge 3 commits into
apache:masterfrom
Anikesh0001:fix/bar-width-sub-daily-grain
Open

Anikesh0001 wants to merge 3 commits into
apache:masterfrom
Anikesh0001:fix/bar-width-sub-daily-grain

Conversation

@Anikesh0001

Copy link
Copy Markdown

SUMMARY

Fixes #45474.

Since #44628, getGrainBarMaxWidth caps the bar width at one time-grain bucket for every grain in TIMEGRAIN_TO_TIMESTAMP. That cap was meant for sparse sub-daily data, as the comment in Timeseries/transformers.ts says ("For a sub-daily time grain, transformProps.ts overrides this…"). For Day and coarser grains it misbehaves when the data is spaced further apart than the grain, which is the common case of the default Day grain on pre-aggregated monthly or yearly rows. One day is then a sliver of the axis, and the bars are drawn as hairlines.

This change follows the fix proposed in the issue:

  • getGrainBarMaxWidth returns undefined when the grain is a day or longer (grainMs >= ONE_DAY_MS).
  • Both call sites (Timeseries/transformProps.ts and MixedTimeseries/transformProps.ts) already keep the default barMaxWidth: 100 in that case, so ECharts sizes the bars from the spacing of the data again, as in 6.1.0.
  • The sub-daily behaviour from fix(echarts): fix sparse sub-daily bar sizing and x-axis mislabeling #44628 is unchanged, and its tests still pass.
  • The docstring now says that only sub-daily grains get a grain-derived cap.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

No screenshots from me. The issue has 6.1.0 vs 7.0.0rc2 screenshots of the same chart. The numbers come from the new tests, with an 800px chart and data from 2019-01-01 to 2024-01-01:

Case barMaxWidth before after
Bar chart, Day grain, yearly data 0.42px 100 (default cap)
Bar chart, Day grain, monthly data 2.27px 100
Bar chart, Month grain, yearly data 12.90px 100
Mixed chart (bar series), Day grain, yearly data 0.42px 100

TESTING INSTRUCTIONS

New tests:

  • plugins/plugin-chart-echarts/test/Timeseries/Bar/sparseSubDailyBarGeometry.test.ts: a Day grain on yearly and on monthly data, and a Month grain on yearly data, keep the default bar width cap.
  • plugins/plugin-chart-echarts/test/MixedTimeseries/transformProps.test.ts: the same for a mixed chart with a bar series, with a Day grain on yearly data.

All 4 fail on master (they receive the hairline widths above) and pass with this change.

Run locally with Node 24.16 / npm 11:

To check it manually, follow the steps in #45474: a Bar Chart on a dataset with one row per year, x-axis on the temporal column, Time Grain left at Day. The bars should have normal width, as in 6.1.0.

ADDITIONAL INFORMATION

Generative AI disclosure, following the ASF guidelines: I used Claude Code (Claude Opus 5.5) to help investigate this issue and draft the change, the tests and this description. I reviewed the result, checked that the new tests fail on master, and ran the checks above locally.

🤖 Generated with Claude Code

…-daily grains

getGrainBarMaxWidth capped bar width at one grain bucket for every grain
in TIMEGRAIN_TO_TIMESTAMP. With the default Day grain on pre-aggregated
monthly or yearly data, one day is a sliver of the axis, so bars were
drawn under 1px wide. The cap was meant for sparse sub-daily data, as
the comment in Timeseries/transformers.ts says. For a day or coarser
grain, return undefined so bars keep the default cap and ECharts sizes
them from the spacing of the data again.

Fixes apache#45474

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: e2b024ab526c

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.73%. Comparing base (e33b7d9) to head (e2b024a).
⚠️ Report is 257 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45519   +/-   ##
=======================================
  Coverage   84.73%   84.73%           
=======================================
  Files        3069     3069           
  Lines      205767   205784   +17     
  Branches    48388    48404   +16     
=======================================
+ Hits       174350   174374   +24     
+ Misses      28123    28116    -7     
  Partials     3294     3294           
Flag Coverage Δ
javascript 80.99% <100.00%> (+0.01%) ⬆️

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.

@sfirke sfirke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hello! Please see the new contributor guidelines here: https://github.com/apache/superset/wiki/New-Contributor-Welcome-&-Expectations In particular please include before + after screenshots of your manual local testing. This helps demonstrate that code authors have deployed their changes and tested them with manual QA and we avoid drive-by AI code contributions.

@xiaobai0529

Copy link
Copy Markdown

Before / after screenshots from local Storybook testing

I independently rendered the PR's target case in Storybook from both revisions, using the same fixture, viewport, and chart dimensions.

Setup

  • Before: d5bccecf58126db88a596164daf6fdda9aa0d341
  • After: aab7f5ba4a9816a90627dcb4d6c79585963657ae
  • Viewport: 960x900
  • Chart width: 900px, height: 260px
  • Bar chart, x-axis: temporal column, Time Grain: P1D
  • Top chart: yearly rows (2019-2024); bottom chart: monthly rows (24 months)

Before

Before

After

After

The before revision draws the yearly and monthly bars as hairlines because the Day-grain cap is far narrower than the spacing between rows. The after revision keeps the default 100px cap for Day and coarser grains, so the bars render at a normal width.

This was Storybook-level QA, not a full Superset web-server deployment. The fixture exercised EchartsTimeseriesChartPlugin and TimeseriesTransformProps, and both screenshots were captured after confirming that two chart canvases had rendered. I did not modify the PR branch.

The screenshot files are stored on a separate evidence branch of my public fork, not in the Superset repository.

@villebro

Copy link
Copy Markdown
Member

@sfirke are we ok to merge? This one is going into 7.0.0rc3, and the screens have been added to the PR

@sfirke

sfirke commented Oct 30, 2026

Copy link
Copy Markdown
Member

I will try to deploy this today to kick the tires on my end.

@sfirke

sfirke commented Oct 30, 2026

Copy link
Copy Markdown
Member

@sadpandajoe and @villebro, please see the two options I laid out in my comment in the issue: #45474 (comment) I am not sure that merging this PR is the right fix, it might be better to revert only the bar-width portion of #44628

@sfirke sfirke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The left-most and right-most bars have their labels off center. This is from my test environment running this PR:

Image

This is also evident in the screenshot you posted.

Separately, I want to get replies to my issue that this is linked to: are we better off reverting part of the PR that introduced this problem? This fix introduces its own downsides.

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Nov 18, 2026

This branch has not been deployed

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

Labels

plugins requires:rebase Requires rebasing on top of current master size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bar chart: bars on a temporal x-axis shrink to hairlines when the time grain is finer than the data (7.0.0rc2)

5 participants