UNPKG

@fusioncharts/charts

Version:

JavaScript Data Visualisation Library

1 lines 52.6 kB
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _lib=require("@fusioncharts/core/src/lib");var _componentInterface=require("@fusioncharts/core/src/component-interface");var _legendItem=_interopRequireDefault(require("./legend-item"));var _dependencyManager=require("@fusioncharts/core/src/dependency-manager");var _toolbox=require("@fusioncharts/core/src/toolbox");var _index=_interopRequireDefault(require("./index.animation"));var _schedular=require("@fusioncharts/core/src/schedular");var _faber=require("@fusioncharts/core/src/_internal/vendors/faberjs/src/faber");function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach((function(r){(0,_defineProperty2.default)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var UNDEF,TEXT_ANCHOR_MAP={left:_lib.POSITION_START,right:_lib.POSITION_END,center:_lib.POSITION_MIDDLE},math=Math,mathMin=math.min,mathMax=math.max,mathFloor=math.floor,mathCeil=math.ceil,INHERIT_STR="inherit",COMMA=",",NONE="none",COLOR_WHITE="#ffffff",PXSTRING="px",ZERO_STR="0,",NORMAL=_lib.preDefStr.NORMAL,BOLD=_lib.preDefStr.BOLD,noneStr=_lib.preDefStr.noneStr,styleValueMap={fontWeight:{1:BOLD,0:NORMAL},fontStyle:{1:"italic",0:NORMAL},textDecoration:{1:"underline",0:noneStr}},scrollTimeOut,handlers=function handlers(legend){var dragInitX,dragInitY;return{dragstart:function dragstart(){dragInitX=legend.config.xL||legend.config.xPos;dragInitY=legend.config.yL||legend.config.yPos},dragmove:function dragmove(e){var dx=e.originalEvent.data[0],dy=e.originalEvent.data[1],config=legend.config,chartConfig=legend.getFromEnv("chartConfig"),translationLimit=(config.borderWidth||0*.5)+2,dragOffsetX,dragOffsetY;dragOffsetX=mathMin(mathMax(dragInitX+dx,translationLimit),chartConfig.width-config.width-translationLimit);dragOffsetY=mathMin(mathMax(dragInitY+dy,translationLimit),chartConfig.height-config.height-translationLimit);config.xPos=config.xL=dragOffsetX;config.yPos=config.yL=dragOffsetY;legend.addJob("draw",legend.dragDraw,_schedular.priorityList&&_schedular.priorityList.draw)}}};(0,_dependencyManager.addDep)({name:"legendAnimation",type:"animationRule",extension:_index.default});var emptyArrayCreator=function emptyArrayCreator(n){return Array(n).fill()};var Legend=function(_ComponentInterface){function Legend(){var _this;_this=_ComponentInterface.call(this)||this;var legend=_this;legend._stateCosmetics={};legend._legendState=[];legend.dragDraw=function(){legend.draw()};legend.drawScroll=function(){legend.createItemGroup();legend.createCaptionGroup()};legend.config.handlers=handlers(legend);return _this}(0,_inheritsLoose2.default)(Legend,_ComponentInterface);var _proto=Legend.prototype;_proto.createItem=function createItem(owner){var legend=this,legendItem;legendItem=new _legendItem.default;legend.attachChild(legendItem,"legendItem");legendItem.setLinkedItem("owner",owner);legendItem.addEventListener("mouseover",(function(){legendItem.setLegendState("hover",true)}));legendItem.addEventListener("mouseout",(function(){legendItem.removeLegendState("hover")}));return legendItem.getId()};_proto.getItem=function getItem(id){var legend=this,items=legend.getChildren().legendItem;if(id!==UNDEF){if(items){for(var i=0;i<items.length;i++){if(items[i].getId()===id){return items[i]}}}}else{return false}};_proto.getSortedLegendItems=function getSortedLegendItems(){var legend=this,items=legend.getChildren("legendItem")||[],reverselegend=legend.config.reverselegend,map={},sortedItems=[],i,len;for(i=0,len=items.length;i<len;i++){if(items[i].config.index===UNDEF){map[len+i]=items[i]}else{map[items[i].config.index]=items[i]}}Object.keys(map).sort((function(index1,index2){if(reverselegend){return index2-index1}return index1-index2})).forEach((function(index){sortedItems.push(map[index])}));return sortedItems};_proto.disposeItem=function disposeItem(id){var legend=this,legendItem=legend.getItem(id);legendItem&&legendItem.remove()};_proto.getName=function getName(){return"legend"};_proto.getType=function getType(){return"legend"};_proto.__setDefaultConfig=function __setDefaultConfig(){_ComponentInterface.prototype.__setDefaultConfig.call(this);var config=this.config;config.enabled=true;config.symbolWidth=12;config.borderRadius=1;config.lastScrollPos=0;config.oriSymbolPadding=3;config.textPadding=4;config.scrollY=0;config.scrollX=0;config.backgroundColor=COLOR_WHITE;config.initialItemX=0;config.title={text:_lib.BLANKSTRING,x:0,y:0,padding:2};config.scroll={};config.horizontalScroll={};config.itemStyle={}};_proto.createLegendGroup=function createLegendGroup(){var legend=this,config=legend.config,chart=legend.getFromEnv("chart"),chartConfig=chart.config,animationManager=legend.getFromEnv("animationManager"),translationLimit=(config.borderWidth||0)*.5+2,legendGroup,legendGroupCheck=legend.getContainer("legendGroup");config.xL&&(config.xL=mathMin(mathMax(config.xL,translationLimit),chartConfig.width-config.width-translationLimit));config.yL&&(config.yL=mathMin(mathMax(config.yL,translationLimit),chartConfig.height-config.height-translationLimit));legendGroup=animationManager.setAnimation({el:legendGroupCheck||"group",attr:{name:"legendGroup",transform:["T",config.xL||config.xPos,config.yL||config.yPos]},container:chart.getChildContainer("legendGroup"),component:legend});if(!legendGroupCheck){legend.addContainer("legendGroup",legendGroup)}};_proto.drawDualScrollRect=function drawDualScrollRect(){var rect=this.getGraphicalElement("dualScrollRect"),scrollbarContainer=this.getGraphicalElement("scrollbarContainer"),animationManager=this.getFromEnv("animationManager");if(this.config.scroll.enabled&&this.config.horizontalScroll.enabled){rect=animationManager.setAnimation({el:rect||"rect",attr:{x:this.config.width-12,y:this.config.height-12,height:12,width:12,fill:this.config.legendScrollBgColor,stroke:"none"},component:this,container:scrollbarContainer});rect=this.addGraphicalElement("dualScrollRect",rect)}else if(rect){rect.remove()}};_proto.draw=function draw(){this.createLegendGroup();this.drawLegendBox();this.createItemGroup();this.createCaptionGroup();this.drawCaption();this.createScrollGroup();this.decideScroll();this.drawDualScrollRect()};_proto.decideScroll=function decideScroll(){var chartAttr=this.getFromEnv("chart-attrib");var disableLegendScrollBar=false;if(chartAttr.disablelegendscroll&&chartAttr.disablelegendscroll==="1"){disableLegendScrollBar=true}if(!disableLegendScrollBar){var legend=this,legendConf=legend.config,scrollEnabled=legendConf.scroll.enabled,horizontalScrollEnabled=legendConf.horizontalScroll.enabled;if(scrollEnabled){this.createScrollBar()}else if(legendConf.hasScroll){legend.getChildren("legendScrollBar")[0].remove();legendConf.hasScroll=false}if(horizontalScrollEnabled){this.createScrollBar(horizontalScrollEnabled)}else if(legendConf.hasHorizontalScroll){legend.getChildren("legendHorizontalScrollBar")[0].remove();legendConf.hasHorizontalScroll=false}}};_proto.createCaptionGroup=function createCaptionGroup(){var captionGroupCheck=this.getChildContainer("captionGroup"),animationManager=this.getFromEnv("animationManager"),legendGroup=this.getContainer("legendGroup"),captionGroup,padding=(0,_lib.pluckNumber)(this.config.padding,4),halfPad=padding*.5,clipSTR1=ZERO_STR,clipH=mathMax(this.config.height-padding,0),clipV=mathMax(this.config.width-padding,0),clipSTR2=COMMA+(this.config.horizontalScroll.enabled?clipV:this.config.width)+COMMA+(this.config.scroll.enabled?clipH:this.config.height);if(this.config.horizontalScroll.enabled){captionGroup=this.addChildContainer("captionGroup",animationManager.setAnimation({el:captionGroupCheck&&captionGroupCheck[0]!==null?captionGroupCheck:"group",attr:{name:"captionGroup",transform:["T",0,this.config.scrollY||0]},container:legendGroup,component:this}));if(this.config.scroll.enabled){captionGroup.attr({"clip-rect":clipSTR1+halfPad+clipSTR2})}else{captionGroup.attr({"clip-rect":null})}}else if(captionGroupCheck){captionGroupCheck.remove()}};_proto.createItemGroup=function createItemGroup(){var legend=this,animationManager=legend.getFromEnv("animationManager"),legendGroup=legend.getContainer("legendGroup"),itemGroup,itemGroupCheck=legend.getChildContainer("itemGroup"),padding=(0,_lib.pluckNumber)(legend.config.padding,4),halfPad=padding*.5,clipSTR1=ZERO_STR,clipH=mathMax(legend.config.height-padding,0),clipV=mathMax(legend.config.width-padding,0),clipSTR2=COMMA+(legend.config.horizontalScroll.enabled?clipV:legend.config.width)+COMMA+(legend.config.scroll.enabled?clipH:legend.config.height);itemGroup=animationManager.setAnimation({el:itemGroupCheck||"group",attr:{name:"item",transform:["T",legend.config.scrollX||0,legend.config.scrollY||0]},container:legendGroup,component:legend});if(!itemGroupCheck){legend.addChildContainer("itemGroup",itemGroup)}if(legend.config.scroll.enabled||legend.config.horizontalScroll.enabled){itemGroup.attr({"clip-rect":clipSTR1+halfPad+clipSTR2})}else{itemGroup.attr({"clip-rect":null})}return itemGroup};_proto.createScrollGroup=function createScrollGroup(){var legend=this,animationManager=legend.getFromEnv("animationManager"),scrollGroupCheck=legend.getChildContainer("scrollGroup"),legendGroup=legend.getContainer("legendGroup");if((legend.config.scroll.enabled||legend.config.horizontalScroll.enabled)&&!legend.getGraphicalElement("scrollbarContainer")){legend.addGraphicalElement("scrollbarContainer",animationManager.setAnimation({el:scrollGroupCheck||"group",attr:{name:"scrollGroup"},container:legendGroup,component:legend,label:"scrollbar"}))}};_proto.createScrollBar=function createScrollBar(isHorizontal){if(isHorizontal===void 0){isHorizontal=false}var legend=this,config=legend.config,scrollItem,chartAttr=legend.getFromEnv("chart-attrib"),childName=isHorizontal?"legendHorizontalScrollBar":"legendScrollBar",LegendScrollGradient=(0,_lib.pluckNumber)(chartAttr.uselegendscrollgradient,0),legendScrollBar=legend.getChildren(childName)&&legend.getChildren(childName)[0],borderWidth=config.borderWidth||0,semiBorder=borderWidth*.5,padding=(0,_lib.pluckNumber)(config.padding,4),scrollConfig,clipH,clipV,width=config.width,height=config.height,x,y,h,w;scrollItem={conf:{isHorizontal:isHorizontal,useLegendScrollGradient:LegendScrollGradient,legendScrollButtonArrowColor:chartAttr.legendscrollbuttonarrowcolor,legendTrackStrokeBorderColor:chartAttr.legendtrackstrokebordercolor,legendAnchorStrokeBorderColor:chartAttr.legendanchorstrokebordercolor,legendScrollTrackColor:chartAttr.legendscrolltrackcolor&&(LegendScrollGradient?chartAttr.legendscrolltrackcolor:(0,_lib.convertColor)(chartAttr.legendscrolltrackcolor)),legendScrollAnchorColor:chartAttr.legendscrollanchorcolor&&(LegendScrollGradient?chartAttr.legendscrollanchorcolor:(0,_lib.convertColor)(chartAttr.legendscrollanchorcolor))},handler:{scroll:function scroll(pos){function preventDefault(e){e.preventDefault();document.removeEventListener("touchmove",preventDefault,{passive:false})}document.addEventListener("touchmove",preventDefault,{passive:false});config.lastScrollPos=pos;if(isHorizontal){config.scrollX=(clipV-config.totalWidth)*pos}else{config.scrollY=(clipH-config.totalHeight)*pos}legend.addJob("scrollDraw",legend.drawScroll,_schedular.priorityList&&_schedular.priorityList.draw);if(scrollTimeOut){clearTimeout(scrollTimeOut)}scrollTimeOut=setTimeout((function(){document.removeEventListener("touchmove",preventDefault)}),250)},mousedown:function mousedown(e){e.preventDefault();e.stopPropagation()}}};if(chartAttr.legendscrollbgcolor){scrollItem.conf.color=(0,_lib.convertColor)(chartAttr.legendscrollbgcolor)}if(!legendScrollBar){legendScrollBar=legend.attachChild(new _toolbox.ScrollBar,childName);if(isHorizontal){this.config.hasHorizontalScroll=true}else{this.config.hasScroll=true}}legendScrollBar.configure(scrollItem.conf);legendScrollBar.attachEventHandlers(scrollItem.handler);scrollConfig=legendScrollBar.config;if(isHorizontal){x=semiBorder;y=height-legendScrollBar.getLogicalSpace().height-borderWidth+padding*.5;w=width-borderWidth;if(this.config.scroll.enabled&&this.config.horizontalScroll.enabled){w-=12}w=mathMax(w,0);clipV=mathMax(width-padding,0);scrollConfig.scrollRatio=(clipV+padding)/config.totalWidth}else{clipH=mathMax(height-padding,0);x=width-legendScrollBar.getLogicalSpace().width-borderWidth+padding*.5;y=semiBorder;h=height-borderWidth;if(this.config.scroll.enabled&&this.config.horizontalScroll.enabled){h-=12}h=mathMax(h,0);scrollConfig.scrollRatio=(clipH+padding)/config.totalHeight}scrollConfig.startPercent=0;scrollConfig.scrollPosition=config.lastScrollPos;scrollConfig.parentLayer=legend.getChildContainer("scrollGroup");legendScrollBar.setDimension({x:x,y:y,height:h,width:w})};_proto.drawCaption=function drawCaption(){var legend=this,caption=legend.getGraphicalElement("caption"),itemGroup=legend.config.horizontalScroll.enabled?legend.getChildContainer("captionGroup"):legend.getChildContainer("itemGroup"),animationManager=this.getFromEnv("animationManager"),config=this.config,attrObj,titleStyle,captionX,padding=(0,_lib.pluckNumber)(config.padding,4),captionCss,scrollEnabled=config.scroll.enabled,scrollbarWidth=10,width=config.width;if(config.title&&config.title.text!==_lib.BLANKSTRING&&config.validLegendItem){switch(config.title.align){case _lib.POSITION_START:captionX=padding;break;case _lib.POSITION_END:captionX=width-padding-(scrollEnabled?scrollbarWidth:0);break;default:captionX=width*.5}titleStyle=config.title.style;attrObj={text:config.title.text,title:config.title.originalText||_lib.BLANKSTRING,x:captionX,y:padding,fill:config.title.style.color,direction:config.textDirection,"line-height":titleStyle.lineHeight,"vertical-align":_lib.POSITION_TOP,"text-anchor":config.title.align,opacity:1};captionCss={"font-weight":titleStyle.fontWeight,"font-style":titleStyle.fontStyle,"font-family":titleStyle.fontFamily,"font-size":titleStyle.fontSize};caption&&caption.show();if(!caption||!caption[0]){caption=animationManager.setAnimation({el:"text",attr:attrObj,component:legend,container:itemGroup,css:captionCss});caption=this.addGraphicalElement("caption",caption)}else{animationManager.setAnimation({el:caption,attr:attrObj,component:legend,container:itemGroup,css:captionCss})}legend.getFromEnv("toolTipController").enableToolTip(caption,config.title.originalText)}else{if(caption){animationManager.setAnimation({el:caption,component:legend,doNotRemove:true,callback:function callback(){caption.hide()}})}}};_proto.drawLegendBox=function drawLegendBox(){var legend=this,animationManager=this.getFromEnv("animationManager"),config=legend.config,box,legendGroup=legend.getContainer("legendGroup"),width=config.width,boxCheck=legend.getGraphicalElement("box"),height=config.height,r=config.borderRadius,backgroundColor=config.backgroundColor,borderColor=config.borderColor,borderAlpha=config.borderAlpha,backgroundAlpha=config.backgroundAlpha,borderWidth=config.borderWidth||0;box=animationManager.setAnimation({el:boxCheck||"rect",attr:{x:0,y:0,width:width,height:height,r:r,stroke:borderColor,"stroke-width":borderWidth,fill:backgroundColor||NONE,"stroke-opacity":borderAlpha/100,"fill-opacity":backgroundAlpha/100,cursor:config.legendAllowDrag?"move":"default"},container:legendGroup,component:legend,label:"legendGroup"});if(!boxCheck){legend.addGraphicalElement("box",box);box.shadow(config.shadow)}return box};_proto._calculateTopPosition=function _calculateTopPosition(y){var legend=this,chart=legend.getFromEnv("chart"),chartConfig=chart.config,yPos=y,caption=chart.getChildren("caption")&&chart.getChildren("caption")[0],subCaption=chart.getChildren("subCaption")&&chart.getChildren("subCaption")[0],toolbar=chart.getChildren("chartMenuBar")&&chart.getChildren("chartMenuBar")[0],oriCanvasTop=chartConfig.oriTopSpace;if(!chartConfig.toolbarY&&toolbar&&toolbar.props&&toolbar.props.height){if(!(oriCanvasTop>toolbar.props.height+toolbar.props.y)){yPos=toolbar.props.y+toolbar.props.height}}if(caption&&caption.config&&caption.config.text&&caption.config.text!==_lib.BLANKSTRING&&caption.config.height&&caption.config.isOnTop===1){yPos=caption.config.height+caption.config.y+caption.config.captionPadding}if(subCaption&&subCaption.config&&subCaption.config.height&&subCaption.config.isOnTop===1){yPos=subCaption.config.y+subCaption.config.height+(caption&&caption.config&&caption.config.captionPadding||0)}return mathMax(yPos,y)};_proto.getPosition=function getPosition(){var legend=this,chart=legend.getFromEnv("chart"),chartConfig=chart.config,xPos,yPos,xLim,yLim,config=legend.config,canvas=chart.getChildren("canvas"),canvasBottom=canvas&&canvas.length>1?chartConfig.height-canvas[0].config.canvasBottom:chartConfig.height-chartConfig.canvasBottom,canvasLeft=chartConfig.canvasLeft,canvasRight=chartConfig.canvasRight,canvasWidth=chartConfig.canvasWidth,marginLeft=config.chartMarginLeft||0,marginRight=config.chartMarginRight||0,marginTop=config.chartMarginTop||0,marginBottom=config.chartMarginBottom||0,actionBarHeight=chartConfig.actionBarHeight||0,canvasMarginLeft=config.actualCanvasMarginLeft||0,canvasMarginTop=chartConfig.actualCanvasMarginTop||0,canvasMarginBottom=chartConfig.actualCanvasMarginBottom||0,canvasMarginRight=chartConfig.actualCanvasMarginRight||0,alignLegendWithCanvas=config.alignLegendWithCanvas,chartHeight=chartConfig.height,canvasTop=chartConfig.canvasTop,width=config.width||0,height=config.height||0,chartBorderWidth=chartConfig.borderWidth,oriCanvasLeft=chartConfig.oriCanvasLeft,oriCanvasRight=chartConfig.oriCanvasRight,oriCanvasTop=chartConfig.oriTopSpace,oriCanvasBottom=chartConfig.oriBottomSpace,topSpace=0,bottomSpace=0,xLeft,xRight,spaceLeftByChart,spaceRightLeft,borderWidth=config.borderWidth||0,isVertical,legendPos=config.legendPos?config.legendPos.split("-"):[],caption=chart.getChildren("caption")&&chart.getChildren("caption")[0],subCaption=chart.getChildren("subCaption")&&chart.getChildren("subCaption")[0],remSpace;if(legendPos[0]===_lib.POSITION_LEFT||legendPos[0]===_lib.POSITION_RIGHT){config.align=legendPos[0];config.verticalAlign=_lib.POSITION_MIDDLE;isVertical=config.layout="vertical"}if(legendPos[0]===_lib.POSITION_ABSOLUTE){xPos=config.legendXPosition;yPos=config.legendYPosition;xLim=chartConfig.width-width-chartBorderWidth;yLim=chartConfig.height-height-chartBorderWidth;if(xPos>xLim){xPos=xLim}if(yPos>yLim){yPos=yLim}}else if(isVertical){if(legendPos[0]===_lib.POSITION_LEFT){xPos=marginLeft+canvasMarginLeft+chartBorderWidth}else if(legendPos[0]===_lib.POSITION_RIGHT){xPos=chartConfig.width-marginRight-canvasMarginRight-width-chartBorderWidth}topSpace=(0,_lib.pluckNumber)(oriCanvasTop,canvasTop);bottomSpace=(0,_lib.pluckNumber)(oriCanvasBottom,canvasBottom);if(legendPos[1]===_lib.POSITION_TOP){yPos=topSpace+(config.y||0);yPos=this._calculateTopPosition(yPos)}else if(legendPos[1]===_lib.POSITION_BOTTOM){yPos=chartHeight-bottomSpace-height+(config.y||0);remSpace=bottomSpace-(chartBorderWidth+marginBottom+actionBarHeight+(caption&&caption.config.isOnTop===0&&caption.config.height?caption.config.height+caption.config.captionPadding:0)+(subCaption&&caption.config.isOnTop===0?subCaption.config.height:0));if(remSpace<0){yPos+=remSpace}}else{yPos=topSpace+(chartHeight-bottomSpace-topSpace-height)*.5+(config.y||0)}}else{spaceLeftByChart=chartConfig.width-(marginLeft+canvasMarginLeft+(marginRight+canvasMarginRight));spaceRightLeft=alignLegendWithCanvas?canvasWidth-width:spaceLeftByChart-width;xLeft=alignLegendWithCanvas?(0,_lib.pluckNumber)(oriCanvasLeft,canvasLeft):marginLeft+canvasMarginLeft;xRight=alignLegendWithCanvas?chartConfig.width-(0,_lib.pluckNumber)(oriCanvasRight,canvasRight):marginRight+canvasMarginRight;if(legendPos[1]===_lib.POSITION_LEFT){xPos=xLeft}else if(legendPos[1]===_lib.POSITION_RIGHT){xPos=chartConfig.width-(width+xRight)}else{xPos=xLeft+spaceRightLeft/2}if(legendPos[0]===_lib.POSITION_TOP){yPos=marginTop+canvasMarginTop;yPos=this._calculateTopPosition(yPos)}else{yPos=chartHeight-height-canvasMarginBottom-marginBottom-actionBarHeight}}return(0,_lib.crispBound)(xPos,yPos,width,height,borderWidth)};_proto.setTranslation=function setTranslation(x,y){var legend=this,config=legend.config;config._translateX=x;config._translateY=y;config.translate="t"+x+","+y};_proto.allocatePosition=function allocatePosition(){var legend=this,legendConfig=legend.config,dim;if(legendConfig.translate){dim=(0,_lib.crispBound)(legendConfig._translateX,legendConfig._translateY,legendConfig.width,legendConfig.height,legendConfig.borderWidth)}else{dim=legend.getPosition()}legendConfig.xPos=dim.x;legendConfig.yPos=dim.y;legendConfig.width=dim.width;legendConfig.height=dim.height};_proto._manageLegendPosition=function _manageLegendPosition(allottedSpace){var legend=this,config=legend.config,legendPosition=config.legendPos?config.legendPos.split("-"):[],spaceTakenByLegend,dim={left:0,right:0,top:0,bottom:0};config.padding=4;config.textPadding=4;if(legendPosition[0]===_lib.POSITION_ABSOLUTE){spaceTakenByLegend=legend._placeLegendBlockBottom(allottedSpace,.6)}else if(legendPosition[0]===_lib.POSITION_LEFT||legendPosition[0]===_lib.POSITION_RIGHT){spaceTakenByLegend=legend._placeLegendBlockRight(allottedSpace)}else{spaceTakenByLegend=legend._placeLegendBlockBottom(allottedSpace)}if(legendPosition[0]===_lib.POSITION_LEFT){dim.left=spaceTakenByLegend&&spaceTakenByLegend.right||0}else if(legendPosition[0]===_lib.POSITION_RIGHT){dim.right=spaceTakenByLegend&&spaceTakenByLegend.right||0}else if(legendPosition[0]===_lib.POSITION_TOP){dim.top=spaceTakenByLegend&&spaceTakenByLegend.bottom||0}else if(legendPosition[0]!==_lib.POSITION_ABSOLUTE){dim.bottom=spaceTakenByLegend&&spaceTakenByLegend.bottom||0;dim.right=spaceTakenByLegend&&spaceTakenByLegend.right||0}return dim};_proto.setDimension=function setDimension(dim){var _customData$legend;var legend=this,config=this.config,itemArr=legend.getSortedLegendItems(),chartAttr=legend.getFromEnv("chart-attrib"),len=itemArr.length,availableWidth=(0,_lib.pluckNumber)(chartAttr.legendwidth,dim.width),availableHeight=dim.height,allowedMaxHeight=availableHeight,itemConfig,userConfig,name,item,maxWidth=0,totalWidth=0,totalNumber=0,averageWidth=0,perItemWidth=0,maxHeight=0,legendCaptionHeight=0,tempTableStructure=[],padding=config.padding,textPadding=config.textPadding,SmartLabel=legend.getFromEnv("smartLabel"),itemStyle=legend.getStateCosmetics("default"),legendFontSize=this.computeFontSize(config.legendFontSizeWithUnit),legendLineHeight=parseInt((0,_lib.setLineHeight)({fontSize:legendFontSize+PXSTRING}),10),itemFontSize=parseInt(itemStyle.text["font-size"],10)||10,nonItemWidth,rowHeight,usedHeight,textWidth,legendCaption=config.title,captionPadding=legendCaption.padding,captionWidth=0,minimiseWrappingInLegend=config.minimiseWrappingInLegend,legendPadding=config.legendPadding,legendScale=config.legendScale,alignLegendWithCanvas=config.alignLegendWithCanvas,legendnumcolumns=config.numColumns,legendnumrows=config.numRows,symbolPadding=config.oriSymbolPadding,legendHeight,symbolWidthSpace,dimensions,i,k,itemWidth,itemHeight=Number.MAX_SAFE_INTEGER,parent,children,childLegends,legendSpace,numRows,validLegendItem,smartText,scroll,horizontalScroll,originalAvailableWidth=availableWidth,nonTextElemWidth,hasLegendCaption=false,hasUserGivenLegendNumRows=!!legendnumrows,shiftRows,shiftColumns,insertionState=0,customData=legend.getFromEnv("dataSource");dimensions={width:2*padding,height:2*padding};if(chartAttr.disablelegendscroll&&chartAttr.disablelegendscroll==="1"){availableWidth=dim.width;originalAvailableWidth=dim.width}if(customData!=null&&(_customData$legend=customData.legend)!=null&&(_customData$legend=_customData$legend.item)!=null&&_customData$legend.legendtextstyle){var _data$0$legendtextsty,_customData$legend$it;var data=customData.legend.item;legend.setStateCosmetics("default",{text:{fill:((_data$0$legendtextsty=data[0].legendtextstyle)==null?void 0:_data$0$legendtextsty.color)||itemStyle.text.fill,"font-family":itemStyle.text["font-family"]||itemStyle.text["font-family"],cursor:itemStyle.text.cursor,"font-size":data[0].legendtextstyle["font-size"]||itemStyle.text["font-size"],"line-height":parseInt((0,_lib.setLineHeight)({fontSize:(data[0].legendtextstyle["font-size"]||itemStyle.text["font-size"])+PXSTRING}),10),"vertical-align":_lib.POSITION_TOP,"text-anchor":_lib.POSITION_START,direction:itemStyle.text.direction,"font-weight":itemStyle.text["font-weight"]},symbol:{bgColor:itemStyle.symbol.bgColor,cursor:itemStyle.symbol.cursor,borderColor:itemStyle.symbol.borderColor,bgAlpha:itemStyle.symbol.bgAlpha,borderAlpha:itemStyle.symbol.borderAlpha,borderThickness:itemStyle.symbol.borderThickness,startAngle:itemStyle.symbol.startAngle,sides:itemStyle.symbol.sides}});itemStyle=legend.getStateCosmetics("default");legendFontSize=this.computeFontSize(config.legendFontSizeWithUnit);itemFontSize=parseInt((_customData$legend$it=customData.legend.item[0].legendsymbolstyle)==null?void 0:_customData$legend$it.width,10)||10+parseInt(customData.legend.item[0].legendtextstyle["font-size"]||itemStyle.text["font-size"],10)||10}else{legend.setStateCosmetics("default",{text:{fill:itemStyle.text.fill,"font-family":itemStyle.text["font-family"],cursor:itemStyle.text.cursor,"font-size":itemStyle.text["font-size"],"line-height":itemStyle.text["line-height"],"vertical-align":_lib.POSITION_TOP,"text-anchor":_lib.POSITION_START,direction:itemStyle.text.direction,"font-weight":itemStyle.text["font-weight"]},symbol:{bgColor:itemStyle.symbol.bgColor,cursor:itemStyle.symbol.cursor,borderColor:itemStyle.symbol.borderColor,bgAlpha:itemStyle.symbol.bgAlpha,borderAlpha:itemStyle.symbol.borderAlpha,borderThickness:itemStyle.symbol.borderThickness,startAngle:itemStyle.symbol.startAngle,sides:itemStyle.symbol.sides}})}symbolWidthSpace=itemFontSize+1;if(symbolWidthSpace<=0){symbolWidthSpace=1}availableWidth=Math.max(availableWidth-.5*padding,0);symbolWidthSpace*=legendScale;symbolPadding*=legendScale;symbolWidthSpace=mathMin(symbolWidthSpace,availableWidth);if(symbolWidthSpace<=0){symbolPadding=symbolWidthSpace=0}config.symbolWidth=symbolWidthSpace;config.textPadding=4;config.legendHeight=legendHeight=symbolWidthSpace+2*symbolPadding;config.rowHeight=rowHeight=mathMax(parseInt(itemStyle.text["line-height"],10)||12,legendHeight);nonItemWidth=textPadding+symbolPadding+padding;SmartLabel.setStyle((0,_lib.extend2)({},itemStyle.text));usedHeight=legendPadding+config.borderWidth/2+1;usedHeight=mathMax(mathMin(usedHeight,availableHeight-legendLineHeight-8),0);legendPadding=rowHeight*.05;config.initialItemY=0;config.initialItemX=0;nonTextElemWidth=legendHeight+legendPadding+textPadding+symbolPadding+2*padding;for(i=0;i<len;i+=1){item=itemArr[i];itemConfig=item.config||(item.config={});userConfig=itemConfig;name=itemConfig.name=(0,_lib.parseUnsafeString)(userConfig.label);if(name===_lib.BLANKSTRING||userConfig.enabled===0||userConfig.enabled===false||item.getState("removed")){itemConfig.enabled=0;continue}else{itemConfig.enabled=1}totalNumber+=1;validLegendItem=true;smartText=SmartLabel.getOriSize(name);maxWidth=mathMax(maxWidth,mathMin(smartText.width,availableWidth-nonTextElemWidth));maxHeight=mathMax(maxHeight,mathMin(smartText.height,allowedMaxHeight));itemConfig._selfTotalWidth=smartText.width+nonTextElemWidth;totalWidth+=smartText.width}config.validLegendItem=validLegendItem;averageWidth=totalWidth/totalNumber;totalWidth+=nonTextElemWidth*totalNumber;config.x=!alignLegendWithCanvas&&totalWidth>originalAvailableWidth?0:config.x;if(validLegendItem){averageWidth+=nonTextElemWidth;maxWidth+=nonTextElemWidth;if(legendCaption.oriText!==_lib.BLANKSTRING){hasLegendCaption=true;SmartLabel.setStyle(legendCaption.style);smartText=SmartLabel.getSmartText(legendCaption.oriText,availableWidth-2*padding);legendCaption.text=smartText.text;smartText.tooltext&&(legendCaption.originalText=smartText.tooltext);captionWidth=smartText.width+2*padding;legendCaptionHeight=smartText.height+captionPadding}itemWidth=maxWidth;if(!legendnumrows){if(totalWidth<=availableWidth){legendnumcolumns=!legendnumcolumns?totalNumber:legendnumcolumns;legendnumrows=mathCeil(totalNumber/legendnumcolumns);itemWidth=legendnumrows===1?totalWidth/totalNumber:maxWidth}else if(!legendnumcolumns&&availableWidth>maxWidth&&(minimiseWrappingInLegend||averageWidth*1.5>maxWidth)){legendnumcolumns=mathFloor(availableWidth/maxWidth);if(totalNumber<legendnumcolumns){legendnumcolumns=totalNumber}itemWidth=maxWidth}else if(legendnumcolumns&&availableWidth/legendnumcolumns>averageWidth){itemWidth=availableWidth/legendnumcolumns;if(itemWidth>maxWidth){itemWidth=maxWidth}}else if(!legendnumcolumns&&availableWidth>=2*averageWidth){legendnumcolumns=mathFloor(availableWidth/averageWidth);if(totalNumber<legendnumcolumns){legendnumcolumns=totalNumber}itemWidth=mathFloor(availableWidth/legendnumcolumns);if(itemWidth>maxWidth){itemWidth=maxWidth}}else if(!legendnumcolumns){legendnumcolumns=1;itemWidth=availableWidth}}else if(!legendnumcolumns&&legendnumrows){insertionState=1;if(totalNumber<legendnumrows){legendnumrows=totalNumber}legendnumcolumns=mathCeil(totalNumber/legendnumrows)}else if(mathCeil(totalNumber/legendnumcolumns)<legendnumrows&&mathCeil(totalNumber/legendnumrows)<legendnumcolumns||totalNumber>legendnumcolumns*legendnumrows){legendnumrows=mathCeil(totalNumber/legendnumcolumns)}else if(legendnumcolumns===mathCeil(totalNumber/legendnumrows)){insertionState=1}perItemWidth=hasUserGivenLegendNumRows?maxWidth:itemWidth;if(!hasUserGivenLegendNumRows&&averageWidth*1.5<maxWidth){itemWidth=averageWidth}if(legendnumrows&&!minimiseWrappingInLegend){var newNumRows,newNumCols,newItemWidth=perItemWidth;if(maxWidth>averageWidth*1.5){newItemWidth=averageWidth}newNumCols=mathMin(totalNumber,mathFloor(availableWidth/newItemWidth));newNumRows=mathCeil(totalNumber/newNumCols);if(!(config.numRows&&newNumRows!==legendnumrows||config.numColumns&&newNumCols!==legendnumcolumns)&&!(legendnumrows===1&&newNumRows!==1)){perItemWidth=newItemWidth;legendnumcolumns=newNumCols;legendnumrows=newNumRows}}SmartLabel.setStyle((0,_lib.extend2)({},itemStyle.text));for(i=0;i<len;i++){itemConfig=itemArr[i].config;if(legendnumrows===1){perItemWidth=maxWidth>averageWidth*2.5?averageWidth:itemConfig._selfTotalWidth}textWidth=Math.ceil(perItemWidth-nonTextElemWidth);if(textWidth===0){itemConfig.name=_lib.BLANKSTRING;itemConfig._totalWidth=symbolWidthSpace+symbolPadding;itemConfig._selfTotalWidth=itemConfig._totalWidth;itemConfig._selfTotalHeight=rowHeight}else{var _itemConfig,_itemConfig2;if((_itemConfig=itemConfig)!=null&&_itemConfig.name&&/\<\/?br\s*\/?\>/i.test((_itemConfig2=itemConfig)==null?void 0:_itemConfig2.name)){smartText=SmartLabel.getSmartText(itemConfig.name,textWidth<=itemConfig._selfTotalWidth-nonTextElemWidth?textWidth+textPadding:UNDEF,availableHeight)}else{smartText=SmartLabel.getSmartText(itemConfig.name,textWidth<itemConfig._selfTotalWidth-nonTextElemWidth?textWidth+textPadding:UNDEF)}itemConfig.name=smartText.text;itemConfig._textHeight=smartText.height;smartText.tooltext&&(itemConfig.originalText=smartText.tooltext);itemConfig._selfTotalHeight=smartText.height+textPadding>rowHeight?textPadding+smartText.height:rowHeight;itemConfig._totalWidth=symbolWidthSpace+nonItemWidth+smartText.width;itemConfig._selfTotalWidth=nonTextElemWidth+smartText.width;itemConfig._legendTestY=rowHeight>smartText.height?(rowHeight-smartText.height)/2:0;maxHeight=mathMax(maxHeight,itemConfig._textHeight);itemHeight=mathMax(1,mathMin(itemHeight,itemConfig._textHeight))}}parent={style:{display:"grid",justifyItems:"center",alignItems:"start"}};children=[];if(hasLegendCaption){children.push({style:{width:captionWidth,height:legendCaptionHeight,gridRowStart:1,gridRowEnd:2,gridColumnStart:1,gridColumnEnd:2}})}children.push({style:{display:"grid",justifyItems:"start",alignItems:"start",width:mathMin(totalWidth,availableWidth,perItemWidth*legendnumcolumns),paddingEnd:padding,paddingTop:padding,gridRowStart:children.length+1,gridRowEnd:children.length+2,gridColumnStart:1,gridColumnEnd:2}});childLegends=[];if(hasUserGivenLegendNumRows||legendnumrows===1){for(k=0,i=1;k<len;k++){item=itemArr[k];itemConfig=item.config;if(itemConfig.enabled===1){if(insertionState===0){shiftRows=mathCeil(i/legendnumcolumns);shiftColumns=i%legendnumcolumns===0?legendnumcolumns:i%legendnumcolumns}else{shiftRows=i%legendnumrows===0?legendnumrows:i%legendnumrows;shiftColumns=mathCeil(i/legendnumrows)}childLegends.push({style:{width:legendnumrows===1?itemConfig._selfTotalWidth:shiftColumns===legendnumcolumns?itemConfig._selfTotalWidth:perItemWidth,height:itemConfig._selfTotalHeight,gridRowStart:shiftRows,gridRowEnd:shiftRows+1,gridColumnStart:shiftColumns,gridColumnEnd:shiftColumns+1}});i+=1}}}else{legendnumrows=0;itemHeight=mathMax(itemHeight,rowHeight);for(k=0;k<len;k++){item=itemArr[k];itemConfig=item.config;if(itemConfig.enabled===1){legendnumrows+=Math.ceil(itemConfig._selfTotalHeight/itemHeight)}}legendnumrows===0&&(legendnumrows=Math.max(1,Math.ceil(totalNumber/legendnumcolumns)));tempTableStructure=emptyArrayCreator(legendnumrows).map((function(){return emptyArrayCreator(legendnumcolumns)}));var m=0,n=0,endRow;for(k=0,i=1;k<len;k++){item=itemArr[k];itemConfig=item.config;if(itemConfig.enabled===1){while(m<legendnumrows){while(n<legendnumcolumns){if(tempTableStructure[m][n]===UNDEF){shiftColumns=n+1;shiftRows=m+1;endRow=legendnumcolumns===1?1:+(itemConfig._selfTotalHeight/itemHeight).toFixed(0);tempTableStructure[m][n]=true;for(var p=m;p<m+endRow;p++){tempTableStructure[p][n]=true}}n++;if(tempTableStructure[m][n-1]){break}}if(n>=legendnumcolumns){n=0;m++}if(endRow){break}}childLegends.push({style:{width:shiftColumns===legendnumcolumns?itemConfig._selfTotalWidth:itemWidth,height:itemConfig._selfTotalHeight,gridRowStart:shiftRows,gridRowEnd:shiftRows+endRow,gridColumnStart:shiftColumns,gridColumnEnd:shiftColumns+1}});i+=1;endRow=UNDEF}}legendnumrows=0;for(i=legendnumrows;i<tempTableStructure.length;i++){for(k=0;k<legendnumcolumns;k++){if(tempTableStructure[i][k]){legendnumrows++;break}}}if(legendnumcolumns>1){children[children.length-1].style.gridTemplateRows=(itemHeight+" ").repeat(legendnumrows).slice(0,-1)}}children[children.length-1].children=childLegends;legendSpace=(0,_faber.computeLayout)(_objectSpread(_objectSpread({},parent),{},{children:children}));config.itemWidth=perItemWidth;textWidth=mathCeil(perItemWidth-nonTextElemWidth);if(textWidth<0){symbolPadding=textWidth=textPadding=0}config.symbolPadding=symbolPadding;config.textPadding=textPadding;config.width=config.totalWidth=Math.floor(mathMax(legendSpace.layout.width,legendSpace.children[legendSpace.children.length-1].layout.width));SmartLabel.setStyle((0,_lib.extend2)({},itemStyle.text));for(k=0,i=0;k<len;k++){item=itemArr[k];itemConfig=item.config;if(legendnumrows===1){textWidth=itemConfig._selfTotalWidth;if(textWidth<0){symbolPadding=textWidth=textPadding=0}}if(itemConfig.enabled===1){if(textWidth===0){itemConfig.name=_lib.BLANKSTRING;itemConfig._totalWidth=symbolWidthSpace+symbolPadding}itemConfig._legendX=legendSpace.children[legendSpace.children.length-1].children[i].layout.x;itemConfig._legendY=legendSpace.children[legendSpace.children.length-1].children[i].layout.y;itemConfig._legendH=legendSpace.children[legendSpace.children.length-1].children[i].layout.height;i+=1}}numRows=legendnumrows;dimensions.height+=numRows*rowHeight+legendCaptionHeight;config.height=config.totalHeight=legendSpace.layout.height+2*padding;config.rowHeight=rowHeight;config.legendNumColumns=legendnumcolumns;var legendPos=config.legendPos?config.legendPos.split("-"):[];if(legendPos[0]===_lib.POSITION_LEFT||legendPos[0]===_lib.POSITION_RIGHT){config.initialItemX=hasLegendCaption&&captionWidth>legendSpace.children[legendSpace.children.length-1].layout.width&&availableWidth>config.width?legendSpace.children[legendSpace.children.length-1].layout.x:0}config.initialItemY=legendSpace.children[legendSpace.children.length-1].layout.y;if(config.height-2*symbolPadding>availableHeight){config.height=availableHeight;scroll=config.scroll||(config.scroll={});scroll.enabled=true;scroll.flatScrollBars=config.flatScrollBars;scroll.scrollBar3DLighting=config.scrollBar3DLighting;config.width=config.width+12>availableWidth?config.width:config.width+12}else{config.scroll.enabled=false}if(config.width>availableWidth&&config.scroll.enabled){config.width=availableWidth;horizontalScroll=config.horizontalScroll||(config.horizontalScroll={});horizontalScroll.enabled=true;horizontalScroll.flatScrollBars=config.flatScrollBars;horizontalScroll.scrollBar3DLighting=config.scrollBar3DLighting;if(config.height+12<=availableHeight){config.height=config.height+12}else{config.height=availableHeight;config.totalHeight+=4;scroll=config.scroll||(config.scroll={});scroll.enabled=true;scroll.flatScrollBars=config.flatScrollBars;scroll.scrollBar3DLighting=config.scrollBar3DLighting;config.scroll.enabled=true}}else{config.horizontalScroll.enabled=false}if(config.totalWidth>config.width&&config.totalWidth-config.width<=4){for(k=0,i=0;k<len;k++){item=itemArr[k];itemConfig=item.config;if(itemConfig.enabled===1){if(legendSpace.children[legendSpace.children.length-1].children[i].style.gridColumnStart%legendnumcolumns!==1){itemConfig._legendX+=4;if(legendSpace.children[legendSpace.children.length-1].children[i].style.gridRowStart===1){config.totalWidth+=4}}i+=1}}config.totalHeight+=4}usedHeight+=config.height;config.isActive=true;config.enabled=true}else{config.enabled=false;config.width=0;usedHeight=0}return{width:config.width,height:usedHeight}};_proto._placeLegendBlockBottom=function _placeLegendBlockBottom(availableHeight,widthFraction){if(widthFraction===void 0){widthFraction=1}var legend=this,chart=legend.getFromEnv("chart"),chartConfig=chart.config,origRenderWidth=chart.getFromEnv("chartWidth"),origRenderHeight=chart.getFromEnv("chartHeight"),spacingLeft=chartConfig.canvasLeft,spacingRight=chartConfig.width-(chartConfig.canvasRight||0),SmartLabel=chart.getFromEnv("smartLabel"),config=legend.config,marginLeft=config.chartMarginLeft,marginRight=config.chartMarginRight,marginTop=config.chartMarginTop,alignLegendWithCanvas=config.alignLegendWithCanvas,itemArr=legend.getSortedLegendItems(),len=itemArr.length,legendPadding=config.legendPadding,canvasMarginRight=chartConfig.canvasMarginRight,canvasMarginLeft=chartConfig.canvasMarginLeft,yAxis=chart.getChildren("yAxis"),verticalAxis=yAxis&&yAxis[0].config.isVertical?yAxis:chart.getChildren("xAxis"),axis1Obj=verticalAxis&&verticalAxis[0],axis2Obj=verticalAxis&&verticalAxis[1],axis1=axis1Obj&&axis1Obj.config||{},axis2=axis2Obj&&axis2Obj.config||{},title1Width=axis1.nameMaxW,title2Width=axis2.nameMaxW,axis1NameStyle=axis1.name&&axis1.name.style||{},axis2NameStyle=axis2.name&&axis2.name.style||{},axis1Title=axis1.axisName||_lib.BLANKSTRING,axis2Title=axis2.axisName||_lib.BLANKSTRING,usedHeight,availableWidth=chartConfig.canvasWidth-chartConfig.canvasMarginLeft-chartConfig.canvasMarginRight,widthLimit=chartConfig.width,heightLimit=chartConfig.height,yAxisTitleHeight,yAxisTitleWidth,title1,title2,legendPos=config.legendPos?config.legendPos.split("-"):[];config.paddingBottom=chartConfig.height-chartConfig.canvasBottom;SmartLabel.useEllipsesOnOverflow(chartConfig.useEllipsesWhenOverflow);SmartLabel.setStyle(axis1NameStyle);title1=SmartLabel.getOriSize(axis1Title);SmartLabel.setStyle(axis2NameStyle);title2=SmartLabel.getOriSize(axis2Title);if(availableWidth<legendPadding){config.padding=legendPadding=availableWidth=0}if(title1||title2){yAxisTitleHeight=(0,_lib.pluckNumber)(title1.height,0)>(0,_lib.pluckNumber)(title2.height,0)?(yAxisTitleWidth=title1Width)&&title1.width:(yAxisTitleWidth=title2Width)&&title2.width}availableWidth=alignLegendWithCanvas?availableWidth:origRenderWidth-(yAxisTitleHeight+marginTop>origRenderHeight-availableHeight?2*yAxisTitleWidth+marginRight+marginLeft+canvasMarginRight+canvasMarginLeft:marginRight+marginLeft+canvasMarginLeft+canvasMarginRight);if(legendPos[0]===_lib.POSITION_ABSOLUTE){availableWidth=widthLimit;if(config.legendMaxWidth<widthLimit){availableWidth=config.legendMaxWidth}else{availableWidth*=widthFraction}}if(!config.showLegend||len===0){usedHeight=0;config.height=0;config.width=0}else{config.x=(spacingLeft-marginLeft-spacingRight+marginRight)/2;usedHeight=legend.setDimension({width:availableWidth,height:legendPos[0]===_lib.POSITION_ABSOLUTE?config.legendMaxHeight<heightLimit?config.legendMaxHeight:heightLimit:availableHeight}).height}return{bottom:usedHeight,right:0}};_proto._placeLegendBlockRight=function _placeLegendBlockRight(availWidth){var legend=this,availableWidth=availWidth,legendConf=legend.config,chart=legend.getFromEnv("chart"),chartConf=chart.config,SmartLabel=chart.getFromEnv("smartLabel"),legendPadding=legendConf.legendPadding,itemStyle=legend.getStateCosmetics("default"),availableHeight=chartConf.canvasHeight,dimensions={},itemArr=legend.getSortedLegendItems(),len=itemArr.length,usedWidth,gutterWidth=10;if(availableWidth<legendPadding){legendConf.padding=legendPadding=availableWidth=0}SmartLabel.useEllipsesOnOverflow(chartConf.useEllipsesWhenOverflow);SmartLabel.setStyle((0,_lib.extend2)({},itemStyle.text));if(!legendConf.numColumns&&!legendConf.numRows){legendConf.numColumns=1}if(!legendConf.showLegend||len===0){dimensions.right=0;legendConf.height=0;legendConf.width=0}else{usedWidth=legend.setDimension({width:availableWidth-legendPadding,height:availableHeight}).width;dimensions.right=usedWidth+legendPadding;if(dimensions.right+gutterWidth<=availableWidth){dimensions.right+=gutterWidth}}return dimensions};_proto.postSpaceManager=function postSpaceManager(){var legend=this,legendConf=legend.config,legendPosition=legendConf.legendPos?legendConf.legendPos.split("-"):[],chart=legend.getFromEnv("chart"),availableHeight=chart.config.canvasHeight;if(legendPosition[0]===_lib.POSITION_RIGHT||legendPosition[0]===_lib.POSITION_LEFT){if(legendConf.totalHeight>availableHeight){if(legendConf.totalHeight<=legendConf.height){legendConf.scroll.enabled=true;legendConf.scroll.flatScrollBars=legendConf.flatScrollBars;legendConf.scroll.scrollBar3DLighting=legendConf.scrollBar3DLighting;legendConf.width+=(legendConf.scroll.scrollBarWidth=10)+(legendConf.scroll.scrollBarPadding=2)}legendConf.height=availableHeight}else{legendConf.scroll.enabled=false}}};_proto.configureAttributes=function configureAttributes(obj){if(obj===void 0){obj={}}_ComponentInterface.prototype.configureAttributes.call(this,obj);var legend=this,config=legend.config,chart=legend.getFromEnv("chart"),chartConfig=chart.config,legendLineHeight,style=legend.getFromEnv("style"),chartAttr=chart.getFromEnv("chart-attrib"),is3D=chart.config.is3D,colorM=legend.getFromEnv("color-manager"),borderColor,palleteString=is3D?_lib.chartPaletteStr.chart3D:_lib.chartPaletteStr.chart2D,interactiveLegend=config.interactiveLegend=chart.hasInteractiveLegend!==false&&Boolean((0,_lib.pluckNumber)(chartAttr.interactivelegend,1)),borderAlpha,backgroundAlpha,roundEdges=(0,_lib.pluckNumber)(chartAttr.useroundedges,0),padding=4,outCancolor=style.outCancolor,textStyle=obj.style&&obj.style.text,legendItemFont=(0,_lib.pluck)(chartAttr.legenditemfont,textStyle&&textStyle["font-family"],style.outCanfontFamily),legendScale=(0,_lib.pluckNumber)(chartAttr.legendiconscale,1),legendFontSize=(0,_lib.pluckFontSize)(chartAttr.legenditemfontsize,textStyle&&textStyle["font-size"],style.fontSize)+PXSTRING,legendFontColor=(0,_lib.pluck)(chartAttr.legenditemfontcolor,textStyle&&textStyle.color,outCancolor).replace(/^#?([a-f0-9]+)/gi,"#$1"),legendItemHoverFontColor=(0,_lib.getFirstColor)((0,_lib.pluck)(chartAttr.legenditemhoverfontcolor,legendFontColor)),anchorMap;config.isActive=false;config.chartMarginTop=chartConfig.origMarginTop;config.chartMarginRight=chartConfig.origMarginRight;config.chartMarginBottom=chartConfig.origMarginBottom;config.chartMarginLeft=chartConfig.origMarginLeft;config.reverselegend=(0,_lib.pluckNumber)(chartAttr.reverselegend,0);config.showLegend=(0,_lib.pluckNumber)(chartAttr.showlegend,!chart.dontShowLegendByDefault,1);config.legendFontSizeWithUnit=(0,_lib.pluckFontSizeMaintainUnit)(chartAttr.legenditemfontsize,style.fontSizeWithUnit||style.fontSize);legendLineHeight=(0,_lib.setLineHeight)({fontSize:legendFontSize});config.legendPos=(0,_lib.pluck)(chartAttr.legendposition,chart.legendposition,obj.legendPosition,_lib.POSITION_BOTTOM).toLowerCase();config.numColumns=(0,_lib.pluckNumber)(Math.floor(chartAttr.legendnumcolumns));config.numRows=(0,_lib.pluckNumber)(Math.floor(chartAttr.legendnumrows));if(config.numColumns<0){config.numColumns=UNDEF}if(config.numRows<0){config.numRows=UNDEF}config.legendXPosition=mathMax((0,_lib.pluckNumber)(chartAttr.legendxposition,chart.legendxposition,obj.legendXPosition,0),0);config.legendYPosition=mathMax((0,_lib.pluckNumber)(chartAttr.legendyposition,chart.legendyposition,obj.legendYPosition,0),0);config.legendMaxWidth=(0,_lib.pluckNumber)(chartAttr.legendmaxwidth,chart.legendmaxwidth,obj.legendMaxWidth);config.legendMaxHeight=(0,_lib.pluckNumber)(chartAttr.legendmaxheight,chart.legendmaxheight,obj.legendMaxHeight);if(config.legendMaxWidth<0){config.legendMaxWidth=UNDEF}if(config.legendMaxHeight<0){config.legendMaxHeight=UNDEF}config.xL=config.yL=0;if(legendScale<=0||legendScale>5){legendScale=1}config.drawCustomLegendIcon=(0,_lib.pluckNumber)(chartAttr.drawcustomlegendicon,obj.drawcustomlegendicon,0);config.legendScale=legendScale;config.legendPadding=(0,_lib.pluckNumber)(chartAttr.legendpadding,7);config.alignLegendWithCanvas=(0,_lib.pluckNumber)(obj.alignlegendwithcanvas,chartConfig.alignLegendWithCanvas);config.title.style={fontFamily:(0,_lib.pluck)(chartAttr.legendcaptionfont,legendItemFont),fontSize:(0,_lib.pluckFontSize)(chartAttr.legendcaptionfontsize,style.fontSize)+PXSTRING,color:(0,_lib.pluck)(chartAttr.legendcaptionfontcolor,outCancolor).replace(/^#?([a-f0-9]+)/gi,"#$1"),fontWeight:styleValueMap.fontWeight[(0,_lib.pluckNumber)(chartAttr.legendcaptionfontbold,1)]||_lib.BLANKSTRING};anchorMap=chartAttr.legendcaptionalignment?chartAttr.legendcaptionalignment.toLowerCase():TEXT_ANCHOR_MAP.center;config.title.align=TEXT_ANCHOR_MAP[anchorMap]||TEXT_ANCHOR_MAP.center;config.title.style["text-anchor"]=config.title.align;config.padding=padding;borderColor=(0,_lib.pluck)(chartAttr.legendbordercolor,colorM.getColor(palleteString.legendBorderColor));borderAlpha=config.borderAlpha=(0,_lib.pluckNumber)(chartAttr.legendborderalpha,100);config.borderColor=(0,_lib.convertColor)(borderColor,borderAlpha);config.borderWidth=(0,_lib.pluckNumber)(chartAttr.legendborderthickness,obj.legendborderthickness,!roundEdges||chartAttr.legendbordercolor?1:0);config.borderRadius=(0,_lib.pluckNumber)(roundEdges,0);config.backgroundAlpha=backgroundAlpha=(0,_lib.pluckNumber)(chartAttr.legendbgalpha,obj.legendbgalpha,100);config.backgroundColor=(0,_lib.convertColor)((0,_lib.pluck)(chartAttr.legendbgcolor,colorM.getColor(palleteString.legendBgColor)),backgroundAlpha);config.symbol3DLighting=Boolean((0,_lib.pluckNumber)(chartAttr.use3dlighting,chartAttr.useplotgradientcolor,1));config.symbol3DLighting=!chartConfig.usePattern&&config.symbol3DLighting;config.shadow=Boolean((0,_lib.pluckNumber)(chartAttr.legendshadow,1));if(config.shadow){config.shadow={enabled:config.shadow,opacity:mathMax(borderAlpha,backgroundAlpha)/100}}config.prevReversed=Boolean((0,_lib.pluckNumber)(config.reversed,0));config.reversed=Boolean((0,_lib.pluckNumber)(chartAttr.reverselegend,0));config.lineWidth=(0,_lib.pluckNumber)(chartAttr.linethickness,2);config.borderRadius=(0,_lib.pluckNumber)(chartAttr.legendborderradius,roundEdges?3:0);config.legendAllowDrag=Boolean((0,_lib.pluckNumber)(chartAttr.legendallowdrag,0));config.title.oriText=(0,_lib.parseUnsafeString)((0,_lib.getFirstValue)(chartAttr.legendcaption,_lib.BLANKSTRING));config.legendScrollBgColor=(0,_lib.getFirstColor)((0,_lib.pluck)(chartAttr.legendscrollbgcolor,chartAttr.scrollcolor,colorM.getColor("altHGridColor")));config.legendScrollBarColor=(0,_lib.pluck)(chartAttr.legendscrollbarcolor,borderColor);config.legendScrollBtnColor=(0,_lib.pluck)(chartAttr.legendscrollbtncolor,borderColor);config.minimiseWrappingInLegend=(0,_lib.pluckNumber)(chartAttr.minimisewrappinginlegend,0);config.flatScrollBars=(0,_lib.pluckNumber)(chartAttr.flatscrollbars,0);config.scrollBar3DLighting=(0,_lib.pluckNumber)(chartAttr.scrollbar3dlighting,1);config.orderReversed=false;legend.setStateCosmetics("hidden",{symbol:{fill:(0,_lib.convertColor)((0,_lib.pluck)(chartAttr.legenditemhiddencolor,"cccccc").replace(/^#?([a-f0-9]+)/gi,"#$1")),stroke:(0,_lib.convertColor)((0,_lib.pluck)(chartAttr.legenditemhiddencolor,"cccccc").replace(/^#?([a-f0-9]+)/gi,"#$1"))},text:{fill:(0,_lib.convertColor)((0,_lib.pluck)(chartAttr.legenditemhiddencolor,"cccccc").replace(/^#?([a-f0-9]+)/gi,"#$1"))}});legend.setStateCosmetics("default",{text:{fill:(0,_lib.convertColor)(legendFontColor),"font-family":legendItemFont,cursor:interactiveLegend?_lib.preDefStr.POINTER:"default","font-size":legendFontSize,"line-height":legendLineHeight,"vertical-align":_lib.POSITION_TOP,"text-anchor":_lib.POSITION_START,direction:chartConfig.textDirection==="rtl"?"rtl":"initial","font-weight":styleValueMap.fontWeight[(0,_lib.pluckNumber)(chartAttr.legenditemfontbold,0)]||_l