@fusioncharts/fusiontime
Version:
FusionCharts JavaScript time-series charting framework
1 lines • 4.61 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 COLOR_FDFDFD="#fdfdfd",COLOR_F7FFFE="#f7fffe",COLOR_E3E3E3="#e3e3e3",UP="up",DOWN="down",M="M",v="v",h="h",NONE="none",DRAGSTART="timeNavBrushStart",DRAGEND="timeNavBrushEnd",DRAG="timeNavBrush",LABELFORMAT="%b %d, %Y",TRANSLATE="translate",STROKE_ATTR_LIST=["stroke","stroke-width","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke-color"];var Selection=function(_SmartRenderer){function Selection(){var _this;_this=_SmartRenderer.call(this)||this;_this._dimensions={};return _this}(0,_inheritsLoose2.default)(Selection,_SmartRenderer);var _proto=Selection.prototype;_proto.__setDefaultConfig=function __setDefaultConfig(){_SmartRenderer.prototype.__setDefaultConfig.call(this);this.config.defaultStyle={fill:(0,_lib.toRaphaelColor)({FCcolor:{color:COLOR_FDFDFD+","+COLOR_F7FFFE,ratio:"0,100",angle:90,alpha:"50,50"}}),stroke:COLOR_E3E3E3,"stroke-width":1,opacity:1,"fill-opacity":.5,cursor:"move"}};_proto.configureAttributes=function configureAttributes(obj){if(obj===void 0){obj={}}_SmartRenderer.prototype.configureAttributes.call(this,obj);var selection=this,selectionConfig=selection.config,defaultStyle=selectionConfig.defaultStyle;selectionConfig.style=Object.assign({},defaultStyle,obj.style.mask);selectionConfig.orientation=obj.orientation};_proto.setDimension=function setDimension(dim){this._dimensions=dim};_proto.getDimension=function getDimension(){return this._dimensions};_proto.attachHandlers=function attachHandlers(){var selection=this,animationManager=selection.getFromEnv("animationManager"),brush=selection.getLinkedParent(),timeNav=brush.getFromEnv("timeNavigator"),timeNavConfig=timeNav.config,scale=timeNavConfig.contextScale,chart=selection.getFromEnv("chart"),currFocusLimit,brushDim,startX,curPx,clampDirection,offsetX,startPx,endPx,options={timeFormatter:timeNavConfig.formatter},forceFireOptions=Object.assign({forceFire:true},options),eventArgs={formatter:LABELFORMAT,action:TRANSLATE};selection.addEventListener("fc-dragstart",selection.dragstartHandler||(selection.dragstartHandler=function(e){startX=(0,_lib.getTouchEvent)(e).clientX;curPx=0;brushDim=brush.getCurrentBrushDimensions();currFocusLimit=chart.getFocusLimit();chart.getFromEnv("fireChartEvents")(DRAGSTART,[+currFocusLimit[0],+currFocusLimit[1]],eventArgs,forceFireOptions)}));selection.addEventListener("fc-dragmove",selection.dragmoveHandler||(selection.dragmoveHandler=function(e){animationManager.setAnimationState("timenavScroll");offsetX=(0,_lib.getTouchEvent)(e).clientX-startX;clampDirection=curPx>=offsetX?DOWN:UP;curPx=offsetX;startPx=brushDim.x+offsetX;endPx=startPx+brushDim.width;chart.setPixelLimit([startPx,endPx],scale,[clampDirection,clampDirection],{name:DRAG,eventArgs:eventArgs,options:options})}));selection.addEventListener("fc-dragend",selection.dragendHandler||(selection.dragendHandler=function(e){currFocusLimit=chart.getFocusLimit();chart.getFromEnv("fireChartEvents")(DRAGEND,[+currFocusLimit[0],+currFocusLimit[1]],eventArgs,forceFireOptions)}))};_proto.draw=function draw(){var selection=this,selfConfig=selection.config,selectionStyle=Object.assign({},selfConfig.style),selectionBorderStyle=Object.assign({},selfConfig.style),i,len=STROKE_ATTR_LIST.length,selectionDimensions=selection.getDimension();for(i=0;i<len;i++){delete selectionStyle[STROKE_ATTR_LIST[i]]}selection.addGraphicalElement({el:"rect",attr:{x:selectionDimensions.x,y:selectionDimensions.y,width:Math.max(selectionDimensions.width,0),height:Math.max(selectionDimensions.height,0),opacity:selectionStyle.opacity,stroke:"none"},css:selectionStyle,id:"selectionBox",label:"selectionBox",component:selection,container:{id:"brushGroup",label:"brushGroup",isParent:true}});selectionBorderStyle.fill=NONE;selection.addGraphicalElement({el:"path",attr:{path:[M,selectionDimensions.x,selectionDimensions.y,v,selectionDimensions.height,h,selectionDimensions.width,v,-selectionDimensions.height],opacity:selectionBorderStyle.opacity},id:"selectionBoxBorder",label:"selectionBoxBorder",css:selectionBorderStyle,component:selection,container:{id:"brushGroup",label:"brushGroup",isParent:true}})};return Selection}(_componentInterface.SmartRenderer);var _default=exports.default=Selection;