sfirke opened a new issue, #45474:
URL: https://github.com/apache/superset/issues/45474

   ### Bug description
   
   (I used Claude AI to assist in writing up an error I encountered - I have 
read and edited this)
   
   In 7.0.0rc2, a Bar Chart with a temporal x-axis draws its bars about 1px 
wide when the time grain is finer than the spacing of the data. The common case 
is the default grain, **Day**, on data that is already monthly or yearly. In 
6.1.0 the same saved chart draws normal-width bars.
   
   Our case is a stacked bar chart with one bar per year. The x-axis column 
`Year` holds `2019-01-01 00:00:00`, `2020-01-01 00:00:00`, …, `2024-01-01 
00:00:00`. The time grain is the default, Day. In 6.1.0 each bar fills most of 
the gap between years. In 7.0.0rc2 each bar is a sliver less than 1px wide.
   
   The cause is `getGrainBarMaxWidth` in 
`superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts`, added by 
#44628. It sets the bar series' `barMaxWidth` to the width of one grain bucket:
   
   ```ts
   const domainSpanMs =
     domainMax > domainMin ? domainMax - domainMin : 2 * ONE_DAY_MS;
   return (grainMs / domainSpanMs) * Math.max(plotLengthPx, 0);
   ```
   
   For our chart:
   
   - **Grain:** Day, so 1 day
   - **Data span:** 2019-01-01 to 2024-01-01, about 1,826 days
   - **Plot width:** about 750px
   - **Result:** 750 × 1/1826 ≈ **0.4px**
   
   Before #44628, ECharts sized bars on a time axis from the actual gap between 
data points (one year here), with `barMaxWidth: 100` as the cap. The grain 
didn't affect bar width.
   
   #44628 was meant for sparse **sub-daily** data, and the comment it added in 
`Timeseries/transformers.ts` says so: "For a sub-daily time grain, 
transformProps.ts overrides this with a grain-derived value". The code doesn't 
match that comment, though. `getGrainBarMaxWidth` applies to every grain in 
`TIMEGRAIN_TO_TIMESTAMP`, which includes Day, Month, Quarter and Year. The PR's 
tests in `test/Timeseries/Bar/sparseSubDailyBarGeometry.test.ts` all use 
`PT1H`, so nothing tests the Day-and-coarser cases.
   
   Day is the default for `time_grain_sqla`, so any saved bar chart of 
pre-aggregated monthly or yearly data that kept the default will show hairline 
bars after upgrading. The override runs in `MixedTimeseries/transformProps.ts` 
too, so mixed charts with a bar series are affected the same way.
   
   Choosing a coarser grain works around it for our chart, but that isn't a 
general fix. The grain also truncates the date column in SQL. Data stamped on 
fiscal-year starts (e.g. July 1) would be moved and possibly merged by a Year 
grain. Irregularly spaced dates have no grain that fits.
   
   **How to reproduce**
   
   1. Use a dataset with a temporal column holding one value per year (or per 
month), e.g. `2019-01-01` through `2024-01-01`, and a numeric metric.
   2. Create a Bar Chart with that column as the x-axis. Leave Time Grain at 
the default, Day. Stacking makes no difference.
   3. The bars are drawn as hairlines.
   4. Change Time Grain to Year (or Month for monthly data). The bars are 
normal width again.
   
   **Expected behavior**
   
   As in 6.1.0, bars on pre-aggregated data are sized from the spacing of the 
data whatever the grain setting, so a Day grain on yearly data draws wide bars.
   
   **Proposed fix**
   
   Apply the grain-based override only to sub-daily grains, as #44628's title 
and comment describe. In `getGrainBarMaxWidth`, return `undefined` (keeping the 
existing `barMaxWidth: 100` fallback and ECharts' own sizing) when the grain is 
a day or longer:
   
   ```ts
   if (!grainMs || grainMs >= ONE_DAY_MS) {
     return undefined;
   }
   ```
   
   This brings back 6.1.0 behavior for Day and coarser grains and keeps the 
#44628 fix for the sparse hourly and minute data it targeted. The existing 
`PT1H` tests should still pass.
   
   Unit tests should cover a Day grain on yearly and monthly data, checking 
that `barMaxWidth` stays at the fallback, in both `Timeseries` and 
`MixedTimeseries`.
   
   I also considered sizing by the larger of the grain and the smallest 
observed gap between points. That would partly undo #44628, because a gap-sized 
bar is what spilled across empty buckets in the original sparse sub-daily bug.
   
   ### Screenshots/recordings
   
   **6.1.0 (expected):**
   <img width="1038" height="552" alt="Image" 
src="https://github.com/user-attachments/assets/15d13c45-c757-4bae-b66b-073548d7a363";
 />
   
   **7.0.0rc2 (regression), same saved chart:**
   <img width="1091" height="591" alt="Image" 
src="https://github.com/user-attachments/assets/aa8eb2e5-3b8a-44ff-842e-44d858a82fdc";
 />
   
   **Chart config** (x-axis `Year`, Time Grain: Day):
   <img width="1520" height="736" alt="Image" 
src="https://github.com/user-attachments/assets/3b964b67-2250-42fe-bc24-3fd2e6f1896c";
 />
   
   ### Superset version
   
   master / latest-dev
   
   ### Python version
   
   3.11
   
   ### Node version
   
   16
   
   ### Browser
   
   Chrome
   
   ### Additional context
   
   _No response_
   
   ### Checklist
   
   - [ ] I have searched Superset docs and Slack and didn't find a solution to 
my problem.
   - [ ] I have searched the GitHub issue tracker and didn't find a similar bug 
report.
   - [ ] I have checked Superset's logs for errors and if I found a relevant 
Python stacktrace, I included it here as text in the "additional context" 
section.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to