UNPKG

@fusioncharts/widgets

Version:

FusionCharts JavaScript charting framework

1 lines 11.4 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 _lib=require("@fusioncharts/core/src/lib");var _funnelpyramidbase=_interopRequireDefault(require("../_internal/funnelpyramidbase"));var _schedular=require("@fusioncharts/core/src/schedular");var _funnelPoint=_interopRequireDefault(require("../_internal/data/funnel-point"));var UNDEF;var FunnelDataset=function(_FunnelPyramidBaseDat){function FunnelDataset(){var _this;_this=_FunnelPyramidBaseDat.call(this)||this;_this.config.pointInContext=_funnelPoint.default;_this.config.LABEL_PLACEMENT_ITERATOR_INDEX_START=1;return _this}(0,_inheritsLoose2.default)(FunnelDataset,_FunnelPyramidBaseDat);var _proto=FunnelDataset.prototype;_proto.getType=function getType(){return"dataset"};_proto.getName=function getName(){return"funnel"};_proto.configure=function configure(datasetJSON){if(!datasetJSON){return false}this.config.JSONData=datasetJSON;var datasetDefStore=this,chart=datasetDefStore.getFromEnv("chart"),numberFormatter=datasetDefStore.getFromEnv("number-formatter"),utils=datasetDefStore.utils(datasetDefStore),sortObjArrByKey=utils.sortObjArrByKey,chartAttr=chart.getFromEnv("dataSource")?chart.getFromEnv("dataSource").chart:{},data=datasetDefStore.config.JSONData.data,streamLinedData,index,dsItem,length;if(!datasetDefStore._checkValidData(data)){return}for(index=0,length=data.length;index<length;index++){dsItem=data[index];if(dsItem&&dsItem.value!==UNDEF){dsItem.value=numberFormatter.getCleanValue(dsItem.value,true)}}streamLinedData=datasetDefStore.config.streamLinedData=(0,_lib.pluckNumber)(chartAttr.streamlineddata,1);datasetDefStore.config.JSONData.data=!streamLinedData?data:sortObjArrByKey(data,"value");datasetDefStore._configure();data=datasetDefStore.getChildren("data");streamLinedData&&(data[0].pseudoPoint=true);chart.config.showLegend&&datasetDefStore.addLegend()};_proto.configureSpecifics=function configureSpecifics(){var datasetStore=this,chart=datasetStore.getFromEnv("chart"),datasetConf=datasetStore.config,chartAttr=chart.getFromEnv("dataSource")?chart.getFromEnv("dataSource").chart:{},utils=datasetStore.utils(datasetStore),copyProperties=utils.copyProperties;copyProperties(chartAttr,datasetConf,[["funnelyscale","yScale",_lib.pluckNumber,UNDEF,function(datasetConfig){var ys=datasetConfig.yScale;datasetConfig.yScale=ys>=0&&ys<=40?ys/200:.2}],["usesameslantangle","useSameSlantAngle",_lib.pluckNumber,function(datasetConfig){return datasetConfig.streamLinedData?0:1}],["ishollow","isHollow",_lib.pluckNumber,UNDEF,function(datasetConfig){var isHollow=datasetConfig.isHollow;if(isHollow===UNDEF){datasetConfig.isHollow=datasetConfig.streamLinedData?1:0}}]])};_proto.prePointProcessingHookFn=function prePointProcessingHookFn(pointsArr){var datasetStore=this,chart=datasetStore.getFromEnv("chart"),chartConf=chart.config,conf=datasetStore.config,chartWorkingWidth=chartConf.canvasWidth,smartLabel=chart.getFromEnv("smartLabel"),nonStreamLinedData=!conf.streamLinedData,point,lineHeight,smartTextObj,origHeight;point=pointsArr[0];point&&(point.pseudoPoint=true);if(point&&point.displayValue){smartLabel.useEllipsesOnOverflow(chart.config.useEllipsesWhenOverflow);point.style.fontSize=this.computeFontSize(point.style.fontSizeWithUnit)+_lib.PXSTRING;smartLabel.setStyle(point.style);(0,_lib.setLineHeight)(point.style);lineHeight=parseFloat(point.style.lineHeight.match(/^\d+/)[0]||conf.lineHeight,10);origHeight=smartLabel.getOriSize(point.displayValue).height;smartTextObj=smartLabel.getSmartText(point.displayValue,chartWorkingWidth,origHeight);point.displayValue=smartTextObj.text;smartTextObj.tooltext&&(point.originalText=smartTextObj.tooltext);point.labelWidth=smartLabel.getOriSize(smartTextObj.text).width;chartConf.marginTop+=lineHeight+4}conf.totalValue=nonStreamLinedData?pointsArr[0].y-pointsArr[1].y:0;conf.offsetVal=function(i){return nonStreamLinedData?-(pointsArr[i+1]&&pointsArr[i+1].y||0):point.y}};_proto.datasetCalculations=function datasetCalculations(dataArr){var datasetStore=this,conf=datasetStore.config,numberFormatter=datasetStore.getFromEnv("number-formatter"),index,length,dataObj,itemValue,res={},isStreamLinedData=conf.streamLinedData,percentOfPrevious=conf.percentOfPrevious;res.highestValue=Number.NEGATIVE_INFINITY;res.refreshedData=[];res.sumValue=res.countPoint=0;for(index=0,length=dataArr.length;index<length;index++){dataObj=dataArr[index];if(dataObj.vline){continue}dataObj.cleanValue=itemValue=Math.abs(numberFormatter.getCleanValue(dataObj.value,true));if(itemValue!==null){res.hasValidPoint=true;res.highestValue=res.highestValue||itemValue;res.refreshedData.push(dataObj);res.sumValue+=itemValue;res.countPoint+=1;res.highestValue=Math.max(res.highestValue,itemValue)}}if(isStreamLinedData){res.sumValue=res.highestValue;percentOfPrevious&&(res.prevPerValReq=true)}return res};_proto.calculatePositionOfPlots=function calculatePositionOfPlots(){var datasetStore=this,chart=datasetStore.getFromEnv("chart"),chartConfig=chart.config,conf=datasetStore.config,utils=datasetStore.utils(datasetStore),getSumValueOfObjArrByKey=utils.getSumValueOfObjArrByKey,DistributionMatrix=utils.DistributionMatrix,calculatePositionCoordinate=datasetStore.calculatePositionCoordinate,psmMargin=conf.psmMargin,dataStore=datasetStore.getChildren("data"),index,length,plotObj,unitHeight,streamLinedData=conf.streamLinedData,heightAllotted,widthAllotted,drawingRadius,section=2,dataStoreLength=datasetStore.getDataLength(),maxDataValue=conf.maxValue=dataStore[0].y,minDataValue=conf.minValue=dataStore[dataStoreLength-1].y,mvMockNonStreamLine,alignmentType,uh,distributionKey,currentSliceHeight=0,blockLabelLenFromOffset,blockLenFromOffset=0,lineHeight=conf.lineHeight,mFloorFn=Math.floor,distributedResult,dMatrix,adMatrix,curr,ele,forceKeys,fKey,distributionMatrix;if(!conf.sumValue){return}datasetStore.postPlotCallback=_lib.stubFN;chartConfig.canvasTop+=chartConfig.marginTop-psmMargin.top;chartConfig.effCanvasHeight=heightAllotted=chartConfig.canvasHeight-(chartConfig.marginTop+chartConfig.marginBottom)+(psmMargin.top+psmMargin.bottom);chartConfig.effCanvasWidth=widthAllotted=chartConfig.width-(chartConfig.marginLeft+chartConfig.marginRight);drawingRadius=conf.drawingRadius=widthAllotted/section;conf.x=chartConfig.canvasLeft+(chartConfig.canvasRight-chartConfig.canvasLeft)/2;if(streamLinedData&&dataStoreLength<2){return}if(!streamLinedData){uh=unitHeight=maxDataValue?heightAllotted/maxDataValue:heightAllotted}else{unitHeight=heightAllotted/(maxDataValue-minDataValue);mvMockNonStreamLine=getSumValueOfObjArrByKey(dataStore,"value");uh=mvMockNonStreamLine?heightAllotted/mvMockNonStreamLine:heightAllotted}conf.unitHeight=unitHeight;conf.lastRadius=drawingRadius;conf.globalMinXShift=0;alignmentType=conf.alignmentType={};alignmentType["default"]=1;alignmentType.alternate=2;distributionMatrix=new DistributionMatrix(mFloorFn(heightAllotted/lineHeight));for(index=0,length=dataStoreLength;index<length;index++){plotObj=dataStore[index];if(plotObj.getState("removed")){continue}if(!streamLinedData&&index===0||!streamLinedData&&index===length-1){distributionMatrix.forcePush(plotObj,index);continue}currentSliceHeight=plotObj.y*uh;blockLenFromOffset+=plotObj.y*uh;blockLabelLenFromOffset=blockLenFromOffset-currentSliceHeight+currentSliceHeight/2;distributionKey=mFloorFn(blockLabelLenFromOffset/lineHeight);distributionMatrix.push(plotObj,distributionKey)}distributedResult=distributionMatrix.getDistributedResult();dataStore.length=0;if(distributedResult.matrix[1]===UNDEF){[].push.apply(dataStore,distributedResult.matrix[0])}else{dMatrix=distributedResult.matrix[0];adMatrix=distributedResult.matrix[1];length=Math.max(dMatrix.length,adMatrix.length);for(index=0;index<length;index++){ele=dMatrix[index];curr=adMatrix[index];dataStore.push(ele||curr)}}forceKeys=Object.keys(distributedResult.forceMatrix);if(forceKeys.length>0){for(fKey in distributedResult.forceMatrix){[].splice.apply(dataStore,[parseInt(fKey,10),0].concat(distributedResult.forceMatrix[fKey]))}}switch(distributedResult.suggestion){case alignmentType["default"]:calculatePositionCoordinate.call(datasetStore,dataStore,false);break;case alignmentType.alternate:conf.labelAlignment=alignmentType.alternate;section=3;drawingRadius=widthAllotted/section;chartConfig.canvasLeft=chartConfig.canvasWidth/2-drawingRadius;conf.x=chartConfig.canvasLeft+drawingRadius;calculatePositionCoordinate.call(datasetStore,dataStore,true);break}};_proto.draw=function draw(){var datasetStore=this,chart=datasetStore.getFromEnv("chart"),conf=datasetStore.config,trackerArgs=datasetStore.config.trackerArgs=[],dataStore=datasetStore.getChildren("data"),index,length,dlGroup=chart.getChildContainer("datalabelsGroup"),streamLinedData=conf.streamLinedData,dataStoreLength=dataStore.length,mMinFn=Math.min,slicingDistance,noOfGap,halfDistance,point,postPlotCallbackInitiated;datasetStore.config.labelDrawingConfig=datasetStore.config.labelDrawingConfig||[];datasetStore.config.labelDrawingConfig.length=0;if(!conf.sumValue){return}datasetStore.animateFunction=function(group){return function(){group.attr({opacity:1})}};slicingDistance=conf.slicingDistance;halfDistance=slicingDistance/2;if(streamLinedData&&dataStoreLength<2){datasetStore.hide(datasetStore.getChildren("data"),dataStoreLength);return}for(index=0,length=dataStore.length;index<length;index++){dataStore[index]&&dataStore[index].shapeArgs&&!dataStore[index].getState("removed")&&(dataStore[index].shapeArgs.renderer=chart.getFromEnv("paper"))}noOfGap=conf.noOfGap;if(noOfGap){conf.perGapDistance=mMinFn(halfDistance*1.5,slicingDistance/noOfGap);conf.distanceAvailed=halfDistance}index=dataStore.length;if(conf.alreadyPlotted){datasetStore.postPlotCallback=function(){if(postPlotCallbackInitiated){return}postPlotCallbackInitiated=true;datasetStore.animateFunction(dlGroup)()}}while(index--){point=dataStore[index];point.index=index;point.syncDraw()}conf.oldLastData=Object.assign({},dataStore[dataStore.length-1].shapeArgs);datasetStore.hide(datasetStore.getChildren("data"),dataStoreLength);conf.connectorEndSwitchHistoryY={};index=dataStore.length;while(index--){if(!dataStore[index].getState("removed")){trackerArgs.push(dataStore[index])}}datasetStore.addJob("labelDrawID",datasetStore.drawAllLabels.bind(datasetStore),_schedular.priorityList.label);datasetStore.addJob("trackerDrawID",datasetStore.drawAllTrackers.bind(datasetStore),_schedular.priorityList.tracker);datasetStore.removePlots();conf.alreadyPlotted=true;conf.prevIs2d=conf.is2d};_proto.getTooltipMacroStub=function getTooltipMacroStub(options){var datasetStore=this,conf=datasetStore.config,numberFormatter=datasetStore.getFromEnv("number-formatter"),baseStub,percentOfPrevValue;if(conf.streamLinedData){percentOfPrevValue=conf.percentOfPrevious?options.pValue:numberFormatter.percentValue(options.dataValue/options.prevValue*100)}baseStub=_FunnelPyramidBaseDat.prototype.getTooltipMacroStub.call(this,options);baseStub.percentValue=conf.percentOfPrevious?numberFormatter.percentValue(options.dataValue/options.highestValue*100):options.pValue;baseStub.percentOfPrevValue=percentOfPrevValue;return baseStub};return FunnelDataset}(_funnelpyramidbase.default);var _default=exports.default=FunnelDataset;