Repository navigation
fix(echarts): only reserve left grid padding when a Y-axis title exists - #43299
Conversation
getPadding() added y_axis_title_margin to the left grid offset whenever y_axis_title_position was 'Left', without checking that a Y-axis title was actually rendered. Since the control defaults are position 'Left' and margin 50, every timeseries chart with no Y-axis title reserved 70px on the left. With grid.containLabel enabled that space sits outside the tick labels, so it is pure dead space. It is unnoticeable on a wide desktop chart but consumes roughly a third of the plot area on a phone. Gate the left margin on the existing addYAxisTitleOffset flag, which callers already compute as `!!yAxisTitle && margin !== 0`, and have Gantt pass that flag instead of a hardcoded false so it keeps its padding when a title is present.
Code Review Agent Run #2f3b05Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
| // The title margin is only reserved when a Y-axis title is actually | ||
| // rendered. Without this guard every chart pays for the default | ||
| // margin, which eats a large share of the plot area on narrow charts. | ||
| left: | ||
| yAxisTitlePosition === 'Left' | ||
| yAxisTitlePosition === 'Left' && addYAxisTitleOffset | ||
| ? TIMESERIES_CONSTANTS.gridOffsetLeft + | ||
| (Number(yAxisTitleMargin) || 0) | ||
| : TIMESERIES_CONSTANTS.gridOffsetLeft, |
There was a problem hiding this comment.
Suggestion: The new comment claims the title margin is reserved only when a title is rendered, but the top branch still adds yAxisTitleMargin whenever yAxisTitlePosition is Top, even when addYAxisTitleOffset is false. Timeseries and MixedTimeseries therefore continue reserving the default top margin for charts without a Y-axis title. Gate the top margin with the same rendered-title condition, or narrow the comment so it only describes the left branch. [comment mismatch]
Severity Level: Major ⚠️
- ⚠️ Timeseries charts waste top plot space with empty titles.
- ⚠️ MixedTimeseries charts retain unnecessary top padding.
- ⚠️ Narrow charts lose usable vertical plotting area.Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts
**Line:** 798:805
**Comment:**
*Comment Mismatch: The new comment claims the title margin is reserved only when a title is rendered, but the `top` branch still adds `yAxisTitleMargin` whenever `yAxisTitlePosition` is `Top`, even when `addYAxisTitleOffset` is false. Timeseries and MixedTimeseries therefore continue reserving the default top margin for charts without a Y-axis title. Gate the top margin with the same rendered-title condition, or narrow the comment so it only describes the left branch.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix|
The flagged issue is correct. In To resolve this, you should gate the top:
yAxisTitlePosition === 'Top' && addYAxisTitleOffset
? TIMESERIES_CONSTANTS.gridOffsetTop + (Number(yAxisTitleMargin) || 0)
: TIMESERIES_CONSTANTS.gridOffsetTop,I have checked the PR comments, and there are no other pending review comments to address. Would you like me to check for any other potential issues in this file? superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #43299 +/- ##
=======================================
Coverage 80.14% 80.14%
=======================================
Files 2924 2924
Lines 172407 172409 +2
Branches 40028 40030 +2
=======================================
+ Hits 138175 138177 +2
Misses 31647 31647
Partials 2585 2585
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The `top` branch of `getPadding()` added `yAxisTitleMargin` whenever the title position was `Top`, without checking that a title is actually rendered — the same defect the `left` branch had. Charts with an empty `y_axis_title` and position `Top` therefore reserved the default 50px of dead space above the plot area. Gate it on `addYAxisTitleOffset`, the flag callers already compute as `!!yAxisTitle && convertInteger(yAxisTitleMargin) !== 0`, so the fall through yields the bare `gridOffsetTop`. Charts with a title keep their existing spacing. Adds a `getPadding()` test for the no-title `Top` case.
Code Review Agent Run #e7fb0eActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rusackas
left a comment
There was a problem hiding this comment.
Thanks for the writeup and the before/after shots, this is a clean fix and catching that Gantt's two getPadding call sites needed the same flag is a nice catch too. CI's green, this looks mergeable to me.
SUMMARY
Timeseries charts render with a large blank strip on the left: the plot area starts well inside the card, far outside the tick labels. It is barely noticeable on a wide desktop chart, but it eats roughly a third of the plot area on a narrow one.
The cause is in
getPadding()(plugins/plugin-chart-echarts/src/Timeseries/transformers.ts):The Y-axis title margin is added whenever the title position is
'Left', without checking that a title is actually rendered. The control defaults (sections/chartTitle.tsx) are position'Left'and margin50, so every chart with an emptyy_axis_title— the default — reserves20 + 50 = 70pxon the left. Becausegrid.containLabelis enabled, that reservation sits outside the axis labels, so it is pure dead space.The guard already exists: callers compute
addYAxisTitleOffset = !!yAxisTitle && convertInteger(yAxisTitleMargin) !== 0, and the'Top'position branch consumes it. Only the'Left'branch ignored it.Changes:
addYAxisTitleOffset. Charts with a Y-axis title keep exactly the spacing they have today; charts without one reclaim the 50px.Gantt/transformProps.tshardcodedfalsefor that flag at bothgetPadding()call sites while relying on the'Left'branch for its left padding, so it now computes the flag properly and passes it to both. Without that, gating the left branch would have silently removed Gantt's title spacing.getPadding()unit test covering the no-title case.This supersedes #43064, which was closed while in draft. Same change, rebased onto current master with a clean history.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — the visible effect is the left grid offset shrinking from 70px to 20px on charts with no Y-axis title, which is easiest to confirm with the testing instructions below.
BEFORE :


AFTER :
TESTING INSTRUCTIONS
Unit tests:
Manually:
Left. Spacing is unchanged from current behaviour — the title still gets its 50px margin.ADDITIONAL INFORMATION