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

feature: support toolbox.dataZoom brush component `dataZoom.slide… #11710

Merged
merged 3 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
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
13 changes: 4 additions & 9 deletions src/component/dataZoom/SliderZoomView.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ var SliderZoomView = DataZoomView.extend({
draggable: true,
cursor: getCursor(this._orient),
drift: bind(this._onDragMove, this, 'all'),
onmousemove: function (e) {
// Fot mobile devicem, prevent screen slider on the button.
eventTool.stop(e.event);
},
ondragstart: bind(this._showDataInfo, this, true),
ondragend: bind(this._onDragEnd, this),
onmouseover: bind(this._showDataInfo, this, true),
Expand Down Expand Up @@ -489,10 +485,6 @@ var SliderZoomView = DataZoomView.extend({
cursor: getCursor(this._orient),
draggable: true,
drift: bind(this._onDragMove, this, handleIndex),
onmousemove: function (e) {
// Fot mobile devicem, prevent screen slider on the button.
eventTool.stop(e.event);
},
ondragend: bind(this._onDragEnd, this),
onmouseover: bind(this._showDataInfo, this, true),
onmouseout: bind(this._showDataInfo, this, false)
Expand Down Expand Up @@ -714,9 +706,12 @@ var SliderZoomView = DataZoomView.extend({
handleLabels[1].attr('invisible', !showOrHide);
},

_onDragMove: function (handleIndex, dx, dy) {
_onDragMove: function (handleIndex, dx, dy, event) {
this._dragging = true;

// For mobile device, prevent screen slider on the button.
eventTool.stop(event.event);

// Transform dx, dy to bar coordination.
var barTransform = this._displayables.barGroup.getLocalTransform();
var vertex = graphic.applyTransform([dx, dy], barTransform, true);
Expand Down
125 changes: 74 additions & 51 deletions src/component/helper/BrushController.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ function BrushController(zr) {
*/
this._dragging;

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

/**
* @private
* @type {Array}
Expand Down Expand Up @@ -186,8 +180,26 @@ function BrushController(zr) {
* @type {Object}
*/
this._handlers = {};
each(mouseHandlers, function (handler, eventName) {
this._handlers[eventName] = zrUtil.bind(handler, this);

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

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

each(localMouseHandlers, function (handler, eventName) {
this._handlers[eventName] =
this._localHandlers[eventName] = zrUtil.bind(handler, this);
}, this);
each(pageMouseHandlers, function (handler, eventName) {
this._handlers[eventName] =
this._pageHandlers[eventName] = zrUtil.bind(handler, this);
}, this);
}

Expand Down Expand Up @@ -382,9 +394,7 @@ function doEnableBrush(controller, brushOption) {
interactionMutex.take(zr, MUTEX_RESOURCE_KEY, controller._uid);
}

each(controller._handlers, function (handler, eventName) {
zr.on(eventName, handler);
});
mountHandlers(zr, controller._localHandlers);

controller._brushType = brushOption.brushType;
controller._brushOption = zrUtil.merge(zrUtil.clone(DEFAULT_BRUSH_OPT), brushOption, true);
Expand All @@ -395,13 +405,23 @@ function doDisableBrush(controller) {

interactionMutex.release(zr, MUTEX_RESOURCE_KEY, controller._uid);

each(controller._handlers, function (handler, eventName) {
zr.off(eventName, handler);
});
unmountHandlers(zr, controller._handlers);

controller._brushType = controller._brushOption = null;
}

function mountHandlers(zr, handlers) {
each(handlers, function (handler, eventName) {
zr.on(eventName, handler);
});
}

function unmountHandlers(zr, handlers) {
each(handlers, function (handler, eventName) {
zr.off(eventName, handler);
});
}

function createCover(controller, brushOption) {
var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
cover.__brushOption = brushOption;
Expand Down Expand Up @@ -744,8 +764,12 @@ function resetCursor(controller, e, localCursorPoint) {
}

function preventDefault(e) {
var rawE = e.event;
rawE.preventDefault && rawE.preventDefault();
// Just be worried about bring some side effect to the world
// out of echarts, we do not `preventDefault` for globalout.
if (e.zrIsFromLocal) {
var rawE = e.event;
rawE.preventDefault && rawE.preventDefault();
}
}

function mainShapeContain(cover, x, y) {
Expand Down Expand Up @@ -820,7 +844,7 @@ function determineBrushType(brushType, panel) {
return brushType;
}

var mouseHandlers = {
var localMouseHandlers = {

mousedown: function (e) {
if (this._dragging) {
Expand All @@ -841,60 +865,44 @@ var mouseHandlers = {
this._dragging = true;
this._track = [localCursorPoint.slice()];
}

// Mount page handlers only when needed to minimize unexpected side-effect.
mountHandlers(this._zr, this._pageHandlers);
}
},

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

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

var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
// resetCursor should be always called when mouse is in zr area,
// but not called when mouse is out of zr area.
resetCursor(this, e, localCursorPoint);
}
};

var pageMouseHandlers = {

pagemousemove: function (e) {
if (this._dragging) {
var xy = getLocalMouseXY(e, this._zr);
var localCursorPoint = this.group.transformCoordToLocal(xy[0], xy[1]);

preventDefault(e);

var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);

eventParams && trigger(this, eventParams);
}
},

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

globalout: function (e) {
handleDragEnd(this, e, true);
}
};

function handleDragEnd(controller, e, isGlobalOut) {
function handleDragEnd(controller, e) {
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 = 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 xy = getLocalMouseXY(e, controller._zr);
var localCursorPoint = controller.group.transformCoordToLocal(xy[0], xy[1]);
var eventParams = updateCoverByMouse(controller, e, localCursorPoint, true);

controller._dragging = false;
Expand All @@ -903,9 +911,24 @@ function handleDragEnd(controller, e, isGlobalOut) {

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

unmountHandlers(controller._zr, controller._pageHandlers);
}
}

function getLocalMouseXY(event, zr) {
var x = event.offsetX;
var y = event.offsetY;
// var w = zr.getWidth();
// var h = zr.getHeight();
// x < 0 && (x = 0);
// x > w && (x = w);
// y < 0 && (y = 0);
// y > h && (y = h);

return [x, y];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to clamp the mouse position to the canvas area.

}

/**
* key: brushType
* @type {Object}
Expand Down
Loading