Skip to content

Commit 41f0736

Browse files
committed
fixes no-data vertical placement
1 parent d0e15db commit 41f0736

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/core/chart-api/chart-extra-nodata.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ChartExtraContext } from "./chart-extra-context";
1111
// It can be used by other components to assert if the chart is in no-data state (by checking if container is present).
1212
export interface ReactiveNodataState {
1313
visible: boolean;
14-
style?: React.CSSProperties;
14+
style: React.CSSProperties;
1515
noMatch: boolean;
1616
}
1717

@@ -32,12 +32,17 @@ export class ChartExtraNodata extends AsyncStore<ReactiveNodataState> {
3232
const visibleSeries = findAllVisibleSeries(this.chart);
3333
// The no-data is not shown when there is at least one series or point (for pie series) non-empty and visible.
3434
if (visibleSeries.length > 0) {
35-
this.set(() => ({ visible: false, noMatch: false }));
35+
this.set(() => ({ visible: false, style: {}, noMatch: false }));
3636
} else {
37-
this.set(() => ({ visible: true, noMatch: allSeriesWithData.length > 0 }));
37+
this.set(() => ({ visible: true, style: this.getContainerStyle(), noMatch: allSeriesWithData.length > 0 }));
3838
}
3939
};
4040

41+
private getContainerStyle(): React.CSSProperties {
42+
const blockOffset = this.chart.chartHeight - this.chart.plotHeight;
43+
return { insetBlockEnd: `${blockOffset}px` };
44+
}
45+
4146
private get chart() {
4247
return this.context.chart();
4348
}
@@ -57,4 +62,4 @@ function findAllVisibleSeries(chart: Highcharts.Chart) {
5762
return allSeriesWithData.filter(
5863
(s) => s.visible && (s.type !== "pie" || s.data.some((d) => d.y !== null && d.visible)),
5964
);
60-
}
65+
}

src/core/chart-container.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ export function ChartContainer({
9696
) : (
9797
<div
9898
style={chartMinWidth !== undefined ? { minInlineSize: chartMinWidth } : {}}
99-
className={testClasses["chart-plot-wrapper"]}
99+
className={clsx(styles["chart-plot-wrapper"], testClasses["chart-plot-wrapper"])}
100100
>
101101
{verticalAxisTitle}
102102
{chart(effectiveChartHeight)}
103+
{!legend || legendPosition === "bottom" ? noData : null}
103104
</div>
104105
)}
105106

@@ -110,8 +111,6 @@ export function ChartContainer({
110111
(legendBottomMaxHeight ? <div style={{ maxHeight: `${legendBottomMaxHeight}px` }}>{legend}</div> : legend)}
111112
{footer}
112113
</div>
113-
114-
{!legend || legendPosition === "bottom" ? noData : null}
115114
</div>
116115
);
117116
}

0 commit comments

Comments
 (0)