codeant-ai-for-open-source[bot] commented on code in PR #41749:
URL: https://github.com/apache/superset/pull/41749#discussion_r3530456738
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts:
##########
@@ -269,21 +259,12 @@ function getHorizontalPlainLegendLayout({
showSelectors,
theme,
);
+ const rowsForMargin = Number.isFinite(rowCount)
+ ? rowCount
+ : legendLabels.length;
const requiredMargin =
defaultLegendPadding[orientation] +
- Math.max(0, rowCount - 1) * LEGEND_HORIZONTAL_ROW_HEIGHT;
- const maxLegendHeight =
- availableHeight > 0
- ? availableHeight * LEGEND_HORIZONTAL_MAX_HEIGHT_RATIO
- : Infinity;
-
- if (
- !Number.isFinite(rowCount) ||
- rowCount > LEGEND_HORIZONTAL_MAX_ROWS ||
- requiredMargin > maxLegendHeight
- ) {
- return SCROLL_LEGEND_LAYOUT;
- }
+ Math.max(0, rowsForMargin - 1) * LEGEND_HORIZONTAL_ROW_HEIGHT;
Review Comment:
**Suggestion:** When row estimation overflows (`Infinity`), this fallback
uses the full legend item count as row count with no cap, which can produce
extremely large `effectiveMargin` values (thousands of pixels for large series
lists) and collapse the plot area. Clamp the computed rows/margin against chart
height (or a sane max rows threshold) before returning the margin. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
❌ Small-width timeseries charts can collapse to near-zero height.
❌ MixedTimeseries legends can reserve disproportionate vertical space.
⚠️ Gantt charts with many series may show barely visible plot.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. In the timeseries chart pipeline, `resolveLegendLayout()` at
`superset-frontend/plugins/plugin-chart-echarts/src/utils/legendLayout.ts:19-36`
calls
`getLegendLayoutResult()` with `availableWidth` computed in
`Timeseries/transformProps.ts:28-38` via
`getHorizontalLegendAvailableWidth({ chartWidth:
width, orientation: legendOrientation, padding, zoomable })`.
2. When the chart container is extremely narrow, or left padding from
`getPadding()`
equals/exceeds `width`, `getHorizontalLegendAvailableWidth()` in
`src/utils/series.ts:62-79` returns `availableWidth = 0` (it does
`chartWidth -
(padding?.left ?? 0)` then `Math.max(availableWidth, 0)`).
3. `getLegendLayoutResult()` in `src/utils/series.ts:110-161` receives this
`availableWidth` and, for a horizontal legend
(`LegendOrientation.Top`/`Bottom`) with
`type: LegendType.Plain`, calls `getHorizontalPlainLegendLayout()` (lines
42-56) with
non-empty `legendItems` (e.g. many series names from
`Timeseries/transformProps.ts:40-43`).
4. Inside `getHorizontalPlainLegendLayout()`,
`estimateHorizontalLegendRows()` at
`src/utils/series.ts:3-15` sees `availableWidth === 0` and returns
`Infinity`. The new
fallback at lines 262-265 sets `rowsForMargin = legendLabels.length` when
`rowCount` is
non-finite. For a legend with many items (e.g. 100 series), `requiredMargin =
defaultLegendPadding[orientation] + (rowsForMargin - 1) *
LEGEND_HORIZONTAL_ROW_HEIGHT`
(lines 265-267) becomes thousands of pixels (99 * 24px ≈ 2376 + padding).
This
`effectiveMargin` is propagated via `resolveLegendLayout()` and then used as
`effectiveLegendMargin` in `Timeseries/transformProps.ts:60-75` and
`MixedTimeseries/transformProps.ts:39-49` when computing grid padding,
causing the ECharts
grid height to be squeezed down to a tiny or zero drawable area on
small-width charts with
many legend items.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c1327b767f644d308b672db7ee67c880&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c1327b767f644d308b672db7ee67c880&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts
**Line:** 262:267
**Comment:**
*Logic Error: When row estimation overflows (`Infinity`), this fallback
uses the full legend item count as row count with no cap, which can produce
extremely large `effectiveMargin` values (thousands of pixels for large series
lists) and collapse the plot area. Clamp the computed rows/margin against chart
height (or a sane max rows threshold) before returning the margin.
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
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41749&comment_hash=58324e495fc809938fd7498b771087b4c226a9da7ad90c824e6aa317ea8d7471&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41749&comment_hash=58324e495fc809938fd7498b771087b4c226a9da7ad90c824e6aa317ea8d7471&reaction=dislike'>👎</a>
--
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]