@fusioncharts/features
Version:
FusionCharts JavaScript charting framework
1 lines • 18.5 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 _utils=require("./utils");var _lib=require("@fusioncharts/core/src/lib");var _dependencyManager=require("@fusioncharts/core/src/dependency-manager");var _annotationAnimation=_interopRequireDefault(require("./annotation-animation"));var _redraphaelShapes=_interopRequireDefault(require("@fusioncharts/core/src/_internal/redraphael/redraphael-shapes/redraphael-shapes.ringpath"));var _redraphaelShapes2=_interopRequireDefault(require("@fusioncharts/core/src/_internal/redraphael/redraphael-shapes/redraphael-shapes.arcpath"));var _annotationGroup=_interopRequireDefault(require("./shapes/annotation-group"));var _componentInterface=require("@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(_utils.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(0,_utils.computeSliceBounds)(traversalArr[3],set.config)}else if(circular3D.indexOf(dataset.getName().toLowerCase())>-1){return(0,_utils.compute3DSliceBounds)(traversalArr[3],set.config)}bbox=(0,_utils.computePlotBounds)(set,dataset.getName());return(0,_utils.xyCalculator)(traversalArr[3],bbox)},xaxis:(0,_utils.axisMacroParser)(chart,"xAxis"),yaxis:(0,_utils.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=(0,_lib.pluck)(rawConfig.tooltext,rawConfig.toolText);itemAttr.animationLabel=(0,_lib.pluck)(rawConfig.animationlabel,rawConfig.animationLabel);itemAttr.dashed=rawConfig.dashed;itemAttr.dashLen=(0,_lib.pluck)(rawConfig.dashlen,rawConfig.dashLen);itemAttr.dashGap=(0,_lib.pluck)(rawConfig.dashgap,rawConfig.dashGap);itemAttr.thickness=rawConfig.thickness;itemAttr.showBorder=(0,_lib.pluck)(rawConfig.showborder,rawConfig.showBorder);itemAttr.borderColor=(0,_lib.pluck)(rawConfig.bordercolor,rawConfig.borderColor);itemAttr.borderAlpha=(0,_lib.pluck)(rawConfig.borderalpha,rawConfig.borderAlpha);itemAttr.borderThickness=(0,_lib.pluck)(rawConfig.borderthickness,rawConfig.borderThickness);itemAttr.alpha=rawConfig.alpha;itemAttr.color=rawConfig.color;itemAttr.fillColor=(0,_lib.pluck)(rawConfig.fillcolor,rawConfig.fillColor);itemAttr.fontColor=(0,_lib.pluck)(rawConfig.fontcolor,rawConfig.fontColor);itemAttr.fillAlpha=(0,_lib.pluck)(rawConfig.fillalpha,rawConfig.fillAlpha);itemAttr.fillAngle=(0,_lib.pluck)(rawConfig.fillangle,rawConfig.fillAngle);itemAttr.fillRatio=(0,_lib.pluck)(rawConfig.fillratio,rawConfig.fillRatio);itemAttr.fillPattern=(0,_lib.pluck)(rawConfig.fillpattern,rawConfig.fillPattern);itemAttr.sides=rawConfig.sides;itemAttr.radius=rawConfig.radius;itemAttr.yRadius=(0,_lib.pluck)(rawConfig.yradius,rawConfig.yRadius);itemAttr.innerRadius=(0,_lib.pluck)(rawConfig.innerradius,rawConfig.innerRadius);itemAttr.endAngle=(0,_lib.pluck)(rawConfig.endangle,rawConfig.endAngle);itemAttr.startAngle=(0,_lib.pluck)(rawConfig.startangle,rawConfig.startAngle);itemAttr.isVisible=getBoolean(rawConfig.visible)===true;itemAttr.x=rawConfig.x;itemAttr.y=rawConfig.y;itemAttr.xPos=(0,_lib.pluck)(rawConfig.xpos,rawConfig.xPos);itemAttr.yPos=(0,_lib.pluck)(rawConfig.ypos,rawConfig.yPos);itemAttr.toY=(0,_lib.pluck)(rawConfig.toy,rawConfig.toY);itemAttr.toX=(0,_lib.pluck)(rawConfig.tox,rawConfig.toX);itemAttr.autoScale=(0,_lib.pluck)(rawConfig.autoscale,rawConfig.autoScale);itemAttr.path=rawConfig.path;itemAttr.css=rawConfig.css;itemAttr.wrap=rawConfig.wrap;itemAttr.text=rawConfig.text!==_lib.UNDEF&&rawConfig.text!==null&&rawConfig.text.toString()||_lib.UNDEF;itemAttr.font=(0,_lib.pluck)(rawConfig.font,groupConfig.font,chartConfig.basefont);itemAttr.bold=(0,_lib.pluck)(rawConfig.bold,rawConfig.isbold,rawConfig.bold,rawConfig.isBold);itemAttr.label=rawConfig.label;itemAttr.align=rawConfig.align;itemAttr.italic=rawConfig.italic;itemAttr.vAlign=(0,_lib.pluck)(rawConfig.valign,rawConfig.vAlign);itemAttr.bgColor=(0,_lib.pluck)(rawConfig.bgcolor,rawConfig.bgColor);itemAttr.fontSize=(0,_lib.pluck)(rawConfig.fontsize,rawConfig.fontSize,groupConfig.fontSize,chartConfig.basefontsize);itemAttr.wrapWidth=(0,_lib.pluck)(rawConfig.wrapwidth,rawConfig.wrapWidth);itemAttr.leftMargin=(0,_lib.pluck)(rawConfig.leftmargin,rawConfig.leftMargin);itemAttr.rotateText=(0,_lib.pluck)(rawConfig.rotatetext,rawConfig.rotateText);itemAttr.wrapHeight=(0,_lib.pluck)(rawConfig.wrapheight,rawConfig.wrapHeight);itemAttr.showShadow=(0,_lib.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=(0,_lib.pluck)(rawConfig.xscale,rawConfig.xScale);itemAttr.yScale=(0,_lib.pluck)(rawConfig.yscale,rawConfig.yScale);itemAttr.onload=rawConfig.onload;itemAttr.onerror=rawConfig.onerror;itemAttr.outlineText=(0,_lib.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=(0,_utils.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=(0,_lib.pluck)(rawConfig.animationlabel,rawConfig.animationLabel);groupAttr.xPos=(0,_lib.pluck)(rawConfig.xpos,rawConfig.xPos);groupAttr.yPos=(0,_lib.pluck)(rawConfig.ypos,rawConfig.yPos);groupAttr.grpXShift=(0,_lib.pluck)(rawConfig.grpxshift,rawConfig.grpXShift);groupAttr.grpYShift=(0,_lib.pluck)(rawConfig.grpyshift,rawConfig.grpYShift);groupAttr.xShift=(0,_lib.pluck)(rawConfig.xshift,rawConfig.xShift);groupAttr.yShift=(0,_lib.pluck)(rawConfig.yshift,rawConfig.yShift);groupAttr.color=rawConfig.color;groupAttr.alpha=rawConfig.alpha;groupAttr.isVisible=Number(rawConfig.visible||1)===1;groupAttr.font=(0,_lib.pluck)(rawConfig.font,chartConfig.basefont);groupAttr.link=rawConfig.link;groupAttr.fontSize=(0,_lib.pluck)(rawConfig.fontsize,rawConfig.fontSize,chartConfig.basefontsize);groupAttr.textAlign=(0,_lib.pluck)(rawConfig.textalign,rawConfig.textAlign);groupAttr.textVAlign=(0,_lib.pluck)(rawConfig.textvalign,rawConfig.textVAlign);groupAttr.rotateText=(0,_lib.pluck)(rawConfig.rotatetext,rawConfig.rotateText);groupAttr.wrapText=(0,_lib.pluck)(rawConfig.wraptext,rawConfig.wrapText);groupAttr.toolText=(0,_lib.pluck)(rawConfig.tooltext,rawConfig.toolText);groupAttr.link=rawConfig.link;groupAttr.showShadow=(0,_lib.pluck)(rawConfig.showshadow,rawConfig.showShadow);groupAttr.items=rawConfig.items;groupAttr.css=rawConfig.css;groupAttr.autoScale=(0,_lib.pluck)(rawConfig.autoscale,rawConfig.autoScale);groupAttr.scaleText=(0,_lib.pluck)(rawConfig.scaletext,rawConfig.scaleText);groupAttr.xScale=(0,_lib.pluck)(rawConfig.xscale,rawConfig.xScale);groupAttr.yScale=(0,_lib.pluck)(rawConfig.yscale,rawConfig.yScale);groupAttr.scaleImages=(0,_lib.pluck)(rawConfig.scaleimages,rawConfig.scaleImages);groupAttr.constrainedScale=(0,_lib.pluck)(rawConfig.constrainedscale);groupAttr.origH=(0,_lib.pluck)(rawConfig.origh,rawConfig.origH,chartConfig.origh);groupAttr.origW=(0,_lib.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=(0,_lib.pluck)(groupConfig.autoscale,rawconfig.autoscale);groupConfig.animationLabel=(0,_lib.pluck)(groupConfig.animationLabel,rawconfig.animationLabel);groupConfig.constrainedscale=(0,_lib.pluck)(groupConfig.constrainedscale,rawconfig.constrainedscale);groupConfig.scaletext=(0,_lib.pluck)(groupConfig.scaletext,rawconfig.scaletext);groupConfig.scaleimages=(0,_lib.pluck)(groupConfig.scaleimages,rawconfig.scaleimages);groupConfig.xshift=(0,_lib.pluck)(groupConfig.xshift,rawconfig.xshift);groupConfig.yshift=(0,_lib.pluck)(groupConfig.yshift,rawconfig.yshift);groupConfig.grpxshift=(0,_lib.pluck)(groupConfig.grpxshift,rawconfig.grpxshift);groupConfig.grpyshift=(0,_lib.pluck)(groupConfig.grpyshift,rawconfig.grpyshift);groupConfig.origw=(0,_lib.pluck)(groupConfig.origw,rawconfig.origw);groupConfig.origh=(0,_lib.pluck)(groupConfig.origh,rawconfig.origh);groupConfig.showbelow=(0,_lib.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){function AnnotationManager(id){var _this;_this=_SmartRenderer.call(this,id)||this;(0,_dependencyManager.addDep)({name:"annotationAnimation",type:"animationRule",extension:_annotationAnimation.default});(0,_redraphaelShapes.default)((0,_dependencyManager.getDep)("redraphael","plugin"));(0,_redraphaelShapes2.default)((0,_dependencyManager.getDep)("redraphael","plugin"));_this.groups=[];_this.config.dependencies={};_this._rawJSON={groups:[]};return _this}(0,_inheritsLoose2.default)(AnnotationManager,_SmartRenderer);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=(0,_lib.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.default,"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;if(rawJSON.groups){rawJSON.groups.push(rawConfig)}else{rawJSON.groups=[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&&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&&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}(_componentInterface.SmartRenderer);var _default=exports.default=AnnotationManager;