123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- var zrUtil = require("zrender/lib/core/util");
- var RoamController = require("../../component/helper/RoamController");
- var throttleUtil = require("../../util/throttle");
- var ATTR = '\0_ec_dataZoom_roams';
- function register(api, dataZoomInfo) {
- var store = giveStore(api);
- var theDataZoomId = dataZoomInfo.dataZoomId;
- var theCoordId = dataZoomInfo.coordId;
-
- zrUtil.each(store, function (record, coordId) {
- var dataZoomInfos = record.dataZoomInfos;
- if (dataZoomInfos[theDataZoomId] && zrUtil.indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0) {
- delete dataZoomInfos[theDataZoomId];
- record.count--;
- }
- });
- cleanStore(store);
- var record = store[theCoordId];
- if (!record) {
- record = store[theCoordId] = {
- coordId: theCoordId,
- dataZoomInfos: {},
- count: 0
- };
- record.controller = createController(api, record);
- record.dispatchAction = zrUtil.curry(dispatchAction, api);
- }
- !record.dataZoomInfos[theDataZoomId] && record.count++;
- record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
- var controllerParams = mergeControllerParams(record.dataZoomInfos);
- record.controller.enable(controllerParams.controlType, controllerParams.opt);
- record.controller.setPointerChecker(dataZoomInfo.containsPoint);
- throttleUtil.createOrUpdate(record, 'dispatchAction', dataZoomInfo.dataZoomModel.get('throttle', true), 'fixRate');
- }
- function unregister(api, dataZoomId) {
- var store = giveStore(api);
- zrUtil.each(store, function (record) {
- record.controller.dispose();
- var dataZoomInfos = record.dataZoomInfos;
- if (dataZoomInfos[dataZoomId]) {
- delete dataZoomInfos[dataZoomId];
- record.count--;
- }
- });
- cleanStore(store);
- }
- function generateCoordId(coordModel) {
- return coordModel.type + '\0_' + coordModel.id;
- }
- function giveStore(api) {
-
-
- var zr = api.getZr();
- return zr[ATTR] || (zr[ATTR] = {});
- }
- function createController(api, newRecord) {
- var controller = new RoamController(api.getZr());
- zrUtil.each(['pan', 'zoom', 'scrollMove'], function (eventName) {
- controller.on(eventName, function (event) {
- var batch = [];
- zrUtil.each(newRecord.dataZoomInfos, function (info) {
-
-
- if (!event.isAvailableBehavior(info.dataZoomModel.option)) {
- return;
- }
- var method = (info.getRange || {})[eventName];
- var range = method && method(newRecord.controller, event);
- !info.dataZoomModel.get('disabled', true) && range && batch.push({
- dataZoomId: info.dataZoomId,
- start: range[0],
- end: range[1]
- });
- });
- batch.length && newRecord.dispatchAction(batch);
- });
- });
- return controller;
- }
- function cleanStore(store) {
- zrUtil.each(store, function (record, coordId) {
- if (!record.count) {
- record.controller.dispose();
- delete store[coordId];
- }
- });
- }
- function dispatchAction(api, batch) {
- api.dispatchAction({
- type: 'dataZoom',
- batch: batch
- });
- }
- function mergeControllerParams(dataZoomInfos) {
- var controlType;
-
- var prefix = 'type_';
- var typePriority = {
- 'type_true': 2,
- 'type_move': 1,
- 'type_false': 0,
- 'type_undefined': -1
- };
- var preventDefaultMouseMove = true;
- zrUtil.each(dataZoomInfos, function (dataZoomInfo) {
- var dataZoomModel = dataZoomInfo.dataZoomModel;
- var oneType = dataZoomModel.get('disabled', true) ? false : dataZoomModel.get('zoomLock', true) ? 'move' : true;
- if (typePriority[prefix + oneType] > typePriority[prefix + controlType]) {
- controlType = oneType;
- }
-
- preventDefaultMouseMove &= dataZoomModel.get('preventDefaultMouseMove', true);
- });
- return {
- controlType: controlType,
- opt: {
-
-
-
- zoomOnMouseWheel: true,
- moveOnMouseMove: true,
- moveOnMouseWheel: true,
- preventDefaultMouseMove: !!preventDefaultMouseMove
- }
- };
- }
- exports.register = register;
- exports.unregister = unregister;
- exports.generateCoordId = generateCoordId;
|