Skip to content

Commit

Permalink
fixed the issue that the bounds are not updated after window resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
Conglei Shi committed Aug 22, 2018
1 parent c99ba69 commit 34de8ea
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion packages/xy-chart/src/utils/brush/Brush.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ export default class Brush extends React.Component {
this.getExtent = this.getExtent.bind(this);
}

componentWillReceiveProps(nextProps) {
if (
['width', 'height'].some(
prop => this.props[prop] !== nextProps[prop], // eslint-disable-line react/destructuring-assignment
)
) {
this.setState(() => ({
bounds: {
x0: 0,
x1: nextProps.width,
y0: 0,
y1: nextProps.height,
},
}));
}
}

getExtent(start, end) {
const { brushDirection, width, height } = this.props;
const x0 = brushDirection === 'vertical' ? 0 : Math.min(start.x, end.x);
Expand Down Expand Up @@ -259,7 +276,8 @@ export default class Brush extends React.Component {
}

reset() {
this.update(prevBrush => ({
const { width, height } = this.props;
this.update(() => ({
start: undefined,
end: undefined,
extent: {
Expand All @@ -268,6 +286,12 @@ export default class Brush extends React.Component {
y0: undefined,
y1: undefined,
},
bounds: {
x0: 0,
x1: width,
y0: 0,
y1: height,
},
isBrushing: false,
activeHandle: undefined,
}));
Expand Down

0 comments on commit 34de8ea

Please sign in to comment.