diff --git a/src/component/dataZoom/DataZoomView.js b/src/component/dataZoom/DataZoomView.js index cf9158a4f5a2f27f562bc3a74b37333da7f7c253..6851a3315f165cd5b237dea46bd97aa03babd75d 100644 --- a/src/component/dataZoom/DataZoomView.js +++ b/src/component/dataZoom/DataZoomView.js @@ -18,10 +18,7 @@ define(function (require) { */ this._lastThrottleRate; - // FIXME - if (!this.__doNotThrottle) { - this._throttleDispatch(dataZoomModel); - } + this._throttleDispatch(dataZoomModel); }, /** @@ -31,13 +28,25 @@ define(function (require) { var originDispatchZoomAction = this.constructor.prototype.dispatchZoomAction; if (originDispatchZoomAction) { var rate = dataZoomModel.get('throttle'); + if (this._lastThrottleRate !== rate) { + this._clearThrottle(); + this.dispatchZoomAction = throttle.fixedRate(originDispatchZoomAction, rate); this._lastThrottleRate = rate; } } }, + /** + * @private + */ + _clearThrottle: function () { + // Dispose + var dispatchZoomAction = this.dispatchZoomAction; + dispatchZoomAction && dispatchZoomAction.clear && dispatchZoomAction.clear(); + }, + /** * @protected */ @@ -45,6 +54,20 @@ define(function (require) { // Implement by Children Classes. }, + /** + * @override + */ + remove: function () { + this._clearThrottle(); + }, + + /** + * @override + */ + dispose: function () { + this._clearThrottle(); + }, + /** * Find the first target coordinate system. * diff --git a/src/component/dataZoom/InsideZoomView.js b/src/component/dataZoom/InsideZoomView.js index 8eee3087e3a873e5d17000dd320f613401604360..0cc2aee94933823e4f9a57486654a0c7e2dd704a 100644 --- a/src/component/dataZoom/InsideZoomView.js +++ b/src/component/dataZoom/InsideZoomView.js @@ -11,18 +11,24 @@ define(function (require) { type: 'dataZoom.inside', - // FIXME - __doNotThrottle: true, - /** * @override */ init: function (ecModel, api) { + /** * @private * @type {Object.} */ this._controllers = {}; + + /** + * 'throttle' is used in this.dispatchAction, so we save range + * to avoid missing some 'pan' info. + * @private + * @type {Array.} + */ + this._range; }, /** @@ -31,6 +37,13 @@ define(function (require) { render: function (dataZoomModel, ecModel, api, payload) { 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); }, @@ -38,6 +51,8 @@ define(function (require) { * @override */ remove: function () { + DataZoomView.prototype.remove.apply(this, arguments); + var controllers = this._controllers; zrUtil.each(controllers, function (controller) { controller.off('pan').off('zoom'); @@ -78,9 +93,8 @@ define(function (require) { * @private */ _onPan: function (controller, coordInfo, dx, dy) { - var dataZoomModel = this.dataZoomModel; - var range = panCartesian( - [dx, dy], dataZoomModel.getRange(), controller, coordInfo + var range = this._range = panCartesian( + [dx, dy], this._range, controller, coordInfo ); if (range) { @@ -94,8 +108,8 @@ define(function (require) { _onZoom: function (controller, coordInfo, scale, mouseX, mouseY) { var dataZoomModel = this.dataZoomModel; scale = 1 / scale; - var range = scaleCartesian( - scale, [mouseX, mouseY], dataZoomModel.getRange(), + var range = this._range = scaleCartesian( + scale, [mouseX, mouseY], this._range, controller, coordInfo, dataZoomModel ); @@ -111,7 +125,7 @@ define(function (require) { type: 'dataZoom', from: this.uid, dataZoomId: this.dataZoomModel.id, - range: range + range: range.slice() }); } diff --git a/src/component/dataZoom/SliderZoomView.js b/src/component/dataZoom/SliderZoomView.js index 6019645d94214dd7ae60e6662b853c0075439646..b3e9f357feca5cbcf75419862f507ffa0b33f8f7 100644 --- a/src/component/dataZoom/SliderZoomView.js +++ b/src/component/dataZoom/SliderZoomView.js @@ -102,6 +102,9 @@ define(function (require) { 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) { this._buildView(); } diff --git a/src/util/throttle.js b/src/util/throttle.js index 859fea443ef1e2d879bb00f6264739d6171cd250..02762dbe5081ce0e3d9ca4be4be32db1f641ba34 100755 --- a/src/util/throttle.js +++ b/src/util/throttle.js @@ -64,7 +64,7 @@ define(function () { (isSingle ? fn : fn[index]).apply(scope, args || []); } - return function () { + var cb = function () { currCall = (new Date()).getTime(); scope = this; args = arguments; @@ -91,6 +91,19 @@ define(function () { lastCall = currCall; }; + + /** + * Clear throttle. + * @public + */ + cb.clear = function () { + if (timer) { + clearTimeout(timer); + timer = null; + } + }; + + return cb; } };