Skip to content

Commit b9886eb

Browse files
committed
fix no-data placement when legend is on the side
1 parent 1846d0f commit b9886eb

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

pages/03-core/empty-line-chart.page.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,40 @@
44
import Highcharts from "highcharts";
55
import { omit } from "lodash";
66

7+
import Checkbox from "@cloudscape-design/components/checkbox";
8+
79
import CoreChart from "../../lib/components/internal-do-not-use/core-chart";
8-
import { PageSettingsForm, useChartSettings } from "../common/page-settings";
10+
import { PageSettings, PageSettingsForm, useChartSettings } from "../common/page-settings";
911
import { Page } from "../common/templates";
1012

13+
interface ThisPageSettings extends PageSettings {
14+
showInLegend?: boolean;
15+
}
16+
1117
export default function () {
12-
const { chartProps } = useChartSettings();
18+
const { chartProps, settings, setSettings } = useChartSettings<ThisPageSettings>();
1319
return (
1420
<Page
1521
title="Empty core chart demo"
1622
settings={
1723
<PageSettingsForm
18-
selectedSettings={["showLegend", "legendPosition", "showLegendTitle", "showLegendActions", "useFallback"]}
24+
selectedSettings={[
25+
"showLegend",
26+
"legendPosition",
27+
"showLegendTitle",
28+
"showLegendActions",
29+
"useFallback",
30+
{
31+
content: (
32+
<Checkbox
33+
checked={!!settings.showInLegend}
34+
onChange={({ detail }) => setSettings({ showInLegend: detail.checked })}
35+
>
36+
Show in legend
37+
</Checkbox>
38+
),
39+
},
40+
]}
1941
/>
2042
}
2143
>
@@ -25,7 +47,7 @@ export default function () {
2547
options={{
2648
xAxis: { min: 1, max: 50 },
2749
yAxis: { min: 0, max: 1 },
28-
series: [{ type: "line", data: [], showInLegend: false }],
50+
series: [{ type: "line", data: [], showInLegend: settings.showInLegend }],
2951
}}
3052
/>
3153
</Page>

src/core/chart-container.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface ChartContainerProps {
3232
legendBottomMaxHeight?: number;
3333
legendPosition: "bottom" | "side";
3434
footer?: React.ReactNode;
35+
noData?: React.ReactNode;
3536
fitHeight?: boolean;
3637
chartHeight?: number;
3738
chartMinHeight?: number;
@@ -49,6 +50,7 @@ export function ChartContainer({
4950
legendPosition,
5051
legendBottomMaxHeight,
5152
navigator,
53+
noData,
5254
fitHeight,
5355
chartHeight,
5456
chartMinHeight,
@@ -85,6 +87,7 @@ export function ChartContainer({
8587
>
8688
{verticalAxisTitle}
8789
{chart(effectiveChartHeight)}
90+
{noData}
8891
</div>
8992
<div className={styles["side-legend-container"]} style={{ maxBlockSize: effectiveChartHeight }}>
9093
{legend}
@@ -107,6 +110,8 @@ export function ChartContainer({
107110
(legendBottomMaxHeight ? <div style={{ maxHeight: `${legendBottomMaxHeight}px` }}>{legend}</div> : legend)}
108111
{footer}
109112
</div>
113+
114+
{!legend || legendPosition === "bottom" ? noData : null}
110115
</div>
111116
);
112117
}

src/core/chart-core.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export function InternalCoreChart({
328328
/>
329329
) : null
330330
}
331+
noData={context.noDataEnabled && <ChartNoData {...noDataOptions} i18nStrings={i18nStrings} api={api} />}
331332
/>
332333

333334
{context.tooltipEnabled && (
@@ -338,8 +339,6 @@ export function InternalCoreChart({
338339
api={api}
339340
/>
340341
)}
341-
342-
{context.noDataEnabled && <ChartNoData {...noDataOptions} i18nStrings={i18nStrings} api={api} />}
343342
</div>
344343
);
345344
}

src/core/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ $side-legend-min-inline-size: max(20%, 150px);
108108
}
109109

110110
.chart-plot-wrapper {
111+
position: relative;
111112
flex: 1;
112113
}
113114

0 commit comments

Comments
 (0)