UNPKG

@fusioncharts/core

Version:

JavaScript Data Visualisation Library

1 lines 10.4 kB
"use strict";exports.__esModule=true;exports.default=_default;var _lib=require("../../lib");function _default(R){var UNDEF,availableAttrs=R._availableAttrs,NONE="none",BLANK="",SPACE=" ",UNDERSCORE="_",COLON=":",SCOLONSPACE="; ",EQUALQUOT='="',QUOT='"',QUOTSPACE=QUOT+SPACE,LT="<",GT=">",NODESTRPART5="</",XLINK=' xlink:href="',IMGNODE="image",TXTNODE="text",GRADIENT="gradient",RECT="rect",ASPRATIO=' preserveAspectRatio="none"',NODESTRPART2=' transform="matrix(',NODESTRPART3=')" style="',VALIGNSTR="vertical-align",TEXTANCHOR="text-anchor",MIDDLE="middle",TOP="top",BOTTOM="bottom",FONTSIZE="font-size",FONT="font",LINEHEIGHT="line-height",FONTFAMILY="font-family",FONTWEIGHT="font-weight",CURSOR="cursor:",TSPANSTR1="<tspan ",TSPANSTR2='dy="',TSPANSTR3='" x="',TSPANSTR4='dy="',RX="rx",RY="ry",TSPANSTR6="</tspan>",PXSPACE="px; ",CLIPRECT="clip-rect",CLIPSTR1='<clipPath id="',CLIPSTR2='"><rect x="',CLIPSTR3='" y="',CLIPSTR4='" width="',CLIPSTR5='" height="',CLIPSTR6='"/></clipPath>',CLIPSTR7=' clip-path="url(#',CLIPSTR8=QUOT+NODESTRPART2,URLCLOSE="')\"",BRACKETCLOSE=")",DTAG=' d="',FILLSTR1="fill:",FILLSTR2=' fill="',FILLSTR3=" fill=\"url('#",FILLSTR4=' fill-opacity="',STROKE1=' stroke="',STROKE2=' stroke-opacity="',STROKEOPAC="stroke-opacity",LINEAR="linear",RADIAL="radial",RGRADIENTSTR1='<radialGradient fx = "',RGRADIENTSTR3="</radialGradient>",RGRADIENTSTR2='" fy = "',RGRADIENTSTR6='" cy = "',RGRADIENTSTR5='" cx = "',RGRADIENTSTR7='" r = "',RGRADIENTSTR8='" gradientUnits = "',ID='" id = "',RGRADIENTSTR4='">',LGRADIENTSTR6="</linearGradient>",LGRADIENTSTR5='" gradientTransform ="matrix(',LGRADIENTSTR1='<linearGradient x1 = "',LGRADIENTSTR2='" y1 = "',LGRADIENTSTR3='" x2 = "',LGRADIENTSTR4='" y2 = "',STOPSTR1="<stop",STOPSTR2=' offset="',STOPSTR3='" stop-color="',STOPSTR4='" stop-opacity="',STOPSTR5='" />',COLORWHITE="#fff",PERCENT100="100%",PERCENT0="0%",matrixSanitizerReg=/^matrix\(|\)$/g,commaSanitizerReg=/\,/g,textNewLineReg=/\n|<br\s*?\/?>/gi,retriveNumReg=/[^\d\.]/gi,idSanitizerReg=/[\%\(\)\s,\xb0#]/g,grouptagtestReg=/group/gi,ampregex=/&/g,quot1regex=/"/g,quot2regex=/'/g,ltregex=/</g,gtregex=/>/g,ampSTR="&amp;",quot1STR="&quot;",quot2STR="&#39;",ltSTR="&lt;",gtSTR="&gt;",IdCounter=0,gradientUnitNames={userSpaceOnUse:"userSpaceOnUse",objectBoundingBox:"objectBoundingBox"},math=Math,toFloat=parseFloat,mmax=math.max,abs=math.abs,pow=math.pow,Str=String,separator=/[, ]+/,attributeParser={blur:function blur(){},transform:function transform(){},src:function src(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj.src;conf.attrSTR+=XLINK+value+QUOT},path:function path(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj.path;value=R._pathToAbsolute(value||BLANK);conf.attrSTR+=DTAG+(value.toString&&value.toString()||BLANK).replace(commaSanitizerReg,SPACE)+QUOT},gradient:function gradient(node,conf,defs){var attrsObj=node.attrs,value=attrsObj.gradient,type=LINEAR,id=value,angle,vector,max,dots,fx=.5,fy=.5,gStr=BLANK,gCloseStr=BLANK,stopStr=BLANK,i,ln,cx,cy,r,units;id=id.replace(idSanitizerReg,UNDERSCORE);if(!defs[id]){value=Str(value).replace(R._radial_gradient,(function(all,_opts){var _fx,_fy,dir,_r,_cx,_cy,sqx,opts=_opts,shifted;opts=opts&&opts.split(",")||[];type=RADIAL;_fx=opts[0];_fy=opts[1];_r=opts[2];_cx=opts[3];_cy=opts[4];units=opts[5];shifted=_fx&&_fy;if(_r){r=/\%/.test(_r)?_r:toFloat(_r)}if(units===gradientUnitNames.userSpaceOnUse){if(shifted){fx=_fx;fy=_fy}if(_cx&&_cy){cx=_cx;cy=_cy;if(!shifted){fx=cx;fy=cy}}return BLANK}if(shifted){fx=toFloat(_fx);fy=toFloat(_fy);dir=(fy>.5)*2-1;(sqx=pow(fx-.5,2))+pow(fy-.5,2)>.25&&sqx<.25&&(fy=math.sqrt(.25-sqx)*dir+.5)&&fy!==.5&&(fy=fy.toFixed(5)-1e-5*dir)}if(_cx&&_cy){cx=toFloat(_cx);cy=toFloat(_cy);dir=(cy>.5)*2-1;(sqx=pow(cx-.5,2))+pow(cy-.5,2)>.25&&sqx<.25&&(cy=math.sqrt(.25-sqx)*dir+.5)&&cy!==.5&&(cy=cy.toFixed(5)-1e-5*dir);if(!shifted){fx=cx;fy=cy}}return BLANK}));value=value.split(/\s*\-\s*/);if(type===LINEAR){angle=value.shift();angle=-toFloat(angle);if(isNaN(angle)){return null}vector=[0,0,math.cos(R.rad(angle)),math.sin(R.rad(angle))];max=1/(mmax(abs(vector[2]),abs(vector[3]))||1);vector[2]*=max;vector[3]*=max;if(vector[2]<0){vector[0]=-vector[2];vector[2]=0}if(vector[3]<0){vector[1]=-vector[3];vector[3]=0}}dots=R._parseDots(value);if(!dots){return null}if(type===RADIAL){gStr=RGRADIENTSTR1+fx+RGRADIENTSTR2+fy+RGRADIENTSTR6+cy+RGRADIENTSTR5+cx+RGRADIENTSTR7+r+RGRADIENTSTR8+units+ID+id+RGRADIENTSTR4;gCloseStr=RGRADIENTSTR3}else{gStr=LGRADIENTSTR1+vector[0]+LGRADIENTSTR2+vector[1]+LGRADIENTSTR3+vector[2]+LGRADIENTSTR4+vector[3]+LGRADIENTSTR5+node.matrix.invert()+BRACKETCLOSE+ID+id+RGRADIENTSTR4;gCloseStr=LGRADIENTSTR6}for(i=0,ln=dots.length;i<ln;i++){stopStr+=STOPSTR1+STOPSTR2+(dots[i].offset?dots[i].offset:i?PERCENT100:PERCENT0)+STOPSTR3+(dots[i].color||COLORWHITE)+STOPSTR4+(dots[i].opacity===UNDEF?1:dots[i].opacity)+STOPSTR5}defs[id]=true;defs.str+=gStr+stopStr+gCloseStr}conf.attrSTR+=FILLSTR3+id+URLCLOSE},fill:function fill(node,conf){var attrsObj=conf.attrs,value=attrsObj.fill,color,opacity;if(!node.attrs.gradient){color=R.color(value);opacity=color.opacity;if(node.type===TXTNODE){conf.styleSTR+=FILLSTR1+color+SCOLONSPACE+STROKEOPAC+COLON+0+SCOLONSPACE}else{conf.attrSTR+=FILLSTR2+color+QUOT;if(!attrsObj["fill-opacity"]&&(opacity||opacity===0)){conf.attrSTR+=FILLSTR4+opacity+QUOT}}}},stroke:function stroke(node,conf){var attrsObj=conf.attrs,value=attrsObj.stroke,color,opacity;color=R.color(value);opacity=color.opacity;if(node.type!==TXTNODE){conf.attrSTR+=STROKE1+color+QUOT;if(!attrsObj[STROKEOPAC]&&(opacity||opacity===0)){conf.attrSTR+=STROKE2+opacity+QUOT}}},"clip-rect":function clipRect(node,conf,defs){var attrsObj=conf.attrs,value=Str(attrsObj[CLIPRECT]),rect=value.split(separator),id=value.replace(idSanitizerReg,UNDERSCORE)+UNDERSCORE+UNDERSCORE+IdCounter++;if(rect.length===4){if(!defs[id]){defs[id]=true;defs.str+=CLIPSTR1+id+CLIPSTR2+rect[0]+CLIPSTR3+rect[1]+CLIPSTR4+rect[2]+CLIPSTR5+rect[3]+CLIPSTR8+node.matrix.invert().toMatrixString().replace(matrixSanitizerReg,BLANK)+BRACKETCLOSE+CLIPSTR6}conf.attrSTR+=CLIPSTR7+id+BRACKETCLOSE+QUOT}},cursor:function cursor(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj.cursor;if(value){conf.styleSTR+=CURSOR+value+SCOLONSPACE}},font:function font(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj.font;conf.styleSTR+=FONT+COLON+value.replace(/\"/gi,SPACE)+SCOLONSPACE},"font-size":function fontSize(){var conf=arguments[1],attrsObj=conf.attrs,value=(0,_lib.pluck)(attrsObj[FONTSIZE],"10");if(value&&value.replace){value=value.replace(retriveNumReg,BLANK)}conf.styleSTR+=FONTSIZE+COLON+value+PXSPACE},"font-weight":function fontWeight(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj[FONTWEIGHT];conf.styleSTR+=FONTWEIGHT+COLON+value+SCOLONSPACE},"font-family":function fontFamily(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj[FONTFAMILY];conf.styleSTR+=FONTFAMILY+COLON+value+SCOLONSPACE},"line-height":_lib.stubFN,"clip-path":_lib.stubFN,visibility:_lib.stubFN,"vertical-align":_lib.stubFN,"text-anchor":function textAnchor(node,conf){var attrsObj=conf.attrs,value=attrsObj[TEXTANCHOR]||MIDDLE;if(node.type===TXTNODE){conf.attrSTR+=SPACE+TEXTANCHOR+EQUALQUOT+value+QUOT}},title:_lib.stubFN,text:function text(){var conf=arguments[1],attrsObj=conf.attrs,value=attrsObj.text,fontSize=(0,_lib.pluck)(attrsObj[FONTSIZE],attrsObj[FONT],"10"),lineHeight=(0,_lib.pluck)(attrsObj[LINEHEIGHT]),baseHeight,x,valign,texts,i,ii,baseAdjust,text;if(fontSize&&fontSize.replace){fontSize=fontSize.replace(retriveNumReg,BLANK)}fontSize=(0,_lib.pluckNumber)(fontSize);if(lineHeight&&lineHeight.replace){lineHeight=lineHeight.replace(retriveNumReg,BLANK)}lineHeight=(0,_lib.pluckNumber)(lineHeight,fontSize&&fontSize*1.2);baseHeight=fontSize?fontSize*.85:lineHeight*.75;x=attrsObj.x;valign=(0,_lib.pluck)(attrsObj[VALIGNSTR],MIDDLE).toLowerCase();texts=Str(value).split(textNewLineReg);ii=texts.length;i=0;baseAdjust=valign===TOP?baseHeight:valign===BOTTOM?baseHeight-lineHeight*ii:baseHeight-lineHeight*ii*.5;for(;i<ii;i++){conf.textSTR+=TSPANSTR1;text=(texts[i]||BLANK).replace(ampregex,ampSTR).replace(quot1regex,quot1STR).replace(quot2regex,quot2STR).replace(ltregex,ltSTR).replace(gtregex,gtSTR);if(i){conf.textSTR+=TSPANSTR2+lineHeight+TSPANSTR3+x+QUOTSPACE}else{conf.textSTR+=TSPANSTR4+baseAdjust+QUOT}conf.textSTR+=GT+text+TSPANSTR6}}},_parseNode=function parseNode(node,defs){var xmlSTR=BLANK,conf={attrSTR:BLANK,styleSTR:BLANK,textSTR:BLANK,attrs:node.attr()},isShadow=node.isShadow,childXMLSTR=BLANK,nextXMLSTR=BLANK,attrName,styleName,nodeType,attrs=conf.attrs;if(node.node.style.display!==NONE&&!isShadow){for(attrName in attrs){if(attrName!==GRADIENT&&(availableAttrs[attrName]!==UNDEF||attributeParser[attrName])&&attrs[attrName]!==UNDEF){if(attributeParser[attrName]){attributeParser[attrName](node,conf,defs)}else{conf.attrSTR+=SPACE+attrName+EQUALQUOT+attrs[attrName]+QUOT}}}if(node.attrs.gradient){attributeParser.gradient(node,conf,defs)}if(node.type===RECT&&attrs.r){conf.attrSTR+=SPACE+RX+EQUALQUOT+attrs.r+QUOT+SPACE+RY+EQUALQUOT+attrs.r+QUOT}for(styleName in node.styles){conf.styleSTR+=styleName+COLON+node.styles[styleName]+SCOLONSPACE}if(node.type===IMGNODE){conf.attrSTR+=ASPRATIO}if(node.type===TXTNODE&&!attrs[TEXTANCHOR]){attributeParser[TEXTANCHOR](node,conf)}if(node.bottom){childXMLSTR=_parseNode(node.bottom,defs)}if(node.next){nextXMLSTR=_parseNode(node.next,defs)}nodeType=node.type;if(nodeType.match(grouptagtestReg)){nodeType="g"}xmlSTR+=LT+nodeType+NODESTRPART2+node.matrix.toMatrixString().replace(matrixSanitizerReg,BLANK)+NODESTRPART3+conf.styleSTR+QUOT+conf.attrSTR+GT+conf.textSTR+childXMLSTR+NODESTRPART5+nodeType+GT+nextXMLSTR}else{if(node.next){xmlSTR+=_parseNode(node.next,defs)}}return xmlSTR};if(R.vml){R.fn.toSVG=function(keepImages){var paper=this,svg=BLANK,defs={str:BLANK},childXMLSTR=BLANK;svg='<svg style="overflow: hidden; position: relative;" xmlns="http://www.w3.org/2000/svg"'+' xmlns:xlink="http://www.w3.org/1999/xlink" width="'+paper.width+'" version="1.1" height="'+paper.height+'">';if(paper.bottom){childXMLSTR=_parseNode(paper.bottom,defs)}svg+="<defs>"+defs.str+"</defs>"+childXMLSTR+"</svg>";if(!keepImages){svg=svg.replace(/<image[^\>]*\>[^\>]*\>/gi,(function(str){if(str.match(/href=\"data\:image/i)){return str}return BLANK}))}return svg}}}