if(!AmCharts.translations["export"]){AmCharts.translations["export"]={}}
if(!AmCharts.translations["export"]["en"]){AmCharts.translations["export"]["en"]={"fallback.save.text":"CTRL + C to copy the data into the clipboard.","fallback.save.image":"Rightclick -> Save picture as... to save the image.","capturing.delayed.menu.label":"{{duration}}","capturing.delayed.menu.title":"Click to cancel","menu.label.print":"Print","menu.label.undo":"Undo","menu.label.redo":"Redo","menu.label.cancel":"Cancel","menu.label.save.image":"Download as ...","menu.label.save.data":"Save as ...","menu.label.draw":"Annotate ...","menu.label.draw.change":"Change ...","menu.label.draw.add":"Add ...","menu.label.draw.shapes":"Shape ...","menu.label.draw.colors":"Color ...","menu.label.draw.widths":"Size ...","menu.label.draw.opacities":"Opacity ...","menu.label.draw.text":"Text","menu.label.draw.modes":"Mode ...","menu.label.draw.modes.pencil":"Pencil","menu.label.draw.modes.line":"Line","menu.label.draw.modes.arrow":"Arrow","label.saved.from":"Saved from: "}}
(function(){AmCharts["export"]=function(chart,config){var _timer;var _this={name:"export",version:"1.4.74",libs:{async:true,autoLoad:true,reload:false,resources:["fabric.js/fabric.min.js","FileSaver.js/FileSaver.min.js",{"jszip/jszip.min.js":["xlsx/xlsx.min.js"],"pdfmake/pdfmake.min.js":["pdfmake/vfs_fonts.js"]}],namespaces:{"pdfmake.min.js":"pdfMake","jszip.min.js":"JSZip","xlsx.min.js":"XLSX","fabric.min.js":"fabric","FileSaver.min.js":"saveAs"},loadTimeout:10000,unsupportedIE9libs:["pdfmake.min.js","jszip.min.js","xlsx.min.js"]},config:{},setup:{chart:chart,hasBlob:false,wrapper:false,isIE:!!window.document.documentMode,IEversion:window.document.documentMode,hasTouch:typeof window.Touch=="object",focusedMenuItem:undefined,hasClasslist:("classList"in document.createElement("_"))},drawing:{enabled:false,undos:[],redos:[],buffer:{position:{x1:0,y1:0,x2:0,y2:0,xD:0,yD:0}},handler:{undo:function(options,skipped){var item=_this.drawing.undos.pop();if(item){item.selectable=true;_this.drawing.redos.push(item);if(item.action=="added"){_this.setup.fabric.remove(item.target);}
var state=JSON.parse(item.state);item.target.set(state);if(item.target instanceof fabric.Group){_this.drawing.handler.change({color:state.cfg.color,width:state.cfg.width,opacity:state.cfg.opacity},true,item.target);}
_this.setup.fabric.renderAll();}},redo:function(options,skipped){var item=_this.drawing.redos.pop();if(item){item.selectable=true;_this.drawing.undos.push(item);if(item.action=="added"){_this.setup.fabric.add(item.target);}
var state=JSON.parse(item.state);item.target.recentState=item.state;item.target.set(state);if(item.target instanceof fabric.Group){_this.drawing.handler.change({color:state.cfg.color,width:state.cfg.width,opacity:state.cfg.opacity},true,item.target);}
_this.setup.fabric.renderAll();}},done:function(options){_this.drawing.enabled=false;_this.drawing.buffer.enabled=false;_this.drawing.undos=[];_this.drawing.redos=[];_this.createMenu(_this.config.menu);_this.setup.fabric.deactivateAll();if(_this.isElement(_this.setup.wrapper)&&_this.isElement(_this.setup.wrapper.parentNode)&&_this.setup.wrapper.parentNode.removeChild){_this.setup.wrapper.parentNode.removeChild(_this.setup.wrapper);_this.setup.wrapper=false;}},add:function(options){var cfg=_this.deepMerge({top:_this.setup.fabric.height/2,left:_this.setup.fabric.width/2},options||{});var method=cfg.url.indexOf(".svg")!=-1?fabric.loadSVGFromURL:fabric.Image.fromURL;method(cfg.url,function(objects,options){var group=options!==undefined?fabric.util.groupSVGElements(objects,options):objects;var ratio=false;if(group.height>_this.setup.fabric.height||group.width>_this.setup.fabric.width){ratio=(_this.setup.fabric.height/2)/ group.height;
}
if(cfg.top>_this.setup.fabric.height){cfg.top=_this.setup.fabric.height/2;}
if(cfg.left>_this.setup.fabric.width){cfg.left=_this.setup.fabric.width/2;}
_this.drawing.buffer.isDrawing=true;group.set({originX:"center",originY:"center",top:cfg.top,left:cfg.left,width:ratio?group.width*ratio:group.width,height:ratio?group.height*ratio:group.height,fill:_this.drawing.color});_this.setup.fabric.add(group);});},change:function(options,skipped,target){var cfg=_this.deepMerge({},options||{});var state,i1,rgba;var current=target||_this.drawing.buffer.target;var objects=current?current._objects?current._objects:[current]:null;if(cfg.mode){_this.drawing.mode=cfg.mode;}
if(cfg.width){_this.drawing.width=cfg.width;_this.drawing.fontSize=cfg.fontSize=cfg.width*3;if(_this.drawing.width==1){_this.drawing.fontSize=cfg.fontSize=_this.defaults.fabric.drawing.fontSize;}}
if(cfg.fontSize){_this.drawing.fontSize=cfg.fontSize;}
if(cfg.color){_this.drawing.color=cfg.color;}
if(cfg.opacity){_this.drawing.opacity=cfg.opacity;}
rgba=_this.getRGBA(_this.drawing.color);rgba.pop();rgba.push(_this.drawing.opacity);_this.drawing.color="rgba("+ rgba.join()+")";_this.setup.fabric.freeDrawingBrush.color=_this.drawing.color;_this.setup.fabric.freeDrawingBrush.width=_this.drawing.width;if(current){state=JSON.parse(current.recentState).cfg;if(state){cfg.color=cfg.color||state.color;cfg.width=cfg.width||state.width;cfg.opacity=cfg.opacity||state.opacity;cfg.fontSize=cfg.fontSize||state.fontSize;rgba=_this.getRGBA(cfg.color);rgba.pop();rgba.push(cfg.opacity);cfg.color="rgba("+ rgba.join()+")";}
for(i1=0;i1<objects.length;i1++){if(objects[i1]instanceof fabric.Text||objects[i1]instanceof fabric.PathGroup||objects[i1]instanceof fabric.Triangle){if(cfg.color||cfg.opacity){objects[i1].set({fill:cfg.color});}
if(cfg.fontSize){objects[i1].set({fontSize:cfg.fontSize});}}else if(objects[i1]instanceof fabric.Path||objects[i1]instanceof fabric.Line){if(current instanceof fabric.Group){if(cfg.color||cfg.opacity){objects[i1].set({stroke:cfg.color});}}else{if(cfg.color||cfg.opacity){objects[i1].set({stroke:cfg.color});}
if(cfg.width){objects[i1].set({strokeWidth:cfg.width});}}}}
if(!skipped){state=JSON.stringify(_this.deepMerge(current.saveState()._stateProperties,{cfg:{color:cfg.color,width:cfg.width,opacity:cfg.opacity}}));current.recentState=state;_this.drawing.redos=[];_this.drawing.undos.push({action:"modified",target:current,state:state});}
_this.setup.fabric.renderAll();}},text:function(options){var cfg=_this.deepMerge({text:_this.i18l("menu.label.draw.text"),top:_this.setup.fabric.height/2,left:_this.setup.fabric.width/2,fontSize:_this.drawing.fontSize,fontFamily:_this.setup.chart.fontFamily||"Verdana",fill:_this.drawing.color},options||{});cfg.click=function(){};var text=new fabric.IText(cfg.text,cfg);_this.drawing.buffer.isDrawing=true;_this.setup.fabric.add(text);_this.setup.fabric.setActiveObject(text);text.selectAll();text.enterEditing();return text;},line:function(options){var cfg=_this.deepMerge({x1:(_this.setup.fabric.width/2)-(_this.setup.fabric.width/10),x2:(_this.setup.fabric.width/2)+(_this.setup.fabric.width/10),y1:(_this.setup.fabric.height/2),y2:(_this.setup.fabric.height/2),angle:90,strokeLineCap:_this.drawing.lineCap,arrow:_this.drawing.arrow,color:_this.drawing.color,width:_this.drawing.width,group:[],},options||{});var i1,arrow,arrowTop,arrowLeft;var line=new fabric.Line([cfg.x1,cfg.y1,cfg.x2,cfg.y2],{stroke:cfg.color,strokeWidth:cfg.width,strokeLineCap:cfg.strokeLineCap});cfg.group.push(line);if(cfg.arrow){cfg.angle=cfg.angle?cfg.angle:_this.getAngle(cfg.x1,cfg.y1,cfg.x2,cfg.y2);if(cfg.arrow=="start"){arrowTop=cfg.y1+(cfg.width/2);arrowLeft=cfg.x1+(cfg.width/2);}else if(cfg.arrow=="middle"){arrowTop=cfg.y2+(cfg.width/2)-((cfg.y2- cfg.y1)/ 2 );
arrowLeft=cfg.x2+(cfg.width/2)-((cfg.x2- cfg.x1)/ 2 );
}else{arrowTop=cfg.y2+(cfg.width/2);arrowLeft=cfg.x2+(cfg.width/2);}
arrow=new fabric.Triangle({top:arrowTop,left:arrowLeft,fill:cfg.color,height:cfg.width*7,width:cfg.width*7,angle:cfg.angle,originX:"center",originY:"bottom"});cfg.group.push(arrow);}
_this.drawing.buffer.isDrawing=true;if(cfg.action!="config"){if(cfg.arrow){var group=new fabric.Group(cfg.group);group.set({cfg:cfg,fill:cfg.color,action:cfg.action,selectable:true,known:cfg.action=="change"});if(cfg.action=="change"){_this.setup.fabric.setActiveObject(group);}
_this.setup.fabric.add(group);return group;}else{_this.setup.fabric.add(line);return line;}}else{for(i1=0;i1<cfg.group.length;i1++){cfg.group[i1].ignoreUndo=true;_this.setup.fabric.add(cfg.group[i1]);}}
return cfg;}}},defaults:{position:"top-right",fileName:"amCharts",action:"download",overflow:true,path:((chart.path||"")+"plugins/export/"),formats:{JPG:{mimeType:"image/jpg",extension:"jpg",capture:true},PNG:{mimeType:"image/png",extension:"png",capture:true},SVG:{mimeType:"text/xml",extension:"svg",capture:true},PDF:{mimeType:"application/pdf",extension:"pdf",capture:true},CSV:{mimeType:"text/plain",extension:"csv"},JSON:{mimeType:"text/plain",extension:"json"},XLSX:{mimeType:"application/octet-stream",extension:"xlsx"}},fabric:{backgroundColor:"#FFFFFF",removeImages:true,forceRemoveImages:false,selection:false,loadTimeout:5000,drawing:{enabled:true,arrow:"end",lineCap:"butt",mode:"pencil",modes:["pencil","line","arrow"],color:"#000000",colors:["#000000","#FFFFFF","#FF0000","#00FF00","#0000FF"],shapes:["11.svg","14.svg","16.svg","17.svg","20.svg","27.svg"],width:1,fontSize:11,widths:[1,5,10,15],opacity:1,opacities:[1,0.8,0.6,0.4,0.2],menu:undefined,autoClose:true},border:{fill:"",fillOpacity:0,stroke:"#000000",strokeWidth:1,strokeOpacity:1}},pdfMake:{images:{},pageOrientation:"portrait",pageMargins:40,pageOrigin:true,pageSize:"A4",pageSizes:{"4A0":[4767.87,6740.79],"2A0":[3370.39,4767.87],"A0":[2383.94,3370.39],"A1":[1683.78,2383.94],"A2":[1190.55,1683.78],"A3":[841.89,1190.55],"A4":[595.28,841.89],"A5":[419.53,595.28],"A6":[297.64,419.53],"A7":[209.76,297.64],"A8":[147.40,209.76],"A9":[104.88,147.40],"A10":[73.70,104.88],"B0":[2834.65,4008.19],"B1":[2004.09,2834.65],"B2":[1417.32,2004.09],"B3":[1000.63,1417.32],"B4":[708.66,1000.63],"B5":[498.90,708.66],"B6":[354.33,498.90],"B7":[249.45,354.33],"B8":[175.75,249.45],"B9":[124.72,175.75],"B10":[87.87,124.72],"C0":[2599.37,3676.54],"C1":[1836.85,2599.37],"C2":[1298.27,1836.85],"C3":[918.43,1298.27],"C4":[649.13,918.43],"C5":[459.21,649.13],"C6":[323.15,459.21],"C7":[229.61,323.15],"C8":[161.57,229.61],"C9":[113.39,161.57],"C10":[79.37,113.39],"RA0":[2437.80,3458.27],"RA1":[1729.13,2437.80],"RA2":[1218.90,1729.13],"RA3":[864.57,1218.90],"RA4":[609.45,864.57],"SRA0":[2551.18,3628.35],"SRA1":[1814.17,2551.18],"SRA2":[1275.59,1814.17],"SRA3":[907.09,1275.59],"SRA4":[637.80,907.09],"EXECUTIVE":[521.86,756.00],"FOLIO":[612.00,936.00],"LEGAL":[612.00,1008.00],"LETTER":[612.00,792.00],"TABLOID":[792.00,1224.00]}},menu:undefined,divId:null,menuReviver:null,menuWalker:null,fallback:true,keyListener:true,fileListener:true,compress:true,debug:false},listenersToRemove:[],i18l:function(key,language){var lang=language?language:_this.setup.chart.language?_this.setup.chart.language:"en";var catalog=AmCharts.translations[_this.name][lang]||AmCharts.translations[_this.name]["en"];return catalog[key]||key;},download:function(data,type,filename){if(window.saveAs&&_this.setup.hasBlob){var blob=_this.toBlob({data:data,type:type},function(data){saveAs(data,filename);});}else if(_this.config.fallback&&type=="text/plain"){var div=document.createElement("div");var msg=document.createElement("div");var textarea=document.createElement("textarea");msg.innerHTML=_this.i18l("fallback.save.text");div.appendChild(msg);div.appendChild(textarea);msg.setAttribute("class","amcharts-export-fallback-message");div.setAttribute("class","amcharts-export-fallback");_this.setup.chart.containerDiv.appendChild(div);textarea.setAttribute("readonly","");textarea.value=data;textarea.focus();textarea.select();_this.createMenu([{"class":"export-main export-close",label:"Done",click:function(){_this.createMenu(_this.config.menu);if(_this.isElement(_this.setup.chart.containerDiv)){_this.setup.chart.containerDiv.removeChild(div);}}}]);}else if(_this.config.fallback&&type.split("/")[0]=="image"){var div=document.createElement("div");var msg=document.createElement("div");var img=_this.toImage({data:data});msg.innerHTML=_this.i18l("fallback.save.image");div.appendChild(msg);div.appendChild(img);msg.setAttribute("class","amcharts-export-fallback-message");div.setAttribute("class","amcharts-export-fallback");_this.setup.chart.containerDiv.appendChild(div);_this.createMenu([{"class":"export-main export-close",label:"Done",click:function(){_this.createMenu(_this.config.menu);if(_this.isElement(_this.setup.chart.containerDiv)){_this.setup.chart.containerDiv.removeChild(div);}}}]);}else{throw new Error("Unable to create file. Ensure saveAs (FileSaver.js) is supported.");}
return data;},loadResource:function(src,addons){var i1,exist,node,item,check,type;var url=src.indexOf("//")!=-1?src:[_this.libs.path,src].join("");function errorCallback(){_this.handleLog(["amCharts[export]: Loading error on ",this.src||this.href].join(""));}
function loadCallback(){if(addons){for(i1=0;i1<addons.length;i1++){_this.loadResource(addons[i1]);}}}
if(src.indexOf(".js")!=-1){node=document.createElement("script");node.setAttribute("type","text/javascript");node.setAttribute("src",url);if(_this.libs.async){node.setAttribute("async","");}}else if(src.indexOf(".css")!=-1){node=document.createElement("link");node.setAttribute("type","text/css");node.setAttribute("rel","stylesheet");node.setAttribute("href",url);}
for(i1=0;i1<document.head.childNodes.length;i1++){item=document.head.childNodes[i1];check=item?(item.src||item.href):false;type=item?item.tagName:false;if(item&&check&&check.indexOf(src)!=-1){if(_this.libs.reload){document.head.removeChild(item);}
exist=true;break;}}
for(i1 in _this.libs.namespaces){var namespace=_this.libs.namespaces[i1];var check=src.toLowerCase();var item=i1.toLowerCase();if(check.indexOf(item)!=-1){if(_this.setup.isIE&&_this.setup.IEversion<=9){if(_this.libs.unsupportedIE9libs&&_this.libs.unsupportedIE9libs.indexOf(item)!=-1){return;}}
if(window[namespace]!==undefined){exist=true;break;}}}
if(!exist||_this.libs.reload){node.addEventListener("load",loadCallback);_this.addListenerToRemove("load",node,loadCallback);node.addEventListener("error",errorCallback);_this.addListenerToRemove("error",node,errorCallback);document.head.appendChild(node);}},addListenerToRemove:function(event,node,method){_this.listenersToRemove.push({node:node,method:method,event:event});},loadDependencies:function(){var i1,i2;if(_this.libs.autoLoad){for(i1=0;i1<_this.libs.resources.length;i1++){if(_this.libs.resources[i1]instanceof Object){for(i2 in _this.libs.resources[i1]){_this.loadResource(i2,_this.libs.resources[i1][i2]);}}else{_this.loadResource(_this.libs.resources[i1]);}}}},pxToNumber:function(attr,returnUndefined){if(!attr&&returnUndefined){return undefined;}
return Number(String(attr).replace("px",""))||0;},numberToPx:function(attr){return String(attr)+"px";},cloneObject:function(o){var clone,v,k,isObject,isDate;clone=Array.isArray(o)?[]:{};for(k in o){v=o[k];isObject=typeof v==="object";isDate=v instanceof Date;clone[k]=isObject&&!isDate?_this.cloneObject(v):v;}
return clone;},deepMerge:function(a,b,overwrite){var i1,v,type=b instanceof Array?"array":"object";if(!(a instanceof Object||a instanceof Array)){return a;}
for(i1 in b){if(type=="array"&&isNaN(i1)){continue;}
v=b[i1];if(a&&a[i1]==undefined||overwrite){if(v instanceof Array){a[i1]=new Array();}else if(v instanceof Function){a[i1]=function(){};}else if(v instanceof Date){a[i1]=new Date();}else if(v instanceof Object){a[i1]=new Object();}else if(v instanceof Number){a[i1]=new Number();}else if(v instanceof String){a[i1]=new String();}}
if((v instanceof Object||v instanceof Array)&&!(v instanceof Function||v instanceof Date||_this.isElement(v))&&i1!="chart"&&i1!="scope"){_this.deepMerge(a[i1],v,overwrite);}else{if(a instanceof Array&&!overwrite){a.push(v);}else if(a){a[i1]=v;}}}
return a;},isElement:function(thingy){return thingy instanceof Object&&thingy&&thingy.nodeType===1;},isHashbanged:function(thingy){var str=String(thingy).replace(/\"/g,"");return str.slice(0,3)=="url"?str.slice(str.indexOf("#")+ 1,str.length- 1):false;},isPressed:function(event){if(event.type=="mousemove"&&event.which===1){}else if(event.type=="touchmove"||event.buttons===1||event.button===1||event.which===1){_this.drawing.buffer.isPressed=true;}else{_this.drawing.buffer.isPressed=false;}
return _this.drawing.buffer.isPressed;},removeImage:function(source){if(source){if(_this.config.fabric.forceRemoveImages){return true;}else if(_this.config.fabric.removeImages&&_this.isTainted(source)){return true;}else if(_this.setup.isIE&&(_this.setup.IEversion==10||_this.setup.IEversion==11)&&source.toLowerCase().indexOf(".svg")!=-1){return true;}}
return false},isTainted:function(source){var origin=String(window.location.origin||window.location.protocol+"//"+ window.location.hostname+(window.location.port?':'+ window.location.port:''));if(source){if(origin.indexOf(":\\")!=-1||source.indexOf(":\\")!=-1||origin.indexOf("file://")!=-1||source.indexOf("file://")!=-1){return true}else if(source.indexOf("//")!=-1&&source.indexOf(origin.replace(/.*:/,""))==-1){return true;}}
return false;},isSupported:function(){if(!_this.config.enabled){return false;}
if(_this.setup.isIE&&_this.setup.IEversion<=9){if(!Array.prototype.indexOf||!document.head||_this.config.fallback===false){return false;}}
return true;},getAngle:function(x1,y1,x2,y2){var x=x2- x1;var y=y2- y1;var angle;if(x==0){if(y==0){angle=0;}else if(y>0){angle=Math.PI/2;}else{angle=Math.PI*3/2;}}else if(y==0){if(x>0){angle=0;}else{angle=Math.PI;}}else{if(x<0){angle=Math.atan(y/x)+ Math.PI;}else if(y<0){angle=Math.atan(y/x)+(2*Math.PI);}else{angle=Math.atan(y/x);}}
return angle*180/Math.PI;},gatherAttribute:function(elm,attr,limit,lvl){var value,lvl=lvl?lvl:0,limit=limit?limit:3;if(elm){value=elm.getAttribute(attr);if(!value&&lvl<limit){return _this.gatherAttribute(elm.parentNode,attr,limit,lvl+ 1);}}
return value;},gatherClassName:function(elm,className,limit,lvl){var value,lvl=lvl?lvl:0,limit=limit?limit:3;if(_this.isElement(elm)){value=(elm.getAttribute("class")||"").split(" ").indexOf(className)!=-1;if(!value&&lvl<limit){return _this.gatherClassName(elm.parentNode,className,limit,lvl+ 1);}else if(value){value=elm;}}
return value;},gatherElements:function(group,cfg,images){var i1,i2;for(i1=0;i1<group.children.length;i1++){var childNode=group.children[i1];if(childNode.tagName=="clipPath"){var bbox={};var transform=fabric.parseTransformAttribute(_this.gatherAttribute(childNode,"transform"));for(i2=0;i2<childNode.childNodes.length;i2++){childNode.childNodes[i2].setAttribute("fill","transparent");bbox={x:_this.pxToNumber(childNode.childNodes[i2].getAttribute("x")),y:_this.pxToNumber(childNode.childNodes[i2].getAttribute("y")),width:_this.pxToNumber(childNode.childNodes[i2].getAttribute("width")),height:_this.pxToNumber(childNode.childNodes[i2].getAttribute("height"))}}
group.clippings[childNode.id]={svg:childNode,bbox:bbox,transform:transform};}else if(childNode.tagName=="pattern"){var props={node:childNode,source:childNode.getAttribute("xlink:href"),width:Number(childNode.getAttribute("width")),height:Number(childNode.getAttribute("height")),repeat:"repeat",offsetX:0,offsetY:0}
for(i2=0;i2<childNode.childNodes.length;i2++){if(childNode.childNodes[i2].tagName=="rect"){props.fill=childNode.childNodes[i2].getAttribute("fill");}else if(childNode.childNodes[i2].tagName=="image"){var attrs=fabric.parseAttributes(childNode.childNodes[i2],fabric.SHARED_ATTRIBUTES);if(attrs.transformMatrix){props.offsetX=attrs.transformMatrix[4];props.offsetY=attrs.transformMatrix[5];}}}
if(_this.removeImage(props.source)){group.patterns[childNode.id]=props.fill?props.fill:"transparent";}else{group.patterns[props.node.id]=props;}}else if(childNode.tagName=="image"){images.included++;fabric.Image.fromURL(childNode.getAttribute("xlink:href"),function(img){images.loaded++;});}else{var attrs=["fill","stroke"];for(i2=0;i2<attrs.length;i2++){var attr=attrs[i2];var attrVal=childNode.getAttribute(attr);var attrRGBA=_this.getRGBA(attrVal);var isHashbanged=_this.isHashbanged(attrVal);if(attrVal&&!attrRGBA&&!isHashbanged){childNode.setAttribute(attr,"none");childNode.setAttribute(attr+"-opacity","0");}}}}
return group;},getRGBA:function(source,returnInstance){if(source!="none"&&source!="transparent"&&!_this.isHashbanged(source)){source=new fabric.Color(source);if(source._source){return returnInstance?source:source.getSource();}}
return false;},gatherPosition:function(event,type){var ref=_this.drawing.buffer.position;var ivt=fabric.util.invertTransform(_this.setup.fabric.viewportTransform);var pos;if(event.type=="touchmove"){if("touches"in event){event=event.touches[0];}else if("changedTouches"in event){event=event.changedTouches[0];}}
pos=fabric.util.transformPoint(_this.setup.fabric.getPointer(event,true),ivt);if(type==1){ref.x1=pos.x;ref.y1=pos.y;}
ref.x2=pos.x;ref.y2=pos.y;ref.xD=(ref.x1- ref.x2)<0?(ref.x1- ref.x2)*-1:(ref.x1- ref.x2);ref.yD=(ref.y1- ref.y2)<0?(ref.y1- ref.y2)*-1:(ref.y1- ref.y2);return ref;},modifyFabric:function(){fabric.ElementsParser.prototype.resolveGradient=function(obj,property){var instanceFillValue=obj.get(property);if(!(/^url\(/).test(instanceFillValue)){return;}
var gradientId=instanceFillValue.slice(instanceFillValue.indexOf("#")+ 1,instanceFillValue.length- 1);if(fabric.gradientDefs[this.svgUid][gradientId]){var tmp=fabric.Gradient.fromElement(fabric.gradientDefs[this.svgUid][gradientId],obj);if(tmp.coords.y1&&_this.setup.chart.type!="pie"){tmp.coords.y2=tmp.coords.y1*-1;tmp.coords.y1=0;}
obj.set(property,tmp);}};fabric.Text.fromElement=function(element,options){if(!element){return null;}
var parsedAttributes=fabric.parseAttributes(element,fabric.Text.ATTRIBUTE_NAMES);options=fabric.util.object.extend((options?fabric.util.object.clone(options):{}),parsedAttributes);options.top=options.top||0;options.left=options.left||0;if('dx'in parsedAttributes){options.left+=parsedAttributes.dx;}
if('dy'in parsedAttributes){options.top+=parsedAttributes.dy;}
if(!('fontSize'in options)){options.fontSize=fabric.Text.DEFAULT_SVG_FONT_SIZE;}
if(!options.originX){options.originX='left';}
var textContent='';var textBuffer=[];if(!('textContent'in element)){if('firstChild'in element&&element.firstChild!==null){if('data'in element.firstChild&&element.firstChild.data!==null){textBuffer.push(element.firstChild.data);}}}else if(element.childNodes){for(var i1=0;i1<element.childNodes.length;i1++){textBuffer.push(element.childNodes[i1].textContent);}}else{textBuffer.push(element.textContent);}
textContent=textBuffer.join("\n");var text=new fabric.Text(textContent,options),offX=0;if(text.originX==='left'){offX=text.getWidth()/ 2;
}
if(text.originX==='right'){offX=-text.getWidth()/ 2;
}
if(textBuffer.length>1){text.set({left:text.getLeft()+ offX,top:text.getTop()+ text.fontSize*(textBuffer.length- 1)*(0.18+ text._fontSizeFraction),textAlign:options.originX,lineHeight:textBuffer.length>1?0.965:1.16,});}else{text.set({left:text.getLeft()+ offX,top:text.getTop()- text.getHeight()/ 2 + text.fontSize * ( 0.18 + text._fontSizeFraction ) /* 0.3 is the old lineHeight */
});}
return text;};},capture:function(options,callback){var i1;var cfg=_this.deepMerge(_this.deepMerge({},_this.config.fabric),options||{});var groups=[];var offset={x:0,y:0,pX:0,pY:0,lX:0,lY:0,width:_this.setup.chart.divRealWidth,height:_this.setup.chart.divRealHeight};var images={loaded:0,included:0}
var legends={items:[],width:0,height:0,maxWidth:0,maxHeight:0}
if(!_this.handleNamespace("fabric",{scope:this,cb:_this.capture,args:arguments})){return false;}
_this.modifyFabric();_this.handleCallback(cfg.beforeCapture,cfg);var svgs=_this.setup.chart.containerDiv.getElementsByTagName("svg");for(i1=0;i1<svgs.length;i1++){var group={svg:svgs[i1],parent:svgs[i1].parentNode,children:svgs[i1].getElementsByTagName("*"),offset:{x:0,y:0},patterns:{},clippings:{},has:{legend:false,panel:false,scrollbar:false}}
group.has.legend=_this.gatherClassName(group.parent,_this.setup.chart.classNamePrefix+"-legend-div",1);group.has.panel=_this.gatherClassName(group.parent,_this.setup.chart.classNamePrefix+"-stock-panel-div");group.has.scrollbar=_this.gatherClassName(group.parent,_this.setup.chart.classNamePrefix+"-scrollbar-chart-div");group=_this.gatherElements(group,cfg,images);groups.push(group);}
if(_this.config.legend){if(_this.setup.chart.type=="stock"){for(i1=0;i1<_this.setup.chart.panels.length;i1++){if(_this.setup.chart.panels[i1].stockLegend&&_this.setup.chart.panels[i1].stockLegend.divId){legends.items.push(_this.setup.chart.panels[i1].stockLegend);}}}else if(_this.setup.chart.legend&&_this.setup.chart.legend.divId){legends.items.push(_this.setup.chart.legend);}
for(i1=0;i1<legends.items.length;i1++){var legend=legends.items[i1];var group={svg:legend.container.container,parent:legend.container.container.parentNode,children:legend.container.container.getElementsByTagName("*"),offset:{x:0,y:0},legend:{id:i1,type:["top","left"].indexOf(_this.config.legend.position)!=-1?"unshift":"push",position:_this.config.legend.position,width:_this.config.legend.width?_this.config.legend.width:legend.container.div.offsetWidth,height:_this.config.legend.height?_this.config.legend.height:legend.container.div.offsetHeight},patterns:{},clippings:{},has:{legend:false,panel:false,scrollbar:false}}
legends.width+=group.legend.width;legends.height+=group.legend.height;legends.maxWidth=group.legend.width>legends.maxWidth?group.legend.width:legends.maxWidth;legends.maxHeight=group.legend.height>legends.maxHeight?group.legend.height:legends.maxHeight;group=_this.gatherElements(group,cfg,images);groups[group.legend.type](group);}
if(["top","bottom"].indexOf(_this.config.legend.position)!=-1){offset.width=legends.maxWidth>offset.width?legends.maxWidth:offset.width;offset.height+=legends.height;}else if(["left","right"].indexOf(_this.config.legend.position)!=-1){offset.width+=legends.maxWidth;offset.height=legends.height>offset.height?legends.height:offset.height;}else{offset.height+=legends.height;offset.width+=legends.maxWidth;}}
_this.drawing.enabled=cfg.drawing.enabled=cfg.action=="draw";_this.drawing.buffer.enabled=_this.drawing.enabled;_this.setup.wrapper=document.createElement("div");_this.setup.wrapper.setAttribute("class",_this.setup.chart.classNamePrefix+"-export-canvas");_this.setup.chart.containerDiv.appendChild(_this.setup.wrapper);if(_this.setup.chart.type=="stock"){var padding={top:0,right:0,bottom:0,left:0}
if(_this.setup.chart.leftContainer){offset.width-=_this.setup.chart.leftContainer.offsetWidth;padding.left=_this.setup.chart.leftContainer.offsetWidth+(_this.setup.chart.panelsSettings.panelSpacing*2);}
if(_this.setup.chart.rightContainer){offset.width-=_this.setup.chart.rightContainer.offsetWidth;padding.right=_this.setup.chart.rightContainer.offsetWidth+(_this.setup.chart.panelsSettings.panelSpacing*2);}
if(_this.setup.chart.periodSelector&&["top","bottom"].indexOf(_this.setup.chart.periodSelector.position)!=-1){offset.height-=_this.setup.chart.periodSelector.offsetHeight+ _this.setup.chart.panelsSettings.panelSpacing;padding[_this.setup.chart.periodSelector.position]+=_this.setup.chart.periodSelector.offsetHeight+ _this.setup.chart.panelsSettings.panelSpacing;}
if(_this.setup.chart.dataSetSelector&&["top","bottom"].indexOf(_this.setup.chart.dataSetSelector.position)!=-1){offset.height-=_this.setup.chart.dataSetSelector.offsetHeight;padding[_this.setup.chart.dataSetSelector.position]+=_this.setup.chart.dataSetSelector.offsetHeight;}
_this.setup.wrapper.style.paddingTop=_this.numberToPx(padding.top);_this.setup.wrapper.style.paddingRight=_this.numberToPx(padding.right);_this.setup.wrapper.style.paddingBottom=_this.numberToPx(padding.bottom);_this.setup.wrapper.style.paddingLeft=_this.numberToPx(padding.left);}
_this.setup.canvas=document.createElement("canvas");_this.setup.wrapper.appendChild(_this.setup.canvas);var fabricCFG=_this.removeFunctionsFromObject(_this.deepMerge({width:offset.width,height:offset.height,isDrawingMode:true},cfg));_this.setup.fabric=new fabric.Canvas(_this.setup.canvas,fabricCFG);_this.deepMerge(_this.setup.fabric,cfg);_this.deepMerge(_this.setup.fabric.freeDrawingBrush,cfg.drawing);_this.deepMerge(_this.drawing,cfg.drawing);_this.drawing.handler.change(cfg.drawing);_this.setup.fabric.on("mouse:down",function(e){var p=_this.gatherPosition(e.e,1);_this.drawing.buffer.pressedTS=Number(new Date());_this.isPressed(e.e);_this.drawing.buffer.isDrawing=false;_this.drawing.buffer.isDrawingTimer=setTimeout(function(){if(!_this.drawing.buffer.isSelected){_this.drawing.buffer.isDrawing=true;}},200);});_this.setup.fabric.on("mouse:move",function(e){var p=_this.gatherPosition(e.e,2);_this.isPressed(e.e);if(_this.drawing.buffer.isPressed&&!_this.drawing.buffer.isSelected){_this.drawing.buffer.isDrawing=true;if(!_this.drawing.buffer.line&&_this.drawing.mode!="pencil"&&(p.xD>5||p.yD>5)){_this.setup.fabric.isDrawingMode=false;_this.setup.fabric._isCurrentlyDrawing=false;_this.drawing.buffer.ignoreUndoOnMouseUp=true;_this.setup.fabric.freeDrawingBrush.onMouseUp();_this.setup.fabric.remove(_this.setup.fabric._objects.pop());_this.drawing.buffer.line=_this.drawing.handler.line({x1:p.x1,y1:p.y1,x2:p.x2,y2:p.y2,arrow:_this.drawing.mode=="line"?false:_this.drawing.arrow,action:"config"});}}
if(_this.drawing.buffer.isSelected){_this.setup.fabric.isDrawingMode=false;}
if(_this.drawing.buffer.line){var obj,top,left;var l=_this.drawing.buffer.line;l.x2=p.x2;l.y2=p.y2;for(i1=0;i1<l.group.length;i1++){obj=l.group[i1];if(obj instanceof fabric.Line){obj.set({x2:l.x2,y2:l.y2});}else if(obj instanceof fabric.Triangle){l.angle=(_this.getAngle(l.x1,l.y1,l.x2,l.y2)+ 90);if(l.arrow=="start"){top=l.y1+(l.width/2);left=l.x1+(l.width/2);}else if(l.arrow=="middle"){top=l.y2+(l.width/2)-((l.y2- l.y1)/ 2 );
left=l.x2+(l.width/2)-((l.x2- l.x1)/ 2 );
}else{top=l.y2+(l.width/2);left=l.x2+(l.width/2);}
obj.set({top:top,left:left,angle:l.angle});}}
_this.setup.fabric.renderAll();}});_this.setup.fabric.on("mouse:up",function(e){if(!_this.drawing.buffer.isDrawing){var target=_this.setup.fabric.findTarget(e.e);if(target&&target.selectable){_this.setup.fabric.setActiveObject(target);}}
if(_this.drawing.buffer.line){for(i1=0;i1<_this.drawing.buffer.line.group.length;i1++){_this.drawing.buffer.line.group[i1].remove();}
delete _this.drawing.buffer.line.action;delete _this.drawing.buffer.line.group;_this.drawing.handler.line(_this.drawing.buffer.line);}
_this.drawing.buffer.line=false;_this.drawing.buffer.hasLine=false;_this.drawing.buffer.isPressed=false;clearTimeout(_this.drawing.buffer.isDrawingTimer);_this.drawing.buffer.isDrawing=false;});_this.setup.fabric.on("object:selected",function(e){_this.drawing.buffer.isSelected=true;_this.drawing.buffer.target=e.target;_this.setup.fabric.isDrawingMode=false;});_this.setup.fabric.on("selection:cleared",function(e){_this.drawing.buffer.target=false;if(_this.drawing.buffer.isSelected){_this.setup.fabric._isCurrentlyDrawing=false;}
_this.drawing.buffer.isSelected=false;_this.setup.fabric.isDrawingMode=true;});_this.setup.fabric.on("path:created",function(e){var item=e.path;if(!_this.drawing.buffer.isDrawing||_this.drawing.buffer.hasLine){_this.setup.fabric.remove(item);_this.setup.fabric.renderAll();return;}});_this.setup.fabric.on("object:added",function(e){var item=e.target;var state=_this.deepMerge(item.saveState()._stateProperties,{cfg:{color:_this.drawing.color,width:_this.drawing.width,opacity:_this.drawing.opacity,fontSize:_this.drawing.fontSize}});state=JSON.stringify(state);item.recentState=state;if(_this.drawing.buffer.ignoreUndoOnMouseUp||!_this.drawing.buffer.isDrawing){_this.drawing.buffer.ignoreUndoOnMouseUp=false;return;}
if(item.selectable&&!item.known&&!item.ignoreUndo){item.isAnnotation=true;_this.drawing.undos.push({action:"added",target:item,state:state});_this.drawing.redos=[];}
item.known=true;_this.setup.fabric.isDrawingMode=true;});_this.setup.fabric.on("object:modified",function(e){var item=e.target;var recentState=JSON.parse(item.recentState);var state=_this.deepMerge(item.saveState()._stateProperties,{cfg:recentState.cfg});state=JSON.stringify(state);item.recentState=state;_this.drawing.undos.push({action:"modified",target:item,state:state});_this.drawing.redos=[];});_this.setup.fabric.on("text:changed",function(e){var item=e.target;clearTimeout(item.timer);item.timer=setTimeout(function(){var state=JSON.stringify(item.saveState()._stateProperties);item.recentState=state;_this.drawing.redos=[];_this.drawing.undos.push({action:"modified",target:item,state:state});},250);});if(_this.drawing.enabled){_this.setup.wrapper.setAttribute("class",_this.setup.chart.classNamePrefix+"-export-canvas active");_this.setup.wrapper.style.backgroundColor=cfg.backgroundColor;_this.setup.wrapper.style.display="block";}else{_this.setup.wrapper.setAttribute("class",_this.setup.chart.classNamePrefix+"-export-canvas");_this.setup.wrapper.style.display="none";}
for(i1=0;i1<groups.length;i1++){var group=groups[i1];if(_this.setup.chart.type=="stock"&&_this.setup.chart.legendSettings.position){if(["top","bottom"].indexOf(_this.setup.chart.legendSettings.position)!=-1){if(group.parent.style.top&&group.parent.style.left){group.offset.y=_this.pxToNumber(group.parent.style.top);group.offset.x=_this.pxToNumber(group.parent.style.left);}else{group.offset.x=offset.x;group.offset.y=offset.y;offset.y+=_this.pxToNumber(group.parent.style.height);if(group.has.panel){offset.pY=_this.pxToNumber(group.has.panel.style.marginTop);group.offset.y+=offset.pY;}else if(group.has.scrollbar){group.offset.y+=offset.pY;}}}else if(["left","right"].indexOf(_this.setup.chart.legendSettings.position)!=-1){group.offset.y=_this.pxToNumber(group.parent.style.top)+ offset.pY;group.offset.x=_this.pxToNumber(group.parent.style.left)+ offset.pX;if(group.has.legend){offset.pY+=_this.pxToNumber(group.has.panel.style.height)+ _this.setup.chart.panelsSettings.panelSpacing;}else if(group.has.scrollbar){group.offset.y-=_this.setup.chart.panelsSettings.panelSpacing;}}}else{if(group.parent.style.position=="absolute"){group.offset.absolute=true;group.offset.top=_this.pxToNumber(group.parent.style.top);group.offset.right=_this.pxToNumber(group.parent.style.right,true);group.offset.bottom=_this.pxToNumber(group.parent.style.bottom,true);group.offset.left=_this.pxToNumber(group.parent.style.left);group.offset.width=_this.pxToNumber(group.parent.style.width);group.offset.height=_this.pxToNumber(group.parent.style.height);}else if(group.parent.style.top&&group.parent.style.left){group.offset.y=_this.pxToNumber(group.parent.style.top);group.offset.x=_this.pxToNumber(group.parent.style.left);}else{if(group.legend){if(group.legend.position=="left"){offset.x=legends.maxWidth;}else if(group.legend.position=="right"){group.offset.x=offset.width- legends.maxWidth;}else if(group.legend.position=="top"){offset.y+=group.legend.height;}else if(group.legend.position=="bottom"){group.offset.y=offset.height- legends.height;}
group.offset.y+=offset.lY;offset.lY+=group.legend.height;}else{group.offset.x=offset.x;group.offset.y=offset.y+ offset.pY;offset.y+=_this.pxToNumber(group.parent.style.height);}}
if(group.has.legend&&group.has.panel&&group.has.panel.style.marginTop){offset.y+=_this.pxToNumber(group.has.panel.style.marginTop);group.offset.y+=_this.pxToNumber(group.has.panel.style.marginTop);}else if(_this.setup.chart.legend&&["left","right"].indexOf(_this.setup.chart.legend.position)!=-1){group.offset.y=_this.pxToNumber(group.parent.style.top);group.offset.x=_this.pxToNumber(group.parent.style.left);}}
fabric.parseSVGDocument(group.svg,(function(group){return function(objects,options){var i1,i2;var g=fabric.util.groupSVGElements(objects,options);var paths=[];var tmp={selectable:false,isCoreElement:true};if(group.offset.absolute){if(group.offset.bottom!==undefined){tmp.top=offset.height- group.offset.height- group.offset.bottom;}else{tmp.top=group.offset.top;}
if(group.offset.right!==undefined){tmp.left=offset.width- group.offset.width- group.offset.right;}else{tmp.left=group.offset.left;}}else{tmp.top=group.offset.y;tmp.left=group.offset.x;}
for(i1=0;i1<g.paths.length;i1++){var PID=null;if(g.paths[i1]){if(_this.removeImage(g.paths[i1]["xlink:href"])){continue;}
if(g.paths[i1].fill instanceof Object){if(g.paths[i1].fill.type=="radial"){if(["pie","gauge"].indexOf(_this.setup.chart.type)==-1){g.paths[i1].fill.coords.r2=g.paths[i1].fill.coords.r1*-1;g.paths[i1].fill.coords.r1=0;g.paths[i1].set({opacity:g.paths[i1].fillOpacity});}}}else if(PID=_this.isHashbanged(g.paths[i1].fill)){if(group.patterns&&group.patterns[PID]){var props=group.patterns[PID];images.included++;fabric.Image.fromURL(props.source,(function(props,i1){return function(img){images.loaded++;img.set({top:props.offsetY,left:props.offsetX,width:props.width,height:props.height});if(_this.setup.fabric._isRetinaScaling()){img.set({top:props.offsetY/2,left:props.offsetX/2,scaleX:0.5,scaleY:0.5});}
var patternSourceCanvas=new fabric.StaticCanvas(undefined,{backgroundColor:props.fill,width:img.getWidth(),height:img.getHeight()});patternSourceCanvas.add(img);var pattern=new fabric.Pattern({source:patternSourceCanvas.getElement(),offsetX:g.paths[i1].width/2,offsetY:g.paths[i1].height/2,repeat:'repeat',});g.paths[i1].set({fill:pattern,opacity:g.paths[i1].fillOpacity});}})(props,i1));}}
if(PID=_this.isHashbanged(g.paths[i1].clipPath)){if(group.clippings&&group.clippings[PID]){(function(i1,PID){var toSVG=g.paths[i1].toSVG;g.paths[i1].toSVG=function(original_reviver){return toSVG.apply(this,[function(string){return original_reviver(string,group.clippings[PID]);}]);}})(i1,PID);g.paths[i1].set({clipTo:(function(i1,PID){return function(ctx){var cp=group.clippings[PID];var tm=this.transformMatrix||[1,0,0,1,0,0];var dim={top:cp.bbox.y,left:cp.bbox.x,width:cp.bbox.width,height:cp.bbox.height}
if(_this.setup.chart.type=="map"){dim.top+=cp.transform[5];dim.left+=cp.transform[4];}
if(cp.bbox.x&&tm[4]&&cp.bbox.y&&tm[5]){dim.top-=tm[5];dim.left-=tm[4];}
if(_this.setup.chart.smoothCustomBullets!==undefined&&this.className==_this.setup.chart.classNamePrefix+"-graph-bullet"&&g.paths[i1].svg.tagName=="image"){radius=cp.svg.firstChild.rx.baseVal.value/2+ 2;ctx.beginPath();ctx.moveTo(dim.left+ radius,dim.top);ctx.lineTo(dim.left+ dim.width- radius,dim.top);ctx.quadraticCurveTo(dim.left+ dim.width,dim.top,dim.left+ dim.width,dim.top+ radius);ctx.lineTo(dim.left+ dim.width,dim.top+ dim.height- radius);ctx.quadraticCurveTo(dim.left+ dim.width,dim.top+ dim.height,dim.left+ dim.width- radius,dim.top+ dim.height);ctx.lineTo(dim.left+ radius,dim.top+ dim.height);ctx.quadraticCurveTo(dim.left,dim.top+ dim.height,dim.left,dim.top+ dim.height- radius);ctx.lineTo(dim.left,dim.top+ radius);ctx.quadraticCurveTo(dim.left,dim.top,dim.left+ radius,dim.top);ctx.closePath();}else{ctx.rect(dim.left,dim.top,dim.width,dim.height);}}})(i1,PID)});}}}
paths.push(g.paths[i1]);}
g.paths=paths;g.set(tmp);_this.setup.fabric.add(g);if(group.svg.parentNode&&group.svg.parentNode.getElementsByTagName){var balloons=group.svg.parentNode.getElementsByClassName(_this.setup.chart.classNamePrefix+"-balloon-div");for(i1=0;i1<balloons.length;i1++){if(cfg.balloonFunction instanceof Function){cfg.balloonFunction.apply(_this,[balloons[i1],group]);}else{var elm_parent=balloons[i1];var style_parent=fabric.parseStyleAttribute(elm_parent);var style_text=fabric.parseStyleAttribute(elm_parent.childNodes[0]);var fabric_label=new fabric.Text(elm_parent.innerText||elm_parent.textContent||elm_parent.innerHTML,{selectable:false,top:_this.pxToNumber(style_parent.top)+ group.offset.y,left:_this.pxToNumber(style_parent.left)+ group.offset.x,fill:style_text["color"],fontSize:_this.pxToNumber(style_text["fontSize"]||style_text["font-size"]),fontFamily:style_text["fontFamily"]||style_text["font-family"],textAlign:style_text["text-align"],isCoreElement:true});_this.setup.fabric.add(fabric_label);}}}
if(group.svg.nextSibling&&group.svg.nextSibling.tagName=="A"){var elm_parent=group.svg.nextSibling;var style_parent=fabric.parseStyleAttribute(elm_parent);var fabric_label=new fabric.Text(elm_parent.innerText||elm_parent.textContent||elm_parent.innerHTML,{selectable:false,top:_this.pxToNumber(style_parent.top)+ group.offset.y,left:_this.pxToNumber(style_parent.left)+ group.offset.x,fill:style_parent["color"],fontSize:_this.pxToNumber(style_parent["fontSize"]||style_parent["font-size"]),fontFamily:style_parent["fontFamily"]||style_parent["font-family"],opacity:style_parent["opacity"],isCoreElement:true});if(!group.has.scrollbar){_this.setup.fabric.add(fabric_label);}}
groups.pop();if(!groups.length){var ts1=Number(new Date());var timer=setInterval(function(){var ts2=Number(new Date());if(images.loaded==images.included||ts2- ts1>_this.config.fabric.loadTimeout){clearTimeout(timer);_this.handleBorder(cfg);_this.handleCallback(cfg.afterCapture,cfg);_this.setup.fabric.renderAll();_this.handleCallback(callback,cfg);}},AmCharts.updateRate);}}})(group),function(svg,obj){var i1;var className=_this.gatherAttribute(svg,"class");var visibility=_this.gatherAttribute(svg,"visibility");var clipPath=_this.gatherAttribute(svg,"clip-path");obj.className=String(className);obj.classList=String(className).split(" ");obj.clipPath=clipPath;obj.svg=svg;var attrs=["fill","stroke"];for(i1=0;i1<attrs.length;i1++){var attr=attrs[i1]
var attrVal=String(svg.getAttribute(attr)||"none");var attrOpacity=Number(svg.getAttribute(attr+"-opacity")||"1");var attrRGBA=_this.getRGBA(attrVal);if(visibility=="hidden"){obj.opacity=0;attrOpacity=0;}
if(attrRGBA){attrRGBA.pop();attrRGBA.push(attrOpacity)
obj[attr]="rgba("+ attrRGBA.join()+")";obj[attr+ _this.capitalize("opacity")]=attrOpacity;}}
_this.handleCallback(cfg.reviver,obj,svg);});}},toCanvas:function(options,callback){var cfg=_this.deepMerge({},options||{});var data=_this.setup.canvas;_this.handleCallback(callback,data,cfg);return data;},toImage:function(options,callback){var cfg=_this.deepMerge({format:"png",quality:1,multiplier:_this.config.multiplier},options||{});var data=cfg.data;var img=document.createElement("img");if(!_this.handleNamespace("fabric",{scope:this,cb:_this.toImage,args:arguments})){return false;}
if(!cfg.data){if(cfg.lossless||cfg.format=="svg"){data=_this.toSVG(_this.deepMerge(cfg,{getBase64:true}));}else{data=_this.setup.fabric.toDataURL(cfg);}}
img.setAttribute("src",data);_this.handleCallback(callback,img,cfg);return img;},toBlob:function(options,callback){var cfg=_this.deepMerge({data:"empty",type:"text/plain"},options||{});var data;var isBase64=/^data:.+;base64,(.*)$/.exec(cfg.data);if(isBase64){cfg.data=isBase64[0];cfg.type=cfg.data.slice(5,cfg.data.indexOf(",")- 7);cfg.data=_this.toByteArray({data:cfg.data.slice(cfg.data.indexOf(",")+ 1,cfg.data.length)});}
if(cfg.getByteArray){data=cfg.data;}else{data=new Blob([cfg.data],{type:cfg.type});}
_this.handleCallback(callback,data,cfg);return data;},toJPG:function(options,callback){var cfg=_this.deepMerge({format:"jpeg",quality:1,multiplier:_this.config.multiplier},options||{});cfg.format=cfg.format.toLowerCase();var data;if(/iP(hone|od|ad)/.test(navigator.platform)){cfg.multiplier=1;}
if(!_this.handleNamespace("fabric",{scope:this,cb:_this.toJPG,args:arguments})){return false;}
data=_this.setup.fabric.toDataURL(cfg);_this.handleCallback(callback,data,cfg);return data;},toPNG:function(options,callback){var cfg=_this.deepMerge({format:"png",quality:1,multiplier:_this.config.multiplier},options||{});var data;if(/iP(hone|od|ad)/.test(navigator.platform)){cfg.multiplier=1;}
if(!_this.handleNamespace("fabric",{scope:this,cb:_this.toPNG,args:arguments})){return false;}
data=_this.setup.fabric.toDataURL(cfg);_this.handleCallback(callback,data,cfg);return data;},toSVG:function(options,callback){var clipPaths=[];var clipPathIds=[];var cfg=_this.deepMerge({compress:_this.config.compress,reviver:function(string,clipPath){var matcher=new RegExp(/\bstyle=(['"])(.*?)\1/);var match=matcher.exec(string)[0].slice(7,-1);var styles=match.split(";");var replacement=[];for(i1=0;i1<styles.length;i1++){if(styles[i1]){var pair=styles[i1].replace(/\s/g,"").split(":");var key=pair[0];var value=pair[1];if(["fill","stroke"].indexOf(key)!=-1){value=_this.getRGBA(value,true);if(value){var color="#"+ value.toHex();var opacity=value._source[3];replacement.push([key,color].join(":"));replacement.push([key+"-opacity",opacity].join(":"));}else{replacement.push(styles[i1]);}}else if(key!="opactiy"){replacement.push(styles[i1]);}}}
string=string.replace(match,replacement.join(";"));if(clipPath&&clipPath.svg){var clipPathId=clipPath.svg.id;var sliceOffset=2;var end=string.slice(-sliceOffset);if(end!="/>"){sliceOffset=3;end=string.slice(-sliceOffset);}
var start=string.slice(0,string.length- sliceOffset);var clipPathAttr=" clip-path=\"url(#"+ clipPathId+")\" ";var parentClassList=_this.gatherAttribute(clipPath.svg,"class");parentClassList=parentClassList?parentClassList.split(" "):[];if(parentClassList.indexOf(_this.setup.chart.classNamePrefix+"-graph-line")!=-1){string=start+ clipPathAttr+ end;}else{string="<g "+ clipPathAttr+">"+ string+"</g>";}
if(clipPathIds.indexOf(clipPathId)==-1){var clipPathString=new XMLSerializer().serializeToString(clipPath.svg);clipPaths.push(clipPathString);clipPathIds.push(clipPathId);}}
return string;}},options||{});var data;if(!_this.handleNamespace("fabric",{scope:this,cb:_this.toSVG,args:arguments})){return false;}
data=_this.setup.fabric.toSVG(cfg,cfg.reviver);if(clipPaths.length){var start=data.slice(0,data.length- 6);var end=data.slice(-6);data=start+ clipPaths.join("")+ end;}
if(cfg.compress){data=data.replace(/[\t\r\n]+/g,"");}
if(cfg.getBase64){data="data:image/svg+xml;base64,"+ btoa(data);}
_this.handleCallback(callback,data,cfg);return data;},toPDF:function(options,callback){var cfg=_this.deepMerge(_this.deepMerge({multiplier:_this.config.multiplier||2,pageOrigin:_this.config.pageOrigin===undefined?true:false},_this.config.pdfMake),options||{},true);var data;if(/iP(hone|od|ad)/.test(navigator.platform)){cfg.multiplier=1;}
if(!_this.handleNamespace("pdfMake",{scope:this,cb:_this.toPDF,args:arguments})){return false;}
cfg.images.reference=_this.toPNG(cfg);function getMargins(margin){if(typeof margin==='number'||margin instanceof Number){margin={left:margin,right:margin,top:margin,bottom:margin};}else if(margin instanceof Array){if(margin.length===2){margin={left:margin[0],top:margin[1],right:margin[0],bottom:margin[1]};}else if(margin.length===4){margin={left:margin[0],top:margin[1],right:margin[2],bottom:margin[3]};}else throw'Invalid pageMargins definition';}else{margin={left:_this.defaults.pdfMake.pageMargins,top:_this.defaults.pdfMake.pageMargins,right:_this.defaults.pdfMake.pageMargins,bottom:_this.defaults.pdfMake.pageMargins};}
return margin;}
function getSize(pageSize,pageOrientation){var pageDimensions=_this.defaults.pdfMake.pageSizes[String(pageSize).toUpperCase()].slice();if(!pageDimensions){throw new Error("The given pageSize \""+ pageSize+"\" does not exist!");}
if(pageOrientation=="landscape"){pageDimensions.reverse();}
return pageDimensions;}
if(!cfg.content){var pageContent=[];var pageDimensions=getSize(cfg.pageSize,cfg.pageOrientation);var pageMargins=getMargins(cfg.pageMargins);pageDimensions[0]-=(pageMargins.left+ pageMargins.right);pageDimensions[1]-=(pageMargins.top+ pageMargins.bottom);if(cfg.pageOrigin){pageContent.push(_this.i18l("label.saved.from"));pageContent.push(window.location.href);pageDimensions[1]-=(14.064*2);}
pageContent.push({image:"reference",fit:pageDimensions});cfg.content=pageContent;}
data=new pdfMake.createPdf(cfg);if(callback){data.getDataUrl((function(callback){return function(a){callback.apply(_this,arguments);}})(callback));}
return data;},toPRINT:function(options,callback){var i1;var cfg=_this.deepMerge({delay:1,lossless:false},options||{});var data=_this.toImage(cfg);var states=[];var items=document.body.childNodes;var scroll=document.documentElement.scrollTop||document.body.scrollTop;data.setAttribute("style","width: 100%; max-height: 100%;");for(i1=0;i1<items.length;i1++){if(_this.isElement(items[i1])){states[i1]=items[i1].style.display;items[i1].style.display="none";}}
document.body.appendChild(data);cfg.delay*=1000;var isIOS=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;if(isIOS&&cfg.delay<1000){cfg.delay=1000;}
setTimeout(function(){window.print();setTimeout(function(){for(i1=0;i1<items.length;i1++){if(_this.isElement(items[i1])){items[i1].style.display=states[i1];}}
document.body.removeChild(data);document.documentElement.scrollTop=document.body.scrollTop=scroll;_this.handleCallback(callback,data,cfg);},cfg.delay);},cfg.delay);return data;},toJSON:function(options,callback){var cfg=_this.deepMerge({dateFormat:_this.config.dateFormat||"dateObject"},options||{},true);var data={};if(!_this.handleNamespace("JSON",{scope:this,cb:_this.toJSON,args:arguments})){return false;}
cfg.data=cfg.data!==undefined?cfg.data:_this.getChartData(cfg);data=JSON.stringify(cfg.data,undefined,"\t");_this.handleCallback(callback,data,cfg);return data;},toCSV:function(options,callback){var row,col;var cfg=_this.deepMerge({delimiter:",",quotes:true,escape:true,withHeader:true},options||{},true);var buffer=[];var data="";buffer=_this.toArray(cfg);for(row in buffer){if(!isNaN(row)){data+=buffer[row].join(cfg.delimiter)+"\n";}}
_this.handleCallback(callback,data,cfg);return data;},toXLSX:function(options,callback){var cfg=_this.deepMerge({name:"amCharts",dateFormat:_this.config.dateFormat||"dateObject",withHeader:true,stringify:false},options||{},true);var buffer=[];var data="";var wb={SheetNames:[],Sheets:{}}
if(!_this.handleNamespace("XLSX",{scope:this,cb:_this.toXLSX,args:arguments})){return false;}
buffer=_this.toArray(cfg);function datenum(v,date1904){if(date1904)v+=1462;var epoch=Date.parse(v);var offset=v.getTimezoneOffset()*60*1000;return(epoch- offset- new Date(Date.UTC(1899,11,30)))/ ( 24 * 60 * 60 * 1000 );
}
function sheet_from_array_of_arrays(data,opts){var ws={};var range={s:{c:10000000,r:10000000},e:{c:0,r:0}};for(var R=0;R!=data.length;++R){for(var C=0;C!=data[R].length;++C){if(range.s.r>R)range.s.r=R;if(range.s.c>C)range.s.c=C;if(range.e.r<R)range.e.r=R;if(range.e.c<C)range.e.c=C;var cell={v:data[R][C]};if(cell.v==null)continue;var cell_ref=XLSX.utils.encode_cell({c:C,r:R});if(typeof cell.v==="number"){cell.t="n";}else if(typeof cell.v==="boolean"){cell.t="b";}else if(cell.v instanceof Date){cell.t="n";cell.z=XLSX.SSF._table[14];cell.v=datenum(cell.v);}else if(cell.v instanceof Object){cell.t="s";cell.v=JSON.stringify(cell.v);}else{cell.t="s";}
ws[cell_ref]=cell;}}
if(range.s.c<10000000)ws["!ref"]=XLSX.utils.encode_range(range);return ws;}
wb.SheetNames.push(cfg.name);wb.Sheets[cfg.name]=sheet_from_array_of_arrays(buffer);data=XLSX.write(wb,{bookType:"xlsx",bookSST:true,type:"base64"});data="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,"+ data;_this.handleCallback(callback,data,cfg);return data;},toArray:function(options,callback){var row,col;var cfg=_this.deepMerge({withHeader:false,stringify:true,escape:false,quotes:false},options||{},true);var data=[];var cols=[];var buffer=[];var _processData=_this.config.processData;function processData(data,cfg){var fields=cfg.exportFields||Object.keys(cfg.dataFieldsMap);for(col=0;col<fields.length;col++){var key=fields[col];var field=cfg.dataFieldsTitlesMap[key];cols.push(field);}
if(_processData){return _this.handleCallback(_processData,data,cfg);}
return data;}
function enchant(value){if(typeof value==="string"){if(cfg.escape){value=value.replace('"','""');}
if(cfg.quotes){value=['"',value,'"'].join("");}}
return value;}
cfg.processData=processData;cfg.data=cfg.data!==undefined?_this.processData(cfg):_this.getChartData(cfg);if(cfg.withHeader){buffer=[];for(col in cols){if(!isNaN(col)){buffer.push(enchant(cols[col]));}}
data.push(buffer);}
for(row in cfg.data){buffer=[];if(!isNaN(row)){for(col in cols){if(!isNaN(col)){var col=cols[col];var value=cfg.data[row][col];if(value==null){value="";}else if(cfg.stringify){value=String(value);}else{value=value;}
buffer.push(enchant(value));}}
data.push(buffer);}}
_this.handleCallback(callback,data,cfg);return data;},toByteArray:function(options,callback){var cfg=_this.deepMerge({},options||{});var Arr=(typeof Uint8Array!=='undefined')?Uint8Array:Array
var PLUS='+'.charCodeAt(0)
var SLASH='/'.charCodeAt(0)
var NUMBER='0'.charCodeAt(0)
var LOWER='a'.charCodeAt(0)
var UPPER='A'.charCodeAt(0)
var data=b64ToByteArray(cfg.data);function decode(elt){var code=elt.charCodeAt(0)
if(code===PLUS)
return 62
if(code===SLASH)
return 63
if(code<NUMBER)
return-1
if(code<NUMBER+ 10)
return code- NUMBER+ 26+ 26
if(code<UPPER+ 26)
return code- UPPER
if(code<LOWER+ 26)
return code- LOWER+ 26}
function b64ToByteArray(b64){var i,j,l,tmp,placeHolders,arr
if(b64.length%4>0){throw new Error('Invalid string. Length must be a multiple of 4')}
var len=b64.length
placeHolders='='===b64.charAt(len- 2)?2:'='===b64.charAt(len- 1)?1:0
arr=new Arr(b64.length*3/4- placeHolders)
l=placeHolders>0?b64.length- 4:b64.length
var L=0
function push(v){arr[L++]=v}
for(i=0,j=0;i<l;i+=4,j+=3){tmp=(decode(b64.charAt(i))<<18)|(decode(b64.charAt(i+ 1))<<12)|(decode(b64.charAt(i+ 2))<<6)|decode(b64.charAt(i+ 3))
push((tmp&0xFF0000)>>16)
push((tmp&0xFF00)>>8)
push(tmp&0xFF)}
if(placeHolders===2){tmp=(decode(b64.charAt(i))<<2)|(decode(b64.charAt(i+ 1))>>4)
push(tmp&0xFF)}else if(placeHolders===1){tmp=(decode(b64.charAt(i))<<10)|(decode(b64.charAt(i+ 1))<<4)|(decode(b64.charAt(i+ 2))>>2)
push((tmp>>8)&0xFF)
push(tmp&0xFF)}
return arr}
_this.handleCallback(callback,data,cfg);return data;},removeFunctionsFromObject:function(obj){for(var key in obj){if(typeof obj[key]==="function"){delete obj[key];}}
return obj;},handleCallback:function(callback){var i1,data=Array();if(callback&&callback instanceof Function){for(i1=0;i1<arguments.length;i1++){if(i1>0){data.push(arguments[i1]);}}
return callback.apply(_this,data);}},handleLog:function(msg){if(_this.config.debug===true){console.log(msg);}},handleNamespace:function(namespace,opts){var scope=_this.config.scope||window;var exists=false;var startTS=Number(new Date());var timer;exists=!!(namespace in scope);function waitForIt(){var tmpTS=Number(new Date());exists=!!(namespace in scope);if(namespace=="pdfMake"&&exists){exists=scope.pdfMake.vfs;}
if(exists){clearTimeout(timer);opts.cb.apply(opts.scope,opts.args);_this.handleLog(["AmCharts [export]: Namespace \"",namespace,"\" showed up in: ",String(scope)].join(""));}else if(tmpTS- startTS<_this.libs.loadTimeout){timer=setTimeout(waitForIt,250);}else{_this.handleLog(["AmCharts [export]: Gave up waiting for \"",namespace,"\" in: ",String(scope)].join(""));}}
if(!exists){_this.handleLog(["AmCharts [export]: Could not find \"",namespace,"\" in: ",String(scope)].join(""));waitForIt();}
return exists;},handleBorder:function(options){if(_this.config.border instanceof Object){var cfg=_this.deepMerge(_this.defaults.fabric.border,options.border||{},true);var border=new fabric.Rect();cfg.width=_this.setup.fabric.width- cfg.strokeWidth;cfg.height=_this.setup.fabric.height- cfg.strokeWidth;border.set(cfg);_this.setup.fabric.add(border);}},handleDropbox:function(e){if(_this.drawing.enabled){e.preventDefault();e.stopPropagation();if(e.type=="dragover"){_this.setup.wrapper.setAttribute("class",_this.setup.chart.classNamePrefix+"-export-canvas active dropbox");}else{_this.setup.wrapper.setAttribute("class",_this.setup.chart.classNamePrefix+"-export-canvas active");if(e.type=="drop"&&e.dataTransfer.files.length){for(var i1=0;i1<e.dataTransfer.files.length;i1++){var reader=new FileReader();reader.onloadend=(function(index){return function(){_this.drawing.handler.add({url:reader.result,top:e.layerY-(index*10),left:e.layerX-(index*10)});}})(i1);reader.readAsDataURL(e.dataTransfer.files[i1]);}}}}},handleReady:function(callback){var t1,t2;var _this=this;var tsStart=Number(new Date());_this.handleCallback(callback,"data",false);for(filename in _this.libs.namespaces){var namespace=_this.libs.namespaces[filename];(function(namespace){var t1=setInterval(function(){var tsEnd=Number(new Date());if(tsEnd- tsStart>_this.libs.loadTimeout||namespace in window){clearTimeout(t1);_this.handleCallback(callback,namespace,tsEnd- tsStart>_this.libs.loadTimeout);}},AmCharts.updateRate)})(namespace);}},getChartData:function(options){var cfg=_this.deepMerge({data:[],titles:{},dateFields:[],dataFields:[],dataFieldsMap:{},exportTitles:_this.config.exportTitles,exportFields:_this.config.exportFields,exportSelection:_this.config.exportSelection,columnNames:_this.config.columnNames},options||{},true);var uid,i1,i2,i3;var lookupFields=["valueField","openField","closeField","highField","lowField","xField","yField"];var buffer;function addField(field,title,type){function checkExistance(field,type){if(cfg.dataFields.indexOf(field)!=-1){return checkExistance([field,".",type].join(""));}
return field;}
if(field&&cfg.exportTitles&&_this.setup.chart.type!="gantt"){uid=checkExistance(field,type);cfg.dataFieldsMap[uid]=field;cfg.dataFields.push(uid);cfg.titles[uid]=title||uid;}}
if(cfg.data.length==0){if(_this.setup.chart.type=="stock"){cfg.data=_this.cloneObject(_this.setup.chart.mainDataSet.dataProvider);addField(_this.setup.chart.mainDataSet.categoryField);cfg.dateFields.push(_this.setup.chart.mainDataSet.categoryField);for(i1=0;i1<_this.setup.chart.mainDataSet.fieldMappings.length;i1++){var fieldMap=_this.setup.chart.mainDataSet.fieldMappings[i1];for(i2=0;i2<_this.setup.chart.panels.length;i2++){var panel=_this.setup.chart.panels[i2]
for(i3=0;i3<panel.stockGraphs.length;i3++){var graph=panel.stockGraphs[i3];for(i4=0;i4<lookupFields.length;i4++){if(graph[lookupFields[i4]]==fieldMap.toField){addField(fieldMap.fromField,graph.title,lookupFields[i4]);}}}}}
if(_this.setup.chart.comparedGraphs.length){buffer=[];for(i1=0;i1<cfg.data.length;i1++){buffer.push(cfg.data[i1][_this.setup.chart.mainDataSet.categoryField]);}
for(i1=0;i1<_this.setup.chart.comparedGraphs.length;i1++){var graph=_this.setup.chart.comparedGraphs[i1];for(i2=0;i2<graph.dataSet.dataProvider.length;i2++){var categoryField=graph.dataSet.categoryField;var categoryValue=graph.dataSet.dataProvider[i2][categoryField];var comparedIndex=buffer.indexOf(categoryValue);if(comparedIndex!=-1){for(i3=0;i3<graph.dataSet.fieldMappings.length;i3++){var fieldMap=graph.dataSet.fieldMappings[i3];var uid=graph.dataSet.id+"_"+ fieldMap.toField;cfg.data[comparedIndex][uid]=graph.dataSet.dataProvider[i2][fieldMap.fromField];if(!cfg.titles[uid]){addField(uid,graph.dataSet.title)}}}}}}}else if(_this.setup.chart.type=="gantt"){addField(_this.setup.chart.categoryField);var field=_this.setup.chart.segmentsField;for(i1=0;i1<_this.setup.chart.dataProvider.length;i1++){var dataItem=_this.setup.chart.dataProvider[i1];if(dataItem[field]){for(i2=0;i2<dataItem[field].length;i2++){dataItem[field][i2][_this.setup.chart.categoryField]=dataItem[_this.setup.chart.categoryField];cfg.data.push(dataItem[field][i2]);}}}
for(i1=0;i1<_this.setup.chart.graphs.length;i1++){var graph=_this.setup.chart.graphs[i1];for(i2=0;i2<lookupFields.length;i2++){var dataField=lookupFields[i2];var graphField=graph[dataField];var title=graph.title;addField(graphField,graph.title,dataField);}}}else if(["pie","funnel"].indexOf(_this.setup.chart.type)!=-1){cfg.data=_this.setup.chart.dataProvider;addField(_this.setup.chart.titleField);cfg.dateFields.push(_this.setup.chart.titleField);addField(_this.setup.chart.valueField);}else if(_this.setup.chart.type!="map"){cfg.data=_this.setup.chart.dataProvider;if(_this.setup.chart.categoryAxis){addField(_this.setup.chart.categoryField,_this.setup.chart.categoryAxis.title);if(_this.setup.chart.categoryAxis.parseDates!==false){cfg.dateFields.push(_this.setup.chart.categoryField);}}
for(i1=0;i1<_this.setup.chart.graphs.length;i1++){var graph=_this.setup.chart.graphs[i1];for(i2=0;i2<lookupFields.length;i2++){var dataField=lookupFields[i2];var graphField=graph[dataField];addField(graphField,graph.title,dataField);}}}}
return _this.processData(cfg);},getAnnotations:function(options,callback){var cfg=_this.deepMerge({},options||{},true);var i1;var data=[];for(i1=0;i1<_this.setup.fabric._objects.length;i1++){if(!_this.setup.fabric._objects[i1].isCoreElement){var obj=_this.setup.fabric._objects[i1].toJSON();_this.handleCallback(cfg.reviver,obj,i1);data.push(obj);}}
_this.handleCallback(callback,data);return data;},setAnnotations:function(options,callback){var cfg=_this.deepMerge({data:[]},options||{},true);fabric.util.enlivenObjects(cfg.data,function(enlivenedObjects){enlivenedObjects.forEach(function(obj,i1){_this.handleCallback(cfg.reviver,obj,i1);_this.setup.fabric.add(obj);});_this.handleCallback(callback,cfg);});return cfg.data;},processData:function(options){var cfg=_this.deepMerge({data:[],titles:{},dateFields:[],dataFields:[],dataFieldsMap:{},dataFieldsTitlesMap:{},dataDateFormat:_this.setup.chart.dataDateFormat,dateFormat:_this.config.dateFormat||_this.setup.chart.dataDateFormat||"YYYY-MM-DD",exportTitles:_this.config.exportTitles,exportFields:_this.config.exportFields,exportSelection:_this.config.exportSelection,columnNames:_this.config.columnNames,processData:_this.config.processData},options||{},true);var i1,i2;if(cfg.data.length){for(i1=0;i1<cfg.data.length;i1++){for(i2 in cfg.data[i1]){if(cfg.dataFields.indexOf(i2)==-1){cfg.dataFields.push(i2);cfg.dataFieldsMap[i2]=i2;}}}
if(cfg.exportFields!==undefined){cfg.dataFields=cfg.exportFields.filter(function(n){return cfg.dataFields.indexOf(n)!=-1;});}
var buffer=[];for(i1=0;i1<cfg.data.length;i1++){var tmp={};var skip=false;for(i2=0;i2<cfg.dataFields.length;i2++){var uniqueField=cfg.dataFields[i2];var dataField=cfg.dataFieldsMap[uniqueField];var title=(cfg.columnNames&&cfg.columnNames[uniqueField])||cfg.titles[uniqueField]||uniqueField;var value=cfg.data[i1][dataField];if(value==null){value=undefined;}
if(cfg.exportTitles&&_this.setup.chart.type!="gantt"){if(title in tmp){title+=["( ",uniqueField," )"].join("");}}
if(cfg.dateFields.indexOf(dataField)!=-1){if(cfg.dataDateFormat&&(value instanceof String||typeof value=="string")){value=AmCharts.stringToDate(value,cfg.dataDateFormat);}else if(cfg.dateFormat&&(value instanceof Number||typeof value=="number")){value=new Date(value);}
if(cfg.exportSelection){if(value instanceof Date){if(value<chart.startDate||value>chart.endDate){skip=true;}}else if(i1<chart.startIndex||i1>chart.endIndex){skip=true;}}
if(cfg.dateFormat&&cfg.dateFormat!="dateObject"&&value instanceof Date){value=AmCharts.formatDate(value,cfg.dateFormat);}}
cfg.dataFieldsTitlesMap[dataField]=title;tmp[title]=value;}
if(!skip){buffer.push(tmp);}}
cfg.data=buffer;}
if(cfg.processData!==undefined){cfg.data=_this.handleCallback(cfg.processData,cfg.data,cfg);}
return cfg.data;},capitalize:function(string){return string.charAt(0).toUpperCase()+ string.slice(1).toLowerCase();},createMenu:function(list,container){var div;var buffer=[];function buildList(list,container){var i1,i2,ul=document.createElement("ul");for(i1=0;i1<list.length;i1++){var item=typeof list[i1]==="string"?{format:list[i1]}:list[i1];var li=document.createElement("li");var a=document.createElement("a");var img=document.createElement("img");var span=document.createElement("span");var action=String(item.action?item.action:item.format).toLowerCase();item.format=String(item.format).toUpperCase();li.addEventListener("mouseleave",function(e){this.classList.remove("active");});a.addEventListener("focus",function(e){if(!_this.setup.hasTouch){_this.setup.focusedMenuItem=this;var list=this.parentNode;if(list.tagName!="UL"){list=list.parentNode;}
var items=list.getElementsByTagName("li");for(i1=0;i1<items.length;i1++){items[i1].classList.remove("active");}
this.parentNode.classList.add("active");this.parentNode.parentNode.parentNode.classList.add("active");}});if(_this.config.formats[item.format]){item=_this.deepMerge({label:item.icon?"":item.format,format:item.format,mimeType:_this.config.formats[item.format].mimeType,extension:_this.config.formats[item.format].extension,capture:_this.config.formats[item.format].capture,action:_this.config.action,fileName:_this.config.fileName},item);}else if(!item.label){item.label=item.label?item.label:_this.i18l("menu.label."+ action);}
if(["CSV","JSON","XLSX"].indexOf(item.format)!=-1&&["map","gauge"].indexOf(_this.setup.chart.type)!=-1){continue;}else if(!_this.setup.hasBlob&&item.format!="UNDEFINED"){if(item.mimeType&&item.mimeType.split("/")[0]!="image"&&item.mimeType!="text/plain"){continue;}}
if(item.action=="draw"){if(_this.config.fabric.drawing.enabled){item.menu=item.menu?item.menu:_this.config.fabric.drawing.menu;item.click=(function(item){return function(){this.capture(item,function(){this.createMenu(item.menu);});}})(item);}else{item.menu=[];}}else if(!item.populated&&item.action&&item.action.indexOf("draw.")!=-1){var type=item.action.split(".")[1];var items=item[type]||_this.config.fabric.drawing[type]||[];item.menu=[];item.populated=true;for(i2=0;i2<items.length;i2++){var tmp={"label":items[i2]}
if(type=="shapes"){var io=items[i2].indexOf("//")==-1;var url=(io?_this.config.path+"shapes/":"")+ items[i2];tmp.action="add";tmp.url=url;tmp.icon=url;tmp.ignore=io;tmp["class"]="export-drawing-shape";}else if(type=="colors"){tmp.style="background-color: "+ items[i2];tmp.action="change";tmp.color=items[i2];tmp["class"]="export-drawing-color";}else if(type=="widths"){tmp.action="change";tmp.width=items[i2];tmp.label=document.createElement("span");tmp.label.style.width=_this.numberToPx(items[i2]);tmp.label.style.height=_this.numberToPx(items[i2]);tmp["class"]="export-drawing-width";}else if(type=="opacities"){tmp.style="opacity: "+ items[i2];tmp.action="change";tmp.opacity=items[i2];tmp.label=(items[i2]*100)+"%";tmp["class"]="export-drawing-opacity";}else if(type=="modes"){tmp.label=_this.i18l("menu.label.draw.modes."+ items[i2]);tmp.click=(function(mode){return function(){_this.drawing.mode=mode;}})(items[i2]);tmp["class"]="export-drawing-mode";}
item.menu.push(tmp);}}else if(!item.click&&!item.menu&&!item.items){if(_this.drawing.handler[action]instanceof Function){item.action=action;item.click=(function(item){return function(){this.drawing.handler[item.action](item);if(item.action!="cancel"){this.createMenu(this.config.fabric.drawing.menu);}}})(item);}else if(_this.drawing.enabled){item.click=(function(item){return function(){if(this.config.drawing.autoClose){this.drawing.handler.done();}
this["to"+ item.format](item,function(data){if(item.action=="download"){this.download(data,item.mimeType,[item.fileName,item.extension].join("."));}});}})(item);}else if(item.format!="UNDEFINED"){item.click=(function(item){return function(){if(item.capture||item.action=="print"||item.format=="PRINT"){this.capture(item,function(){this.drawing.handler.done();this["to"+ item.format](item,function(data){if(item.action=="download"){this.download(data,item.mimeType,[item.fileName,item.extension].join("."));}});})}else if(this["to"+ item.format]){this["to"+ item.format](item,function(data){this.download(data,item.mimeType,[item.fileName,item.extension].join("."));});}else{throw new Error('Invalid format. Could not determine output type.');}}})(item);}}
if(item.menu!==undefined&&!item.menu.length){continue;}
a.setAttribute("href","#");if(_this.setup.hasTouch&&li.classList){a.addEventListener("touchend",(function(callback,item){return function(e){e.preventDefault();var args=[e,item];if((item.action=="draw"||item.format=="PRINT"||(item.format!="UNDEFINED"&&item.capture))&&!_this.drawing.enabled){if(!isNaN(item.delay)||!isNaN(_this.config.delay)){item.delay=!isNaN(item.delay)?item.delay:_this.config.delay;_this.delay(item,callback);return;}}
callback.apply(_this,args);}})(item.click||function(e){e.preventDefault();},item));a.addEventListener("touchend",(function(item){return function(e){e.preventDefault();var li=item.elements.li;var parentIsActive=hasActiveParent(li);var siblingIsActive=hasActiveSibling(li);var childHasSubmenu=hasSubmenu(li);function hasActiveParent(elm){var parentNode=elm.parentNode.parentNode;var classList=parentNode.classList;if(parentNode.tagName=="LI"&&classList.contains("active")){return true;}
return false;}
function hasActiveSibling(elm){var siblings=elm.parentNode.children;for(i1=0;i1<siblings.length;i1++){var sibling=siblings[i1];var classList=sibling.classList;if(sibling!==elm&&classList.contains("active")){classList.remove("active");return true;}}
return false;}
function hasSubmenu(elm){return elm.getElementsByTagName("ul").length>0;}
function isRoot(elm){return elm.classList.contains("export-main")||elm.classList.contains("export-drawing");}
if(isRoot(li)||!childHasSubmenu){_this.setup.menu.classList.toggle("active");}
if(!parentIsActive||!childHasSubmenu){while(buffer.length){var tmp=buffer.pop();var tmpRoot=isRoot(tmp);var tmpOdd=tmp!==li;if(tmpRoot){if(!childHasSubmenu){tmp.classList.remove("active");}}else if(tmpOdd){tmp.classList.remove("active");}}}
buffer.push(li);if(childHasSubmenu){li.classList.toggle("active");}}})(item));}else{a.addEventListener("click",(function(callback,item){return function(e){e.preventDefault();var args=[e,item];if((item.action=="draw"||item.format=="PRINT"||(item.format!="UNDEFINED"&&item.capture))&&!_this.drawing.enabled){if(!isNaN(item.delay)||!isNaN(_this.config.delay)){item.delay=!isNaN(item.delay)?item.delay:_this.config.delay;_this.delay(item,callback);return;}}
callback.apply(_this,args);}})(item.click||function(e){e.preventDefault();},item));}
li.appendChild(a);if(_this.isElement(item.label)){span.appendChild(item.label);}else{span.innerHTML=item.label;}
if(item["class"]){li.className=item["class"];}
if(item.style){li.setAttribute("style",item.style);}
if(item.icon){img.setAttribute("src",(!item.ignore&&item.icon.slice(0,10).indexOf("//")==-1?chart.pathToImages:"")+ item.icon);a.appendChild(img);}
if(item.label){a.appendChild(span);}
if(item.title){a.setAttribute("title",item.title);}
if(_this.config.menuReviver){li=_this.config.menuReviver.apply(_this,[item,li]);}
item.elements={li:li,a:a,img:img,span:span}
if((item.menu||item.items)&&item.action!="draw"){if(buildList(item.menu||item.items,li).childNodes.length){ul.appendChild(li);}}else{ul.appendChild(li);}}
if(ul.childNodes.length){container.appendChild(ul);}
return ul;}
if(!container){if(typeof _this.config.divId=="string"){_this.config.divId=container=document.getElementById(_this.config.divId);}else if(_this.isElement(_this.config.divId)){container=_this.config.divId;}else{container=_this.setup.chart.containerDiv;}}
if(_this.isElement(_this.setup.menu)){_this.setup.menu.innerHTML="";}else{_this.setup.menu=document.createElement("div");}
_this.setup.menu.setAttribute("class",_this.setup.chart.classNamePrefix+"-export-menu "+ _this.setup.chart.classNamePrefix+"-export-menu-"+ _this.config.position+" amExportButton");if(_this.config.menuWalker){buildList=_this.config.menuWalker;}
buildList.apply(this,[list,_this.setup.menu]);if(_this.setup.menu.childNodes.length){container.appendChild(_this.setup.menu);}
return _this.setup.menu;},delay:function(options,callback){var cfg=_this.deepMerge({delay:3,precision:2},options||{});var t1,t2,start=Number(new Date());var menu=_this.createMenu([{label:_this.i18l("capturing.delayed.menu.label").replace("{{duration}}",AmCharts.toFixed(cfg.delay,cfg.precision)),title:_this.i18l("capturing.delayed.menu.title"),"class":"export-delayed-capturing",click:function(){clearTimeout(t1);clearTimeout(t2);_this.createMenu(_this.config.menu);}}]);var label=menu.getElementsByTagName("a")[0];t1=setInterval(function(){var diff=cfg.delay-(Number(new Date())- start)/ 1000;
if(diff<=0){clearTimeout(t1);if(cfg.action!="draw"){_this.createMenu(_this.config.menu);}}else if(label){label.innerHTML=_this.i18l("capturing.delayed.menu.label").replace("{{duration}}",AmCharts.toFixed(diff,2));}},AmCharts.updateRate);t2=setTimeout(function(){callback.apply(_this,arguments);},cfg.delay*1000);},migrateSetup:function(setup){var cfg={enabled:true,migrated:true,libs:{autoLoad:true},menu:[]};function crawler(object){var key;for(key in object){var value=object[key];if(key.slice(0,6)=="export"&&value){cfg.menu.push(key.slice(6));}else if(key=="userCFG"){crawler(value);}else if(key=="menuItems"){cfg.menu=value;}else if(key=="libs"){cfg.libs=value;}else if(typeof key=="string"){cfg[key]=value;}}}
crawler(setup);return cfg;},clear:function(){var i1,listener;if(_this.setup.fabric!==undefined){_this.setup.fabric.removeListeners();}
for(i1=0;i1<_this.listenersToRemove.length;i1++){listener=_this.listenersToRemove[i1];listener.node.removeEventListener(listener.event,listener.method);}
if(_this.isElement(_this.setup.wrapper)&&_this.isElement(_this.setup.wrapper.parentNode)&&_this.setup.wrapper.parentNode.removeChild){_this.setup.wrapper.parentNode.removeChild(_this.setup.wrapper);}
if(_this.isElement(_this.setup.menu)&&_this.isElement(_this.setup.wrapper.parentNode)&&_this.setup.wrapper.parentNode.removeChild){_this.setup.menu.parentNode.removeChild(_this.setup.menu);}
_this.listenersToRemove=[];_this.setup.chart.AmExport=undefined;_this.setup.chart.export=undefined;_this.setup=undefined;},loadListeners:function(){function handleClone(clone){if(clone){clone.set({top:clone.top+ 10,left:clone.left+ 10});_this.setup.fabric.add(clone);}}
if(_this.config.keyListener&&_this.config.keyListener!="attached"){_this.docListener=function(e){var current=_this.drawing.buffer.target;var KEY_WHITELIST=[37,38,39,40,13,9,27];var MENU_LEFT=["top-left","bottom-left"].indexOf(_this.config.position)!=-1;var MENU_RIGHT=["top-right","bottom-right"].indexOf(_this.config.position)!=-1;function focusFirst(list,throughTab){for(i1=0;i1<list.length;i1++){var item=list[i1];item.parentNode.classList.remove("active");if(i1==0&&!throughTab){item.focus();}}}
function focusNext(throughTab){if(_this.setup.focusedMenuItem&&_this.setup.focusedMenuItem.nextSibling){_this.setup.focusedMenuItem.parentNode.classList.add("active");focusFirst(_this.setup.focusedMenuItem.nextSibling.getElementsByTagName("a"),throughTab);}}
function focusPrev(throughTab){if(_this.setup.focusedMenuItem&&_this.setup.focusedMenuItem.parentNode.parentNode.parentNode){_this.setup.focusedMenuItem.parentNode.classList.add("active");focusFirst(_this.setup.focusedMenuItem.parentNode.parentNode.parentNode.getElementsByTagName("a"),throughTab);}}
function focusDown(throughTab){if(_this.setup.focusedMenuItem&&_this.setup.focusedMenuItem.parentNode.nextSibling){_this.setup.focusedMenuItem.parentNode.classList.remove("active");focusFirst(_this.setup.focusedMenuItem.parentNode.nextSibling.getElementsByTagName("a"),throughTab);}}
function focusUp(throughTab){if(_this.setup.focusedMenuItem&&_this.setup.focusedMenuItem.parentNode.previousSibling){_this.setup.focusedMenuItem.parentNode.classList.remove("active");focusFirst(_this.setup.focusedMenuItem.parentNode.previousSibling.getElementsByTagName("a"),throughTab);}}
function blurAll(){function unselectParents(elm){if(_this.isElement(elm)){try{elm.blur();}catch(e){}
if(elm.parentNode){elm.parentNode.classList.remove("active");}
if(!elm.classList.contains("amExportButton")){unselectParents(elm.parentNode);}}}
if(_this.setup.focusedMenuItem){unselectParents(_this.setup.focusedMenuItem);_this.setup.focusedMenuItem=undefined;}}
if(_this.setup.focusedMenuItem&&KEY_WHITELIST.indexOf(e.keyCode)!=-1){if(e.keyCode==9){if(!_this.setup.focusedMenuItem.nextSibling){_this.setup.focusedMenuItem.parentNode.classList.remove("active");if(!_this.setup.focusedMenuItem.parentNode.nextSibling){_this.setup.focusedMenuItem.parentNode.classList.remove("active");_this.setup.focusedMenuItem.parentNode.parentNode.parentNode.classList.remove("active");}}else if(e.shiftKey){_this.setup.focusedMenuItem.parentNode.classList.remove("active");}
return;}
if(e.keyCode==13&&_this.setup.focusedMenuItem.nextSibling){focusNext();}
if(e.keyCode==37){if(MENU_RIGHT){focusNext();}else{focusPrev();}}
if(e.keyCode==39){if(MENU_RIGHT){focusPrev();}else{focusNext();}}
if(e.keyCode==40){focusDown();}
if(e.keyCode==38){focusUp();}
if(e.keyCode==27){blurAll();}}
if((e.keyCode==8||e.keyCode==46)&&current){e.preventDefault();_this.setup.fabric.remove(current);}else if(e.keyCode==27&&_this.drawing.enabled){e.preventDefault();if(_this.drawing.buffer.isSelected){_this.setup.fabric.discardActiveObject();}else{_this.drawing.handler.done();}}else if(e.keyCode==67&&(e.metaKey||e.ctrlKey)&&current){_this.drawing.buffer.copy=current;}else if(e.keyCode==88&&(e.metaKey||e.ctrlKey)&&current){_this.drawing.buffer.copy=current;_this.setup.fabric.remove(current);}else if(e.keyCode==86&&(e.metaKey||e.ctrlKey)){if(_this.drawing.buffer.copy){handleClone(_this.drawing.buffer.copy.clone(handleClone))}}else if(e.keyCode==90&&(e.metaKey||e.ctrlKey)){e.preventDefault();if(e.shiftKey){_this.drawing.handler.redo();}else{_this.drawing.handler.undo();}}}
_this.config.keyListener="attached";document.addEventListener("keydown",_this.docListener);_this.addListenerToRemove("keydown",document,_this.docListener);}
if(_this.config.fileListener){_this.setup.chart.containerDiv.addEventListener("dragover",_this.handleDropbox);_this.addListenerToRemove("dragover",_this.setup.chart.containerDiv,_this.handleDropbox);_this.setup.chart.containerDiv.addEventListener("dragleave",_this.handleDropbox);_this.addListenerToRemove("dragleave",_this.setup.chart.containerDiv,_this.handleDropbox);_this.setup.chart.containerDiv.addEventListener("drop",_this.handleDropbox);_this.addListenerToRemove("drop",_this.setup.chart.containerDiv,_this.handleDropbox);}},init:function(){clearTimeout(_timer);_timer=setInterval(function(){if(_this.setup&&_this.setup.chart.containerDiv){clearTimeout(_timer);if(_this.config.enabled){_this.setup.chart.AmExport=_this;if(_this.config.overflow){_this.setup.chart.div.style.overflow="visible";}
_this.loadListeners();_this.createMenu(_this.config.menu);_this.handleReady(_this.config.onReady);}}},AmCharts.updateRate);},construct:function(){_this.drawing.handler.cancel=_this.drawing.handler.done;try{_this.setup.hasBlob=!!new Blob;}catch(e){}
window.safari=window.safari?window.safari:{};_this.defaults.fabric.drawing.fontSize=_this.setup.chart.fontSize||11;_this.config.drawing=_this.deepMerge(_this.defaults.fabric.drawing,_this.config.drawing||{},true);if(_this.config.border){_this.config.border=_this.deepMerge(_this.defaults.fabric.border,_this.config.border||{},true);}
_this.deepMerge(_this.defaults.fabric,_this.config,true);_this.deepMerge(_this.defaults.fabric,_this.config.fabric||{},true);_this.deepMerge(_this.defaults.pdfMake,_this.config,true);_this.deepMerge(_this.defaults.pdfMake,_this.config.pdfMake||{},true);_this.deepMerge(_this.libs,_this.config.libs||{},true);_this.config.drawing=_this.defaults.fabric.drawing;_this.config.fabric=_this.defaults.fabric;_this.config.pdfMake=_this.defaults.pdfMake;_this.config=_this.deepMerge(_this.defaults,_this.config,true);if(_this.config.fabric.drawing.enabled){if(_this.config.fabric.drawing.menu===undefined){_this.config.fabric.drawing.menu=[];_this.deepMerge(_this.config.fabric.drawing.menu,[{"class":"export-drawing",menu:[{label:_this.i18l("menu.label.draw.add"),menu:[{label:_this.i18l("menu.label.draw.shapes"),action:"draw.shapes"},{label:_this.i18l("menu.label.draw.text"),action:"text"}]},{label:_this.i18l("menu.label.draw.change"),menu:[{label:_this.i18l("menu.label.draw.modes"),action:"draw.modes"},{label:_this.i18l("menu.label.draw.colors"),action:"draw.colors"},{label:_this.i18l("menu.label.draw.widths"),action:"draw.widths"},{label:_this.i18l("menu.label.draw.opacities"),action:"draw.opacities"},"UNDO","REDO"]},{label:_this.i18l("menu.label.save.image"),menu:["PNG","JPG","SVG","PDF"]},"PRINT","CANCEL"]}]);}}
if(_this.config.menu===undefined){_this.config.menu=[];_this.deepMerge(_this.config,{menu:[{"class":"export-main",menu:[{label:_this.i18l("menu.label.save.image"),menu:["PNG","JPG","SVG","PDF"]},{label:_this.i18l("menu.label.save.data"),menu:["CSV","XLSX","JSON"]},{label:_this.i18l("menu.label.draw"),action:"draw",menu:_this.config.fabric.drawing.menu},{format:"PRINT",label:_this.i18l("menu.label.print")}]}]});}
if(!_this.libs.path){_this.libs.path=_this.config.path+"libs/";}
if(!_this.setup.hasClasslist){_this.libs.resources.push("classList.js/classList.min.js");}
if(_this.isSupported()){_this.loadDependencies(_this.libs.resources,_this.libs.reload);_this.setup.chart.addClassNames=true;_this.setup.chart[_this.name]=_this;_this.init();}}}
if(config){_this.config=config;}else if(_this.setup.chart[_this.name]){_this.config=_this.setup.chart[_this.name];}else if(_this.setup.chart.amExport||_this.setup.chart.exportConfig){_this.config=_this.migrateSetup(_this.setup.chart.amExport||_this.setup.chart.exportConfig);}else{return;}
_this.construct();return _this.deepMerge(this,_this);}})();AmCharts.addInitHandler(function(chart){new AmCharts["export"](chart);},["pie","serial","xy","funnel","radar","gauge","stock","map","gantt"]);