@fusioncharts/charts
Version:
JavaScript Data Visualisation Library
1 lines • 6.79 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 _lib=require("@fusioncharts/core/src/lib");var _bar2d=_interopRequireDefault(require("../bar2d"));var UNDEF,visibleStr=_lib.preDefStr.visibleStr,hiddenStr=_lib.preDefStr.hiddenStr,POSITION_MIDDLE=_lib.preDefStr.POSITION_MIDDLE,POSITION_START=_lib.preDefStr.POSITION_START,POSITION_END=_lib.preDefStr.POSITION_END,math=Math,mathMax=math.max,defined=function defined(obj){return obj!==UNDEF&&obj!==null};function checkOverlap(currDataDimensions,prevDataDimensions){var i,len,currentLabelXPos=currDataDimensions.x,prevLabelXPos,currentLabelWidth=currDataDimensions.width,prevlabelWidth;for(i=0,len=prevDataDimensions.length;i<len;i++){prevlabelWidth=prevDataDimensions[i].width;prevLabelXPos=prevDataDimensions[i].x;if(prevDataDimensions[i].labelShown&¤tLabelXPos+currentLabelWidth>=prevLabelXPos&&prevLabelXPos+prevlabelWidth>=currentLabelXPos){return true}}return false}var OverlappedColumn=function(_Bar){function OverlappedColumn(){var _this;_this=_Bar.call(this)||this;_this._labeldimensionMap={};return _this}(0,_inheritsLoose2.default)(OverlappedColumn,_Bar);var _proto=OverlappedColumn.prototype;_proto.drawLabel=function drawLabel(){var dataSet=this,chart=dataSet.getFromEnv("chart"),chartConf=chart.config,conf=dataSet.config,JSONData=conf.JSONData,animationManager=dataSet.getFromEnv("animationManager"),toolTipController=dataSet.getFromEnv("toolTipController"),canvasConf=chart.getChildren("canvas")[0].config,style=chart.config.dataLabelStyle,setDataArr=JSONData.data,categories=chart.config.categories,is3D=chart.config.is3D,isStacked=chart.config.isstacked,catLen=categories&&categories.length,dataSetLen=setDataArr&&setDataArr.length,len,dataStore=dataSet.getData(),SmartLabel=chart.getFromEnv("smartLabel"),dataObj,attr,yDepth=canvasConf.yDepth,xDepth=canvasConf.xDepth,numberFormatter=chart.getFromEnv("number-formatter"),i,j,displayValue=_lib.BLANKSTRING,setData,placeValuesInside=chartConf.placevaluesinside,canvasWidth=chartConf.canvasWidth,canvasLeft=chartConf.canvasLeft,graphic,height,gutter=2,valuePadding,textY,textX,outsideColSpace,isNegative,yPos,xPos,width,setValue,dataLabelContainer=dataSet.getContainer("labelGroup"),textAnchor,textWidth,xAdjust,GUTTER_4=4,skipInfo=dataSet.getSkippingInfo&&dataSet.getSkippingInfo(),skippingApplied=skipInfo&&skipInfo.skippingApplied,plotDrawArray=skipInfo&&skipInfo.labelDraw||[],plotDrawArrayLength=plotDrawArray.length,config,plotLabel,prevDataDims,currentDataDim,currDatasetIndex=dataSet.getJSONIndex(),skipLabelDraw,plotLabelCheck,dim,tempGraphics,visible=dataSet.getState("visible"),hideCallback=function hideCallback(){this.hide()},showCallback=function showCallback(){this.show()};visible&&dataLabelContainer.show();SmartLabel.setStyle(style);len=skippingApplied?plotDrawArrayLength:catLen<dataSetLen?catLen:dataSetLen;for(j=0;j<len;j++){i=skippingApplied?plotDrawArray[j]:j;dataObj=dataStore[i];config=dataObj&&dataObj.config;setValue=config&&config.setValue;if(dataObj===UNDEF||setValue===UNDEF||setValue===null||config.labelSkip===true){tempGraphics=dataObj&&dataObj.graphics;if(tempGraphics){tempGraphics.label&&tempGraphics.label.hide()}config&&delete config.labelSkip;continue}graphic=dataObj.graphics;if(!graphic){continue}setData=setDataArr[i];yPos=dataObj._yPos;xPos=dataObj._xPos;setValue=numberFormatter.getCleanValue(setData.value);isNegative=(0,_lib.pluckNumber)(setValue)<0;height=dataObj._height;width=dataObj._width;valuePadding=config.valuePadding+gutter;textAnchor=isStacked?POSITION_MIDDLE:isNegative?placeValuesInside?POSITION_START:POSITION_END:placeValuesInside?POSITION_END:POSITION_START;displayValue=config.displayValue;plotLabelCheck=graphic.label;if(config.showValue&&defined(displayValue)&&displayValue!==_lib.BLANKSTRING&&setValue!==null){attr={text:displayValue,fill:style.color,"text-bound":[style.backgroundColor,style.borderColor,style.borderThickness,style.borderPadding,style.borderRadius,style.borderDash],"line-height":style.lineHeight,visibility:dataSet.getState("visible")?visibleStr:hiddenStr};dim=SmartLabel.getOriSize(displayValue);textWidth=dim.width;textWidth+=valuePadding;xAdjust=valuePadding;textY=yPos+height*.5;textX=xPos+(isNegative?0:width);if(isNegative){outsideColSpace=xPos-canvasLeft}else{outsideColSpace=canvasLeft+canvasWidth-(xPos+width)}if(placeValuesInside){if(width>=textWidth){textX+=isNegative?xAdjust:-xAdjust;if(is3D){textY+=yDepth;textX-=xDepth}}else{if(textWidth<outsideColSpace){textX+=isNegative?-xAdjust:xAdjust;textAnchor=isNegative?POSITION_END:POSITION_START;if(is3D&&isNegative){textX-=xDepth}}else{if(isNegative){textX=xPos+width+mathMax(textWidth-xPos-width+canvasLeft,0)-xAdjust;textAnchor=POSITION_END}else{textX=xPos-mathMax(textWidth-(canvasLeft+canvasWidth-xPos),0)+xAdjust;textAnchor=POSITION_START}}}}else{if(outsideColSpace>=textWidth){textX+=isNegative?-xAdjust:xAdjust;if(is3D&&isNegative){textX-=xDepth;textY+=xDepth}}else{textX+=isNegative?xAdjust+textWidth:-(xAdjust+textWidth)}}if(textX>canvasLeft+canvasWidth||textX<canvasLeft){textX=canvasLeft+GUTTER_4;textAnchor=POSITION_START}attr["text-anchor"]=textAnchor;attr.x=textX;attr.y=textY;attr["text-bound"]=[style.backgroundColor,style.borderColor,style.borderThickness,style.borderPadding,style.borderRadius,style.borderDash];attr.opacity=visible?1:0;prevDataDims=chart.getDatasets().map((function(dataset){return dataset.getJSONIndex()<currDatasetIndex&&dataset._labeldimensionMap[j]})).filter(Boolean);currentDataDim={x:textX,y:textY,width:dim.width,height:dim.height};skipLabelDraw=checkOverlap(currentDataDim,prevDataDims);dataSet._labeldimensionMap[j]=currentDataDim;if(!skipLabelDraw){plotLabel=animationManager.setAnimation({el:plotLabelCheck||"text",container:dataLabelContainer,component:dataSet,attr:attr,callback:!visible?hideCallback:showCallback,label:"plotLabel"});plotLabel&&plotLabel.outlineText(conf.showTextOutline,attr.fill);if(chartConf.showtooltip&&plotLabel.abbrArr&&plotLabel.abbrArr.length){toolTipController.enableToolTip(plotLabel,UNDEF)}if(!plotLabelCheck){graphic.label=plotLabel}}else if(graphic.label){graphic.label=animationManager.setAnimation({el:graphic.label,component:dataSet});dataSet._labeldimensionMap[j].labelShown=false}if(visible&&!skipLabelDraw){dataSet._labeldimensionMap[j].labelShown=true}else{dataSet._labeldimensionMap[j].labelShown=false}}else if(graphic.label){graphic.label=animationManager.setAnimation({el:graphic.label,component:dataSet});dataSet._labeldimensionMap[j].labelShown=false}}};return OverlappedColumn}(_bar2d.default);var _default=exports.default=OverlappedColumn;