UNPKG

@fusioncharts/charts

Version:

JavaScript Data Visualisation Library

1 lines 6.6 kB
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports.drawLabel=exports.default=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _column=_interopRequireDefault(require("../column"));var _lib=require("@fusioncharts/core/src/lib");var _dependencyManager=require("@fusioncharts/core/src/dependency-manager");var _index=_interopRequireDefault(require("./index.animation"));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,mathMin=math.min,mathMax=math.max,defined=function defined(obj){return obj!==UNDEF&&obj!==null},_drawLabel=exports.drawLabel=function drawLabel(start,end){var dataSet=this,chart=dataSet.getFromEnv("chart"),toolTipController=dataSet.getFromEnv("toolTipController"),chartConf=chart.config,conf=dataSet.config,JSONData=conf.JSONData,animationManager=dataSet.getFromEnv("animationManager"),canvasConf=chart.getChildren("canvas")[0].config,style=chart.config.dataLabelStyle,plotDataLabelStyle,setDataArr=JSONData.data,categories=chart.config.categories,is3D=chart.config.is3D,isStacked=chart.config.isstacked,catLen=categories&&categories.length,dataSetLen=setDataArr&&setDataArr.length,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,startIndex=(0,_lib.pluckNumber)(start,0),endIndex=(0,_lib.pluckNumber)(end,skippingApplied?plotDrawArrayLength:catLen<dataSetLen?catLen:dataSetLen),notParticularLabeDraw=plotDrawArrayLength===Math.abs(endIndex-(startIndex+1)),config,plotLabel,plotLabelCheck,dim,tempGraphics,visible=dataSet.getState("visible"),callback=function callback(){this.hide()};visible&&dataLabelContainer.show();SmartLabel.setStyle(style);for(j=startIndex;j<endIndex;j++){var _SmartLabel$getOriSiz;i=skippingApplied&&notParticularLabeDraw?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(width<((_SmartLabel$getOriSiz=SmartLabel.getOriSize(displayValue))==null?void 0:_SmartLabel$getOriSiz.width)&&isStacked){config.showValue=0}if(config.showValue&&defined(displayValue)&&displayValue!==_lib.BLANKSTRING&&setValue!==null){plotDataLabelStyle=config.dataLabelStyle;attr={text:displayValue,fill:plotDataLabelStyle.color,"text-bound":[plotDataLabelStyle.backgroundColor,plotDataLabelStyle.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(isStacked){textX+=(isNegative?width:-width)*.5;textX=mathMax(canvasLeft+textWidth*.5,textX);textX=mathMin(canvasLeft+canvasWidth-textWidth*.5,textX);textX-=is3D?xDepth:0;textY+=is3D?yDepth:0}else{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}if(is3D){textX-=xDepth;textY+=yDepth}}}}else{if(outsideColSpace>=textWidth){textX+=isNegative?-xAdjust:xAdjust;if(is3D&&isNegative){textX-=xDepth;textY+=xDepth}}else{textX+=isNegative?xAdjust+textWidth:-(xAdjust+textWidth);if(is3D){textX-=xDepth;textY+=yDepth}}}}if(textX>canvasLeft+canvasWidth||textX<canvasLeft){textX=canvasLeft+GUTTER_4;textAnchor=POSITION_START}attr["text-anchor"]=textAnchor;attr.x=textX;attr.y=textY;attr.opacity=visible?1:0;plotLabel=animationManager.setAnimation({el:plotLabelCheck||"text",container:dataLabelContainer,component:dataSet,attr:attr,callback:!visible&&callback,label:"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.config.labelDrawn=true};(0,_dependencyManager.addDep)({name:"barAnimation",type:"animationRule",extension:_index.default});var Bar2DDataset=function(_ColumnDataset){function Bar2DDataset(){return _ColumnDataset.apply(this,arguments)||this}(0,_inheritsLoose2.default)(Bar2DDataset,_ColumnDataset);var _proto=Bar2DDataset.prototype;_proto.getType=function getType(){return"dataset"};_proto.getName=function getName(){return"bar2D"};_proto.drawLabel=function drawLabel(){var conf=this.config;_drawLabel.call(this,conf.scrollMinValForLabel,conf.scrollMaxValForLabel)};return Bar2DDataset}(_column.default);var _default=exports.default=Bar2DDataset;