Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(brush): resize brush selection when chart resizes #1536

Merged
merged 1 commit into from
Jul 7, 2022
Merged
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
34 changes: 26 additions & 8 deletions packages/visx-brush/src/BaseBrush.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,32 @@ export default class BaseBrush extends React.Component<BaseBrushProps, BaseBrush
componentDidUpdate(prevProps: BaseBrushProps) {
if (this.props.width !== prevProps.width || this.props.height !== prevProps.height) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState(() => ({
bounds: {
x0: 0,
x1: this.props.width,
y0: 0,
y1: this.props.height,
},
}));
this.setState((prevBrush: BaseBrushState) => {
const widthRatio = this.props.width / prevProps.width;
const heightRatio = this.props.height / prevProps.height;

const start = {
x: widthRatio * prevBrush.extent.x0,
y: heightRatio * prevBrush.extent.y0,
};

const end = {
x: widthRatio * prevBrush.extent.x1,
y: heightRatio * prevBrush.extent.y1,
};

const extent = this.getExtent(start, end);

return {
extent,
bounds: {
x0: 0,
x1: this.props.width,
y0: 0,
y1: this.props.height,
},
};
});
}
}

Expand Down