Skip to content

Commit

Permalink
Merge pull request #4 from billneff79/global-brush-mousing
Browse files Browse the repository at this point in the history
Brush: use global mouse hooks
  • Loading branch information
billneff79 authored Oct 11, 2016
2 parents 7dbed47 + 3b6ad4e commit 7c560af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recharts",
"version": "1.1.2",
"version": "1.1.4",
"description": "React charts",
"main": "lib/index",
"jsnext:main": "es6/index",
Expand Down
25 changes: 7 additions & 18 deletions src/cartesian/Brush.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class Brush extends Component {
}
}

componentDidMount() {
addEventListener('mousemove', this.handleMove);
addEventListener('mouseup', this.handleUp);
}

componentWillReceiveProps(nextProps) {
const { data, width, x, travellerWidth, startIndex, endIndex } = this.props;

Expand Down Expand Up @@ -102,10 +107,8 @@ class Brush extends Component {
this.scale = null;
this.scaleValues = null;

if (this.leaveTimer) {
clearTimeout(this.leaveTimer);
this.leaveTimer = null;
}
removeEventListener('mousemove', this.handleMove);
removeEventListener('mouseup', this.handleUp);
}

getIndexInRange(range, x) {
Expand Down Expand Up @@ -157,11 +160,6 @@ class Brush extends Component {
}

handleMove = (e) => {
if (this.leaveTimer) {
clearTimeout(this.leaveTimer);
this.leaveTimer = null;
}

if (this.state.isTravellerMoving) {
this.handleTravellerMove(e);
} else if (this.state.isSlideMoving) {
Expand All @@ -176,12 +174,6 @@ class Brush extends Component {
});
};

handleLeaveWrapper = () => {
if (this.state.isTravellerMoving || this.state.isSlideMoving) {
this.leaveTimer = setTimeout(this.handleUp, 1000);
}
};

handleEnterSlideOrTraveller = () => {
this.setState({
isTextActive: true,
Expand Down Expand Up @@ -419,9 +411,6 @@ class Brush extends Component {
return (
<Layer
className={layerClass}
onMouseUp={this.handleUp}
onMouseMove={this.handleMove}
onMouseLeave={this.handleLeaveWrapper}
>
{this.renderBackground()}
{this.renderSlide(startX, endX)}
Expand Down

0 comments on commit 7c560af

Please sign in to comment.