UNPKG

taucharts

Version:

Data-focused charting library based on D3

9 lines 93.8 kB
/*! * /* * taucharts@2.8.0 (2020-02-26) * Copyright 2020 Targetprocess, Inc. * Licensed under Apache License 2.0 * * / * */ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("taucharts"),require("d3-selection"));else if("function"==typeof define&&define.amd)define(["taucharts","d3-selection"],e);else{var i="object"==typeof exports?e(require("taucharts"),require("d3-selection")):e(t.Taucharts,t.d3);for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(window,(function(t,e){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=19)}([function(e,i){e.exports=t},function(t,i){t.exports=e},,,,,function(t,e,i){t.exports=function(t,e){"use strict";var i;return t=t&&t.hasOwnProperty("default")?t.default:t,e=e&&e.hasOwnProperty("default")?e.default:e,function(i){var n;function r(){return document.createElement("canvas")}i.exports,(n=window).DOMParser=window.DOMParser;var a,s=function(i,o,l){if(null!=i||null!=o||null!=l){var h=function(i){var s={opts:i,FRAMERATE:30,MAX_VIRTUAL_PIXELS:3e4,rootEmSize:12,emSize:12,log:function(t){}};1==s.opts.log&&"undefined"!=typeof console&&(s.log=function(t){console.log(t)}),s.init=function(t){var e=0;s.UniqueId=function(){return"canvg"+ ++e},s.Definitions={},s.Styles={},s.StylesSpecificity={},s.Animations=[],s.Images=[],s.ctx=t,s.ViewPort=new function(){this.viewPorts=[],this.Clear=function(){this.viewPorts=[]},this.SetCurrent=function(t,e){this.viewPorts.push({width:t,height:e})},this.RemoveCurrent=function(){this.viewPorts.pop()},this.Current=function(){return this.viewPorts[this.viewPorts.length-1]},this.width=function(){return this.Current().width},this.height=function(){return this.Current().height},this.ComputeSize=function(t){return null!=t&&"number"==typeof t?t:"x"==t?this.width():"y"==t?this.height():Math.sqrt(Math.pow(this.width(),2)+Math.pow(this.height(),2))/Math.sqrt(2)}}},s.init(),s.ImagesLoaded=function(){for(var t=0;t<s.Images.length;t++)if(!s.Images[t].loaded)return!1;return!0},s.trim=function(t){return t.replace(/^\s+|\s+$/g,"")},s.compressSpaces=function(t){return t.replace(/(?!\u3000)\s+/gm," ")},s.ajax=function(t){var e;return(e=n.XMLHttpRequest?new n.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"))?(e.open("GET",t,!1),e.send(null),e.responseText):null},s.parseXml=function(t){if("undefined"!=typeof Windows&&void 0!==Windows.Data&&void 0!==Windows.Data.Xml){var e=new Windows.Data.Xml.Dom.XmlDocument,r=new Windows.Data.Xml.Dom.XmlLoadSettings;return r.prohibitDtd=!1,e.loadXml(t,r),e}if(!n.DOMParser)return t=t.replace(/<!DOCTYPE svg[^>]*>/,""),(e=new ActiveXObject("Microsoft.XMLDOM")).async="false",e.loadXML(t),e;try{var a=i.xmldom?new n.DOMParser(i.xmldom):new n.DOMParser;return a.parseFromString(t,"image/svg+xml")}catch(e){return(a=i.xmldom?new n.DOMParser(i.xmldom):new n.DOMParser).parseFromString(t,"text/xml")}},s.Property=function(t,e){this.name=t,this.value=e},s.Property.prototype.getValue=function(){return this.value},s.Property.prototype.hasValue=function(){return null!=this.value&&""!==this.value},s.Property.prototype.numValue=function(){if(!this.hasValue())return 0;var t=parseFloat(this.value);return(this.value+"").match(/%$/)&&(t/=100),t},s.Property.prototype.valueOrDefault=function(t){return this.hasValue()?this.value:t},s.Property.prototype.numValueOrDefault=function(t){return this.hasValue()?this.numValue():t},s.Property.prototype.addOpacity=function(e){var i=this.value;if(null!=e.value&&""!=e.value&&"string"==typeof this.value){var n=new t(this.value);n.ok&&(i="rgba("+n.r+", "+n.g+", "+n.b+", "+e.numValue()+")")}return new s.Property(this.name,i)},s.Property.prototype.getDefinition=function(){var t=this.value.match(/#([^\)'"]+)/);return t&&(t=t[1]),t||(t=this.value),s.Definitions[t]},s.Property.prototype.isUrlDefinition=function(){return 0==this.value.indexOf("url(")},s.Property.prototype.getFillStyleDefinition=function(t,e){var i=this.getDefinition();if(null!=i&&i.createGradient)return i.createGradient(s.ctx,t,e);if(null!=i&&i.createPattern){if(i.getHrefAttribute().hasValue()){var n=i.attribute("patternTransform");i=i.getHrefAttribute().getDefinition(),n.hasValue()&&(i.attribute("patternTransform",!0).value=n.value)}return i.createPattern(s.ctx,t)}return null},s.Property.prototype.getDPI=function(t){return 96},s.Property.prototype.getREM=function(t){return s.rootEmSize},s.Property.prototype.getEM=function(t){return s.emSize},s.Property.prototype.getUnits=function(){return(this.value+"").replace(/[0-9\.\-]/g,"")},s.Property.prototype.isPixels=function(){if(!this.hasValue())return!1;var t=this.value+"";return!!t.match(/px$/)||!!t.match(/^[0-9]+$/)},s.Property.prototype.toPixels=function(t,e){if(!this.hasValue())return 0;var i=this.value+"";if(i.match(/rem$/))return this.numValue()*this.getREM(t);if(i.match(/em$/))return this.numValue()*this.getEM(t);if(i.match(/ex$/))return this.numValue()*this.getEM(t)/2;if(i.match(/px$/))return this.numValue();if(i.match(/pt$/))return this.numValue()*this.getDPI(t)*(1/72);if(i.match(/pc$/))return 15*this.numValue();if(i.match(/cm$/))return this.numValue()*this.getDPI(t)/2.54;if(i.match(/mm$/))return this.numValue()*this.getDPI(t)/25.4;if(i.match(/in$/))return this.numValue()*this.getDPI(t);if(i.match(/%$/))return this.numValue()*s.ViewPort.ComputeSize(t);var n=this.numValue();return e&&n<1?n*s.ViewPort.ComputeSize(t):n},s.Property.prototype.toMilliseconds=function(){if(!this.hasValue())return 0;var t=this.value+"";return t.match(/s$/)?1e3*this.numValue():(t.match(/ms$/),this.numValue())},s.Property.prototype.toRadians=function(){if(!this.hasValue())return 0;var t=this.value+"";return t.match(/deg$/)?this.numValue()*(Math.PI/180):t.match(/grad$/)?this.numValue()*(Math.PI/200):t.match(/rad$/)?this.numValue():this.numValue()*(Math.PI/180)};var o={baseline:"alphabetic","before-edge":"top","text-before-edge":"top",middle:"middle",central:"middle","after-edge":"bottom","text-after-edge":"bottom",ideographic:"ideographic",alphabetic:"alphabetic",hanging:"hanging",mathematical:"alphabetic"};return s.Property.prototype.toTextBaseline=function(){return this.hasValue()?o[this.value]:null},s.Font=new function(){this.Styles="normal|italic|oblique|inherit",this.Variants="normal|small-caps|inherit",this.Weights="normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit",this.CreateFont=function(t,e,i,n,r,a){var o=null!=a?this.Parse(a):this.CreateFont("","","","","",s.ctx.font);return{fontFamily:r=r||o.fontFamily,fontSize:n||o.fontSize,fontStyle:t||o.fontStyle,fontWeight:i||o.fontWeight,fontVariant:e||o.fontVariant,toString:function(){return[this.fontStyle,this.fontVariant,this.fontWeight,this.fontSize,this.fontFamily].join(" ")}}};var t=this;this.Parse=function(e){for(var i={},n=s.trim(s.compressSpaces(e||"")).split(" "),r={fontSize:!1,fontStyle:!1,fontWeight:!1,fontVariant:!1},a="",o=0;o<n.length;o++)r.fontStyle||-1==t.Styles.indexOf(n[o])?r.fontVariant||-1==t.Variants.indexOf(n[o])?r.fontWeight||-1==t.Weights.indexOf(n[o])?r.fontSize?"inherit"!=n[o]&&(a+=n[o]):("inherit"!=n[o]&&(i.fontSize=n[o].split("/")[0]),r.fontStyle=r.fontVariant=r.fontWeight=r.fontSize=!0):("inherit"!=n[o]&&(i.fontWeight=n[o]),r.fontStyle=r.fontVariant=r.fontWeight=!0):("inherit"!=n[o]&&(i.fontVariant=n[o]),r.fontStyle=r.fontVariant=!0):("inherit"!=n[o]&&(i.fontStyle=n[o]),r.fontStyle=!0);return""!=a&&(i.fontFamily=a),i}},s.ToNumberArray=function(t){for(var e=s.trim(s.compressSpaces((t||"").replace(/,/g," "))).split(" "),i=0;i<e.length;i++)e[i]=parseFloat(e[i]);return e},s.Point=function(t,e){this.x=t,this.y=e},s.Point.prototype.angleTo=function(t){return Math.atan2(t.y-this.y,t.x-this.x)},s.Point.prototype.applyTransform=function(t){var e=this.x*t[0]+this.y*t[2]+t[4],i=this.x*t[1]+this.y*t[3]+t[5];this.x=e,this.y=i},s.CreatePoint=function(t){var e=s.ToNumberArray(t);return new s.Point(e[0],e[1])},s.CreatePath=function(t){for(var e=s.ToNumberArray(t),i=[],n=0;n<e.length;n+=2)i.push(new s.Point(e[n],e[n+1]));return i},s.BoundingBox=function(t,e,i,n){this.x1=Number.NaN,this.y1=Number.NaN,this.x2=Number.NaN,this.y2=Number.NaN,this.x=function(){return this.x1},this.y=function(){return this.y1},this.width=function(){return this.x2-this.x1},this.height=function(){return this.y2-this.y1},this.addPoint=function(t,e){null!=t&&((isNaN(this.x1)||isNaN(this.x2))&&(this.x1=t,this.x2=t),t<this.x1&&(this.x1=t),t>this.x2&&(this.x2=t)),null!=e&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=e,this.y2=e),e<this.y1&&(this.y1=e),e>this.y2&&(this.y2=e))},this.addX=function(t){this.addPoint(t,null)},this.addY=function(t){this.addPoint(null,t)},this.addBoundingBox=function(t){this.addPoint(t.x1,t.y1),this.addPoint(t.x2,t.y2)},this.addQuadraticCurve=function(t,e,i,n,r,a){var s=t+2/3*(i-t),o=e+2/3*(n-e),l=s+1/3*(r-t),h=o+1/3*(a-e);this.addBezierCurve(t,e,s,l,o,h,r,a)},this.addBezierCurve=function(t,e,i,n,r,a,s,o){var l=[t,e],h=[i,n],u=[r,a],c=[s,o];this.addPoint(l[0],l[1]),this.addPoint(c[0],c[1]);for(var f=0;f<=1;f++){var d=function(t){return Math.pow(1-t,3)*l[f]+3*Math.pow(1-t,2)*t*h[f]+3*(1-t)*Math.pow(t,2)*u[f]+Math.pow(t,3)*c[f]},p=6*l[f]-12*h[f]+6*u[f],m=-3*l[f]+9*h[f]-9*u[f]+3*c[f],g=3*h[f]-3*l[f];if(0!=m){var y=Math.pow(p,2)-4*g*m;if(!(y<0)){var v=(-p+Math.sqrt(y))/(2*m);0<v&&v<1&&(0==f&&this.addX(d(v)),1==f&&this.addY(d(v)));var b=(-p-Math.sqrt(y))/(2*m);0<b&&b<1&&(0==f&&this.addX(d(b)),1==f&&this.addY(d(b)))}}else{if(0==p)continue;var x=-g/p;0<x&&x<1&&(0==f&&this.addX(d(x)),1==f&&this.addY(d(x)))}}},this.isPointInBox=function(t,e){return this.x1<=t&&t<=this.x2&&this.y1<=e&&e<=this.y2},this.addPoint(t,e),this.addPoint(i,n)},s.Transform=function(t){var e=this;this.Type={},this.Type.translate=function(t){this.p=s.CreatePoint(t),this.apply=function(t){t.translate(this.p.x||0,this.p.y||0)},this.unapply=function(t){t.translate(-1*this.p.x||0,-1*this.p.y||0)},this.applyToPoint=function(t){t.applyTransform([1,0,0,1,this.p.x||0,this.p.y||0])}},this.Type.rotate=function(t){var e=s.ToNumberArray(t);this.angle=new s.Property("angle",e[0]),this.cx=e[1]||0,this.cy=e[2]||0,this.apply=function(t){t.translate(this.cx,this.cy),t.rotate(this.angle.toRadians()),t.translate(-this.cx,-this.cy)},this.unapply=function(t){t.translate(this.cx,this.cy),t.rotate(-1*this.angle.toRadians()),t.translate(-this.cx,-this.cy)},this.applyToPoint=function(t){var e=this.angle.toRadians();t.applyTransform([1,0,0,1,this.p.x||0,this.p.y||0]),t.applyTransform([Math.cos(e),Math.sin(e),-Math.sin(e),Math.cos(e),0,0]),t.applyTransform([1,0,0,1,-this.p.x||0,-this.p.y||0])}},this.Type.scale=function(t){this.p=s.CreatePoint(t),this.apply=function(t){t.scale(this.p.x||1,this.p.y||this.p.x||1)},this.unapply=function(t){t.scale(1/this.p.x||1,1/this.p.y||this.p.x||1)},this.applyToPoint=function(t){t.applyTransform([this.p.x||0,0,0,this.p.y||0,0,0])}},this.Type.matrix=function(t){this.m=s.ToNumberArray(t),this.apply=function(t){t.transform(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5])},this.unapply=function(t){var e=this.m[0],i=this.m[2],n=this.m[4],r=this.m[1],a=this.m[3],s=this.m[5],o=1/(e*(1*a-0*s)-i*(1*r-0*s)+n*(0*r-0*a));t.transform(o*(1*a-0*s),o*(0*s-1*r),o*(0*n-1*i),o*(1*e-0*n),o*(i*s-n*a),o*(n*r-e*s))},this.applyToPoint=function(t){t.applyTransform(this.m)}},this.Type.SkewBase=function(t){this.base=e.Type.matrix,this.base(t),this.angle=new s.Property("angle",t)},this.Type.SkewBase.prototype=new this.Type.matrix,this.Type.skewX=function(t){this.base=e.Type.SkewBase,this.base(t),this.m=[1,0,Math.tan(this.angle.toRadians()),1,0,0]},this.Type.skewX.prototype=new this.Type.SkewBase,this.Type.skewY=function(t){this.base=e.Type.SkewBase,this.base(t),this.m=[1,Math.tan(this.angle.toRadians()),0,1,0,0]},this.Type.skewY.prototype=new this.Type.SkewBase,this.transforms=[],this.apply=function(t){for(var e=0;e<this.transforms.length;e++)this.transforms[e].apply(t)},this.unapply=function(t){for(var e=this.transforms.length-1;0<=e;e--)this.transforms[e].unapply(t)},this.applyToPoint=function(t){for(var e=0;e<this.transforms.length;e++)this.transforms[e].applyToPoint(t)};for(var i=s.trim(s.compressSpaces(t)).replace(/\)([a-zA-Z])/g,") $1").replace(/\)(\s?,\s?)/g,") ").split(/\s(?=[a-z])/),n=0;n<i.length;n++)if("none"!==i[n]){var r=s.trim(i[n].split("(")[0]),a=i[n].split("(")[1].replace(")",""),o=this.Type[r];if(void 0!==o){var l=new o(a);l.type=r,this.transforms.push(l)}}},s.AspectRatio=function(t,e,i,n,r,a,o,l,h,u){var c=(e=(e=s.compressSpaces(e)).replace(/^defer\s/,"")).split(" ")[0]||"xMidYMid",f=e.split(" ")[1]||"meet",d=i/n,p=r/a,m=Math.min(d,p),g=Math.max(d,p);"meet"==f&&(n*=m,a*=m),"slice"==f&&(n*=g,a*=g),h=new s.Property("refX",h),u=new s.Property("refY",u),h.hasValue()&&u.hasValue()?t.translate(-m*h.toPixels("x"),-m*u.toPixels("y")):(c.match(/^xMid/)&&("meet"==f&&m==p||"slice"==f&&g==p)&&t.translate(i/2-n/2,0),c.match(/YMid$/)&&("meet"==f&&m==d||"slice"==f&&g==d)&&t.translate(0,r/2-a/2),c.match(/^xMax/)&&("meet"==f&&m==p||"slice"==f&&g==p)&&t.translate(i-n,0),c.match(/YMax$/)&&("meet"==f&&m==d||"slice"==f&&g==d)&&t.translate(0,r-a)),"none"==c?t.scale(d,p):"meet"==f?t.scale(m,m):"slice"==f&&t.scale(g,g),t.translate(null==o?0:-o,null==l?0:-l)},s.Element={},s.EmptyProperty=new s.Property("EMPTY",""),s.Element.ElementBase=function(t){this.attributes={},this.styles={},this.stylesSpecificity={},this.children=[],this.attribute=function(t,e){var i=this.attributes[t];return null!=i?i:(1==e&&(i=new s.Property(t,""),this.attributes[t]=i),i||s.EmptyProperty)},this.getHrefAttribute=function(){for(var t in this.attributes)if("href"==t||t.match(/:href$/))return this.attributes[t];return s.EmptyProperty},this.style=function(t,e,i){var n=this.styles[t];if(null!=n)return n;var r=this.attribute(t);if(null!=r&&r.hasValue())return this.styles[t]=r;if(1!=i){var a=this.parent;if(null!=a){var o=a.style(t);if(null!=o&&o.hasValue())return o}}return 1==e&&(n=new s.Property(t,""),this.styles[t]=n),n||s.EmptyProperty},this.render=function(t){if("none"!=this.style("display").value&&"hidden"!=this.style("visibility").value){if(t.save(),this.style("mask").hasValue()){var e=this.style("mask").getDefinition();null!=e&&e.apply(t,this)}else if(this.style("filter").hasValue()){var i=this.style("filter").getDefinition();null!=i&&i.apply(t,this)}else this.setContext(t),this.renderChildren(t),this.clearContext(t);t.restore()}},this.setContext=function(t){},this.clearContext=function(t){},this.renderChildren=function(t){for(var e=0;e<this.children.length;e++)this.children[e].render(t)},this.addChild=function(t,e){var i=t;e&&(i=s.CreateElement(t)),i.parent=this,"title"!=i.type&&this.children.push(i)},this.addStylesFromStyleDefinition=function(){for(var e in s.Styles)if("@"!=e[0]&&a(t,e)){var i=s.Styles[e],n=s.StylesSpecificity[e];if(null!=i)for(var r in i){var o=this.stylesSpecificity[r];void 0===o&&(o="000"),o<n&&(this.styles[r]=i[r],this.stylesSpecificity[r]=n)}}};var e,i=new RegExp("^[A-Z-]+$");if(null!=t&&1==t.nodeType){for(var n=0;n<t.attributes.length;n++){var r=t.attributes[n],o=(e=r.nodeName,i.test(e)?e.toLowerCase():e);this.attributes[o]=new s.Property(o,r.value)}if(this.addStylesFromStyleDefinition(),this.attribute("style").hasValue()){var l=this.attribute("style").value.split(";");for(n=0;n<l.length;n++)if(""!=s.trim(l[n])){var h=l[n].split(":"),u=s.trim(h[0]),c=s.trim(h[1]);this.styles[u]=new s.Property(u,c)}}for(this.attribute("id").hasValue()&&null==s.Definitions[this.attribute("id").value]&&(s.Definitions[this.attribute("id").value]=this),n=0;n<t.childNodes.length;n++){var f=t.childNodes[n];if(1==f.nodeType&&this.addChild(f,!0),this.captureTextNodes&&(3==f.nodeType||4==f.nodeType)){var d=f.value||f.text||f.textContent||"";""!=s.compressSpaces(d)&&this.addChild(new s.Element.tspan(f),!1)}}}},s.Element.RenderedElementBase=function(t){this.base=s.Element.ElementBase,this.base(t),this.calculateOpacity=function(){for(var t=1,e=this;null!=e;){var i=e.style("opacity",!1,!0);i.hasValue()&&(t*=i.numValue()),e=e.parent}return t},this.setContext=function(t,e){if(!e){var i;if(this.style("fill").isUrlDefinition())null!=(i=this.style("fill").getFillStyleDefinition(this,this.style("fill-opacity")))&&(t.fillStyle=i);else if(this.style("fill").hasValue()){var n;"currentColor"==(n=this.style("fill")).value&&(n.value=this.style("color").value),"inherit"!=n.value&&(t.fillStyle="none"==n.value?"rgba(0,0,0,0)":n.value)}if(this.style("fill-opacity").hasValue()&&(n=(n=new s.Property("fill",t.fillStyle)).addOpacity(this.style("fill-opacity")),t.fillStyle=n.value),this.style("stroke").isUrlDefinition())null!=(i=this.style("stroke").getFillStyleDefinition(this,this.style("stroke-opacity")))&&(t.strokeStyle=i);else if(this.style("stroke").hasValue()){var r;"currentColor"==(r=this.style("stroke")).value&&(r.value=this.style("color").value),"inherit"!=r.value&&(t.strokeStyle="none"==r.value?"rgba(0,0,0,0)":r.value)}if(this.style("stroke-opacity").hasValue()&&(r=(r=new s.Property("stroke",t.strokeStyle)).addOpacity(this.style("stroke-opacity")),t.strokeStyle=r.value),this.style("stroke-width").hasValue()){var a=this.style("stroke-width").toPixels();t.lineWidth=0==a?.001:a}if(this.style("stroke-linecap").hasValue()&&(t.lineCap=this.style("stroke-linecap").value),this.style("stroke-linejoin").hasValue()&&(t.lineJoin=this.style("stroke-linejoin").value),this.style("stroke-miterlimit").hasValue()&&(t.miterLimit=this.style("stroke-miterlimit").value),this.style("paint-order").hasValue()&&(t.paintOrder=this.style("paint-order").value),this.style("stroke-dasharray").hasValue()&&"none"!=this.style("stroke-dasharray").value){var o=s.ToNumberArray(this.style("stroke-dasharray").value);void 0!==t.setLineDash?t.setLineDash(o):void 0!==t.webkitLineDash?t.webkitLineDash=o:void 0===t.mozDash||1==o.length&&0==o[0]||(t.mozDash=o);var l=this.style("stroke-dashoffset").toPixels();void 0!==t.lineDashOffset?t.lineDashOffset=l:void 0!==t.webkitLineDashOffset?t.webkitLineDashOffset=l:void 0!==t.mozDashOffset&&(t.mozDashOffset=l)}}if(void 0!==t.font){t.font=s.Font.CreateFont(this.style("font-style").value,this.style("font-variant").value,this.style("font-weight").value,this.style("font-size").hasValue()?this.style("font-size").toPixels()+"px":"",this.style("font-family").value).toString();var h=this.style("font-size",!1,!1);h.isPixels()&&(s.emSize=h.toPixels())}if(this.style("transform",!1,!0).hasValue()&&new s.Transform(this.style("transform",!1,!0).value).apply(t),this.style("clip-path",!1,!0).hasValue()){var u=this.style("clip-path",!1,!0).getDefinition();null!=u&&u.apply(t)}t.globalAlpha=this.calculateOpacity()}},s.Element.RenderedElementBase.prototype=new s.Element.ElementBase,s.Element.PathElementBase=function(t){this.base=s.Element.RenderedElementBase,this.base(t),this.path=function(t){return null!=t&&t.beginPath(),new s.BoundingBox},this.renderChildren=function(t){this.path(t),s.Mouse.checkPath(this,t),""!=t.fillStyle&&("inherit"!=this.style("fill-rule").valueOrDefault("inherit")?t.fill(this.style("fill-rule").value):t.fill()),""!=t.strokeStyle&&t.stroke();var e=this.getMarkers();if(null!=e){if(this.style("marker-start").isUrlDefinition()&&(i=this.style("marker-start").getDefinition()).render(t,e[0][0],e[0][1]),this.style("marker-mid").isUrlDefinition())for(var i=this.style("marker-mid").getDefinition(),n=1;n<e.length-1;n++)i.render(t,e[n][0],e[n][1]);this.style("marker-end").isUrlDefinition()&&(i=this.style("marker-end").getDefinition()).render(t,e[e.length-1][0],e[e.length-1][1])}},this.getBoundingBox=function(){return this.path()},this.getMarkers=function(){return null}},s.Element.PathElementBase.prototype=new s.Element.RenderedElementBase,s.Element.svg=function(t){this.base=s.Element.RenderedElementBase,this.base(t),this.baseClearContext=this.clearContext,this.clearContext=function(t){this.baseClearContext(t),s.ViewPort.RemoveCurrent()},this.baseSetContext=this.setContext,this.setContext=function(t){if(t.strokeStyle="rgba(0,0,0,0)",t.lineCap="butt",t.lineJoin="miter",t.miterLimit=4,t.canvas.style&&void 0!==t.font&&void 0!==n.getComputedStyle){t.font=n.getComputedStyle(t.canvas).getPropertyValue("font");var e=new s.Property("fontSize",s.Font.Parse(t.font).fontSize);e.hasValue()&&(s.rootEmSize=s.emSize=e.toPixels("y"))}this.baseSetContext(t),this.attribute("x").hasValue()||(this.attribute("x",!0).value=0),this.attribute("y").hasValue()||(this.attribute("y",!0).value=0),t.translate(this.attribute("x").toPixels("x"),this.attribute("y").toPixels("y"));var i=s.ViewPort.width(),r=s.ViewPort.height();if(this.attribute("width").hasValue()||(this.attribute("width",!0).value="100%"),this.attribute("height").hasValue()||(this.attribute("height",!0).value="100%"),void 0===this.root){i=this.attribute("width").toPixels("x"),r=this.attribute("height").toPixels("y");var a=0,o=0;this.attribute("refX").hasValue()&&this.attribute("refY").hasValue()&&(a=-this.attribute("refX").toPixels("x"),o=-this.attribute("refY").toPixels("y")),"visible"!=this.attribute("overflow").valueOrDefault("hidden")&&(t.beginPath(),t.moveTo(a,o),t.lineTo(i,o),t.lineTo(i,r),t.lineTo(a,r),t.closePath(),t.clip())}if(s.ViewPort.SetCurrent(i,r),this.attribute("viewBox").hasValue()){var l=s.ToNumberArray(this.attribute("viewBox").value),h=l[0],u=l[1];i=l[2],r=l[3],s.AspectRatio(t,this.attribute("preserveAspectRatio").value,s.ViewPort.width(),i,s.ViewPort.height(),r,h,u,this.attribute("refX").value,this.attribute("refY").value),s.ViewPort.RemoveCurrent(),s.ViewPort.SetCurrent(l[2],l[3])}}},s.Element.svg.prototype=new s.Element.RenderedElementBase,s.Element.rect=function(t){this.base=s.Element.PathElementBase,this.base(t),this.path=function(t){var e=this.attribute("x").toPixels("x"),i=this.attribute("y").toPixels("y"),n=this.attribute("width").toPixels("x"),r=this.attribute("height").toPixels("y"),a=this.attribute("rx").toPixels("x"),o=this.attribute("ry").toPixels("y");if(this.attribute("rx").hasValue()&&!this.attribute("ry").hasValue()&&(o=a),this.attribute("ry").hasValue()&&!this.attribute("rx").hasValue()&&(a=o),a=Math.min(a,n/2),o=Math.min(o,r/2),null!=t){var l=(Math.sqrt(2)-1)/3*4;t.beginPath(),t.moveTo(e+a,i),t.lineTo(e+n-a,i),t.bezierCurveTo(e+n-a+l*a,i,e+n,i+o-l*o,e+n,i+o),t.lineTo(e+n,i+r-o),t.bezierCurveTo(e+n,i+r-o+l*o,e+n-a+l*a,i+r,e+n-a,i+r),t.lineTo(e+a,i+r),t.bezierCurveTo(e+a-l*a,i+r,e,i+r-o+l*o,e,i+r-o),t.lineTo(e,i+o),t.bezierCurveTo(e,i+o-l*o,e+a-l*a,i,e+a,i),t.closePath()}return new s.BoundingBox(e,i,e+n,i+r)}},s.Element.rect.prototype=new s.Element.PathElementBase,s.Element.circle=function(t){this.base=s.Element.PathElementBase,this.base(t),this.path=function(t){var e=this.attribute("cx").toPixels("x"),i=this.attribute("cy").toPixels("y"),n=this.attribute("r").toPixels();return null!=t&&(t.beginPath(),t.arc(e,i,n,0,2*Math.PI,!1),t.closePath()),new s.BoundingBox(e-n,i-n,e+n,i+n)}},s.Element.circle.prototype=new s.Element.PathElementBase,s.Element.ellipse=function(t){this.base=s.Element.PathElementBase,this.base(t),this.path=function(t){var e=(Math.sqrt(2)-1)/3*4,i=this.attribute("rx").toPixels("x"),n=this.attribute("ry").toPixels("y"),r=this.attribute("cx").toPixels("x"),a=this.attribute("cy").toPixels("y");return null!=t&&(t.beginPath(),t.moveTo(r+i,a),t.bezierCurveTo(r+i,a+e*n,r+e*i,a+n,r,a+n),t.bezierCurveTo(r-e*i,a+n,r-i,a+e*n,r-i,a),t.bezierCurveTo(r-i,a-e*n,r-e*i,a-n,r,a-n),t.bezierCurveTo(r+e*i,a-n,r+i,a-e*n,r+i,a),t.closePath()),new s.BoundingBox(r-i,a-n,r+i,a+n)}},s.Element.ellipse.prototype=new s.Element.PathElementBase,s.Element.line=function(t){this.base=s.Element.PathElementBase,this.base(t),this.getPoints=function(){return[new s.Point(this.attribute("x1").toPixels("x"),this.attribute("y1").toPixels("y")),new s.Point(this.attribute("x2").toPixels("x"),this.attribute("y2").toPixels("y"))]},this.path=function(t){var e=this.getPoints();return null!=t&&(t.beginPath(),t.moveTo(e[0].x,e[0].y),t.lineTo(e[1].x,e[1].y)),new s.BoundingBox(e[0].x,e[0].y,e[1].x,e[1].y)},this.getMarkers=function(){var t=this.getPoints(),e=t[0].angleTo(t[1]);return[[t[0],e],[t[1],e]]}},s.Element.line.prototype=new s.Element.PathElementBase,s.Element.polyline=function(t){this.base=s.Element.PathElementBase,this.base(t),this.points=s.CreatePath(this.attribute("points").value),this.path=function(t){var e=new s.BoundingBox(this.points[0].x,this.points[0].y);null!=t&&(t.beginPath(),t.moveTo(this.points[0].x,this.points[0].y));for(var i=1;i<this.points.length;i++)e.addPoint(this.points[i].x,this.points[i].y),null!=t&&t.lineTo(this.points[i].x,this.points[i].y);return e},this.getMarkers=function(){for(var t=[],e=0;e<this.points.length-1;e++)t.push([this.points[e],this.points[e].angleTo(this.points[e+1])]);return 0<t.length&&t.push([this.points[this.points.length-1],t[t.length-1][1]]),t}},s.Element.polyline.prototype=new s.Element.PathElementBase,s.Element.polygon=function(t){this.base=s.Element.polyline,this.base(t),this.basePath=this.path,this.path=function(t){var e=this.basePath(t);return null!=t&&(t.lineTo(this.points[0].x,this.points[0].y),t.closePath()),e}},s.Element.polygon.prototype=new s.Element.polyline,s.Element.path=function(t){this.base=s.Element.PathElementBase,this.base(t);var e=this.attribute("d").value;e=e.replace(/,/gm," ");for(var i=0;i<2;i++)e=e.replace(/([MmZzLlHhVvCcSsQqTtAa])([^\s])/gm,"$1 $2");for(e=(e=e.replace(/([^\s])([MmZzLlHhVvCcSsQqTtAa])/gm,"$1 $2")).replace(/([0-9])([+\-])/gm,"$1 $2"),i=0;i<2;i++)e=e.replace(/(\.[0-9]*)(\.)/gm,"$1 $2");e=e.replace(/([Aa](\s+[0-9]+){3})\s+([01])\s*([01])/gm,"$1 $3 $4 "),e=s.compressSpaces(e),e=s.trim(e),this.PathParser=new function(t){this.tokens=t.split(" "),this.reset=function(){this.i=-1,this.command="",this.previousCommand="",this.start=new s.Point(0,0),this.control=new s.Point(0,0),this.current=new s.Point(0,0),this.points=[],this.angles=[]},this.isEnd=function(){return this.i>=this.tokens.length-1},this.isCommandOrEnd=function(){return!!this.isEnd()||null!=this.tokens[this.i+1].match(/^[A-Za-z]$/)},this.isRelativeCommand=function(){switch(this.command){case"m":case"l":case"h":case"v":case"c":case"s":case"q":case"t":case"a":case"z":return!0}return!1},this.getToken=function(){return this.i++,this.tokens[this.i]},this.getScalar=function(){return parseFloat(this.getToken())},this.nextCommand=function(){this.previousCommand=this.command,this.command=this.getToken()},this.getPoint=function(){var t=new s.Point(this.getScalar(),this.getScalar());return this.makeAbsolute(t)},this.getAsControlPoint=function(){var t=this.getPoint();return this.control=t},this.getAsCurrentPoint=function(){var t=this.getPoint();return this.current=t},this.getReflectedControlPoint=function(){return"c"!=this.previousCommand.toLowerCase()&&"s"!=this.previousCommand.toLowerCase()&&"q"!=this.previousCommand.toLowerCase()&&"t"!=this.previousCommand.toLowerCase()?this.current:new s.Point(2*this.current.x-this.control.x,2*this.current.y-this.control.y)},this.makeAbsolute=function(t){return this.isRelativeCommand()&&(t.x+=this.current.x,t.y+=this.current.y),t},this.addMarker=function(t,e,i){null!=i&&0<this.angles.length&&null==this.angles[this.angles.length-1]&&(this.angles[this.angles.length-1]=this.points[this.points.length-1].angleTo(i)),this.addMarkerAngle(t,null==e?null:e.angleTo(t))},this.addMarkerAngle=function(t,e){this.points.push(t),this.angles.push(e)},this.getMarkerPoints=function(){return this.points},this.getMarkerAngles=function(){for(var t=0;t<this.angles.length;t++)if(null==this.angles[t])for(var e=t+1;e<this.angles.length;e++)if(null!=this.angles[e]){this.angles[t]=this.angles[e];break}return this.angles}}(e),this.path=function(t){var e=this.PathParser;e.reset();var i=new s.BoundingBox;for(null!=t&&t.beginPath();!e.isEnd();)switch(e.nextCommand(),e.command){case"M":case"m":var n=e.getAsCurrentPoint();for(e.addMarker(n),i.addPoint(n.x,n.y),null!=t&&t.moveTo(n.x,n.y),e.start=e.current;!e.isCommandOrEnd();)n=e.getAsCurrentPoint(),e.addMarker(n,e.start),i.addPoint(n.x,n.y),null!=t&&t.lineTo(n.x,n.y);break;case"L":case"l":for(;!e.isCommandOrEnd();){var r=e.current;n=e.getAsCurrentPoint(),e.addMarker(n,r),i.addPoint(n.x,n.y),null!=t&&t.lineTo(n.x,n.y)}break;case"H":case"h":for(;!e.isCommandOrEnd();){var a=new s.Point((e.isRelativeCommand()?e.current.x:0)+e.getScalar(),e.current.y);e.addMarker(a,e.current),e.current=a,i.addPoint(e.current.x,e.current.y),null!=t&&t.lineTo(e.current.x,e.current.y)}break;case"V":case"v":for(;!e.isCommandOrEnd();)a=new s.Point(e.current.x,(e.isRelativeCommand()?e.current.y:0)+e.getScalar()),e.addMarker(a,e.current),e.current=a,i.addPoint(e.current.x,e.current.y),null!=t&&t.lineTo(e.current.x,e.current.y);break;case"C":case"c":for(;!e.isCommandOrEnd();){var o=e.current,l=e.getPoint(),h=e.getAsControlPoint(),u=e.getAsCurrentPoint();e.addMarker(u,h,l),i.addBezierCurve(o.x,o.y,l.x,l.y,h.x,h.y,u.x,u.y),null!=t&&t.bezierCurveTo(l.x,l.y,h.x,h.y,u.x,u.y)}break;case"S":case"s":for(;!e.isCommandOrEnd();)o=e.current,l=e.getReflectedControlPoint(),h=e.getAsControlPoint(),u=e.getAsCurrentPoint(),e.addMarker(u,h,l),i.addBezierCurve(o.x,o.y,l.x,l.y,h.x,h.y,u.x,u.y),null!=t&&t.bezierCurveTo(l.x,l.y,h.x,h.y,u.x,u.y);break;case"Q":case"q":for(;!e.isCommandOrEnd();)o=e.current,h=e.getAsControlPoint(),u=e.getAsCurrentPoint(),e.addMarker(u,h,h),i.addQuadraticCurve(o.x,o.y,h.x,h.y,u.x,u.y),null!=t&&t.quadraticCurveTo(h.x,h.y,u.x,u.y);break;case"T":case"t":for(;!e.isCommandOrEnd();)o=e.current,h=e.getReflectedControlPoint(),e.control=h,u=e.getAsCurrentPoint(),e.addMarker(u,h,h),i.addQuadraticCurve(o.x,o.y,h.x,h.y,u.x,u.y),null!=t&&t.quadraticCurveTo(h.x,h.y,u.x,u.y);break;case"A":case"a":for(;!e.isCommandOrEnd();){o=e.current;var c=e.getScalar(),f=e.getScalar(),d=e.getScalar()*(Math.PI/180),p=e.getScalar(),m=e.getScalar(),g=(u=e.getAsCurrentPoint(),new s.Point(Math.cos(d)*(o.x-u.x)/2+Math.sin(d)*(o.y-u.y)/2,-Math.sin(d)*(o.x-u.x)/2+Math.cos(d)*(o.y-u.y)/2)),y=Math.pow(g.x,2)/Math.pow(c,2)+Math.pow(g.y,2)/Math.pow(f,2);1<y&&(c*=Math.sqrt(y),f*=Math.sqrt(y));var v=(p==m?-1:1)*Math.sqrt((Math.pow(c,2)*Math.pow(f,2)-Math.pow(c,2)*Math.pow(g.y,2)-Math.pow(f,2)*Math.pow(g.x,2))/(Math.pow(c,2)*Math.pow(g.y,2)+Math.pow(f,2)*Math.pow(g.x,2)));isNaN(v)&&(v=0);var b=new s.Point(v*c*g.y/f,v*-f*g.x/c),x=new s.Point((o.x+u.x)/2+Math.cos(d)*b.x-Math.sin(d)*b.y,(o.y+u.y)/2+Math.sin(d)*b.x+Math.cos(d)*b.y),w=function(t){return Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2))},E=function(t,e){return(t[0]*e[0]+t[1]*e[1])/(w(t)*w(e))},P=function(t,e){return(t[0]*e[1]<t[1]*e[0]?-1:1)*Math.acos(E(t,e))},C=P([1,0],[(g.x-b.x)/c,(g.y-b.y)/f]),B=[(g.x-b.x)/c,(g.y-b.y)/f],T=[(-g.x-b.x)/c,(-g.y-b.y)/f],S=P(B,T);E(B,T)<=-1&&(S=Math.PI),1<=E(B,T)&&(S=0);var M=1-m?1:-1,k=C+M*(S/2),V=new s.Point(x.x+c*Math.cos(k),x.y+f*Math.sin(k));if(e.addMarkerAngle(V,k-M*Math.PI/2),e.addMarkerAngle(u,k-M*Math.PI),i.addPoint(u.x,u.y),null!=t){E=f<c?c:f;var A=f<c?1:c/f,D=f<c?f/c:1;t.translate(x.x,x.y),t.rotate(d),t.scale(A,D),t.arc(0,0,E,C,C+S,1-m),t.scale(1/A,1/D),t.rotate(-d),t.translate(-x.x,-x.y)}}break;case"Z":case"z":null!=t&&i.x1!==i.x2&&i.y1!==i.y2&&t.closePath(),e.current=e.start}return i},this.getMarkers=function(){for(var t=this.PathParser.getMarkerPoints(),e=this.PathParser.getMarkerAngles(),i=[],n=0;n<t.length;n++)i.push([t[n],e[n]]);return i}},s.Element.path.prototype=new s.Element.PathElementBase,s.Element.pattern=function(t){this.base=s.Element.ElementBase,this.base(t),this.createPattern=function(t,e){var i=this.attribute("width").toPixels("x",!0),n=this.attribute("height").toPixels("y",!0),a=new s.Element.svg;a.attributes.viewBox=new s.Property("viewBox",this.attribute("viewBox").value),a.attributes.width=new s.Property("width",i+"px"),a.attributes.height=new s.Property("height",n+"px"),a.attributes.transform=new s.Property("transform",this.attribute("patternTransform").value),a.children=this.children;var o=r();o.width=i,o.height=n;var l=o.getContext("2d");this.attribute("x").hasValue()&&this.attribute("y").hasValue()&&l.translate(this.attribute("x").toPixels("x",!0),this.attribute("y").toPixels("y",!0));for(var h=-1;h<=1;h++)for(var u=-1;u<=1;u++)l.save(),a.attributes.x=new s.Property("x",h*o.width),a.attributes.y=new s.Property("y",u*o.height),a.render(l),l.restore();return t.createPattern(o,"repeat")}},s.Element.pattern.prototype=new s.Element.ElementBase,s.Element.marker=function(t){this.base=s.Element.ElementBase,this.base(t),this.baseRender=this.render,this.render=function(t,e,i){if(e){t.translate(e.x,e.y),"auto"==this.attribute("orient").valueOrDefault("auto")&&t.rotate(i),"strokeWidth"==this.attribute("markerUnits").valueOrDefault("strokeWidth")&&t.scale(t.lineWidth,t.lineWidth),t.save();var n=new s.Element.svg;n.attributes.viewBox=new s.Property("viewBox",this.attribute("viewBox").value),n.attributes.refX=new s.Property("refX",this.attribute("refX").value),n.attributes.refY=new s.Property("refY",this.attribute("refY").value),n.attributes.width=new s.Property("width",this.attribute("markerWidth").value),n.attributes.height=new s.Property("height",this.attribute("markerHeight").value),n.attributes.fill=new s.Property("fill",this.attribute("fill").valueOrDefault("black")),n.attributes.stroke=new s.Property("stroke",this.attribute("stroke").valueOrDefault("none")),n.children=this.children,n.render(t),t.restore(),"strokeWidth"==this.attribute("markerUnits").valueOrDefault("strokeWidth")&&t.scale(1/t.lineWidth,1/t.lineWidth),"auto"==this.attribute("orient").valueOrDefault("auto")&&t.rotate(-i),t.translate(-e.x,-e.y)}}},s.Element.marker.prototype=new s.Element.ElementBase,s.Element.defs=function(t){this.base=s.Element.ElementBase,this.base(t),this.render=function(t){}},s.Element.defs.prototype=new s.Element.ElementBase,s.Element.GradientBase=function(t){this.base=s.Element.ElementBase,this.base(t),this.stops=[];for(var e=0;e<this.children.length;e++){var i=this.children[e];"stop"==i.type&&this.stops.push(i)}this.getGradient=function(){},this.gradientUnits=function(){return this.attribute("gradientUnits").valueOrDefault("objectBoundingBox")},this.attributesToInherit=["gradientUnits"],this.inheritStopContainer=function(t){for(var e=0;e<this.attributesToInherit.length;e++){var i=this.attributesToInherit[e];!this.attribute(i).hasValue()&&t.attribute(i).hasValue()&&(this.attribute(i,!0).value=t.attribute(i).value)}},this.createGradient=function(t,e,i){var n=this;this.getHrefAttribute().hasValue()&&(n=this.getHrefAttribute().getDefinition(),this.inheritStopContainer(n));var a=function(t){return i.hasValue()?new s.Property("color",t).addOpacity(i).value:t},o=this.getGradient(t,e);if(null==o)return a(n.stops[n.stops.length-1].color);for(var l=0;l<n.stops.length;l++)o.addColorStop(n.stops[l].offset,a(n.stops[l].color));if(this.attribute("gradientTransform").hasValue()){var h=s.ViewPort.viewPorts[0],u=new s.Element.rect;u.attributes.x=new s.Property("x",-s.MAX_VIRTUAL_PIXELS/3),u.attributes.y=new s.Property("y",-s.MAX_VIRTUAL_PIXELS/3),u.attributes.width=new s.Property("width",s.MAX_VIRTUAL_PIXELS),u.attributes.height=new s.Property("height",s.MAX_VIRTUAL_PIXELS);var c=new s.Element.g;c.attributes.transform=new s.Property("transform",this.attribute("gradientTransform").value),c.children=[u];var f=new s.Element.svg;f.attributes.x=new s.Property("x",0),f.attributes.y=new s.Property("y",0),f.attributes.width=new s.Property("width",h.width),f.attributes.height=new s.Property("height",h.height),f.children=[c];var d=r();d.width=h.width,d.height=h.height;var p=d.getContext("2d");return p.fillStyle=o,f.render(p),p.createPattern(d,"no-repeat")}return o}},s.Element.GradientBase.prototype=new s.Element.ElementBase,s.Element.linearGradient=function(t){this.base=s.Element.GradientBase,this.base(t),this.attributesToInherit.push("x1"),this.attributesToInherit.push("y1"),this.attributesToInherit.push("x2"),this.attributesToInherit.push("y2"),this.getGradient=function(t,e){var i="objectBoundingBox"==this.gradientUnits()?e.getBoundingBox(t):null;this.attribute("x1").hasValue()||this.attribute("y1").hasValue()||this.attribute("x2").hasValue()||this.attribute("y2").hasValue()||(this.attribute("x1",!0).value=0,this.attribute("y1",!0).value=0,this.attribute("x2",!0).value=1,this.attribute("y2",!0).value=0);var n="objectBoundingBox"==this.gradientUnits()?i.x()+i.width()*this.attribute("x1").numValue():this.attribute("x1").toPixels("x"),r="objectBoundingBox"==this.gradientUnits()?i.y()+i.height()*this.attribute("y1").numValue():this.attribute("y1").toPixels("y"),a="objectBoundingBox"==this.gradientUnits()?i.x()+i.width()*this.attribute("x2").numValue():this.attribute("x2").toPixels("x"),s="objectBoundingBox"==this.gradientUnits()?i.y()+i.height()*this.attribute("y2").numValue():this.attribute("y2").toPixels("y");return n==a&&r==s?null:t.createLinearGradient(n,r,a,s)}},s.Element.linearGradient.prototype=new s.Element.GradientBase,s.Element.radialGradient=function(t){this.base=s.Element.GradientBase,this.base(t),this.attributesToInherit.push("cx"),this.attributesToInherit.push("cy"),this.attributesToInherit.push("r"),this.attributesToInherit.push("fx"),this.attributesToInherit.push("fy"),this.getGradient=function(t,e){var i=e.getBoundingBox(t);this.attribute("cx").hasValue()||(this.attribute("cx",!0).value="50%"),this.attribute("cy").hasValue()||(this.attribute("cy",!0).value="50%"),this.attribute("r").hasValue()||(this.attribute("r",!0).value="50%");var n="objectBoundingBox"==this.gradientUnits()?i.x()+i.width()*this.attribute("cx").numValue():this.attribute("cx").toPixels("x"),r="objectBoundingBox"==this.gradientUnits()?i.y()+i.height()*this.attribute("cy").numValue():this.attribute("cy").toPixels("y"),a=n,s=r;this.attribute("fx").hasValue()&&(a="objectBoundingBox"==this.gradientUnits()?i.x()+i.width()*this.attribute("fx").numValue():this.attribute("fx").toPixels("x")),this.attribute("fy").hasValue()&&(s="objectBoundingBox"==this.gradientUnits()?i.y()+i.height()*this.attribute("fy").numValue():this.attribute("fy").toPixels("y"));var o="objectBoundingBox"==this.gradientUnits()?(i.width()+i.height())/2*this.attribute("r").numValue():this.attribute("r").toPixels();return t.createRadialGradient(a,s,0,n,r,o)}},s.Element.radialGradient.prototype=new s.Element.GradientBase,s.Element.stop=function(t){this.base=s.Element.ElementBase,this.base(t),this.offset=this.attribute("offset").numValue(),this.offset<0&&(this.offset=0),1<this.offset&&(this.offset=1);var e=this.style("stop-color",!0);""===e.value&&(e.value="#000"),this.style("stop-opacity").hasValue()&&(e=e.addOpacity(this.style("stop-opacity"))),this.color=e.value},s.Element.stop.prototype=new s.Element.ElementBase,s.Element.AnimateBase=function(t){this.base=s.Element.ElementBase,this.base(t),s.Animations.push(this),this.duration=0,this.begin=this.attribute("begin").toMilliseconds(),this.maxDuration=this.begin+this.attribute("dur").toMilliseconds(),this.getProperty=function(){var t=this.attribute("attributeType").value,e=this.attribute("attributeName").value;return"CSS"==t?this.parent.style(e,!0):this.parent.attribute(e,!0)},this.initialValue=null,this.initialUnits="",this.removed=!1,this.calcValue=function(){return""},this.update=function(t){if(null==this.initialValue&&(this.initialValue=this.getProperty().value,this.initialUnits=this.getProperty().getUnits()),this.duration>this.maxDuration){if("indefinite"==this.attribute("repeatCount").value||"indefinite"==this.attribute("repeatDur").value)this.duration=0;else if("freeze"!=this.attribute("fill").valueOrDefault("remove")||this.frozen){if("remove"==this.attribute("fill").valueOrDefault("remove")&&!this.removed)return this.removed=!0,this.getProperty().value=this.parent.animationFrozen?this.parent.animationFrozenValue:this.initialValue,!0}else this.frozen=!0,this.parent.animationFrozen=!0,this.parent.animationFrozenValue=this.getProperty().value;return!1}this.duration=this.duration+t;var e=!1;if(this.begin<this.duration){var i=this.calcValue();this.attribute("type").hasValue()&&(i=this.attribute("type").value+"("+i+")"),this.getProperty().value=i,e=!0}return e},this.from=this.attribute("from"),this.to=this.attribute("to"),this.values=this.attribute("values"),this.values.hasValue()&&(this.values.value=this.values.value.split(";")),this.progress=function(){var t={progress:(this.duration-this.begin)/(this.maxDuration-this.begin)};if(this.values.hasValue()){var e=t.progress*(this.values.value.length-1),i=Math.floor(e),n=Math.ceil(e);t.from=new s.Property("from",parseFloat(this.values.value[i])),t.to=new s.Property("to",parseFloat(this.values.value[n])),t.progress=(e-i)/(n-i)}else t.from=this.from,t.to=this.to;return t}},s.Element.AnimateBase.prototype=new s.Element.ElementBase,s.Element.animate=function(t){this.base=s.Element.AnimateBase,this.base(t),this.calcValue=function(){var t=this.progress();return t.from.numValue()+(t.to.numValue()-t.from.numValue())*t.progress+this.initialUnits}},s.Element.animate.prototype=new s.Element.AnimateBase,s.Element.animateColor=function(e){this.base=s.Element.AnimateBase,this.base(e),this.calcValue=function(){var e=this.progress(),i=new t(e.from.value),n=new t(e.to.value);if(i.ok&&n.ok){var r=i.r+(n.r-i.r)*e.progress,a=i.g+(n.g-i.g)*e.progress,s=i.b+(n.b-i.b)*e.progress;return"rgb("+parseInt(r,10)+","+parseInt(a,10)+","+parseInt(s,10)+")"}return this.attribute("from").value}},s.Element.animateColor.prototype=new s.Element.AnimateBase,s.Element.animateTransform=function(t){this.base=s.Element.AnimateBase,this.base(t),this.calcValue=function(){for(var t=this.progress(),e=s.ToNumberArray(t.from.value),i=s.ToNumberArray(t.to.value),n="",r=0;r<e.length;r++)n+=e[r]+(i[r]-e[r])*t.progress+" ";return n}},s.Element.animateTransform.prototype=new s.Element.animate,s.Element.font=function(t){this.base=s.Element.ElementBase,this.base(t),this.horizAdvX=this.attribute("horiz-adv-x").numValue(),this.isRTL=!1,this.isArabic=!1,this.fontFace=null,this.missingGlyph=null,this.glyphs=[];for(var e=0;e<this.children.length;e++){var i=this.children[e];"font-face"==i.type?(this.fontFace=i).style("font-family").hasValue()&&(s.Definitions[i.style("font-family").value]=this):"missing-glyph"==i.type?this.missingGlyph=i:"glyph"==i.type&&(""!=i.arabicForm?(this.isRTL=!0,this.isArabic=!0,void 0===this.glyphs[i.unicode]&&(this.glyphs[i.unicode]=[]),this.glyphs[i.unicode][i.arabicForm]=i):this.glyphs[i.unicode]=i)}},s.Element.font.prototype=new s.Element.ElementBase,s.Element.fontface=function(t){this.base=s.Element.ElementBase,this.base(t),this.ascent=this.attribute("ascent").value,this.descent=this.attribute("descent").value,this.unitsPerEm=this.attribute("units-per-em").numValue()},s.Element.fontface.prototype=new s.Element.ElementBase,s.Element.missingglyph=function(t){this.base=s.Element.path,this.base(t),this.horizAdvX=0},s.Element.missingglyph.prototype=new s.Element.path,s.Element.glyph=function(t){this.base=s.Element.path,this.base(t),this.horizAdvX=this.attribute("horiz-adv-x").numValue(),this.unicode=this.attribute("unicode").value,this.arabicForm=this.attribute("arabic-form").value},s.Element.glyph.prototype=new s.Element.path,s.Element.text=function(t){this.captureTextNodes=!0,this.base=s.Element.RenderedElementBase,this.base(t),this.baseSetContext=this.setContext,this.setContext=function(t){this.baseSetContext(t);var e=this.style("dominant-baseline").toTextBaseline();null==e&&(e=this.style("alignment-baseline").toTextBaseline()),null!=e&&(t.textBaseline=e)},this.initializeCoordinates=function(t){this.x=this.attribute("x").toPixels("x"),this.y=this.attribute("y").toPixels("y"),this.attribute("dx").hasValue()&&(this.x+=this.attribute("dx").toPixels("x")),this.attribute("dy").hasValue()&&(this.y+=this.attribute("dy").toPixels("y")),this.x+=this.getAnchorDelta(t,this,0)},this.getBoundingBox=function(t){this.initializeCoordinates(t);for(var e=null,i=0;i<this.children.length;i++){var n=this.getChildBoundingBox(t,this,this,i);null==e?e=n:e.addBoundingBox(n)}return e},this.renderChildren=function(t){this.initializeCoordinates(t);for(var e=0;e<this.children.length;e++)this.renderChild(t,this,this,e)},this.getAnchorDelta=function(t,e,i){var n=this.style("text-anchor").valueOrDefault("start");if("start"!=n){for(var r=0,a=i;a<e.children.length;a++){var s=e.children[a];if(i<a&&s.attribute("x").hasValue())break;r+=s.measureTextRecursive(t)}return-1*("end"==n?r:r/2)}return 0},this.adjustChildCoordinates=function(t,e,i,n){var r=i.children[n];return r.attribute("x").hasValue()?(r.x=r.attribute("x").toPixels("x")+e.getAnchorDelta(t,i,n),r.attribute("dx").hasValue()&&(r.x+=r.attribute("dx").toPixels("x"))):(r.attribute("dx").hasValue()&&(e.x+=r.attribute("dx").toPixels("x")),r.x=e.x),e.x=r.x+r.measureText(t),r.attribute("y").hasValue()?(r.y=r.attribute("y").toPixels("y"),r.attribute("dy").hasValue()&&(r.y+=r.attribute("dy").toPixels("y"))):(r.attribute("dy").hasValue()&&(e.y+=r.attribute("dy").toPixels("y")),r.y=e.y),e.y=r.y,r},this.getChildBoundingBox=function(t,e,i,n){var r=this.adjustChildCoordinates(t,e,i,n),a=r.getBoundingBox(t);for(n=0;n<r.children.length;n++){var s=e.getChildBoundingBox(t,e,r,n);a.addBoundingBox(s)}return a},this.renderChild=function(t,e,i,n){var r=this.adjustChildCoordinates(t,e,i,n);for(r.render(t),n=0;n<r.children.length;n++)e.renderChild(t,e,r,n)}},s.Element.text.prototype=new s.Element.RenderedElementBase,s.Element.TextElementBase=function(t){this.base=s.Element.RenderedElementBase,this.base(t),this.getGlyph=function(t,e,i){var n=e[i],r=null;if(t.isArabic){var a="isolated";(0==i||" "==e[i-1])&&i<e.length-2&&" "!=e[i+1]&&(a="terminal"),0<i&&" "!=e[i-1]&&i<e.length-2&&" "!=e[i+1]&&(a="medial"),0<i&&" "!=e[i-1]&&(i==e.length-1||" "==e[i+1])&&(a="initial"),void 0!==t.glyphs[n]&&null==(r=t.glyphs[n][a])&&"glyph"==t.glyphs[n].type&&(r=t.glyphs[n])}else r=t.glyphs[n];return null==r&&(r=t.missingGlyph),r},this.renderChildren=function(t){var e=this.parent.style("font-family").getDefinition();if(null==e)"stroke"==t.paintOrder?(""!=t.strokeStyle&&t.strokeText(s.compressSpaces(this.getText()),this.x,this.y),""!=t.fillStyle&&t.fillText(s.compressSpaces(this.getText()),this.x,this.y)):(""!=t.fillStyle&&t.fillText(s.compressSpaces(this.getText()),this.x,this.y),""!=t.strokeStyle&&t.strokeText(s.compressSpaces(this.getText()),this.x,this.y));else{var i=this.parent.style("font-size").numValueOrDefault(s.Font.Parse(s.ctx.font).fontSize),n=this.parent.style("font-style").valueOrDefault(s.Font.Parse(s.ctx.font).fontStyle),r=this.getText();e.isRTL&&(r=r.split("").reverse().join(""));for(var a=s.ToNumberArray(this.parent.attribute("dx").value),o=0;o<r.length;o++){var l=this.getGlyph(e,r,o),h=i/e.fontFace.unitsPerEm;t.translate(this.x,this.y),t.scale(h,-h);var u=t.lineWidth;t.lineWidth=t.lineWidth*e.fontFace.unitsPerEm/i,"italic"==n&&t.transform(1,0,.4,1,0,0),l.render(t),"italic"==n&&t.transform(1,0,-.4,1,0,0),t.lineWidth=u,t.scale(1/h,-1/h),t.translate(-this.x,-this.y),this.x+=i*(l.horizAdvX||e.horizAdvX)/e.fontFace.unitsPerEm,void 0===a[o]||isNaN(a[o])||(this.x+=a[o])}}},this.getText=function(){},this.measureTextRecursive=function(t){for(var e=this.measureText(t),i=0;i<this.children.length;i++)e+=this.children[i].measureTextRecursive(t);return e},this.measureText=function(t){var e=this.parent.style("font-family").getDefinition();if(null!=e){var i=this.parent.style("font-size").numValueOrDefault(s.Font.Parse(s.ctx.font).fontSize),n=0,r=this.getText();e.isRTL&&(r=r.split("").reverse().join(""));for(var a=s.ToNumberArray(this.parent.attribute("dx").value),o=0;o<r.length;o++)n+=(this.getGlyph(e,r,o).horizAdvX||e.horizAdvX)*i/e.fontFace.unitsPerEm,void 0===a[o]||isNaN(a[o])||(n+=a[o]);return n}var l=s.compressSpaces(this.getText());if(!t.measureText)return 10*l.length;t.save(),this.setContext(t,!0);var h=t.measureText(l).width;return t.restore(),h},this.getBoundingBox=function(t){var e=this.parent.style("font-size").numValueOrDefault(s.Font.Parse(s.ctx.font).fontSize);return new s.BoundingBox(this.x,this.y-e,this.x+this.measureText(t),this.y)}},s.Element.TextElementBase.prototype=new s.Element.RenderedElementBase,s.Element.tspan=function(t){this.captureTextNodes=!0,this.base=s.Element.TextElementBase,this.base(t),this.text=s.compressSpaces(t.value||t.text||t.textContent||""),this.getText=function(){return 0<this.children.length?"":this.text}},s.Element.tspan.prototype=new s.Element.TextElementBase,s.Element.tref=function(t){this.base=s.Element.TextElementBase,this.base(t),this.getText=function(){var t=this.getHrefAttribute().getDefinition();if(null!=t)return t.children[0].getText()}},s.Element.tref.prototype=new s.Element.TextElementBase,s.Element.a=function(t){this.base=s.Element.TextElementBase,this.base(t),this.hasText=0<t.childNodes.length;for(var e=0;e<t.childNodes.length;e++)3!=t.childNodes[e].nodeType&&(this.hasText=!1);this.text=this.hasText?t.childNodes[0].value||t.childNodes[0].data:"",this.getText=function(){return this.text},this.baseRenderChildren=this.renderChildren,this.renderChildren=function(t){if(this.hasText){this.baseRenderChildren(t);var e=new s.Property("fontSize",s.Font.Parse(s.ctx.font).fontSize);s.Mouse.checkBoundingBox(this,new s.BoundingBox(this.x,this.y-e.toPixels("y"),this.x+this.measureText(t),this.y))}else if(0<this.children