@@ -15,6 +15,8 @@ import testClasses from "./test-classes/styles.css.js";
1515// Chart container implements the layout for top-level components, including chart plot, legend, and more.
1616// It also implements the height- and width overflow behaviors.
1717
18+ const DEFAULT_CHART_MIN_HEIGHT = 200 ;
19+
1820interface ChartContainerProps {
1921 // The header, footer, vertical axis title, and legend are rendered as is, and we measure the height of these components
2022 // to compute the available height for the chart plot when fitHeight=true. When there is not enough vertical space, the
@@ -51,6 +53,8 @@ export function ChartContainer({
5153 chartMinHeight,
5254 chartMinWidth,
5355} : ChartContainerProps ) {
56+ chartMinHeight = chartMinHeight ?? DEFAULT_CHART_MIN_HEIGHT ;
57+
5458 // The vertical axis title is rendered above the chart, and is technically not a part of the chart plot.
5559 // However, we want to include it to the chart's height computations as it does belong to the chart logically.
5660 // We do so by taking the title's constant height into account, when "top" axis placement is chosen.
@@ -63,47 +67,49 @@ export function ChartContainer({
6367 const measuredChartHeight = withMinHeight ( measures . chart - measures . header - measures . footer ) ;
6468 const effectiveChartHeight = fitHeight ? measuredChartHeight : withMinHeight ( chartHeight ) ;
6569 return (
66- < div
67- ref = { refs . chart }
68- className = { clsx ( {
69- [ styles [ "chart-container-fit-height" ] ] : fitHeight ,
70- [ styles [ "chart-container-min-width" ] ] : chartMinWidth !== undefined ,
71- } ) }
72- >
73- < div ref = { refs . header } >
74- { header }
75- { filter }
76- </ div >
70+ < div className = { styles [ "chart-container-root" ] } style = { { minBlockSize : chartMinHeight } } >
71+ < div
72+ ref = { refs . chart }
73+ className = { clsx ( {
74+ [ styles [ "chart-container-fit-height" ] ] : fitHeight ,
75+ [ styles [ "chart-container-min-width" ] ] : chartMinWidth !== undefined ,
76+ } ) }
77+ >
78+ < div ref = { refs . header } >
79+ { header }
80+ { filter }
81+ </ div >
7782
78- { legend && legendPosition === "side" ? (
79- < div className = { styles [ "chart-plot-and-legend-wrapper" ] } >
83+ { legend && legendPosition === "side" ? (
84+ < div className = { styles [ "chart-plot-and-legend-wrapper" ] } >
85+ < div
86+ style = { { minInlineSize : chartMinWidth ?? 0 } }
87+ className = { clsx ( styles [ "chart-plot-wrapper" ] , testClasses [ "chart-plot-wrapper" ] ) }
88+ >
89+ { verticalAxisTitle }
90+ { chart ( effectiveChartHeight ) }
91+ </ div >
92+ < div className = { styles [ "side-legend-container" ] } style = { { maxBlockSize : effectiveChartHeight } } >
93+ { legend }
94+ </ div >
95+ </ div >
96+ ) : (
8097 < div
81- style = { { minInlineSize : chartMinWidth ?? 0 } }
82- className = { clsx ( styles [ "chart-plot-wrapper" ] , testClasses [ "chart-plot-wrapper" ] ) }
98+ style = { chartMinWidth !== undefined ? { minInlineSize : chartMinWidth } : { } }
99+ className = { testClasses [ "chart-plot-wrapper" ] }
83100 >
84101 { verticalAxisTitle }
85102 { chart ( effectiveChartHeight ) }
86103 </ div >
87- < div className = { styles [ "side-legend-container" ] } style = { { maxBlockSize : effectiveChartHeight } } >
88- { legend }
89- </ div >
90- </ div >
91- ) : (
92- < div
93- style = { chartMinWidth !== undefined ? { minInlineSize : chartMinWidth } : { } }
94- className = { testClasses [ "chart-plot-wrapper" ] }
95- >
96- { verticalAxisTitle }
97- { chart ( effectiveChartHeight ) }
104+ ) }
105+
106+ < div ref = { refs . footer } style = { chartMinWidth !== undefined ? { minInlineSize : chartMinWidth } : { } } >
107+ { navigator && < div className = { testClasses [ "chart-navigator" ] } > { navigator } </ div > }
108+ { legend &&
109+ legendPosition === "bottom" &&
110+ ( legendBottomMaxHeight ? < div style = { { maxHeight : `${ legendBottomMaxHeight } px` } } > { legend } </ div > : legend ) }
111+ { footer }
98112 </ div >
99- ) }
100-
101- < div ref = { refs . footer } style = { chartMinWidth !== undefined ? { minInlineSize : chartMinWidth } : { } } >
102- { navigator && < div className = { testClasses [ "chart-navigator" ] } > { navigator } </ div > }
103- { legend &&
104- legendPosition === "bottom" &&
105- ( legendBottomMaxHeight ? < div style = { { maxHeight : `${ legendBottomMaxHeight } px` } } > { legend } </ div > : legend ) }
106- { footer }
107113 </ div >
108114 </ div >
109115 ) ;
0 commit comments