提交 3ef4d9e7 编写于 作者: P pah100

add throttle to datazoom inside

上级 ecb53a2d
...@@ -18,10 +18,7 @@ define(function (require) { ...@@ -18,10 +18,7 @@ define(function (require) {
*/ */
this._lastThrottleRate; this._lastThrottleRate;
// FIXME this._throttleDispatch(dataZoomModel);
if (!this.__doNotThrottle) {
this._throttleDispatch(dataZoomModel);
}
}, },
/** /**
...@@ -31,13 +28,25 @@ define(function (require) { ...@@ -31,13 +28,25 @@ define(function (require) {
var originDispatchZoomAction = this.constructor.prototype.dispatchZoomAction; var originDispatchZoomAction = this.constructor.prototype.dispatchZoomAction;
if (originDispatchZoomAction) { if (originDispatchZoomAction) {
var rate = dataZoomModel.get('throttle'); var rate = dataZoomModel.get('throttle');
if (this._lastThrottleRate !== rate) { if (this._lastThrottleRate !== rate) {
this._clearThrottle();
this.dispatchZoomAction = throttle.fixedRate(originDispatchZoomAction, rate); this.dispatchZoomAction = throttle.fixedRate(originDispatchZoomAction, rate);
this._lastThrottleRate = rate; this._lastThrottleRate = rate;
} }
} }
}, },
/**
* @private
*/
_clearThrottle: function () {
// Dispose
var dispatchZoomAction = this.dispatchZoomAction;
dispatchZoomAction && dispatchZoomAction.clear && dispatchZoomAction.clear();
},
/** /**
* @protected * @protected
*/ */
...@@ -45,6 +54,20 @@ define(function (require) { ...@@ -45,6 +54,20 @@ define(function (require) {
// Implement by Children Classes. // Implement by Children Classes.
}, },
/**
* @override
*/
remove: function () {
this._clearThrottle();
},
/**
* @override
*/
dispose: function () {
this._clearThrottle();
},
/** /**
* Find the first target coordinate system. * Find the first target coordinate system.
* *
......
...@@ -11,18 +11,24 @@ define(function (require) { ...@@ -11,18 +11,24 @@ define(function (require) {
type: 'dataZoom.inside', type: 'dataZoom.inside',
// FIXME
__doNotThrottle: true,
/** /**
* @override * @override
*/ */
init: function (ecModel, api) { init: function (ecModel, api) {
/** /**
* @private * @private
* @type {Object.<string, module:echarts/component/helper/RoamController>} * @type {Object.<string, module:echarts/component/helper/RoamController>}
*/ */
this._controllers = {}; this._controllers = {};
/**
* 'throttle' is used in this.dispatchAction, so we save range
* to avoid missing some 'pan' info.
* @private
* @type {Array.<number>}
*/
this._range;
}, },
/** /**
...@@ -31,6 +37,13 @@ define(function (require) { ...@@ -31,6 +37,13 @@ define(function (require) {
render: function (dataZoomModel, ecModel, api, payload) { render: function (dataZoomModel, ecModel, api, payload) {
DataZoomView.prototype.render.apply(this, arguments); DataZoomView.prototype.render.apply(this, arguments);
// Notice: this._resetInterval() should not be executed when payload.type
// is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
// or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
this._range = dataZoomModel.getRange();
}
this._resetController(api); this._resetController(api);
}, },
...@@ -38,6 +51,8 @@ define(function (require) { ...@@ -38,6 +51,8 @@ define(function (require) {
* @override * @override
*/ */
remove: function () { remove: function () {
DataZoomView.prototype.remove.apply(this, arguments);
var controllers = this._controllers; var controllers = this._controllers;
zrUtil.each(controllers, function (controller) { zrUtil.each(controllers, function (controller) {
controller.off('pan').off('zoom'); controller.off('pan').off('zoom');
...@@ -78,9 +93,8 @@ define(function (require) { ...@@ -78,9 +93,8 @@ define(function (require) {
* @private * @private
*/ */
_onPan: function (controller, coordInfo, dx, dy) { _onPan: function (controller, coordInfo, dx, dy) {
var dataZoomModel = this.dataZoomModel; var range = this._range = panCartesian(
var range = panCartesian( [dx, dy], this._range, controller, coordInfo
[dx, dy], dataZoomModel.getRange(), controller, coordInfo
); );
if (range) { if (range) {
...@@ -94,8 +108,8 @@ define(function (require) { ...@@ -94,8 +108,8 @@ define(function (require) {
_onZoom: function (controller, coordInfo, scale, mouseX, mouseY) { _onZoom: function (controller, coordInfo, scale, mouseX, mouseY) {
var dataZoomModel = this.dataZoomModel; var dataZoomModel = this.dataZoomModel;
scale = 1 / scale; scale = 1 / scale;
var range = scaleCartesian( var range = this._range = scaleCartesian(
scale, [mouseX, mouseY], dataZoomModel.getRange(), scale, [mouseX, mouseY], this._range,
controller, coordInfo, dataZoomModel controller, coordInfo, dataZoomModel
); );
...@@ -111,7 +125,7 @@ define(function (require) { ...@@ -111,7 +125,7 @@ define(function (require) {
type: 'dataZoom', type: 'dataZoom',
from: this.uid, from: this.uid,
dataZoomId: this.dataZoomModel.id, dataZoomId: this.dataZoomModel.id,
range: range range: range.slice()
}); });
} }
......
...@@ -102,6 +102,9 @@ define(function (require) { ...@@ -102,6 +102,9 @@ define(function (require) {
return; return;
} }
// Notice: this._resetInterval() should not be executed when payload.type
// is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
// or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) { if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
this._buildView(); this._buildView();
} }
......
...@@ -64,7 +64,7 @@ define(function () { ...@@ -64,7 +64,7 @@ define(function () {
(isSingle ? fn : fn[index]).apply(scope, args || []); (isSingle ? fn : fn[index]).apply(scope, args || []);
} }
return function () { var cb = function () {
currCall = (new Date()).getTime(); currCall = (new Date()).getTime();
scope = this; scope = this;
args = arguments; args = arguments;
...@@ -91,6 +91,19 @@ define(function () { ...@@ -91,6 +91,19 @@ define(function () {
lastCall = currCall; lastCall = currCall;
}; };
/**
* Clear throttle.
* @public
*/
cb.clear = function () {
if (timer) {
clearTimeout(timer);
timer = null;
}
};
return cb;
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册