UNPKG

@fusioncharts/fusiontime

Version:

FusionCharts JavaScript time-series charting framework

1 lines 4.12 kB
"use strict";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 SCALE="scale",DRAGSTART="timeNavBrushStart",DRAGEND="timeNavBrushEnd",DRAG="timeNavBrush",UP="up",DOWN="down",LABELFORMAT="%b %d, %Y";var Handle=function(_SmartRenderer){function Handle(){var _this;_this=_SmartRenderer.call(this)||this;_this._dimensions={};return _this}(0,_inheritsLoose2.default)(Handle,_SmartRenderer);var _proto=Handle.prototype;_proto.__setDefaultConfig=function __setDefaultConfig(){_SmartRenderer.prototype.__setDefaultConfig.call(this);var config=this.config;config._defaultHandleStyle={fill:"#dfdfdf",stroke:"none",cursor:"ew-resize"};config._defaultHandleGripStyle={cursor:"ew-resize",stroke:"#808080","stroke-width":1,"stroke-linecap":"round"}};_proto.configureAttributes=function configureAttributes(obj){if(obj===void 0){obj={}}_SmartRenderer.prototype.configureAttributes.call(this,obj);var handle=this,handleConfig=handle.config;handleConfig.style={handle:Object.assign({},handleConfig._defaultHandleStyle,obj.style.handle),"handle-grip":Object.assign({},handleConfig._defaultHandleGripStyle,obj.style["handle-grip"])};handleConfig.orientation=obj.orientation;handleConfig.type=obj.type};_proto.setDimension=function setDimension(dim){this._dimensions=dim};_proto.getDimension=function getDimension(){return this._dimensions};_proto.attachHandlers=function attachHandlers(){var handle=this,brush=handle.getLinkedParent(),timeNav=brush.getFromEnv("timeNavigator"),timeNavConfig=timeNav.config,chart=handle.getFromEnv("chart"),currFocusLimit,brushDim,lastX,clampDirection,startX,offsetX,startPx,endPx,options={timeFormatter:timeNavConfig.formatter},forceFireOptions=Object.assign({forceFire:true},options),eventArgs={formatter:LABELFORMAT,action:SCALE};handle.addEventListener("fc-dragstart",handle.dragstartHandler||(handle.dragstartHandler=function(e){startX=(0,_lib.getTouchEvent)(e).clientX;lastX=0;brushDim=brush.getCurrentBrushDimensions();currFocusLimit=chart.getFocusLimit();chart.getFromEnv("fireChartEvents")(DRAGSTART,[+currFocusLimit[0],+currFocusLimit[1]],eventArgs,forceFireOptions)}));handle.addEventListener("fc-dragmove",handle.dragmoveHandler||(handle.dragmoveHandler=function(e){offsetX=(0,_lib.getTouchEvent)(e).clientX-startX;clampDirection=offsetX>=lastX?UP:DOWN;lastX=offsetX;if(handle.config.type==="leftHandle"){startPx=brushDim.x+offsetX;endPx=brushDim.x+brushDim.width}else{startPx=brushDim.x;endPx=brushDim.x+brushDim.width+offsetX}handle.getFromEnv("animationManager").setAnimationState("timenavSqueeze");timeNav.validateDomain([startPx,endPx],[clampDirection,clampDirection],{eventName:DRAG,eventArgs:eventArgs,options:options})}));handle.addEventListener("fc-dragend",handle.dragendHandler||(handle.dragendHandler=function(e){currFocusLimit=chart.getFocusLimit();chart.getFromEnv("fireChartEvents")(DRAGEND,[+currFocusLimit[0],+currFocusLimit[1]],eventArgs,forceFireOptions)}))};_proto.draw=function draw(){var handle=this,handleConfig=handle.config,handleStyle=handleConfig.style.handle,handleGripStyle=handleConfig.style["handle-grip"],handleDimensions=handle.getDimension(),startX=handleDimensions.x,startY=handleDimensions.y,width=handleDimensions.width,height=handleDimensions.height;handle.addGraphicalElement({el:"rect",attr:{x:startX,y:startY,width:width,height:height,opacity:handleStyle.opacity},css:handleStyle,label:"handleButton",component:handle,container:{id:"brushGroup",label:"brushGroup",isParent:true}});handle.addGraphicalElement({el:"path",attr:{path:"M "+(startX+3.5)+","+(startY+6)+" v "+(height-12)+"\n M "+(startX+6.5)+","+(startY+6)+" v "+(height-12)},label:"handlePath",component:handle,css:handleGripStyle,container:{id:"brushGroup",label:"brushGroup",isParent:true}})};return Handle}(_componentInterface.SmartRenderer);var _default=exports.default=Handle;