Skip to content

[WC-3594] Charts: keep design preview within its parent - #2473

Merged
yordan-st merged 2 commits into
mainfrom
fix/WC-3594_chart-preview-overlaps-widgets
Oct 28, 2026
Merged

yordan-st merged 2 commits into
mainfrom
fix/WC-3594_chart-preview-overlaps-widgets

Conversation

@yordan-st

Copy link
Copy Markdown
Contributor

Pull request type

Bug fix (non-breaking change which fixes an issue)


Description

The design mode preview of the chart widgets ignored the width and height settings and always rendered at a fixed 300×232px (385px wide with legend) inside an inline-flex wrapper. In a parent narrower than that, for example a layout grid column with a manual width, the preview spilled over neighbouring widgets.

The shared ChartPreview now applies width unit, width, height unit and height the same way the runtime does, and is capped at 100% of its parent, so it follows the configuration and never grows past its container. This covers the area, bar, bubble, column, heatmap, line, pie/doughnut and time series charts. Custom chart has its own preview and is not changed.

Note: the recording on the ticket was made with the legacy Charts module (1.4.11, com.mendix.widget.custom.*), which is not in this repo and is not affected by this change.

Ticket: https://mendix.atlassian.net/browse/WC-3594

No XML changes, no docs PR needed. Changelog entries added to the eight affected chart widgets.

What should be covered while testing?

All checks are in Studio Pro design mode, no need to run the app.

  1. Add a layout grid with four columns and set one column to a manual width. Place a chart in it: the preview stays inside the column, with and without legend.
  2. Width: with unit Percentage, set 100 and 50, the preview takes that share of its parent. With unit Pixels, set a value larger than the parent, the preview stops at the parent edge.
  3. Height: check Percentage of width (height follows the width), Pixels and Percentage of parent.
  4. Toggle "Show playground slot" and check the preview still stays within its parent.
  5. Repeat a quick check for each chart type: area, bar, bubble, column, heatmap, line, pie/doughnut, time series.
  6. Custom chart preview is unchanged.

@yordan-st yordan-st changed the title [WC-3594]: Keep chart design preview within its parent [WC-3594] Charts: keep design preview within its parent Oct 13, 2026
@yordan-st
yordan-st marked this pull request as ready for review October 13, 2026 12:42
@yordan-st
yordan-st requested a review from a team as a code owner October 13, 2026 12:42
@yordan-st
yordan-st force-pushed the fix/WC-3594_chart-preview-overlaps-widgets branch from dc7d9d8 to 89b207d Compare October 13, 2026 12:42
@yordan-st
yordan-st force-pushed the fix/WC-3594_chart-preview-overlaps-widgets branch from 26b9e3f to 03edcd8 Compare October 14, 2026 09:32
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

samuelreichert
samuelreichert previously approved these changes Oct 14, 2026
@yordan-st
yordan-st force-pushed the fix/WC-3594_chart-preview-overlaps-widgets branch from 03edcd8 to 6bfc334 Compare October 22, 2026 09:06
@github-actions

This comment has been minimized.

@yordan-st
yordan-st force-pushed the fix/WC-3594_chart-preview-overlaps-widgets branch from 6bfc334 to cbb55a0 Compare October 27, 2026 09:25
@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

⚠️ Approved with suggestions — low-severity items only, safe to merge


What was reviewed

File Change
packages/shared/charts/src/components/ChartPreview.tsx New widthUnit, width, heightUnit, height props; getPreviewDimensions helper; replaces fixed pixel dimensions
packages/shared/charts/src/components/__tests__/ChartPreview.spec.tsx New test file covering all dimension branches
packages/pluggableWidgets/*/CHANGELOG.md (×8) Bug-fix changelog entries across affected chart widgets

Skipped (out of scope): dist/, pnpm-lock.yaml

CI checks: could not be fetched (required approval). All editorPreview callers spread {...props} so the new required props flow through from each widget's generated PreviewProps, which already include widthUnit, width, heightUnit, height (confirmed in AreaChartProps.d.ts, BarChartProps.d.ts).


Findings

⚠️ Low — Falsy-zero guard skips explicit width: 0 and height: 0

File: packages/shared/charts/src/components/ChartPreview.tsx lines 60, 64
Note: if (props.width) and if (props.height) treat 0 as falsy. A user who deliberately sets width or height to 0 (valid, even if unusual) would silently get no dimension applied. The prop type is number | null, so the correct null-check is != null (or !== null && props.width !== undefined).
Fix:

if (props.width != null) {
    style.width = props.widthUnit === "percentage" ? `${props.width}%` : `${props.width}px`;
}

if (props.height != null) {
    ...
}

⚠️ Low — Test missing coverage for null width/height (no-dimension default)

File: packages/shared/charts/src/components/__tests__/ChartPreview.spec.tsx
Note: All tests pass explicit numeric values. There is no test asserting that width: null and height: null (the initial Studio Pro state before a user sets a value) produces a chart element with no width or height style set. This is the most common state and worth a single snapshot guard.
Fix: Add a case:

it("applies no explicit dimensions when width and height are null", () => {
    const chart = renderChart({ width: null, height: null });
    expect(chart.style.width).toBe("");
    expect(chart.style.height).toBe("");
    expect(chart.style.aspectRatio).toBe("");
});

Positives

  • Every editorPreview caller already spreads {...props}, so the shared-library API change requires zero callsite changes — clean, low-risk migration.
  • getPreviewDimensions cleanly mirrors the runtime sizing logic without duplicating it into each widget, exactly as intended.
  • maxWidth: "100%" is applied at two levels (outer wrapper and inner Chart div) so the constraint holds regardless of which element the parent measures against.
  • Changelog entries are correctly placed under ### Fixed in the unreleased block across all eight affected packages.
  • Tests use direct DOM style assertions rather than snapshots — resilient to unrelated markup changes.

@yordan-st
yordan-st merged commit dc58ecc into main Oct 28, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants