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

   ## Bug description
   
   In the Calendar Heatmap (`cal_heatmap`) with **Domain = Month** and 
**Subdomain = Week**, the cell for a month's first week is positioned roughly 
one cell-width to the *left* of its month block whenever the 1st of that month 
falls on a Monday (the week start day).
   
   It lands on top of the previous month's last cell, so the two overlap and 
only one dot is visible. The month then appears to begin at its second week, 
and a week of data looks missing.
   
   The data itself is correct and present — only the position is wrong.
   
   ## How to reproduce
   
   1. Create a Calendar Heatmap on any dataset with a date column and daily 
values
   2. Set **Domain = Month**, **Subdomain = Week**
   3. Use a time range covering a month whose 1st is a Monday — e.g. June 2026, 
or February / March / November 2027
   4. Look at that month: its first week is not visible, and the month appears 
to start at the second week
   
   ## What is actually happening
   
   Inspecting the rendered SVG for June 2026 (`cellSize: 12`, `cellPadding: 
10`; screen coordinates will vary with viewport width):
   
   ```
   month block "June"   spans screen x 754–854
     cell 2026-06-01    x=-22   screen 754    <-- negative position
     cell 2026-06-08    x=0     screen 776
     cell 2026-06-15    x=22    screen 798
     cell 2026-06-22    x=44    screen 820
     cell 2026-06-29    x=66    screen 842
   
   month block "May"    spans screen x 686–764
     cell 2026-05-25    x=66    screen 752
   ```
   
   The 1 June cell exists, carries its value and colour-level class, and is 
painted — at `x = -22`, which puts it 2px from the 25 May cell. The two overlap 
almost exactly, so one hides the other. The month blocks themselves also 
overlap (May ends at 764, June starts at 754).
   
   ## Root cause
   
   Two off-by-one errors in
   
`superset-frontend/plugins/legacy-plugin-chart-calendar/src/vendor/cal-heatmap.ts`:
   
   **1. Negative x position** — `getMonthWeekNumber`:
   
   ```js
   return this.getWeekNumber(d) - monthFirstWeekNumber - 1;
   ```
   
   The `- 1` assumes a month's first week cell always begins in the *previous* 
month, which holds only when the 1st is not the week start. When the 1st **is** 
the week start, both week numbers are equal and this returns `-1`, so 
`positionSubDomainX` yields `-1 * (cellSize + cellPadding)`.
   
   **2. Month block sized one column short** — 
`_domainType.week.defaultColumnNumber` for `domain: 'month'`:
   
   ```js
   return self.options.domainDynamicDimension
     ? self.getWeekNumber(new Date(d.getFullYear(), d.getMonth() + 1, 0))
         - self.getWeekNumber(d)
     : 5;
   ```
   
   `domainDynamicDimension` defaults to `true`, so this returns `endWeekNb - 
startWeekNb`, while `computeWeekSubDomainSize` generates `endWeekNb - 
startWeekNb + 1` cells. The block is therefore exactly one column narrower than 
the number of cells it must hold, which is why adjacent month blocks overlap.
   
   ## Already fixed upstream; Superset vendors the older code
   
   This is wa0x6e/cal-heatmap#222 ("Some weeks info is missing", opened 2016), 
which describes the same trigger:
   
   > When we put Month as Domain and Week as SubDomain the weeks which are 
staring 1st of the month as Monday are missing
   
   A later comment on that issue matches the behaviour above: *"some weeks 
appear out of order, some weeks over-write other weeks, some weeks are 
duplicated in more than one month"*.
   
   Upstream reported "Weeks positioning issues is fixed in master" (Dec 2022) 
and closed the issue as completed in Feb 2023. The library is now on 4.x. 
Superset's vendored copy predates that rewrite — it is built on the d3 v3 
`d3.time.*` API — and still contains both lines above, including on `master`.
   
   ## A second defect worth fixing at the same time
   
   The natural workaround — switching Domain to Year — avoids the `-1`, but 
runs into an unguarded lookup in the data-fill loop:
   
   ```js
   var index = temp[domainUnit].indexOf(
     this._domainType[this.options.subDomain].extractUnit(date),
   );
   subDomainsData[index].v = data[d];
   ```
   
   `indexOf` returns `-1` when a data point's week has no generated cell, and 
`subDomainsData[-1]` is `undefined`, so the chart fails with:
   
   ```
   TypeError: Cannot read properties of undefined (reading 'v')
   ```
   
   With `domain: year`, no cell is generated for the final partial week of the 
year, so any dataset containing data in that week crashes the chart outright 
rather than dropping a point. (Related upstream report of the same 
unguarded-index pattern in a different configuration: wa0x6e/cal-heatmap#52.)
   
   A bounds check there would turn a crash into a skipped value.
   
   ## Environment
   
   Superset 6.1.0. Both code paths verified unchanged on `master`.
   


-- 
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