Skip to content

Commit c7c9393

Browse files
authored
fix(charts): round x-axis bbox height to avoid subpixel re-render loop (UI5#8741)
1 parent da2b8cd commit c7c9393

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

packages/charts/src/hooks/useObserveXAxisHeights.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const defaultAxisHeight = 30;
1111
function measure(container: Element | null, axisCount: number, prevHeightsRef: MutableRefObject<number[]>) {
1212
const heights = Array(axisCount).fill(defaultAxisHeight);
1313
container?.querySelectorAll<SVGGraphicsElement>('.xAxis').forEach((xAxis, index) => {
14-
const height = xAxis?.getBBox()?.height;
14+
const height = Math.ceil(xAxis?.getBBox()?.height ?? 0);
1515
if (height > defaultAxisHeight) {
1616
heights[index] = height;
1717
}
@@ -31,6 +31,7 @@ export const useObserveXAxisHeights = (chartRef: RefObject<SVGElement>, axisCoun
3131
const [xAxisHeights, setXAxisHeights] = useState(Array(axisCount).fill(defaultAxisHeight));
3232
const prevHeightsRef = useRef(xAxisHeights);
3333

34+
// TODO (v3): evaluate if ResizeObserver is better here for measuring, so it doesn't run on every component update
3435
// check on every render if height changed
3536
useIsomorphicLayoutEffect(() => {
3637
const result = measure(chartRef.current, axisCount, prevHeightsRef);

0 commit comments

Comments
 (0)