@fusioncharts/fusiontime
Version:
FusionCharts JavaScript time-series charting framework
1 lines • 17.8 kB
JavaScript
"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 _lib=require("@fusioncharts/core/src/lib");var _index=_interopRequireDefault(require("@fusioncharts/utils/src/chunker/index.js"));var _dependencyManager=require("@fusioncharts/core/src/dependency-manager");var _libGraphics=require("@fusioncharts/core/src/lib/lib-graphics");var _isValidNumber=_interopRequireDefault(require("@fusioncharts/utils/src/type/is-valid-number"));var _areaGenerator=_interopRequireDefault(require("@fusioncharts/utils/src/shape-generators/area-generator"));var _lineGenerator=_interopRequireDefault(require("@fusioncharts/utils/src/shape-generators/line-generator"));var _step=_interopRequireDefault(require("@fusioncharts/utils/src/shape-generators/curve-factories/step"));var _linear=_interopRequireDefault(require("@fusioncharts/utils/src/shape-generators/curve-factories/linear"));var _monotone=_interopRequireDefault(require("@fusioncharts/utils/src/shape-generators/curve-factories/monotone"));var _timeConverter=_interopRequireDefault(require("@fusioncharts/utils/src/time-converter"));var _line=_interopRequireDefault(require("./line.animation"));var _line2=_interopRequireDefault(require("./line"));var _rangedPlotUtils=require("./ranged-plot-utils");var PLOT_HOVERED_ANCHOR_RADIUS=5.5,DEFAULT_LINE_LENGTH=10,DEFAULT_GAP_LENGTH=5,maxRadius=5,VISIBLE="visible",CRISP_CONSTANT=.0625,DEFAULT_COLOR="9194CC",calculateMid=function calculateMid(a,b){return(a+b)/2},unBlankify=function unBlankify(pathString){if(pathString===void 0){pathString=""}return pathString===""?"M0,0":pathString},crisper=function crisper(_ref){var x=_ref.x,y=_ref.y,width=_ref.width,height=_ref.height;return{y:y,height:height,x:x-CRISP_CONSTANT,width:width+CRISP_CONSTANT*2}},toPathRect=function toPathRect(acc,rect){return acc+"M"+rect.x+","+rect.y+"L"+(rect.x+rect.width)+","+rect.y+"L"+(rect.x+rect.width)+","+(rect.y+rect.height)+"L"+rect.x+","+(rect.y+rect.height)+"Z"};var LINE="line",AREA="area",WHITE="#ffffff";function getGenerator(type){switch(type){case"area":case"area-range":case"smooth-area":case"step-area":return _areaGenerator.default;case"line":case"smooth-line":case"mean-line":case"step-line":default:return _lineGenerator.default}}function getCurve(type){switch(type){case"smooth-line":case"smooth-area":return _monotone.default;case"step-area":case"step-line":return _step.default;case"line":case"area":case"area-range":default:return _linear.default}}function isArea(type){return type==="area"||type==="smooth-area"||type==="step-area"||"area-range"}function isLine(type){return type==="line"||type==="smooth-line"||type==="step-line"}(0,_dependencyManager.addDep)({name:"continuousAnimation",type:"animationRule",extension:_line.default});var AreaRange=function(_Line){function AreaRange(){return _Line.apply(this,arguments)||this}(0,_inheritsLoose2.default)(AreaRange,_Line);var _proto=AreaRange.prototype;_proto.getName=function getName(){return"continuous-range"};_proto.getHighlightedIndices=function getHighlightedIndices(range){var dataset=this,config=dataset.config,dataInfo=config.dataInfo,hightlightedPoints=[];dataInfo.forEach((function(data,index){if(data.base<=range.minValue&&data.y>=range.maxValue){hightlightedPoints.push(index)}}));return hightlightedPoints};_proto.__setDefaultConfig=function __setDefaultConfig(){_Line.prototype.__setDefaultConfig.call(this);var config=this.config;config["default-stroke"]=DEFAULT_COLOR;config["default-fill"]=DEFAULT_COLOR;config["default-anchor-stroke"]=(0,_libGraphics.convertColor)(WHITE);config.type=LINE;config.isRange=true;config.plotStyle={};config.nullPlotStyle={};config.linePlotStyle={};config.nullLinePlotStyle={};config.areaPlotStyle={};config.nullAreaPlotStyle={};config.anchorStyle={};config.anchorHoverInStyle={};config.anchorHoverOutStyle={};config.anchorHighlightObj={};config.defaultLineStyle={"stroke-opacity":1,"stroke-width":2,"stroke-dasharray":"none",fill:"none"};config.defaultNullLineStyle={"stroke-opacity":1,"stroke-width":2,"stroke-dasharray":[DEFAULT_LINE_LENGTH,DEFAULT_GAP_LENGTH],fill:"none"};config.defaultLinePredictiveStyle={"stroke-opacity":1,"stroke-width":1,"stroke-dasharray":5,fill:"none"};config.defaultAreaStyle={"stroke-opacity":1,"stroke-width":0,"fill-opacity":.6};config.defaultNullAreaStyle={"stroke-opacity":1,"stroke-width":0,"fill-opacity":.3};config.defaultAreaPredictiveStyle={"stroke-opacity":1,opacity:.5};config.defaultAnchorStyle={"fill-opacity":1,"stroke-width":1};config.willInjectNulls=true};_proto.allocatePosition=function allocatePosition(){var dataset=this,config=dataset.config,_config$indices=config.indices,xIdx=_config$indices[0],highIdx=_config$indices[1],lowIdx=_config$indices[2],seriesInfo=config.seriesInfo,dateColumn=dataset.getFromEnv("dateColumn"),isUTC=dataset.getFromEnv("UTC"),dsType=config.type,data=config.data,dataInfo=config.dataInfo,dataInfoNull=[],dataObj,binDecider=dataset.getFromEnv("binDecider"),xScale=dataset.getFromEnv("xScale"),yScale=dataset.getFromEnv("yScale"),xThresholdDuration=binDecider.getRangeThreshold()[2],nullClipAdjustment=Number.parseFloat(config.nullLinePlotStyle["stroke-width"]),predictionClipAdjustment=Number.parseFloat(config.predictiveStyleAttributesLine["stroke-width"]),clipAdjustment=Number.parseFloat(config.linePlotStyle["stroke-width"]),pathGenerator,startDate,endDate,midDate,nextData,nextMidDate,yValue,highValue,lowValue,pX,base,y,i,len,bins=xScale.bins,yBaseValue,paddingInTimestamp,dataLen=data.length,_xScale$getDomain=xScale.getDomain(),startDomain=_xScale$getDomain[0],endDomain=_xScale$getDomain[1],xValue,duration,eventArgs,seriesName,format=dateColumn.format,formatter=isUTC?_timeConverter.default.utcFormatter(format):_timeConverter.default.formatter(format),isPlotOverTick=xScale.showPlotOverTick();config.firstTimeStamp=data&&data[0]&&data[0][xIdx]&&data[0][xIdx].start;if(config.repositioningDone=dataset._isRepositioningNeeded()){if(config.visibility!=="visible"){return}dataInfo=config.dataInfo=[];config.timeStampGap=xThresholdDuration;config.availableWidth=0;for(i=0,len=bins.length;i<len;i++){if(bins[i].clipType!==2){config.availableWidth=xScale.getRangeValue(bins[i].end)-xScale.getRangeValue(bins[i].start);break}}paddingInTimestamp=+xScale.getDomainValue(PLOT_HOVERED_ANCHOR_RADIUS)-+xScale.getDomainValue(0);config.actualStartDomain=+startDomain-paddingInTimestamp;config.actualEndDomain=+endDomain+paddingInTimestamp;data.forEach((function(d,index,dataArr){xValue=d[xIdx];highValue=Math.max(d[highIdx],d[lowIdx]);lowValue=Math.min(d[lowIdx],d[highIdx]);yValue=highValue;duration=xValue.config.duration;startDate=xValue.start;endDate=xValue.end;midDate=calculateMid(startDate,endDate);nextData=dataArr[index+1];yBaseValue=lowValue;base=yScale.getRangeValue(yBaseValue||Math.max(yScale.getDomain()[0],0));y=yScale.getRangeValue(yValue);if(!index){config.firstTimeStamp=startDate}if(dsType===AREA&&!(0,_isValidNumber.default)(base)){return}if((0,_isValidNumber.default)(yValue)&&(0,_isValidNumber.default)(y)){pX=xScale.getBinIndex(startDate);dataObj={startDate:startDate,endDate:endDate,highValue:highValue,lowValue:lowValue,timeInstant:isPlotOverTick?startDate:midDate,value:yValue,paddingInTimestamp:paddingInTimestamp,yBaseValue:dsType===AREA?yBaseValue:_lib.UNDEF,x:xScale.getRangeValue(new Date(startDate),new Date(endDate)),endXPosition:xScale.getRangeValue(new Date(startDate),new Date(endDate)),y:y,base:base};eventArgs={index:index,dataValue:yValue,highValue:highValue,lowValue:lowValue,start:startDate,startText:formatter.format(startDate),end:endDate,endText:formatter.format(endDate),binUnit:duration.Unit,binMultiplier:duration.number,plotType:config.type,timeFormatter:format,aggregation:config.aggregation,measure:config.measures[0],binValue:yValue,binValueFormatted:config.formatterFn&&config.formatterFn({value:yValue,type:"tooltip",prefix:config.prefix,suffix:config.suffix})};seriesName=null;if(seriesName){eventArgs.series=seriesName;eventArgs.seriesValue=seriesInfo[seriesName]}dataObj.eventArgs=eventArgs;dataInfo[pX]=dataObj;if(nextData){var nextPX=xScale.getBinIndex(nextData[xIdx].start);dataInfoNull.push(dataObj);nextMidDate=calculateMid(nextData[xIdx].start,nextData[xIdx].end);if(config.willInjectNulls&&nextMidDate-midDate-(xScale.clips[nextPX]-xScale.clips[pX])>xThresholdDuration*1.5){dataInfoNull.push(null)}}else if(dataLen-index===1){dataInfoNull.push(dataObj)}}else if(config.willInjectNulls){dataInfoNull.push(null)}}));pathGenerator=new _index.default(getGenerator(dsType)).setConnectUndefineds(config.connectNullData).setChunks({def:{clipAdjustment:clipAdjustment},undef:{clipAdjustment:nullClipAdjustment},predictive:{clipAdjustment:predictionClipAdjustment}}).setCurve(getCurve(dsType)).setDefined((function(d){return!!d})).setChunkDecider((function(d){return d.startDate>=config.prediction.dateMs?"predictive":"def"})).setXAccessor((function(d){return d.x})).setYAccessor((function(d){return d.y}));if(isArea(dsType)){pathGenerator.setYBaseAccessor((function(d){return d.base}))}config.chunks=pathGenerator.generate(dataInfoNull);config.path=unBlankify(config.chunks.def.path);config.clipPath=unBlankify(config.chunks.def.clipRects.map(crisper).reduce(toPathRect,""));config.nullPath=unBlankify(config.chunks.undef.path);config.nullClipPath=unBlankify(config.chunks.undef.clipRects.map(crisper).reduce(toPathRect,""));config.predictivePath=unBlankify(config.chunks.predictive.path);config.predictiveClipPath=unBlankify(config.chunks.predictive.clipRects.map(crisper).reduce(toPathRect,""));config.topChunks=pathGenerator.getLineChunkerYTop().generate(dataInfoNull);config.topPath=unBlankify(config.topChunks.def.path);config.topClipPath=unBlankify(config.topChunks.def.clipRects.map(crisper).reduce(toPathRect,""));config.topNullPath=unBlankify(config.topChunks.undef.path);config.topNullClipPath=unBlankify(config.topChunks.undef.clipRects.map(crisper).reduce(toPathRect,""));config.topPredictivePath=unBlankify(config.topChunks.predictive.path);config.topPredictiveClipPath=unBlankify(config.topChunks.predictive.clipRects.map(crisper).reduce(toPathRect,""));config.bottomChunks=pathGenerator.getLineChunkerYBase().generate(dataInfoNull);config.bottomPath=unBlankify(config.bottomChunks.def.path);config.bottomClipPath=unBlankify(config.bottomChunks.def.clipRects.map(crisper).reduce(toPathRect,""));config.bottomNullPath=unBlankify(config.bottomChunks.undef.path);config.bottomNullClipPath=unBlankify(config.bottomChunks.undef.clipRects.map(crisper).reduce(toPathRect,""));config.bottomPredictivePath=unBlankify(config.bottomChunks.predictive.path);config.bottomPredictiveClipPath=unBlankify(config.bottomChunks.predictive.clipRects.map(crisper).reduce(toPathRect,""))}};_proto._drawPlot=function _drawPlot(){var dataset=this,config=dataset.config,linePlotStyleObj=config.linePlotStyle,areaPlotStyleObj=config.areaPlotStyle,nullLinePlotStyleObj=config.nullLinePlotStyle,nullAreaPlotStyleObj=config.nullAreaPlotStyle,predictiveStyleAttributesLine=config.predictiveStyleAttributesLine,predictiveStyleAttributesArea=config.predictiveStyleAttributesArea,dataInfo=config.dataInfo,data;dataset.addGraphicalElement({el:"group",container:{id:"meso",label:"group"},component:dataset,label:"group",id:"meso-line",attr:{name:"line-common-meso",visibility:config.visibility}});dataset.addGraphicalElement({el:"group",container:{id:"thermo",label:"group"},component:dataset,label:"group",id:"thermo-line",attr:{name:"line-common-thermo",visibility:config.visibility}});dataset.addGraphicalElement({el:"group",container:{id:"meso-line",label:"group"},component:dataset,label:"group",id:"meso-plot",attr:{name:"line-plot-meso",visibility:config.visibility}},true);dataset.addGraphicalElement({el:"group",container:{id:"thermo-line",label:"group"},component:dataset,label:"group",id:"thermo-plot",attr:{name:"line-plot-thermo",visibility:config.visibility}},true);dataset.addGraphicalElement({el:"group",container:{id:"thermo-line",label:"group"},component:dataset,label:"group",id:"thermo-anchor",attr:{name:"line-anchor-thermo",visibility:config.visibility}},true);if(config.connectNullData){dataset.addGraphicalElement({el:"path",container:{label:"group",id:"meso-plot"},attr:Object.assign({path:config.nullPath,"clip-path":config.nullClipPath},isLine(config.type)?nullLinePlotStyleObj:nullAreaPlotStyleObj),label:"path",component:dataset},true)}dataset.addGraphicalElement({el:"path",container:{label:"group",id:"meso-plot"},attr:Object.assign({path:config.path,"clip-path":config.clipPath},isLine(config.type)?linePlotStyleObj:areaPlotStyleObj),label:"path",component:dataset},true);if(config.prediction.enabled){dataset.addGraphicalElement({el:"path",container:{label:"group",id:"meso-plot"},attr:Object.assign({path:config.predictivePath,"clip-path":config.predictiveClipPath},isLine(config.type)?predictiveStyleAttributesLine:predictiveStyleAttributesArea),label:"path",component:dataset},true)}if(config.topPath){if(config.connectNullData){dataset.addGraphicalElement({el:"path",container:{label:"group",id:"thermo-plot"},attr:Object.assign({path:config.topNullPath,"clip-path":config.topNullClipPath},nullLinePlotStyleObj),label:"topPath",component:dataset},true)}dataset.addGraphicalElement({el:"path",container:{label:"group",id:"thermo-plot"},attr:Object.assign({path:config.topPath,"clip-path":config.topClipPath},linePlotStyleObj),label:"topPath",component:dataset},true);if(config.prediction.enabled){dataset.addGraphicalElement({el:"path",container:{label:"group",id:"meso-plot"},attr:Object.assign({path:config.topPredictivePath,"clip-path":config.topPredictiveClipPath},predictiveStyleAttributesLine),label:"path",component:dataset},true)}}if(config.bottomPath){if(config.connectNullData){dataset.addGraphicalElement({el:"path",container:{label:"group",id:"thermo-plot"},attr:Object.assign({path:config.bottomNullPath,"clip-path":config.bottomNullClipPath},nullLinePlotStyleObj),label:"topPath",component:dataset},true)}dataset.addGraphicalElement({el:"path",container:{label:"group",id:"thermo-plot"},attr:Object.assign({path:config.bottomPath,"clip-path":config.bottomClipPath},linePlotStyleObj),label:"bottomPath",component:dataset},true);if(config.prediction.enabled){dataset.addGraphicalElement({el:"path",container:{label:"group",id:"meso-plot"},attr:Object.assign({path:config.bottomPredictivePath,"clip-path":config.bottomPredictiveClipPath},predictiveStyleAttributesLine),label:"path",component:dataset},true)}}if(config.mode==="show"){if(config.sharedAnchorIndices&&config.sharedAnchorIndices.length){config.sharedAnchorIndices.forEach((function(index){data=dataInfo[index];config.lastShownIndices=config.sharedAnchorIndices;data&&!isNaN(data.value)&&dataset.addGraphicalElement({el:"path",container:{label:"group",id:"thermo-anchor"},attr:Object.assign({path:(0,_lib.polyPathToPath)([2,data.x,data.y,config.radius,0,0]),visibility:"show"},config.isDsHovered?config.anchorHoverInStyle:config.isOtherDsHovered?config.anchorStyle:config.anchorHighlightObj),id:"shared-anchor-"+index,label:config.dsType+"-anchor"});data&&!isNaN(data.value)&&dataset.addGraphicalElement({el:"path",container:{label:"group",id:"thermo-anchor"},attr:Object.assign({path:(0,_lib.polyPathToPath)([2,data.x,data.base,config.radius,0,0]),visibility:"show"},config.isDsHovered?config.anchorHoverInStyle:config.isOtherDsHovered?config.anchorStyle:config.anchorHighlightObj),id:"shared-anchor-"+index,label:config.dsType+"-anchor"})}))}}else{if(config.hideIndices&&config.hideIndices.length){config.hideIndices.forEach((function(index){data=dataInfo[index];data&&!isNaN(data.value)&&dataset.addGraphicalElement({el:"path",container:{label:"group",id:"meso-anchor"},attr:{visibility:"hidden"},id:"shared-anchor-"+index,label:config.dsType+"-anchor"})}))}}};_proto._getHoveredPlot=function _getHoveredPlot(chartXArg,chartYArg){var dataset=this,chartX=chartXArg,chartY=chartYArg,xScale=dataset.getFromEnv("xScale"),xScaleRange=xScale.getRange(),dataMarkers=[dataset.getChildren("dataMarker")],config=dataset.config,visible=config.visibility===VISIBLE,dataInfo=config.dataInfo,len=dataInfo.length,canvas=dataset.getLinkedParent(),translationObj=canvas.getTranslation(),translationX=translationObj.x,translationY=translationObj.y,pointObj,xMin,xMax,returnValue,j,pX;chartX-=translationX;chartY-=translationY;if(chartX<xScaleRange[0]||chartX>xScaleRange[1]){return{component:dataset}}pX=xScale.getBinIndex(xScale.getDomainValue(chartX));xMin=Math.floor(Math.max(pX,0));xMax=Math.ceil(Math.min(pX,len-1));dataMarkers.forEach((function(dataMarkerArg){var dataMarker=dataMarkerArg;if(!returnValue&&dataMarker&&(dataMarker=dataMarker[0])){returnValue=dataMarker._checkPointOverMarker(pX,chartX,chartY,config.availableWidth)}}));if(!returnValue){for(j=xMax;j>=xMin;j--){pointObj=dataInfo[j];returnValue=visible?(0,_rangedPlotUtils.isWithinShape)(pointObj,j,chartX,chartY,dataset,maxRadius):{};if(returnValue.hovered){break}}}!returnValue&&(returnValue={});if(!returnValue.hovered){returnValue.binIndexHovered=xScale.getBinIndex(xScale.getDomainValue(chartX));returnValue.pointObj=config.dataInfo[returnValue.binIndexHovered]||xScale.getBinBounds(pX);returnValue.component=dataset}else{returnValue.binIndexHovered=returnValue.pointIndex}config.binIndexHovered=returnValue.binIndexHovered;return returnValue};_proto._calculateLimits=function _calculateLimits(){return(0,_rangedPlotUtils.calculateLimits)(this)};_proto._getTooltext=function _getTooltext(pointFound,datasetHovered,dataIndex){return(0,_rangedPlotUtils.getTooltext)(this,pointFound,datasetHovered,dataIndex)};return AreaRange}(_line2.default);var _default=exports.default=AreaRange;