text: import _inheritsLoose from"@babel/runtime/helpers/inheritsLoose";import{computePlotBounds,computeSliceBounds,compute3DSliceBounds,arrangeItems,DEFAULT_MACRO_SEPARATOR,xyCalculator,axisMacroParser}from"./utils";import{pluck,pluckNumber,UNDEF,extend2}from"@fusioncharts/core/src/lib";import{addDep,getDep}from"@fusioncharts/core/src/dependency-manager";import annotationAnimation from"./annotation-animation";import raphaelShapesRingpath from"@fusioncharts/core/src/_internal/redraphael/redraphael-shapes/redraphael-shapes.ringpath";import raphaelShapesArcpath from"@fusioncharts/core/src/_internal/redraphael/redraphael-shapes/redraphael-shapes.arcpath";import AnnotationGroup from"./shapes/annotation-group";import{SmartRenderer}from"@fusioncharts/core/src/component-interface";var circular2D=["pie2d","doughnut2d"],circular3D=["pie3d","doughnut3d"],GROUP="group",SHAPE="shape",sortDatasetByJSONIndex=function sortDatasetByJSONIndex(a,b){return a.getJSONIndex()-b.getJSONIndex()},getSnapPoints=function getSnapPoints(chart){var chartConfig=chart.config,chartComponents=chart.getChildren(),caption=chartComponents.caption[0],subCaption=chartComponents.subCaption[0],legend=chartComponents.legend&&chartComponents.legend[0]||{},gradientLegend=chartComponents.gLegend&&chartComponents.gLegend[0]||{},captionConfig=caption.config,subCaptionConfig=subCaption.config,captionwidth=captionConfig.width||0,subcaptionwidth=subCaptionConfig.width||0,captionstartx,legendConfig,subcaptionstartx;if(captionConfig.align==="end"){captionstartx=captionConfig.x-captionwidth;subcaptionstartx=captionConfig.x-subcaptionwidth}else if(captionConfig.align==="start"){captionstartx=subcaptionstartx=captionConfig.x}else{captionstartx=captionConfig.x-captionwidth/2;subcaptionstartx=captionConfig.x-subcaptionwidth/2}legendConfig=chartConfig.gLegendEnabled?gradientLegend.conf:legend.config;return{canvasendx:chartConfig.canvasRight,canvasendy:chartConfig.canvasBottom,canvasheight:chartConfig.canvasHeight,canvasstartx:chartConfig.canvasLeft,canvasstarty:chartConfig.canvasTop,canvaswidth:chartConfig.canvasWidth,canvascenterx:chartConfig.canvasCenterX||chartConfig.canvasLeft+(chartConfig.canvasRight-chartConfig.canvasLeft)/2,canvascentery:chartConfig.canvasCenterY||chartConfig.canvasTop+(chartConfig.canvasBottom-chartConfig.canvasTop)/2,chartcenterx:chartConfig.width/2,chartcentery:chartConfig.height/2,chartstartx:0,chartstarty:0,chartendx:chartConfig.width,chartendy:chartConfig.height,chartheight:chartConfig.height,chartwidth:chartConfig.width,chartleftmargin:chartConfig.marginLeft,chartrightmargin:chartConfig.marginRight,chartbottommargin:chartConfig.marginBottom,charttopmargin:chartConfig.marginTop,captionendx:captionstartx+captionConfig.width,captionendy:captionConfig.y+captionConfig.height,captionheight:captionConfig.height,captionstartx:captionstartx,captionstarty:captionConfig.y,captionwidth:captionwidth,subcaptionendx:subcaptionstartx+subCaptionConfig.width,subcaptionendy:subCaptionConfig.y+subCaptionConfig.height,subcaptionheight:subCaptionConfig.height,subcaptionstartx:subcaptionstartx,subcaptionstarty:subCaptionConfig.y,subcaptionwidth:subcaptionwidth,legendendx:legendConfig&&legendConfig.xPos+legendConfig.width,legendendy:legendConfig&&legendConfig.yPos+legendConfig.height,legendheight:legendConfig&&legendConfig.height,legendstartx:legendConfig&&legendConfig.xPos,legendstarty:legendConfig&&legendConfig.yPos,legendwidth:legendConfig&&legendConfig.width,dataset:function dataset(string){var traversalArr=string.split(DEFAULT_MACRO_SEPARATOR).slice(1),set,dataset,bbox,datasets=[];chart.iterateComponents(function(component){if(component.getType()==="dataset"){datasets.push(component)}});datasets.sort(sortDatasetByJSONIndex);dataset=datasets[Number(traversalArr[0])];set=dataset.components.data[Number(traversalArr[2])];if(circular2D.indexOf(dataset.getName().toLowerCase())>-1){return computeSliceBounds(traversalArr[3],set.config)}else if(circular3D.indexOf(dataset.getName().toLowerCase())>-1){return compute3DSliceBounds(traversalArr[3],set.config)}bbox=computePlotBounds(set,dataset.getName());return xyCalculator(traversalArr[3],bbox)},xaxis:axisMacroParser(chart,"xAxis"),yaxis:axisMacroParser(chart,"yAxis"),gaugestartx:chartConfig.gaugeStartX,gaugestarty:chartConfig.gaugeStartY,gaugeendx:chartConfig.gaugeEndX,gaugeendy:chartConfig.gaugeEndY,gaugecenterx:chartConfig.gaugeCenterX,gaugecentery:chartConfig.gaugeCenterY,gaugestartangle:chartConfig.gaugeStartAngle,gaugeendangle:chartConfig.gaugeEndAngle,gaugeradius:chartConfig.gaugeRadius,plotwidth:chartConfig.plotWidth,plotsemiwidth:chartConfig.plotSemiWidth}},getBoolean=function getBoolean(numericBool){return!(parseInt(numericBool,10)===0)},parseShapeConfiguration=function parseShapeConfiguration(rawConfig,groupConfig,chartConfig){if(groupConfig===void 0){groupConfig={}}if(chartConfig===void 0){chartConfig={}}var itemAttr={};itemAttr.annotationType=SHAPE;itemAttr.id=rawConfig.id;itemAttr.type=rawConfig.type&&rawConfig.type.toLowerCase();itemAttr.toolText=pluck(rawConfig.tooltext,rawConfig.toolText);itemAttr.animationLabel=pluck(rawConfig.animationlabel,rawConfig.animationLabel);itemAttr.dashed=rawConfig.dashed;itemAttr.dashLen=pluck(rawConfig.dashlen,rawConfig.dashLen);itemAttr.dashGap=pluck(rawConfig.dashgap,rawConfig.dashGap);itemAttr.thickness=rawConfig.thickness;itemAttr.showBorder=pluck(rawConfig.showborder,rawConfig.showBorder);itemAttr.borderColor=pluck(rawConfig.bordercolor,rawConfig.borderColor);itemAttr.borderAlpha=pluck(rawConfig.borderalpha,rawConfig.borderAlpha);itemAttr.borderThickness=pluck(rawConfig.borderthickness,rawConfig.borderThickness);itemAttr.alpha=rawConfig.alpha;itemAttr.color=rawConfig.color;itemAttr.fillColor=pluck(rawConfig.fillcolor,rawConfig.fillColor);itemAttr.fontColor=pluck(rawConfig.fontcolor,rawConfig.fontColor);itemAttr.fillAlpha=pluck(rawConfig.fillalpha,rawConfig.fillAlpha);itemAttr.fillAngle=pluck(rawConfig.fillangle,rawConfig.fillAngle);itemAttr.fillRatio=pluck(rawConfig.fillratio,rawConfig.fillRatio);itemAttr.fillPattern=pluck(rawConfig.fillpattern,rawConfig.fillPattern);itemAttr.sides=rawConfig.sides;itemAttr.radius=rawConfig.radius;itemAttr.yRadius=pluck(rawConfig.yradius,rawConfig.yRadius);itemAttr.innerRadius=pluck(rawConfig.innerradius,rawConfig.innerRadius);itemAttr.endAngle=pluck(rawConfig.endangle,rawConfig.endAngle);itemAttr.startAngle=pluck(rawConfig.startangle,rawConfig.startAngle);itemAttr.isVisible=getBoolean(rawConfig.visible)===true;itemAttr.x=rawConfig.x;itemAttr.y=rawConfig.y;itemAttr.xPos=pluck(rawConfig.xpos,rawConfig.xPos);itemAttr.yPos=pluck(rawConfig.ypos,rawConfig.yPos);itemAttr.toY=pluck(rawConfig.toy,rawConfig.toY);itemAttr.toX=pluck(rawConfig.tox,rawConfig.toX);itemAttr.autoScale=pluck(rawConfig.autoscale,rawConfig.autoScale);itemAttr.path=rawConfig.path;itemAttr.css=rawConfig.css;itemAttr.wrap=rawConfig.wrap;itemAttr.text=rawConfig.text!==UNDEF&&rawConfig.text!==null&&rawConfig.text.toString()||UNDEF;itemAttr.font=pluck(rawConfig.font,groupConfig.font,chartConfig.basefont);itemAttr.bold=pluck(rawConfig.bold,rawConfig.isbold,rawConfig.bold,rawConfig.isBold);itemAttr.label=rawConfig.label;itemAttr.align=rawConfig.align;itemAttr.italic=rawConfig.italic;itemAttr.vAlign=pluck(rawConfig.valign,rawConfig.vAlign);itemAttr.bgColor=pluck(rawConfig.bgcolor,rawConfig.bgColor);itemAttr.fontSize=pluck(rawConfig.fontsize,rawConfig.fontSize,groupConfig.fontSize,chartConfig.basefontsize);itemAttr.wrapWidth=pluck(rawConfig.wrapwidth,rawConfig.wrapWidth);itemAttr.leftMargin=pluck(rawConfig.leftmargin,rawConfig.leftMargin);itemAttr.rotateText=pluck(rawConfig.rotatetext,rawConfig.rotateText);itemAttr.wrapHeight=pluck(rawConfig.wrapheight,rawConfig.wrapHeight);itemAttr.showShadow=pluck(rawConfig.showshadow,rawConfig.showShadow);itemAttr.link=rawConfig.link;itemAttr.url=rawConfig.url;itemAttr.link=rawConfig.link;itemAttr.width=rawConfig.width;itemAttr.height=rawConfig.height;itemAttr.xScale=pluck(rawConfig.xscale,rawConfig.xScale);itemAttr.yScale=pluck(rawConfig.yscale,rawConfig.yScale);itemAttr.onload=rawConfig.onload;itemAttr.onerror=rawConfig.onerror;itemAttr.outlineText=pluckNumber(rawConfig.outlinetext,rawConfig.outlineText,0);if(typeof rawConfig.component==="object"){itemAttr.component=rawConfig.component}for(var attribute in itemAttr){if(itemAttr.hasOwnProperty(attribute)){var val=itemAttr[attribute];if(typeof val==="undefined")delete itemAttr[attribute]}}return itemAttr},parseConfiguration=function parseConfiguration(rawConfig,chartConfig){var groupAttr={},rawItemConfigs=rawConfig.items;rawItemConfigs=rawConfig.items=arrangeItems(rawItemConfigs);groupAttr.annotationType=GROUP;groupAttr.id=rawConfig.id;groupAttr.showBelow=typeof rawConfig.showbelow==="undefined"||rawConfig.showbelow===null?1:Number(rawConfig.showbelow);groupAttr.x=rawConfig.x;groupAttr.y=rawConfig.y;groupAttr.animationLabel=pluck(rawConfig.animationlabel,rawConfig.animationLabel);groupAttr.xPos=pluck(rawConfig.xpos,rawConfig.xPos);groupAttr.yPos=pluck(rawConfig.ypos,rawConfig.yPos);groupAttr.grpXShift=pluck(rawConfig.grpxshift,rawConfig.grpXShift);groupAttr.grpYShift=pluck(rawConfig.grpyshift,rawConfig.grpYShift);groupAttr.xShift=pluck(rawConfig.xshift,rawConfig.xShift);groupAttr.yShift=pluck(rawConfig.yshift,rawConfig.yShift);groupAttr.color=rawConfig.color;groupAttr.alpha=rawConfig.alpha;groupAttr.isVisible=Number(rawConfig.visible||1)===1;groupAttr.font=pluck(rawConfig.font,chartConfig.basefont);groupAttr.link=rawConfig.link;groupAttr.fontSize=pluck(rawConfig.fontsize,rawConfig.fontSize,chartConfig.basefontsize);groupAttr.textAlign=pluck(rawConfig.textalign,rawConfig.textAlign);groupAttr.textVAlign=pluck(rawConfig.textvalign,rawConfig.textVAlign);groupAttr.rotateText=pluck(rawConfig.rotatetext,rawConfig.rotateText);groupAttr.wrapText=pluck(rawConfig.wraptext,rawConfig.wrapText);groupAttr.toolText=pluck(rawConfig.tooltext,rawConfig.toolText);groupAttr.link=rawConfig.link;groupAttr.showShadow=pluck(rawConfig.showshadow,rawConfig.showShadow);groupAttr.items=rawConfig.items;groupAttr.css=rawConfig.css;groupAttr.autoScale=pluck(rawConfig.autoscale,rawConfig.autoScale);groupAttr.scaleText=pluck(rawConfig.scaletext,rawConfig.scaleText);groupAttr.xScale=pluck(rawConfig.xscale,rawConfig.xScale);groupAttr.yScale=pluck(rawConfig.yscale,rawConfig.yScale);groupAttr.scaleImages=pluck(rawConfig.scaleimages,rawConfig.scaleImages);groupAttr.constrainedScale=pluck(rawConfig.constrainedscale);groupAttr.origH=pluck(rawConfig.origh,rawConfig.origH,chartConfig.origh);groupAttr.origW=pluck(rawConfig.origw,rawConfig.origW,chartConfig.origw);groupAttr.onAnnotationClick=rawConfig.onAnnotationClick;groupAttr.onAnnotationRollover=rawConfig.onAnnotationRollover;groupAttr.onAnnotationRollout=rawConfig.onAnnotationRollout;if(typeof rawConfig.component==="object"){groupAttr.component=rawConfig.component}for(var attribute in groupAttr){if(groupAttr.hasOwnProperty(attribute)){var val=groupAttr[attribute];if(typeof val==="undefined")delete groupAttr[attribute]}}if(Array.isArray(rawItemConfigs)){groupAttr.itemConfigs=rawItemConfigs.map(function(itemConfig){return parseShapeConfiguration(itemConfig,groupAttr,chartConfig)})}return groupAttr},mergeConfig=function mergeConfig(rawconfig,groupConfig){groupConfig.css=groupConfig.css||rawconfig.css;groupConfig.autoscale=pluck(groupConfig.autoscale,rawconfig.autoscale);groupConfig.animationLabel=pluck(groupConfig.animationLabel,rawconfig.animationLabel);groupConfig.constrainedscale=pluck(groupConfig.constrainedscale,rawconfig.constrainedscale);groupConfig.scaletext=pluck(groupConfig.scaletext,rawconfig.scaletext);groupConfig.scaleimages=pluck(groupConfig.scaleimages,rawconfig.scaleimages);groupConfig.xshift=pluck(groupConfig.xshift,rawconfig.xshift);groupConfig.yshift=pluck(groupConfig.yshift,rawconfig.yshift);groupConfig.grpxshift=pluck(groupConfig.grpxshift,rawconfig.grpxshift);groupConfig.grpyshift=pluck(groupConfig.grpyshift,rawconfig.grpyshift);groupConfig.origw=pluck(groupConfig.origw,rawconfig.origw);groupConfig.origh=pluck(groupConfig.origh,rawconfig.origh);groupConfig.showbelow=pluck(groupConfig.showbelow,rawconfig.showbelow,1);groupConfig.onAnnotationClick=rawconfig.onAnnotationClick;groupConfig.onAnnotationRollover=rawconfig.onAnnotationRollover;groupConfig.onAnnotationRollout=rawconfig.onAnnotationRollout},isRootGroupConfig=function isRootGroupConfig(value,key){return key!=="itemConfigs"},getParsedConfig=function getParsedConfig(rawConfig,chartConfig){if(rawConfig===void 0){rawConfig={groups:[]}}if(chartConfig===void 0){chartConfig={}}return(rawConfig.groups||[]).map(function(rawConfigGroup){mergeConfig(rawConfig,rawConfigGroup);return parseConfiguration(rawConfigGroup,chartConfig)})};var AnnotationManager=function(_SmartRenderer){_inheritsLoose(AnnotationManager,_SmartRenderer);function AnnotationManager(id){var _this;_this=_SmartRenderer.call(this,id)||this;addDep({name:"annotationAnimation",type:"animationRule",extension:annotationAnimation});raphaelShapesRingpath(getDep("redraphael","plugin"));raphaelShapesArcpath(getDep("redraphael","plugin"));_this.groups=[];_this.config.dependencies={};_this._rawJSON={groups:[]};return _this}var _proto=AnnotationManager.prototype;_proto.getName=function getName(){return"annotation"};_proto.getType=function getType(){return"extension"};_proto.configureAttributes=function configureAttributes(rawConfig){if(rawConfig===void 0){rawConfig={groups:[]}}var annManager=this,annManagerConfig=annManager.config;annManager._rawJSON=extend2({},annManager._rawJSON,rawConfig);if(rawConfig.groups){annManagerConfig.parsedConfigs=getParsedConfig(rawConfig,annManager.getFromEnv("chart").config)}else{annManagerConfig.parsedConfigs=[]}annManagerConfig.parsedConfigs.forEach(function(groupConfig){annManager.attachChild(AnnotationGroup,"group",groupConfig.id).configure(groupConfig)});annManager.groups=annManager.getChildren("group")||[]};_proto.addItem=function addItem(groupId,itemConfig,component){if(itemConfig===void 0){itemConfig={}}var annManager=this,rawJSON=annManager._rawJSON,index,targetedGroup,itemsAr,len=rawJSON.groups.length;for(index=0;index<len;index++){if(rawJSON.groups[index].id===groupId){targetedGroup=rawJSON.groups[index];break}}if(targetedGroup){targetedGroup.items=targetedGroup.items||[]}else{targetedGroup={id:groupId,items:[]};rawJSON.groups.push(targetedGroup)}targetedGroup.items.push(itemConfig);annManager.setData(rawJSON,true);itemsAr=annManager.retrieveGroup(groupId).items;return itemsAr[itemsAr.length-1]};_proto.addGroup=function addGroup(rawConfig){if(rawConfig===void 0){rawConfig={}}var annManager=this,rawJSON=annManager._rawJSON;rawJSON.groups.push(rawConfig);annManager.setData(rawJSON,true);return annManager.groups[annManager.groups.length-1]};_proto.addCustomGroup=function addCustomGroup(group){group&&(this.config.customGroup=group)};_proto.update=function update(id,rawConfig){var ext=this,item,key,config={},itemRawConfig,parsedConfig;if(id){for(key in rawConfig){config[key.toLowerCase()]=rawConfig[key]&&rawConfig[key].toString()}item=ext.retrieveItem(id)||ext.retrieveGroup(id);if(!item||!item.getElement()){return}typeof config.visible==="undefined"&&(config.visible=item.config.isVisible);itemRawConfig=item.rawConfig;itemRawConfig=Object.assign(itemRawConfig,config);parsedConfig=parseShapeConfiguration(itemRawConfig);parsedConfig.isVisible=config.visible;item.setData(parsedConfig);return item}};_proto.destroy=function destroy(id){var ext=this,rawJSON=ext._rawJSON,i,j,groupLength,itemLength,group,item,found=false;if(id){for(i=0,groupLength=rawJSON.groups.length;i<groupLength;i++){group=rawJSON.groups[i];for(j=0,itemLength=(group.items||[]).length;j<itemLength;j++){item=group.items[j];if(item.id===id){group.items.splice(j,1);found=true;break}}}if(!found){for(i=0,groupLength=rawJSON.groups.length;i<groupLength;i++){group=rawJSON.groups[i];if(group.id===id){rawJSON.groups.splice(i,1)}}}}else{rawJSON=ext._rawJSON={groups:[]}}ext.setData(rawJSON)};_proto.clear=function clear(){this.destroy()};_proto.retrieveItem=function retrieveItem(id){var found,item,i,len=this.groups.length;for(i=0;i<len;i++){found=this.groups[i].retrieveItem(id);if(found){item=found;break}}return item};_proto.retrieveGroup=function retrieveGroup(id){var controller=this,i,len;for(i=0,len=controller.groups.length;i<len;i++){if(controller.groups[i].getId()===id){return controller.groups[i]}}};_proto.show=function show(id){var item;if(id){item=this.retrieveItem(id)||this.retrieveGroup(id);item&&item.show()}else{this.groups.forEach(function(group){group.show()})}};_proto.hide=function hide(id){var item;if(id){item=this.retrieveItem(id)||this.retrieveGroup(id);item&&item.hide()}else{this.groups.forEach(function(group){group.hide()})}};_proto.draw=function draw(){var ext=this;ext.addToEnv("snapPoints",getSnapPoints(ext.getFromEnv("chart")));ext.addGraphicalElement({el:"group",attr:{name:"upperannotations"},component:ext,container:{label:"group",id:"abovePlotGroup",isParent:true},id:"upperAnnotationGroup",label:"group"});ext.addGraphicalElement({el:"group",attr:{name:"lowerannotations"},component:ext,container:{label:"group",id:"belowPlotGroup",isParent:true},id:"lowerAnnotationGroup",label:"group"})};return AnnotationManager}(SmartRenderer);export default AnnotationManager;