UNPKG

@fusioncharts/widgets

Version:

FusionCharts JavaScript charting framework

1 lines 13.2 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 _pyramidPoint=_interopRequireDefault(require("../_internal/data/pyramid-point"));var UNDEF,POSITION_START=_lib.preDefStr.POSITION_START,POSITION_MIDDLE=_lib.preDefStr.POSITION_MIDDLE;var PyramidDataset=function(_FunnelPyramidBaseDat){function PyramidDataset(){var _this;_this=_FunnelPyramidBaseDat.call(this)||this;_this.preDrawingHook=function(){};_this.config.pointInContext=_pyramidPoint.default;_this.config.LABEL_PLACEMENT_ITERATOR_INDEX_START=0;return _this}(0,_inheritsLoose2.default)(PyramidDataset,_FunnelPyramidBaseDat);var _proto=PyramidDataset.prototype;_proto.getType=function getType(){return"dataset"};_proto.getName=function getName(){return"pyramid"};_proto.configure=function configure(datasetJSON){if(!datasetJSON){return false}this.config.JSONData=datasetJSON;var datasetDefStore=this,chartConfig=datasetDefStore.getFromEnv("chartConfig");if(!datasetDefStore._checkValidData(datasetDefStore.config.JSONData.data)){return}datasetDefStore._configure();chartConfig.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,[["pyramidyscale","yScale",_lib.pluckNumber,UNDEF,function(datasetConfig){var ys=datasetConfig.yScale;datasetConfig.yScale=ys>=0&&ys<=40?ys/200:.2}],["use3dlighting","use3DLighting",_lib.pluckNumber,1]])};_proto.calculatePositionOfPlots=function calculatePositionOfPlots(){var datasetStore=this,chart=datasetStore.getFromEnv("chart"),chartConfig=chart.config,conf=datasetStore.config,utils=datasetStore.utils(datasetStore),DistributionMatrix=utils.DistributionMatrix,calculatePositionCoordinate=datasetStore.calculatePositionCoordinate,psmMargin=conf.psmMargin,dataStore=datasetStore.getChildren("data"),index,length,plotObj,unitHeight,heightAllotted,widthAllotted,drawingRadius,section=2,dataStoreLength=dataStore.length,alignmentType,distributionKey,currentSliceHeight=0,blockLabelLenFromOffset,blockLenFromOffset=0,lineHeight=conf.lineHeight,mFloorFn=Math.floor,distributedResult,dMatrix,adMatrix,curr,ele,distributionMatrix,inclination;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;inclination=Math.atan(widthAllotted/2/heightAllotted);conf.unitHeight=unitHeight=heightAllotted/conf.sumValue;conf.lastRadius=0;conf.globalMinXShift=Math.floor(lineHeight/Math.cos(inclination));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}currentSliceHeight=plotObj.y*unitHeight;blockLenFromOffset+=plotObj.y*unitHeight;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)}}switch(distributedResult.suggestion){case alignmentType["default"]:calculatePositionCoordinate.call(datasetStore,dataStore,false);break;case alignmentType.alternate:conf.labelAlignment=alignmentType.alternate;section=3;conf.drawingRadius=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,dataStoreLength=dataStore.length,mMinFn=Math.min,slicingDistance,noOfGap,halfDistance,point,postPlotCallbackInitiated;if(!conf.sumValue){return}datasetStore.config.labelDrawingConfig=datasetStore.config.labelDrawingConfig||[];datasetStore.config.labelDrawingConfig.length=0;datasetStore.animateFunction=function(group){return function(){group.attr({opacity:1})}};slicingDistance=conf.slicingDistance;halfDistance=slicingDistance/2;for(index=0,length=dataStore.length;index<length;index++){dataStore[index]&&dataStore[index].shapeArgs&&(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}}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--){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.calculatePositionCoordinate=function calculatePositionCoordinate(dataArr,placeOtherSide){var datasetStore=this,conf=datasetStore.config,is2d=conf.is2d,x=conf.x,chart=datasetStore.getFromEnv("chart"),chartConfig=chart.config,y=chartConfig.canvasTop,unitHeight=conf.unitHeight,labelDistance=conf.labelDistance,showLabelsAtCenter=conf.showLabelsAtCenter,fontSize=chartConfig.style.fontSize,yShift=fontSize*.3,yScale=conf.yScale,blankSpace=conf.blankSpace,lastRadius=conf.lastRadius,smartLabel=datasetStore.getFromEnv("smartLabel"),index,length,point,sliceHeight,lastIndex=dataArr.length-1,alignmentSwitchToggle=false,distributionOffset=0,labelMeasurement,newRadius,negativeSpanningDataEnd,normalizedLabel,lineHeight=conf.lineHeight,totalValues=0,trimmedInfo={flag:false,point:UNDEF,sLabel:UNDEF,setAll:function setAll(flag,pt,sLabel){this.flag=flag;this.point=pt;this.sLabel=sLabel}},largestLabel={point:UNDEF,sLabel:UNDEF,set:function set(calcFn,predicate){var _calcFn=calcFn,_predicate=predicate;return function(pt,sLabel){var existingLabelSpan,currentLabelSpan;if(pt.dontPlot){return}if(!(this.point&&this.sLabel)){this.point=pt;this.sLabel=sLabel;return}existingLabelSpan=_calcFn(this.point,this.sLabel);currentLabelSpan=_calcFn(pt,sLabel);if(_predicate(existingLabelSpan,currentLabelSpan)){this.point=pt;this.sLabel=sLabel}}}},leftTrimmedInfo={},rightTrimmedInfo={},lLargestLabel={},rLargestLabel={},xPos,chartWidth=chart.config.width-2,slicingGapPosition=conf.slicingGapPosition={};(0,_lib.extend2)(leftTrimmedInfo,trimmedInfo);(0,_lib.extend2)(rightTrimmedInfo,trimmedInfo);leftTrimmedInfo.setAll=function(flag,pt,sLabel){var _point=this.point,_sLabel=this.sLabel,existingLabelSpan,currentLabelSpan;this.flag=flag;if(!(_point&&_sLabel)){this.point=pt;this.sLabel=sLabel;return}existingLabelSpan=_point.labelX-(_sLabel.oriTextWidth-_sLabel.width);currentLabelSpan=pt.labelX-(sLabel.oriTextWidth-sLabel.width);if(existingLabelSpan>currentLabelSpan){this.point=pt;this.sLabel=sLabel}};rightTrimmedInfo.setAll=function(flag,pt,sLabel){var _point=this.point,_sLabel=this.sLabel,existingLabelSpan,currentLabelSpan;this.flag=flag;if(!(_point&&_sLabel)){this.point=pt;this.sLabel=sLabel;return}existingLabelSpan=_point.labelX+_sLabel.oriTextWidth;currentLabelSpan=pt.labelX+sLabel.oriTextWidth;if(existingLabelSpan<currentLabelSpan){this.point=pt;this.sLabel=sLabel}};(0,_lib.extend2)(lLargestLabel,largestLabel);(0,_lib.extend2)(rLargestLabel,largestLabel);lLargestLabel.set=function(){return largestLabel.set.apply(lLargestLabel,[function(pt){return pt.labelX},function(existingLabelSpan,currentLabelSpan){return existingLabelSpan>currentLabelSpan}])}();rLargestLabel.set=function(){return largestLabel.set.apply(rLargestLabel,[function(pt,sLabel){return pt.labelX+sLabel.oriTextWidth},function(existingLabelSpan,currentLabelSpan){return existingLabelSpan<currentLabelSpan}])}();conf.noOfGap=0;smartLabel.useEllipsesOnOverflow(chartConfig.useEllipsesWhenOverflow);for(index=0,length=dataArr.length;index<length;index++){point=dataArr[index];if(!point){continue}point.x=index;if(point.plot){point.isSliced=!!point.isSliced||!!conf.isSliced}point.isSliced=(0,_lib.pluckNumber)(point.isSliced,conf.isSliced);placeOtherSide&&(alignmentSwitchToggle=!alignmentSwitchToggle);if(point.isSliced){xPos=point.x;if(xPos&&!slicingGapPosition[xPos]){slicingGapPosition[xPos]=true;conf.noOfGap+=1}if(xPos<lastIndex){slicingGapPosition[xPos+1]=true;conf.noOfGap+=1}}smartLabel.setStyle(point.style);point.oriText=point.displayValue;labelMeasurement=labelMeasurement=smartLabel.getSmartText(point.displayValue,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY);totalValues+=point.y;newRadius=conf.drawingRadius*totalValues/conf.sumValue;sliceHeight=unitHeight*point.y;point.shapeArgs={x:x,y:y,R1:lastRadius,R2:newRadius,h:sliceHeight,r3dFactor:yScale,gStr:"point",is2D:is2d,use3DLighting:!!conf.use3DLighting,renderer:datasetStore.getFromEnv("paper")};if(showLabelsAtCenter){point.labelAline=POSITION_MIDDLE;point.labelX=x;point.labelY=(is2d?y:y+yScale*lastRadius)+sliceHeight/2+yShift}else{point.labelAline=POSITION_START;point.alignmentSwitch=alignmentSwitchToggle;point.distributionFactor=point.distributionFactor||0;if(alignmentSwitchToggle){point.labelX=x-(labelDistance+(newRadius+lastRadius)/2+blankSpace+labelMeasurement.width);point.labelX-=point.distributionFactor*conf.globalMinXShift;lLargestLabel.set(point,labelMeasurement)}else{point.labelX=x+labelDistance+(newRadius+lastRadius)/2+blankSpace;point.labelX+=point.distributionFactor*conf.globalMinXShift;rLargestLabel.set(point,labelMeasurement)}distributionOffset=point.distributionFactor*lineHeight;point.labelY=y+yShift+sliceHeight/2+distributionOffset}if(placeOtherSide){if(alignmentSwitchToggle&&point.labelX<0){negativeSpanningDataEnd=point.labelX+labelMeasurement.width;normalizedLabel=smartLabel.getSmartText(point.displayValue,negativeSpanningDataEnd,Number.POSITIVE_INFINITY,true);point.labelX=2;point.isLabelTruncated=true;point.displayValue=normalizedLabel.text;point.virtualWidth=normalizedLabel.maxWidth;leftTrimmedInfo.setAll(true,point,normalizedLabel)}else if(!alignmentSwitchToggle&&point.labelX+labelMeasurement.width>chartWidth){normalizedLabel=smartLabel.getSmartText(point.displayValue,chartWidth-point.labelX,Number.POSITIVE_INFINITY,true);point.isLabelTruncated=true;point.displayValue=normalizedLabel.text;point.virtualWidth=normalizedLabel.maxWidth;rightTrimmedInfo.setAll(true,point,normalizedLabel)}point.pWidth=point.virtualWidth||labelMeasurement.width;distributionOffset=point.distributionFactor*lineHeight;point.labelY=y+yShift+sliceHeight/2+distributionOffset}y+=sliceHeight;point.plotX=x;point.plotY=y-sliceHeight/2;lastRadius=newRadius;point.virtualWidth=point.virtualWidth||labelMeasurement.width}datasetStore.findBestPosition(dataArr,{lTrimmedInfo:leftTrimmedInfo,rTrimmedInfo:rightTrimmedInfo,lLargestLabel:lLargestLabel,rLargestLabel:rLargestLabel})};_proto.getTooltipMacroStub=function getTooltipMacroStub(options){var datasetStore=this,conf=datasetStore.config,numberFormatter=datasetStore.getFromEnv("number-formatter"),baseStub,percentOfPrevValue;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 PyramidDataset}(_funnelpyramidbase.default);var _default=exports.default=PyramidDataset;