Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Charts: fix chart height and size calculations for Pie Chart and variants.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
useChartDataTransform,
useZeroValueDisplay,
useChartMargin,
useElementHeight,
useElementSize,
useHasLegendChild,
usePrefersReducedMotion,
} from '../../hooks';
Expand Down Expand Up @@ -125,7 +125,7 @@ const BarChartInternal: FC< BarChartProps > = ( {
const legendItems = useChartLegendItems( dataSorted );
const chartOptions = useBarChartOptions( dataWithVisibleZeros, horizontal, options );
const defaultMargin = useChartMargin( height, chartOptions, dataSorted, theme, horizontal );
const [ svgWrapperRef, svgWrapperHeight ] = useElementHeight< HTMLDivElement >();
const [ svgWrapperRef, , svgWrapperHeight ] = useElementSize< HTMLDivElement >();
const chartRef = useRef< HTMLDivElement >( null );

// Check if children contain a Legend component (composition pattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import userEvent from '@testing-library/user-event';
import { GlobalChartsProvider } from '../../../providers';
import BarChart from '../bar-chart';

// Mock useElementHeight to return a non-zero height in jsdom so charts render
// Mock useElementSize to return non-zero dimensions in jsdom so charts render
const mockRefCallback = jest.fn();
jest.mock( '../../../hooks/use-element-height', () => ( {
useElementHeight: () => [ mockRefCallback, 300 ], // Return test height to allow chart rendering
jest.mock( '../../../hooks/use-element-size', () => ( {
useElementSize: () => [ mockRefCallback, 500, 300 ],
} ) );

describe( 'BarChart', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useXYChartTheme,
useChartDataTransform,
useChartMargin,
useElementHeight,
useElementSize,
useHasLegendChild,
usePrefersReducedMotion,
} from '../../hooks';
Expand Down Expand Up @@ -288,7 +288,7 @@ const LineChartInternal = forwardRef< SingleChartRef, LineChartProps >(
const providerTheme = useGlobalChartsTheme();
const theme = useXYChartTheme( data );
const chartId = useChartId( providedChartId );
const [ svgWrapperRef, svgWrapperHeight ] = useElementHeight< HTMLDivElement >();
const [ svgWrapperRef, , svgWrapperHeight ] = useElementSize< HTMLDivElement >();
const chartRef = useRef< HTMLDivElement >( null );
const [ selectedIndex, setSelectedIndex ] = useState< number | undefined >( undefined );
const [ isNavigating, setIsNavigating ] = useState( false );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { GlobalChartsProvider, defaultTheme } from '../../../providers';
import LineChart, { LineChartUnresponsive } from '../line-chart';
import type { SingleChartRef } from '../../private/single-chart-context';

// Mock useElementHeight to return a non-zero height in jsdom so charts render
// Mock useElementSize to return non-zero dimensions in jsdom so charts render
const mockRefCallback = jest.fn();
jest.mock( '../../../hooks/use-element-height', () => ( {
useElementHeight: () => [ mockRefCallback, 300 ], // Return test height to allow chart rendering
jest.mock( '../../../hooks/use-element-size', () => ( {
useElementSize: () => [ mockRefCallback, 500, 300 ],
} ) );

const customTheme = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
flex-direction: column;
overflow: hidden;
align-items: center;
gap: 20px;

&--legend-top {
flex-direction: column-reverse;
// Fill parent when no explicit width/height provided
&--responsive {
height: 100%;
width: 100%;
}

&__svg-wrapper {
flex: 1;
min-height: 0; // Required for flex shrinking
min-width: 0; // Required for flex shrinking
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
}
Loading
Loading