@fusioncharts/features
Version:
FusionCharts JavaScript charting framework
1 lines • 6.39 kB
JavaScript
;var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports.default=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _componentInterface=require("@fusioncharts/core/src/component-interface");var _lib=require("@fusioncharts/core/src/lib");var _updateDependancyObj=function _updateDependancyObj(nativeInteraction,callback,component,store){var index,eventStore;if(eventStore=store[nativeInteraction]){eventStore.some((function(eventInfo,i){if(eventInfo.callback===callback&&eventInfo.component===component){index=i;return true}return false}));index!==_lib.UNDEF&&eventStore.splice(index,1)}};var InputManager=function(_ComponentInterface){function InputManager(){return _ComponentInterface.apply(this,arguments)||this}(0,_inheritsLoose2.default)(InputManager,_ComponentInterface);var _proto=InputManager.prototype;_proto.configure=function configure(){var manager=this,chart=manager.getFromEnv("chart"),getInputConfigurations=chart.getInputConfigurations;manager.addToEnv("canvas",manager.getLinkedParent());manager.addToEnv("inputOptions",getInputConfigurations&&getInputConfigurations.call(chart));manager.config={controlObj:{},dependancyObj:{}}};_proto.addEventToChild=function addEventToChild(){var manager=this,children=manager.getChildren(),derivedEvents=["zoomin","zoomout","dragzoomenabled","dragzoomdisabled","pinenabled","pindisabled","panenabled","pandisabled"];var _loop=function _loop(child){derivedEvents.forEach((function(event){manager.addExtEventListener(event,manager.manageEvents.bind(manager),children[child][0])}))};for(var child in children){_loop(child)}};_proto.manageEvents=function manageEvents(event){var dependancyObj=this.config.dependancyObj,eventType=event.type;dependancyObj[eventType]&&dependancyObj[eventType].forEach((function(inputObj){if(inputObj.component!==event.sender){inputObj.callback.call(inputObj.component,event)}}))};_proto.fetchZoomableAxes=function fetchZoomableAxes(){var manager=this;if(!manager.config.axesObArr){var axesObArr=manager.config.axesObArr=[];manager.getLinkedParent().getAxes().forEach((function(axisOb){if(axisOb.config.zoomable||axisOb.config.pannable){axesObArr.push({axis:axisOb.axis,stack:[],isY:axisOb.isY})}}));manager.addToEnv("axesObArr",axesObArr)}};_proto.draw=function draw(){var manager=this;manager.fetchZoomableAxes();manager.addEventToChild()};_proto.getControl=function getControl(inputParams,exclusive){var inputManager=this,controlObj=inputManager.config.controlObj,canvas=inputManager.getLinkedParent(),nativeInteraction,control;if(exclusive){return}inputParams.forEach((function(inputParam){nativeInteraction=inputParam.nativeInteraction;if(nativeInteraction instanceof Array){nativeInteraction.forEach((function(nativeInteractionElement){control=controlObj[nativeInteractionElement]||(controlObj[nativeInteractionElement]=[]);control.push({callback:inputParam.callback,component:inputParam.component});inputParam.component.addExtEventListener(nativeInteractionElement,inputParam.callback,canvas)}))}else{control=controlObj[nativeInteraction]||(controlObj[nativeInteraction]=[]);control.push({callback:inputParam.callback,component:inputParam.component});inputParam.component.addExtEventListener(nativeInteraction,inputParam.callback,canvas)}}))};_proto.releaseControl=function releaseControl(inputParams){var inputManager=this,canvas=inputManager.getLinkedParent(),nativeInteraction;inputParams.forEach((function(inputParam){nativeInteraction=inputParam.nativeInteraction;if(nativeInteraction instanceof Array){nativeInteraction.forEach((function(nativeInteractionElement){inputParam.component.removeExtEventListener(nativeInteractionElement,inputParam.callback,canvas);_updateDependancyObj(nativeInteractionElement,inputParam.callback,inputParam.component,inputManager.config.controlObj)}))}else{inputParam.component.removeExtEventListener(nativeInteraction,inputParam.callback,canvas);_updateDependancyObj(nativeInteraction,inputParam.callback,inputParam.component,inputManager.config.controlObj)}}))};_proto._updateControlObj=function _updateControlObj(nativeInteraction,callback){var controlObj=this.config.controlObj,index,eventStore;if(eventStore=controlObj[nativeInteraction]){eventStore.some((function(eventInfo,i){if(eventInfo.callback===callback){index=i;return true}return false}));index!==_lib.UNDEF&&eventStore.splice(index,1)}};_proto.registerDependancy=function registerDependancy(inputParams){var dependancyObj=this.config.dependancyObj,derivedInteraction,specificDependancy;inputParams.forEach((function(inputParam){derivedInteraction=inputParam.derivedInteraction;if(derivedInteraction instanceof Array){derivedInteraction.forEach((function(derivedInteractionElement){specificDependancy=dependancyObj[derivedInteractionElement]||(dependancyObj[derivedInteractionElement]=[]);specificDependancy.push({callback:inputParam.callback,component:inputParam.component,derivedInteraction:derivedInteractionElement})}))}else{specificDependancy=dependancyObj[derivedInteraction]||(dependancyObj[derivedInteraction]=[]);specificDependancy.push(inputParam)}}))};_proto.removeDependancy=function removeDependancy(inputParams){var inputManager=this,derivedInteraction;inputParams.forEach((function(inputParam){derivedInteraction=inputParam.derivedInteraction;if(derivedInteraction instanceof Array){derivedInteraction.forEach((function(derivedIntr){_updateDependancyObj(derivedIntr,inputParam.callback,inputParam.component,inputManager.config.dependancyObj)}))}else{_updateDependancyObj(derivedInteraction,inputParam.callback,inputParam.component,inputManager.config.dependancyObj)}}))};_proto.zoomOut=function zoomOut(){var zoomOutButton=this.getChildren("ZoomOutButton");zoomOutButton&&zoomOutButton[0].zoomOut()};_proto.zoomTo=function zoomTo(startIndex,endIndex){var dragZoomIn=this.getChildren("DragZoomIn");dragZoomIn&&dragZoomIn[0].zoomTo(startIndex,endIndex)};_proto.resetChart=function resetChart(){var zoomResetButton=this.getChildren("ZoomResetButton");zoomResetButton&&zoomResetButton[0].zoomOut()};_proto.setZoomMode=function setZoomMode(zoomModeEnable){var dragPin=this.getChildren("DragPin");dragPin&&(zoomModeEnable?dragPin[0].disable():dragPin[0].enable())};return InputManager}(_componentInterface.ComponentInterface);var _default=exports.default=InputManager;