Skip to content

Commit

Permalink
Update chart dimensions to update on chart height resize
Browse files Browse the repository at this point in the history
  • Loading branch information
maryamkaka committed Sep 12, 2023
1 parent afa1e1b commit 51f2809
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/polaris-viz/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## Unreleased -->

- Fixed issue where chart would not resize on height change

## [9.10.7] - 2023-09-06

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export function ChartDimensions({

const updateDimensions = useCallback(() => {
if (
previousEntry?.contentRect.width === entry?.contentRect.width ||
(previousEntry?.contentRect.width === entry?.contentRect.width &&
previousEntry?.contentRect.height === entry?.contentRect.height) ||
entry == null
) {
return;
Expand All @@ -65,7 +66,7 @@ export function ChartDimensions({
const {x, y} = entry.target.getBoundingClientRect();

setChartDimensions({width, height, x, y: y + window.scrollY});
}, [entry, previousEntry?.contentRect.width]);
}, [entry, previousEntry?.contentRect]);

const debouncedUpdateDimensions = useDebouncedCallback(() => {
updateDimensions();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export {META as default} from './meta';

import {LineChart, LineChartProps} from '../../../components';
import type {Story} from '@storybook/react';
import {DEFAULT_DATA, DEFAULT_PROPS} from './data';

export const ResizeableChart: Story<LineChartProps> = (
args: LineChartProps,
) => {
return (
<div
style={{
resize: 'both',
overflow: 'hidden',
maxHeight: '100%',
maxWidth: '100%',
}}
>
<LineChart {...args} />
</div>
);
};

ResizeableChart.args = {
...DEFAULT_PROPS,
data: DEFAULT_DATA,
};

0 comments on commit 51f2809

Please sign in to comment.