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

enhance: enhance the behavior that when mouse move is out of echarts are. #11516

Merged
merged 1 commit into from
Oct 31, 2019
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
59 changes: 44 additions & 15 deletions src/component/helper/BrushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ function BrushController(zr) {
*/
this._dragging;

/**
* @private
* @type {Object}
*/
this._lastMouseMovePoint = {};

/**
* @private
* @type {Array}
Expand Down Expand Up @@ -820,7 +826,7 @@ var mouseHandlers = {
if (this._dragging) {
// In case some browser do not support globalOut,
// and release mose out side the browser.
handleDragEnd.call(this, e);
handleDragEnd(this, e);
}
else if (!e.target || !e.target.draggable) {

Expand All @@ -839,7 +845,11 @@ var mouseHandlers = {
},

mousemove: function (e) {
var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
var lastPoint = this._lastMouseMovePoint;
lastPoint.x = e.offsetX;
lastPoint.y = e.offsetY;

var localCursorPoint = this.group.transformCoordToLocal(lastPoint.x, lastPoint.y);

resetCursor(this, e, localCursorPoint);

Expand All @@ -853,27 +863,46 @@ var mouseHandlers = {
}
},

mouseup: handleDragEnd //,
mouseup: function (e) {
handleDragEnd(this, e);
},

// FIXME
// in tooltip, globalout should not be triggered.
// globalout: handleDragEnd
globalout: function (e) {
handleDragEnd(this, e, true);
}
};

function handleDragEnd(e) {
if (this._dragging) {
function handleDragEnd(controller, e, isGlobalOut) {
if (controller._dragging) {

preventDefault(e);
// Just be worried about bring some side effect to the world
// out of echarts, we do not `preventDefault` for globalout.
!isGlobalOut && preventDefault(e);

var pointerX = e.offsetX;
var pointerY = e.offsetY;
var lastPoint = controller._lastMouseMovePoint;
if (isGlobalOut) {
pointerX = lastPoint.x;
pointerY = lastPoint.y;
}

var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
var eventParams = updateCoverByMouse(this, e, localCursorPoint, true);
var localCursorPoint = controller.group.transformCoordToLocal(pointerX, pointerY);
// FIXME
// Here `e` is used only in `onIrrelevantElement` finally. And it's OK
// that pass the `e` of `globalout` to `onIrrelevantElement`. But it is
// not a good design of these interfaces. However, we do not refactor
// these code now because the implementation of `onIrrelevantElement`
// need to be discussed and probably be changed in future, becuase it
// slows down the performance of zrender in some cases.
var eventParams = updateCoverByMouse(controller, e, localCursorPoint, true);

this._dragging = false;
this._track = [];
this._creatingCover = null;
controller._dragging = false;
controller._track = [];
controller._creatingCover = null;

// trigger event shoule be at final, after procedure will be nested.
eventParams && trigger(this, eventParams);
eventParams && trigger(controller, eventParams);
}
}

Expand Down