@fusioncharts/charts
Version:
JavaScript Data Visualisation Library
1 lines • 14.1 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 _pie2d=_interopRequireDefault(require("../../dataset/pie2d"));var _commonchartapi=_interopRequireDefault(require("../_internal/commonchartapi"));var _lib=require("@fusioncharts/core/src/lib");var _caption=_interopRequireDefault(require("../../_internal/components/caption"));var _subCaption=_interopRequireDefault(require("../../_internal/components/sub-caption"));var _background=_interopRequireDefault(require("../../_internal/components/background"));var _pieDataset=_interopRequireDefault(require("../../factories/pie-dataset"));var _legend=_interopRequireDefault(require("../../factories/legend"));var _legendSpacemanager=require("../_internal/legend-spacemanager");var _schedular=require("@fusioncharts/core/src/schedular");var math=Math,mathMin=math.min,mathMax=math.max,mathAbs=math.abs,mathPI=math.PI,mathRound=math.round,deg2rad=mathPI/180,rad2deg=180/mathPI,PIE_STR="pie",CHART_STR="Pie Chart",PIE2D_STR="Pie2D",count=0,UNDEF,performSlicing=function performSlicing(dataset,indx,slice){var sliceVal=!!slice,index=indx,willSlice=function willSlice(dataPlot){return sliceVal!==dataPlot.config.sliced||typeof slice==="undefined"},data,dataConfig,output,selectedDataPlot;if(!dataset){return output}data=dataset.components&&dataset.components.data||[];index=dataset.config.reversePlotOrder?data.length-index-1:index;selectedDataPlot=data[index];if(selectedDataPlot){dataConfig=selectedDataPlot.config;if(willSlice(selectedDataPlot)){output=dataset.plotGraphicClick.call(selectedDataPlot.graphics.element)}else{output=dataConfig.sliced}}return output};var Pie2D=function(_CommonAPI){function Pie2D(){var _this;_this=_CommonAPI.call(this)||this;_this.defaultSeriesType=PIE_STR;_this.defaultPlotShadow=1;_this.reverseLegend=1;_this.defaultPaletteOptions=UNDEF;_this.sliceOnLegendClick=true;_this.dontShowLegendByDefault=true;_this.defaultZeroPlaneHighlighted=false;_this.hasCanvas=true;_this.eiMethods={isPlotItemSliced:function isPlotItemSliced(index){var data,config,apiInstance=this.apiInstance,dataset=apiInstance&&apiInstance.getDatasets();return dataset&&(dataset=dataset[0])&&(data=dataset.components.data)&&data[index]&&(config=data[index].config)&&config.sliced},addData:function addData(){var apiInstance=this.apiInstance,dataset=apiInstance&&apiInstance.getDatasets();return dataset&&(dataset=dataset[0])&&dataset.addData.apply(dataset,arguments)},removeData:function removeData(){var apiInstance=this.apiInstance,dataset=apiInstance&&apiInstance.getDatasets();return dataset&&(dataset=dataset[0])&&dataset.removeData.apply(dataset,arguments)},updateData:function updateData(){var apiInstance=this.apiInstance,dataset=apiInstance&&apiInstance.getDatasets();return dataset&&(dataset=dataset[0])&&dataset.updateData.apply(dataset,arguments)},slicePlotItem:function slicePlotItem(index,slice,callback){var fcInstance=this,apiInstance=fcInstance.apiInstance;if(callback){apiInstance.addJob("eiMethods-slice-plot"+count++,(function(){var slicingResult=performSlicing(apiInstance.getDatasets()[0],index,slice);return typeof callback==="function"&&callback(slicingResult)}),_schedular.priorityList.postRender)}else{return performSlicing(apiInstance.getDatasets()[0],index,slice)}},startingAngle:function startingAngle(angle,relative,callback){var chart=this.apiInstance,output;if(callback){chart.addJob("eiMethods-start-angle"+count++,(function(){output=chart._startingAngle(angle,relative);if(typeof callback==="function"){callback(output)}}),_schedular.priorityList.postRender)}else{return chart._startingAngle(angle,relative)}}};_this.registerFactory("dataset",_pieDataset.default,["vCanvas","legend"]);_this.registerFactory("legend",_legend.default);return _this}(0,_inheritsLoose2.default)(Pie2D,_CommonAPI);Pie2D.getName=function getName(){return"Pie2D"};var _proto=Pie2D.prototype;_proto.getName=function getName(){return"Pie2D"};_proto.__setDefaultConfig=function __setDefaultConfig(){_CommonAPI.prototype.__setDefaultConfig.call(this);var config=this.config;config.alignCaptionWithCanvas=0;config.formatnumberscale=1;config.isSingleSeries=true;config.friendlyName=CHART_STR;config.defaultDatasetType=PIE2D_STR;config.plotborderthickness=1;config.decimals=2;config.alphaanimation=0;config.singletonPlaceValue=true;config.usedataplotcolorforlabels=0;config.enableslicing=_lib.ONESTRING;config.skipCanvasDrawing=true};_proto.parseChartAttr=function parseChartAttr(dataObj){_CommonAPI.prototype.parseChartAttr.call(this,dataObj);var iapi=this,chartAttrs=iapi.getFromEnv("chart-attrib");iapi.config.showLegend=(0,_lib.pluckNumber)(chartAttrs.showlegend,0);iapi.config.showvalues=(0,_lib.pluckNumber)(chartAttrs.showvalues,1);iapi.config.showlabels=(0,_lib.pluckNumber)(chartAttrs.showlabels,1)};_proto.configureAttributes=function configureAttributes(dataObj){var iapi=this,chartConfig=iapi.config,toolTipController;iapi.parseChartAttr(dataObj);iapi.createComponent(dataObj);iapi.config.skipConfigureIteration.axis=true;iapi.configureChildren();toolTipController=iapi.getFromEnv("toolTipController");toolTipController.setStyle({backgroundColor:_lib.hasSVG?(0,_lib.convertColor)(chartConfig.tooltipbgcolor||"FFF",chartConfig.tooltipbgalpha||100):(chartConfig.tooltipbgcolor||"FFF").replace(/\s+/g,"").replace(/^#?([a-f0-9]+)/gi,"#$1"),color:(chartConfig.tooltipcolor||chartConfig.basefontcolor||"545454").replace(/^#?([a-f0-9]+)/gi,"#$1"),borderColor:_lib.hasSVG?(0,_lib.convertColor)(chartConfig.tooltipbordercolor||"666",chartConfig.tooltipborderalpha||100):(chartConfig.tooltipbordercolor||"666").replace(/\s+/g,"").replace(/^#?([a-f0-9]+)/gi,"#$1"),borderWidth:(0,_lib.pluckNumber)(chartConfig.tooltipborderthickness,1)+"px",showToolTipShadow:(0,_lib.pluckNumber)(chartConfig.showtooltipshadow||0),borderRadius:(0,_lib.pluckNumber)(chartConfig.tooltipborderradius,0)+"px",fontSize:(0,_lib.pluckNumber)(this.computeFontSize(chartConfig.basefontsize),10)+"px",fontFamily:chartConfig.basefont||this.getFromEnv("style").inCanfontFamily,padding:(0,_lib.pluckNumber)(chartConfig.tooltippadding||3)+"px"})};_proto.createComponent=function createComponent(){var iapi=this,skipConfigureIteration;skipConfigureIteration=iapi.config.skipConfigureIteration={};iapi.createBaseComponent();iapi.getFromEnv("animationManager").setAnimationState(iapi._firstConfigure?"initial":"update");(0,_lib.componentFactory)(iapi,_caption.default,"caption");skipConfigureIteration.caption=true;(0,_lib.componentFactory)(iapi,_subCaption.default,"subCaption");skipConfigureIteration.subCaption=true;(0,_lib.componentFactory)(iapi,_background.default,"background");skipConfigureIteration.background=true;skipConfigureIteration.canvas=true;iapi._createConfigurableComponents&&iapi._createConfigurableComponents();if(iapi.config.realtimeEnabled){iapi._realTimeConfigure&&iapi._realTimeConfigure()}};_proto._postSpaceManagement=function _postSpaceManagement(){this.config.showLegend&&this.getChildren("legend")&&this.getChildren("legend")[0].postSpaceManager();this.allocateDimensionOfChartMenuBar()};_proto._checkInvalidSpecificData=function _checkInvalidSpecificData(){var chart=this,chartAttr=chart.getFromEnv("dataSource"),i,len,zeroSum=0,nullSum=0,data=chartAttr.data,value;if(!data){return true}len=data.length||0;for(i=0;i<len;i++){value=Number(data[i].value);zeroSum+=!isNaN(value)&&value===0?1:0;nullSum+=isNaN(value)?1:0}if(zeroSum+nullSum>=len){return true}return false};_proto._spaceManager=function _spaceManager(){var chart=this,chartConfig=chart.config,dataSet=chart.getChildren("dataset")[0],data=dataSet.components.data,conf=dataSet.config,legend=chart.getFromEnv("legend"),colorM=chart.getFromEnv("color-manager"),SmartLabel=chart.getFromEnv("smartLabel"),chartwidth=chart.getFromEnv("chartWidth"),chartHeight=chart.getFromEnv("chartHeight"),textWidthArr=[],length=conf.dataLabelCounter,labelMaxW=0,fcJSONChart=chart.getFromEnv("dataSource").chart,manageLabelOverflow=(0,_lib.pluckNumber)(fcJSONChart.managelabeloverflow,0),userGivenSlicingDist=(0,_lib.pluckNumber)(fcJSONChart.slicingdistance),slicingDistance=!conf.preSliced&&chartConfig.allPlotSliceEnabled===_lib.ZEROSTRING&&(fcJSONChart.showlegend!==_lib.ONESTRING||fcJSONChart.interactivelegend===_lib.ZEROSTRING)?0:mathAbs((0,_lib.pluckNumber)(userGivenSlicingDist,20)),isPieRadiusInPerentage=/%/g.test(fcJSONChart.pieradius),pieRadius=(0,_lib.pluckNumber)(isPieRadiusInPerentage?Math.min(chartwidth/2,chartHeight/2)*(parseFloat(fcJSONChart.pieradius)/100):fcJSONChart.pieradius,0),enableSmartLabels=(0,_lib.pluckNumber)(fcJSONChart.enablesmartlabels,fcJSONChart.enablesmartlabel,1),skipOverlapLabels=enableSmartLabels?(0,_lib.pluckNumber)(fcJSONChart.skipoverlaplabels,fcJSONChart.skipoverlaplabel,1):0,isSmartLineSlanted=(0,_lib.pluckNumber)(fcJSONChart.issmartlineslanted,1),labelDistance=length?(0,_lib.pluckNumber)(fcJSONChart.labeldistance,fcJSONChart.smartlabelclearance,5):slicingDistance,totalDistnace,width=chartConfig.width,height=chartConfig.height,actionBarHeight=(chart._manageActionBarSpace(height*.225)||{}).bottom,chartWorkingWidth=width-(chartConfig.marginRight+chartConfig.marginLeft),chartWorkingHeight=height-(chartConfig.marginTop+chartConfig.marginBottom)-(actionBarHeight?actionBarHeight+chartConfig.marginBottom:0),minOfWH=mathMin(chartWorkingHeight,chartWorkingWidth),smartLineColor=(0,_lib.pluck)(fcJSONChart.smartlinecolor,colorM.getColor("plotFillColor")),smartLineAlpha=(0,_lib.pluckNumber)(fcJSONChart.smartlinealpha,100),smartLineThickness=(0,_lib.pluckNumber)(fcJSONChart.smartlinethickness,.7),dataLabelOptions=conf.dataLabelOptions=dataSet._parseDataLabelOptions(),style=dataLabelOptions.style,lineHeight=length?(0,_lib.pluckNumber)(parseInt(style.lineHeight,10),12):0,pieMinRadius=pieRadius===0?minOfWH*.15:pieRadius,pieMinDia=2*pieMinRadius,legendSpace,captionSpace,pieYScale=conf.pieYScale,pieSliceDepth=conf.pieSliceDepth,textObj,avaiableMaxpieSliceDepth,totalSpaceReq,legendPos=(0,_lib.pluck)(fcJSONChart.legendposition,_lib.POSITION_BOTTOM).toLowerCase().split("-");dataLabelOptions.connectorWidth=smartLineThickness;dataLabelOptions.connectorPadding=(0,_lib.pluckNumber)(fcJSONChart.connectorpadding,5);dataLabelOptions.connectorColor=(0,_lib.convertColor)(smartLineColor,smartLineAlpha);totalDistnace=!(chartConfig.showvalues||chartConfig.showlabels)?labelDistance:conf.labelPosition!=="inside"||conf.valuePosition!=="inside"?labelDistance+slicingDistance:labelDistance;totalSpaceReq=pieMinDia+(lineHeight+totalDistnace)*2;captionSpace=chart._manageChartMenuBar(totalSpaceReq<chartWorkingHeight?chartWorkingHeight-totalSpaceReq:chartWorkingHeight/2);chartWorkingHeight-=(captionSpace.top||0)+(captionSpace.bottom||0);if(conf.showLegend){chart.config.hasLegend=true;if(legendPos[0]===_lib.POSITION_RIGHT||legendPos[0]===_lib.POSITION_LEFT){legendSpace=legend._manageLegendPosition(chartWorkingHeight/2);chartWorkingWidth-=mathMax(legendSpace.left,legendSpace.right)}else{legendSpace=legend._manageLegendPosition(chartWorkingHeight/2);chartWorkingHeight-=mathMax(legendSpace.top,legendSpace.bottom)}legendSpace&&chart._allocateSpace(legendSpace)}SmartLabel.useEllipsesOnOverflow(chartConfig.useEllipsesWhenOverflow);if(length!==1){for(;length--;){SmartLabel.setStyle(data[length].config.style||chartConfig.dataLabelStyle);textWidthArr[length]=textObj=SmartLabel.getOriSize(data[length].config.displayValue);labelMaxW=conf.labelPosition!=="inside"||conf.valuePosition!=="inside"?mathMax(labelMaxW,textObj.width):0}}if(pieRadius===0){pieMinRadius=chart._stubRadius(chartWorkingWidth,labelMaxW,chartWorkingHeight,totalDistnace,slicingDistance,lineHeight,pieMinRadius,labelDistance)}else{conf.slicingDistance=slicingDistance;conf.pieMinRadius=pieMinRadius;dataLabelOptions.distance=labelDistance}avaiableMaxpieSliceDepth=chartWorkingHeight-2*(pieMinRadius*pieYScale+lineHeight);conf.managedPieSliceDepth=pieSliceDepth>avaiableMaxpieSliceDepth?pieSliceDepth-avaiableMaxpieSliceDepth:conf.pieSliceDepth;dataLabelOptions.isSmartLineSlanted=isSmartLineSlanted;dataLabelOptions.enableSmartLabels=enableSmartLabels;dataLabelOptions.skipOverlapLabels=skipOverlapLabels;dataLabelOptions.manageLabelOverflow=manageLabelOverflow};_proto._stubRadius=function _stubRadius(chartWorkingWidth,labelMaxW,chartWorkingHeight,totalDist,sliceDistance,lineHeight,minRadius,labelDistance){var chart=this,pieMinRadius=minRadius,slicingDistance=sliceDistance,dataSet=chart.getChildren("dataset")[0],conf=dataSet.config,fcJSONChart=chart.getFromEnv("dataSource").chart,userGivenSlicingDist=(0,_lib.pluckNumber)(fcJSONChart.slicingdistance),dataLabelOptions=conf.dataLabelOptions||(conf.dataLabelOptions=dataSet._parseDataLabelOptions()),availableRadius=0,MINSLICINGDIST=10,shortFall;availableRadius=mathMin(chartWorkingWidth/2-labelMaxW-slicingDistance,chartWorkingHeight/2-lineHeight)-totalDist;if(availableRadius>=pieMinRadius){pieMinRadius=availableRadius}else if(!userGivenSlicingDist){shortFall=pieMinRadius-availableRadius;slicingDistance=mathMax(mathMin(totalDist-shortFall,slicingDistance),MINSLICINGDIST)}conf.slicingDistance=slicingDistance;conf.pieMinRadius=pieMinRadius;dataLabelOptions.distance=labelDistance;return pieMinRadius};_proto._startingAngle=function _startingAngle(angl,relative){var angle=angl,ang,chart=this,dataSet=chart.getChildren("dataset")[0],seriesData=dataSet.config,currentAngle=(ang=seriesData.startAngle)*-rad2deg+(-1*ang<0?360:0);if(!isNaN(angle)){if(!(seriesData.singletonCase||seriesData.isRotating)){angle+=relative?currentAngle:0;seriesData.startAngle=-angle*deg2rad;dataSet._rotate(angle);currentAngle=angle}}return mathRound(((currentAngle%=360)+(currentAngle<0?360:0))*100)/100};_proto._manageLegendSpace=function _manageLegendSpace(){_legendSpacemanager._manageLegendSpace.call(this)};_proto.getDSdef=function getDSdef(){return _pie2d.default};return Pie2D}(_commonchartapi.default);var _default=exports.default=Pie2D;