Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/area-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/bar-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/bubble-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/column-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/heatmap-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions packages/pluggableWidgets/line-chart-web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

### Fixed

- We fixed an issue where the chart preview in design mode overlapped other widgets when placed in a narrow container.

## [6.2.1] - 2025-07-15

### Changed
Expand Down
14 changes: 10 additions & 4 deletions packages/shared/charts/src/components/ChartPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ChartPreviewProps {
export function ChartPreview(props: ChartPreviewProps): ReactElement {
const { renderer: PlaygroundSlot } = props.playground ?? { renderer: () => null };
return (
<div style={{ display: "inline-flex", flexFlow: "column nowrap" }}>
<div style={{ display: "flex", flexFlow: "column nowrap", maxWidth: props.showLegend ? "385px" : "300px" }}>
<div
style={
props.showPlaygroundSlot
Expand All @@ -30,11 +30,17 @@ export function ChartPreview(props: ChartPreviewProps): ReactElement {
}

ChartPreview.PlotImage = (props: { src: string; alt: string }) => {
return <img src={props.src} alt={props.alt} style={{ objectFit: "contain", width: "300px", height: "100%" }} />;
return (
<img
src={props.src}
alt={props.alt}
style={{ objectFit: "contain", flex: "1 1 0", minWidth: 0, height: "100%" }}
/>
);
};

ChartPreview.PlotLegend = (props: { src: string; alt: string }) => {
return <img src={props.src} alt={props.alt} style={{ width: "85px" }} />;
return <img src={props.src} alt={props.alt} style={{ flex: "none", width: "85px" }} />;
};

function Chart(props: ChartPreviewProps): ReactElement {
Expand All @@ -43,7 +49,7 @@ function Chart(props: ChartPreviewProps): ReactElement {
className={props.class}
style={{
display: "flex",
width: props.showLegend ? "385px" : "300px",
width: "100%",
height: "232px"
}}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { render, screen } from "@testing-library/react";
import { ReactNode } from "react";
import { ChartPreview, ChartPreviewProps } from "../ChartPreview";

function renderPreview(showLegend: boolean): void {
const props: ChartPreviewProps = {
class: "test-chart",
showLegend,
playground: { widgetCount: 0, renderer: ({ children }: { children: ReactNode }) => <div>{children}</div> },
image: <ChartPreview.PlotImage src="plot.svg" alt="Plot" />,
legend: <ChartPreview.PlotLegend src="legend.svg" alt="Legend" />
};
render(<ChartPreview {...props} />);
}

describe("ChartPreview", () => {
it("fills the available width up to the legend size", () => {
renderPreview(true);

const chart = screen.getByRole("img", { name: "Plot" }).parentElement!;
expect(chart.style.width).toBe("100%");
expect(chart.parentElement!.style.display).toBe("flex");
expect(chart.parentElement!.style.maxWidth).toBe("385px");
expect(screen.getByRole("img", { name: "Legend" }).style.flexShrink).toBe("0");
});

it("caps the width at the plot size when the legend is hidden", () => {
renderPreview(false);

const chart = screen.getByRole("img", { name: "Plot" }).parentElement!;
expect(chart.parentElement!.style.maxWidth).toBe("300px");
expect(screen.queryByRole("img", { name: "Legend" })).toBeNull();
});

it("lets the plot image shrink instead of overflowing", () => {
renderPreview(true);

const plot = screen.getByRole("img", { name: "Plot" });
expect(plot.style.width).toBe("");
expect(plot.style.minWidth).toMatch(/^0(px)?$/);
});
});
Loading