UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 6.8 kB
import{drawSvgOnCanvas,downloadCharts,browserDetails}from'../utils/lib-svg-to-canvas';import{addImage,getDataUrl}from'../utils/jpeg-to-pdf';import{pluck,pluckNumber,PROJECT_VERSION}from'../../../fc-core/src/lib';import{EXPORTACTION,EXPORTMODE,EXPORTFORMAT,LOGMODE,createExportActionOldString,logCharts,cacheAllImages,replaceImagesWithNonDataUrl}from'../utils/export-utils';import{triggerEvent}from'../../../fc-core/src/event-api';let UNDEF,FCGlobal,win=window,math=Math,mathMax=math.max,Image=win.Image,isIOS=win.navigator.userAgent.match(/(iPad|iPhone|iPod)/g),IMAGEDATA='IMAGE-DATA',DEFAULT_LOG_URL='https:'===win.location.protocol?'https://export.api3.fusioncharts.com/api/v1.0/logs':'http://export.api3.fusioncharts.com/api/v1.0/logs',DEFAULT_EXPORT_URL='https:'===win.location.protocol?'https://export.api3.fusioncharts.com/':'http://export.api3.fusioncharts.com/',BLANKSTRING='';function batchExport(){let a,b,c,d,e,f,g,h,j,k=arguments[0],l=k||{},m=0,n=!1,o={exportTargetWindow:pluck(l.exportTargetWindow,isIOS?'_parent':'_self'),exportAction:function(){var a;return l.exportAction&&'string'==typeof l.exportAction?(a=l.exportAction.toLowerCase(),0<=[EXPORTACTION.DOWNLOAD,EXPORTACTION.SAVE,EXPORTACTION.DOWNLOADSAVE].indexOf(a)?a:EXPORTACTION.DOWNLOAD):EXPORTACTION.DOWNLOAD}(),exportFileName:pluck(l.exportFileName,'FusionCharts'),exportHandler:pluck(l.exportHandler,DEFAULT_EXPORT_URL),exportParameters:pluck(l.exportParameters,BLANKSTRING),exportFormat:pluck(l.exportFormat,EXPORTFORMAT.PNG),exportCallback:pluck(l.exportCallback,BLANKSTRING),exportAtClientSide:pluckNumber(l.exportAtClientSide,1),exportMode:function(){var a;return'undefined'!=typeof l.exportAtClientSide&&(a={1:EXPORTMODE.AUTO,0:EXPORTMODE.SERVER}[l.exportAtClientSide]),a=l.exportMode||a||EXPORTMODE.AUTO,a=a.toLowerCase(),a}(),logEnabled:pluckNumber(l.logEnabled,0),logMode:function(){var a=l.logMode;return'undefined'!=typeof a&&'string'==typeof a&&a.toUpperCase()in LOGMODE?LOGMODE[a.toUpperCase()]:LOGMODE.AUTO}(),logHandler:pluck(l.logHandler,DEFAULT_LOG_URL)},p=o.exportFormat.toLowerCase(),q=0,r=0,s=5,t=win.document,u=FCGlobal.items,v=function(a){return!(a.match(/http:\/\/|https:\/\//)&&/(http:\/\/|https:\/\/)([^\/\:]*)/.exec(a)[2]&&win.location.hostname!==/(http:\/\/|https:\/\/)([^\/\:]*)/.exec(a)[2])},w=function(a,b,c,d){var e=a,f=b;return isNaN(e)&&(e=pluckNumber(b,d)*(c/d)),isNaN(f)&&(f=pluckNumber(a,c)*(d/c)),{width:e,height:f}},x=function(a,b,c){var d,e,f,g;return c=c||o.exportAction,d=o.exportAction,e=createExportActionOldString(o.exportAction),f=['exportfilename='+o.exportFileName,'exportformat='+o.exportFormat,'exportaction='+e,'exportactionnew='+d,'configuredexportaction='+c,'exportparameters='+o].join('|'),g=!!o.logEnabled,o.logMode===LOGMODE.CLIENT&&(g=!1),{charttype:'combined',stream_type:a||'',stream:b||'',is_single_export:!1,is_full_version:!1,version:PROJECT_VERSION,user_time_zone:-new Date().getTimezoneOffset(),log_enabled:g,parameters:f}},y=function(){var a=o.exportAction;return{chartType:'combined',isSingleExport:!1,isFullVersion:!1,exportAction:a,userTimeZone:-new Date().getTimezoneOffset(),exportFileName:[o.exportFileName,o.exportFormat].join('.'),exportFormat:o.exportFormat,version:PROJECT_VERSION}},z=function(a){a===LOGMODE.CLIENT&&logCharts(y(),o)},A=function(a){var b,c,d;triggerEvent('beforeexport',UNDEF,UNDEF,UNDEF,function(){c='undefined'!=typeof win.btoa&&('Chrome'===browserDetails.name||'Firefox'===browserDetails.name||'Safari'===browserDetails.name||'Edge'===browserDetails.name||'ie'===browserDetails.name),o.exportMode===EXPORTMODE.CLIENT||o.exportMode===EXPORTMODE.AUTO&&c?((o.exportAction===EXPORTACTION.DOWNLOAD||o.exportAction===EXPORTACTION.DOWNLOADSAVE)&&(b=o.exportMode===EXPORTMODE.AUTO?x(IMAGEDATA,a):null,downloadCharts('url',a,o.exportFileName+'.'+p,b,o),triggerEvent('exported',UNDEF,{fileName:o.exportFileName+'.'+p})),o.exportAction===EXPORTACTION.SAVE||o.exportAction===EXPORTACTION.DOWNLOADSAVE?(d=o.exportAction,o.exportAction===EXPORTACTION.DOWNLOADSAVE&&(o.exportAction=EXPORTACTION.SAVE),b=x(IMAGEDATA,a,d),o.paper={width:void 0,height:void 0},o.fusionCharts={},downloadCharts(null,null,null,b,o),delete o.paper,delete o.fusioncharts,z(o.logMode)):o.logMode!==LOGMODE.SERVER&&logCharts(y(),o)):(b=x(IMAGEDATA,a),o.paper={width:void 0,height:void 0},o.fusionCharts={},downloadCharts(null,null,null,b,o),delete o.paper,delete o.fusioncharts,z(o.logMode))},function(){triggerEvent('exportcancelled')})},B=function(){var a=this;drawSvgOnCanvas({svg:arguments[0],canvas:c,x:a.x,y:a.y,width:a.width,height:a.height,useCanvas:arguments[1]},function(){m-=1,0==m&&n&&('png'===p?A(c.toDataURL('image/png')):'jpeg'===p?A(c.toDataURL('image/jpeg')):'pdf'===p?(addImage(c.toDataURL('image/jpeg'),q,r),A(getDataUrl())):A(c.toDataURL('image/png')))})},C=function(a){var b=l.background;c=t.createElement('canvas'),c.id='newCanvas',c.width=r,c.height=q,c.style.border='1px solid black',d=c.getContext('2d'),d.fillStyle=b&&b.bgColor||'#ffffff',d.fillRect(0,0,r,q),b&&b.bgImage&&v(b.bgImage)?(g=new Image,g.src=b.bgImage,g._userData=b,d.globalAlpha=pluckNumber(b.bgImageAlpha,100)/100,g.onload=function(){var b=this._userData,c=pluckNumber(b.bgImageX,0),e=pluckNumber(b.bgImageY,0),f=w(+b.bgImageWidth,+b.bgImageHeight,this.width,this.height),g=f.width,h=f.height;try{d.drawImage(this,c,e,g,h)}finally{d.globalAlpha=1,a()}},g.onerror=function(){a()}):a()},D=function(b,c){a=FCGlobal.items[b],a.jsVars.instanceAPI&&(e=a.jsVars.instanceAPI.getFromEnv('paper').toSVG(!0),e=e.replace(/NS\d+:/gi,'xlink:'),e=e.replace(/(\sd\s*=\s*["'])[M\s\d\.]*(["'])/ig,'$1M 0 0 L 0 0$2'),e=e.replace(/(xlink:title\s*=\s*)['"].*?["']/ig,''),m+=1,function(){var b=e,d=FCGlobal.options['export'].useCanvas;cacheAllImages(b,!1,function(){b=replaceImagesWithNonDataUrl(b),B.call(c||a,b,d)})}())},E=function(){var a,c,d,e,f=l.charts;if(b=[],f)for(d in f)f.hasOwnProperty(d)&&(a=u[f[d].id])&&(c=f[d],e=w(+c.width,+c.height,a.width,a.height),b.push({id:a.id,width:e.width,height:e.height,x:c.x,y:c.y}));else for(d in u)u.hasOwnProperty(d)&&(a=u[d],b.push({id:a.id,width:a.width,height:a.height}))};if(function(){var a,b;a=o.exportMode,b={},b[EXPORTMODE.CLIENT]=1,b[EXPORTMODE.AUTO]=0,b[EXPORTMODE.SERVER]=0,o.exportatclientside=b[a]}(),!!browserDetails.hasCanvas){for(E(),j=0,f=b.length;j<f;j+=1)h=b[j],h.x=pluckNumber(h.x,s),h.y=pluckNumber(h.y,q+s),h.height=pluckNumber(h.height),h.width=pluckNumber(h.width),q=mathMax(q,h.y+h.height),r=mathMax(r,h.x+h.width);q=l.imageHeight||q+5,r=l.imageWidth||r+5,C(function(){return function(){for(j=0,f=b.length;j<f;j+=1)h=b[j],j===f-1&&(n=!0),D(h.id,h)}}())}}function batchExportLinker(a){a.batchExport=batchExport,FCGlobal=a}export default{extension:batchExportLinker,name:'batchExportLinker',type:'extension',requiresFusionCharts:!0};