UNPKG

26.6 kBJavaScriptView Raw
1
2 /*!
3 * image2D - 🍇 使用ECMAScript绘制二维图片。Drawing Two-Dimensional Pictures Using ECMAScript.
4 * git+https://github.com/yelloxing/image2D.git
5 *
6 * author 心叶
7 *
8 * version 1.4.0
9 *
10 * build Thu Apr 11 2019
11 *
12 * Copyright yelloxing
13 * Released under the MIT license
14 *
15 * Date:Fri Sep 06 2019 23:09:28 GMT+0800 (中国标准时间)
16 */
17
18"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol==="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};(function(){"use strict";var e=Object.prototype.toString;function r(t){if(t==null){return t===undefined?"[object Undefined]":"[object Null]"}return e.call(t)}function n(t){if(t===null||(typeof t==="undefined"?"undefined":_typeof(t))!=="object"||r(t)!="[object Object]"){return false}if(Object.getPrototypeOf(t)===null){return true}var e=t;while(Object.getPrototypeOf(e)!==null){e=Object.getPrototypeOf(e)}return Object.getPrototypeOf(t)===e}function y(t){return t!==null&&(typeof t==="undefined"?"undefined":_typeof(t))==="object"&&(t.nodeType===1||t.nodeType===9||t.nodeType===11)&&!n(t)}function i(t){var e=typeof t==="undefined"?"undefined":_typeof(t);return t!=null&&(e==="object"||e==="function")}function m(t){if(!i(t)){return false}var e=r(t);return e==="[object Function]"||e==="[object AsyncFunction]"||e==="[object GeneratorFunction]"||e==="[object Proxy]"}var u=function t(e,r){for(var n in r){try{e[n]=r[n]}catch(t){throw new Error("Illegal property value!")}}return e};var a={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};var b={whitespace:"[\\x20\\t\\r\\n\\f]",blank:"[\\n\\f\\r]",identifier:"(?:\\\\.|[\\w-]|[^\0-\\xa0])+"};var f=["href","title","show","type","role","actuate"];function l(t){return t!==null&&(typeof t==="undefined"?"undefined":_typeof(t))==="object"&&t.nodeType===3&&!n(t)}var c=function t(e,r){if("innerHTML"in SVGElement.prototype===false||"innerHTML"in SVGSVGElement.prototype===false){var n=document.createElement("div");n.innerHTML=r;var o=function t(e){var r=document.createElementNS(a.svg,e.tagName.toLowerCase());var n=e.attributes,i=void 0;for(i=0;n&&i<n.length;i++){if(f.indexOf(n[i].nodeName)>=0){r.setAttributeNS(a.xlink,"xlink:"+n[i].nodeName,e.getAttribute(n[i].nodeName))}else{r.setAttribute(n[i].nodeName,e.getAttribute(n[i].nodeName))}}return r};var i=o(n.firstChild);(function t(e,r){var n=e.firstChild;if(l(n)){r.textContent=e.innerText;return}while(n){var i=o(n);r.appendChild(i);if(n.firstChild)t(n,i);n=n.nextSibling}})(n.firstChild,i);e.appendChild(i)}else{e.innerHTML=r}};var o=function t(e,r){var n=void 0,i=void 0;if(r==="html"||r==="HTML"){n=document.createElement("div");n.innerHTML=e;if(!/</.test(n.innerHTML)){throw new Error("This template cannot be generated using div as a container:"+e)}}else{n=document.createElementNS(a.svg,"svg");c(n,e)}i=n.childNodes;for(var o=0;o<i.length;o++){if(y(i[o]))return i[o]}};function x(t,e){if(new RegExp("^"+b.identifier+"$").test(t))t="<"+t+"></"+t+">";var r=/<([^>]+)>.*/.exec(t)[1];if("canvas"===r.toLowerCase())e="HTML";return o(t,e)}function s(t,e){if(typeof e=="string"||typeof t==="string"){t=t.trim().replace(new RegExp(b.blank,"g"),"");if(typeof e=="string"||/^</.test(t)){var r=x(t,e);if(y(r))return[r];else return[]}else if(t==="*"){return e.getElementsByTagName("*")}var n=t.match(new RegExp("#"+b.identifier,"g"));if(n){var i=document.getElementById(n[0].replace("#",""));if(y(i))return[i];else return[]}var o=t.match(new RegExp("\\."+b.identifier,"g")),a=t.match(new RegExp("^"+b.identifier));if(a||o){var u=e.getElementsByTagName(a?a[0]:"*"),f=[];for(var l=0;l<u.length;l++){var c=" "+u[l].getAttribute("class")+" ",s=true;for(var d=0;o&&d<o.length;d++){if(!c.match(" "+o[d].replace(".","")+" ")){s=false;break}}if(s)f.push(u[l])}return f}else{throw new Error("Unsupported selector:"+t)}}else if(y(t)){return[t]}else if(t&&(t.constructor===Array||t.constructor===HTMLCollection||t.constructor===NodeList)){var h=[];for(var v=0;v<t.length;v++){if(y(t[v]))h.push(t[v])}return h}else if(t&&t.constructor===_){return t}else if(m(t)){var p=e.getElementsByTagName("*"),g=[];for(var w=0;w<p.length;w++){if(t(p[w]))g.push(p[w])}return g}else{throw new Error("Unknown selector:"+t)}}var _=function t(e,r){return new t.prototype.init(e,r)};_.prototype.init=function(t,e){this.context=e=e||document;var r=s(t,e),n=void 0;for(n=0;n<r.length;n++){this[n]=r[n]}this.length=r.length;return this};_.prototype.extend=_.extend=function(){var t=arguments[0]||{};var e=arguments[1]||{};var r=arguments.length;if(r===1){e=t;t=this}if(!i(t)){t={}}for(var n in e){try{t[n]=e[n]}catch(t){throw new Error("Illegal property value!")}}return t};_.prototype.init.prototype=_.prototype;function t(){var f={},l=void 0,n=void 0;var i=function t(){var a=[],u=0,f=0;(function t(e,r){if(r>f)f=r;var n=void 0;for(n=0;n<e.children.length;n++){t(l[e.children[n]],r+1)}l[e.id].left=r+.5;if(n==0){if(a[r]==undefined)a[r]=-.5;if(a[r-1]==undefined)a[r-1]=-.5;l[e.id].top=a[r]+1;var i=a[r]+1+(l[e.pid].children.length-1)*.5;if(i-1<a[r-1])l[e.id].top=a[r-1]+1-(l[e.pid].children.length-1)*.5}else{l[e.id].top=(l[e.children[0]].top+l[e.children[n-1]].top)*.5}if(l[e.id].top<=a[r]){var o=a[r]+1-l[e.id].top;(function t(e,r){l[e].top+=o;if(a[r]<l[e].top)a[r]=l[e].top;var n=void 0;for(n=0;n<l[e].children.length;n++){t(l[e].children[n],r+1)}})(e.id,r)}a[r]=l[e.id].top;if(l[e.id].top+.5>u)u=l[e.id].top+.5})(l[n],0);return{node:l,root:n,size:u,deep:f+1}};var o=function t(o){var a={};var e=f.root(o),u=void 0,r=void 0;u=r=f.id(e);a[u]={data:e,pid:null,id:u,children:[]};(function t(e,r){var n=f.child(e,o),i=void 0;for(i=0;n&&i<n.length;i++){u=f.id(n[i]);a[r].children.push(u);a[u]={data:n[i],pid:r,id:u,children:[]};t(n[i],u)}})(e,u);return[r,a]};var e=function t(e){var r=o(e);l=r[1];n=r[0];return i()};e.root=function(t){f.root=t;return e};e.child=function(t){f.child=t;return e};e.id=function(t){f.id=t;return e};return e}var T=function t(e,r,n,i,o){var a=Math.cos(n),u=Math.sin(n);return[+((i-e)*a-(o-r)*u+e).toFixed(7),+((i-e)*u+(o-r)*a+r).toFixed(7)]};var d=function t(e,r,n,i,o){var a=Math.sqrt(e*e+r*r);return[+(e*n/a+i).toFixed(7),+(r*n/a+o).toFixed(7)]};var h=function t(e,r,n,i,o){return[+(n*(i-e)+e).toFixed(7),+(n*(o-r)+r).toFixed(7)]};var v=function t(o){o=u({d:[1,1],c:[0,0],p:[0,0]},o);var a={rotate:function t(e){var r=o.d[0]+o.p[0],n=o.d[1]+o.p[1];var i=T(o.p[0],o.p[1],e,r,n);o.d=[i[0]-o.p[0],i[1]-o.p[1]];return a},move:function t(e){o.p=d(o.d[0],o.d[1],e,o.p[0],o.p[1]);return a},scale:function t(e){o.p=h(o.c[0],o.c[1],e,o.p[0],o.p[1]);return a},value:function t(){return o.p}};return a};function p(y){y=u({"begin-deg":0,deg:Math.PI*2},y);var m=t().root(y.root).child(y.child).id(y.id);var e=function t(e){var r=m(e);if(y.type==="LR"||y.type==="RL"){var n=y.width/r.deep;if("RL"===y.type)n*=-1;var i=y.height/(r.size- -.5);for(var o in r.node){var a=r.node[o];r.node[o].left=+(("RL"==y.type?y.width:0)- -a.left*n).toFixed(7);r.node[o].top=+(a.top*i).toFixed(7)}}else if(y.type==="TB"||y.type==="BT"){var u=y.height/r.deep;if("BT"==y.type)u*=-1;var f=y.width/(r.size- -.5);var l=void 0,c=void 0;for(var s in r.node){var d=r.node[s];l=d.left;c=d.top;r.node[s].top=+(("BT"==y.type?y.height:0)- -l*u).toFixed(7);r.node[s].left=+(c*f).toFixed(7)}}else if(y.type==="circle"){var h=y.radius/(r.deep-1);var v=y.deg/(r.size- -.5);for(var p in r.node){var g=r.node[p];r.node[p].deg=(y["begin-deg"]- -v*g.top)%(Math.PI*2);var w=T(y.cx,y.cy,r.node[p].deg,y.cx- -h*(g.left-.5),y.cy);r.node[p].left=+w[0];r.node[p].top=+w[1]}}y.drawer(r);return t};e.config=function(t){y=u(y,t);return e};e.drawer=function(t){y.drawer=t;return e};return e}function g(t){return typeof t==="number"||t!==null&&(typeof t==="undefined"?"undefined":_typeof(t))==="object"&&r(t)==="[object Number]"}function w(f){f=u({"begin-deg":-Math.PI/2,deg:Math.PI*2,radius:[]},f);if(!m(f.value)){throw new Error("config.value must be a function!")}var e=function t(e){var r=0,n=[],i=0;for(var o in e){n.push({value:f.value(e[o],o,r),data:e[o],key:o,index:r,dots:[]});i+=n[r].value;r+=1}for(r=0;r<n.length;r++){n[r].beginDeg=r===0?f["begin-deg"]:n[r-1].beginDeg+n[r-1].deg;var a=n[r].value/i;n[r].deg=a*f.deg;n[r].percent=new Number(a*100).toFixed(2)}if(g(f.cx)&&g(f.cy)){for(r=0;r<f.radius.length;r++){for(var u=0;u<n.length;u++){n[u].dots.push(T(f.cx,f.cy,n[u].beginDeg+n[u].deg*.5,f.cx+f.radius[r],f.cy))}}}if(m(f.drawer)){f.drawer(n)}};e.config=function(t){f=u(f,t);return e};e.drawer=function(t){f.drawer=t;return e};return e}function E(t,e,r,n){n=n||0;var i=Math.sqrt(e*e+r*r+n*n);return[1,0,0,0,0,1,0,0,0,0,1,0,e*t/i,r*t/i,n*t/i,1]}function k(t){var e=Math.sin(t),r=Math.cos(t);return[r,e,0,0,-e,r,0,0,0,0,1,0,0,0,0,1]}function C(t,e,r,n,i,o){n=n||0;i=i||0;o=o||0;return[t,0,0,0,0,e,0,0,0,0,r,0,n-n*t,i-i*e,o-o*r,1]}function M(t,e,r,n,i,o){if(typeof t==="number"&&typeof e==="number"){if(typeof r!=="number"){r=0;n=t;i=e;o=1}else if(typeof n!=="number"||typeof i!=="number"||typeof o!=="number"){n=t;i=e;o=r;t=0;e=0;r=0}if(t==n&&e==i&&r==o)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((n-t)*(n-t)+(i-e)*(i-e)),u=a!=0?(i-e)/a:1,f=a!=0?(n-t)/a:0,l=(n-t)*f+(i-e)*u,c=o-r,s=Math.sqrt(l*l+c*c),d=s!=0?c/s:1,h=s!=0?l/s:0;return[[u,d*f,f*h,0,-f,u*d,u*h,0,0,-h,d,0,e*f-t*u,r*h-t*f*d-e*u*d,-t*f*h-e*u*h-r*d,1],[u,-f,0,0,d*f,d*u,-h,0,f*h,u*h,d,0,t,e,r,1]]}else{throw new Error("a1 and b1 is required!")}}var N=function t(e,r){var n=[];for(var i=0;i<4;i++){for(var o=0;o<r.length/4;o++){n[o*4+i]=e[i]*r[o*4]+e[i+4]*r[o*4+1]+e[i+8]*r[o*4+2]+e[i+12]*r[o*4+3]}}return n};function A(t){var l=t||[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];var c={move:function t(e,r,n,i){l=N(E(e,r,n,i),l);return c},rotate:function t(e,r,n,i,o,a,u){var f=M(r,n,i,o,a,u);l=N(N(N(f[1],k(e)),f[0]),l);return c},scale:function t(e,r,n,i,o,a){l=N(C(e,r,n,i,o,a),l);return c},multiply:function t(e,r){l=r?N(l,e):N(e,l);return c},use:function t(e,r,n,i){n=n||0;i=i||1;var o=N(l,[e,r,n,i]);o[0]=+o[0].toFixed(7);o[1]=+o[1].toFixed(7);o[2]=+o[2].toFixed(7);o[3]=+o[3].toFixed(7);return o},value:function t(){return l}};return c}var L=[];var P=13;var S=400;var j=null;function I(e,t,r){var f={timer:function t(e,r,n){if(!e){throw new Error("Tick is required!")}r=r||S;var i=(new Date).valueOf()+"_"+(Math.random()*1e3).toFixed(0);L.push({id:i,createTime:new Date,tick:e,duration:r,callback:n});f.start();return i},start:function t(){if(!j){j=window.setInterval(f.tick,P)}},tick:function t(){var e=void 0,r=void 0,t=void 0,n=void 0,i=void 0,o=void 0,a=void 0,u=L;L=[];L.length=0;for(r=0;r<u.length;r++){i=u[r];e=i.createTime;t=i.tick;o=i.duration;n=i.callback;a=(+new Date-e)/o;a=a>1?1:a;t(a);if(a<1&&i.id){L.push(i)}else if(n){n(a)}}if(L.length<=0){f.stop()}},stop:function t(){if(j){window.clearInterval(j);j=null}}};var n=f.timer(function(t){e(t)},t,r);return function(){var t=void 0;for(t in L){if(L[t].id==n){L[t].id=undefined;return}}}}function R(t,e){for(var r in e){try{t[r]=e[r]}catch(t){throw new Error("Illegal property value!")}}return t}function F(f){f=R({u:.5},f);var l=void 0,c=void 0,s=void 0;var d=function t(e){if(l){var r=(e-c)/(s-c),n=r*r,i=r*n;var o=i*l[0]+n*l[1]+r*l[2]+l[3];return o*(s-c)}else throw new Error("You shoud first set the position!")};d.setP=function(t,e,r,n,i,o){if(t<r){c=t;s=r;var a=f.u*i,u=f.u*o;e/=r-t;n/=r-t;l=[2*e-2*n+a+u,3*n-3*e-2*a-u,a,e]}else throw new Error("The point x-position should be increamented!");return d};return d}function B(i){i=u({t:0},i);var o=void 0,r=void 0;var a=function t(e){if(o){r=-1;while(r+1<o.x.length&&(e>o.x[r+1]||r==-1&&e>=o.x[r+1])){r+=1}if(r==-1||r>=o.h.length)throw new Error("Coordinate crossing!");return o.h[r](e)}else{throw new Error("You shoud first set the position!")}};a.setT=function(t){if(typeof t==="number"){i.t=t}else{throw new Error("Expecting a figure!")}return a};a.setP=function(t){o={x:[],h:[]};var e=void 0,r=(t[1][1]-t[0][1])/(t[1][0]-t[0][0]),n=void 0;o.x[0]=t[0][0];for(e=1;e<t.length;e++){if(t[e][0]<=t[e-1][0])throw new Error("The point position should be increamented!");o.x[e]=t[e][0];n=e<t.length-1?(t[e+1][1]-t[e-1][1])/(t[e+1][0]-t[e-1][0]):(t[e][1]-t[e-1][1])/(t[e][0]-t[e-1][0]);o.h[e-1]=F({u:(1-i.t)*.5}).setP(t[e-1][0],t[e-1][1],t[e][0],t[e][1],r,n);r=n}return a};return a}var z=function t(e,r){var n=s(e,r||document);if(n.length>0){for(var i=0;i<this.length;i++){n[0].appendChild(this[i])}}else{throw new Error("Target empty!")}return this};var D=function t(e,r){var n=s(e,r||document);if(n.length>0){for(var i=0;i<this.length;i++){n[0].insertBefore(this[i],n[0].childNodes[0])}}else{throw new Error("Target empty!")}return this};var O=function t(e,r){var n=s(e,r||document);if(n.length>0){for(var i=0;i<this.length;i++){n[0].parentNode.insertBefore(this[i],n[0].nextSibling)}}else{throw new Error("Target empty!")}return this};var H=function t(e,r){var n=s(e,r||document);if(n.length>0){for(var i=0;i<this.length;i++){n[0].parentNode.insertBefore(this[i],n[0])}}else{throw new Error("Target empty!")}return this};var G=function t(){for(var e=0;e<this.length;e++){this[e].parentNode.removeChild(this[e])}return this};var q=function t(e){var r=[];for(var n=0;n<this.length;n++){if(e(n,_(this[n])))r.push(this[n])}return _(r)};var $=function t(e){if(e){for(var r=0;r<this.length;r++){this[r].textContent=e}return this}if(this.length<=0)throw new Error("Target empty!");return this[0].textContent};function V(t,e){var r=document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(t,null):t.currentStyle;return typeof e==="string"?r.getPropertyValue(e):r}function W(){if(arguments.length<=1&&(arguments.length<=0||_typeof(arguments[0])!=="object")){if(this.length<=0)throw new Error("Target empty!");return V(this[0],arguments[0])}for(var t=0;t<this.length;t++){if(arguments.length===1){for(var e in arguments[0]){this[t].style[e]=arguments[0][e]}}else this[t].style[arguments[0]]=arguments[1]}return this}var U=function t(e,r,n){if(/[a-z]/.test(e.tagName)&&f.indexOf(r)>=0){e.setAttributeNS(a.xlink,"xlink:"+r,n)}else e.setAttribute(r,n)};function Y(){if(arguments.length===1&&_typeof(arguments[0])!=="object"){if(this.length<=0)throw new Error("Target empty!");return this[0].getAttribute(arguments[0])}else if(arguments.length>0){for(var t=0;t<this.length;t++){if(arguments.length===1){for(var e in arguments[0]){U(this[t],e,arguments[0][e])}}else U(this[t],arguments[0],arguments[1])}}return this}var X=function t(e,r){if(arguments.length<=0){if(this.length<=0)throw new Error("Target empty!");return this[0].__data__}for(var n=0;n<this.length;n++){this[n].__data__=typeof r==="function"?r(e,n):e}return this};var Q=function t(e,r){if(arguments.length<=0){var n=[];for(var i=0;i<this.length;i++){n[i]=this[i].__data__}return n}var o=[],a=void 0;for(a=0;a<this.length&&a<e.length;a++){this[a].__data__=typeof r==="function"?r(e[a],a):e[a];o.push(this[a])}var u=_(o);u.__enter__=[];for(;a<e.length;a++){u.__enter__.push(typeof r==="function"?r(e[a],a):e[a])}u.__exit__=[];for(;a<this.length;a++){u.__exit__.push(this[a])}return u};var Z=function t(e,r){if(!this.__enter__||this.__enter__.constructor!==Array)throw new Error("Not a data node object to be balanced!");var n=[];for(var i=0;i<this.__enter__.length;i++){n[i]=x(e,r);n[i].__data__=this.__enter__[i]}delete this.__enter__;return _(n)};var J=function t(){if(!this.__exit__||this.__exit__.constructor!==Array)throw new Error("Not a data node object to be balanced!");var e=_(this.__exit__);delete this.__exit__;return e};var K=function t(e){for(var r=0;r<this.length;r++){e(this[r].__data__,r,_(this[r]))}return this};var tt=function t(e,r){if(window.attachEvent){for(var n=0;n<this.length;n++){this[n].attachEvent("on"+e,r)}}else{for(var i=0;i<this.length;i++){this[i].addEventListener(e,r,false)}}return this};var et=function t(e){var r=this[0].getBoundingClientRect();if(!e||!e.clientX)throw new Error("Event is necessary!");return{x:e.clientX-r.left,y:e.clientY-r.top}};function rt(t,e,r,n,i,o,a){if(e>Math.PI*2)e=Math.PI*2;if(e<-Math.PI*2)e=-Math.PI*2;if(e<0){t+=e;e*=-1}var u=[],f=void 0;f=T(0,0,t,i,0);u[0]=f[0];u[1]=f[1];f=T(0,0,e,f[0],f[1]);u[2]=f[0];u[3]=f[1];f=T(0,0,t,o,0);u[4]=f[0];u[5]=f[1];f=T(0,0,e,f[0],f[1]);u[6]=f[0];u[7]=f[1];a(t,t+e,u[0]+r,u[1]+n,u[4]+r,u[5]+n,u[2]+r,u[3]+n,u[6]+r,u[7]+n,(o-i)*.5)}var nt=function t(e,r,n,i,o){e.beginPath();e.translate(n,i);e.rotate(o);e.font=r["font-size"]+"px "+r["font-family"];return e};var it=function t(s,d,h,v,p,g,e,r){rt(e,r,h,v,p,g,function(t,e,r,n,i,o,a,u,f,l,c){if(c<0)c=-c;s.beginPath();s.moveTo(r,n);s.arc(h,v,p,t,e,false);if(d["arc-end-cap"]!="round")s.lineTo(f,l);else s.arc((a+f)*.5,(u+l)*.5,c,e-Math.PI,e,true);s.arc(h,v,g,e,t,true);if(d["arc-start-cap"]!="round")s.lineTo(r,n);else s.arc((r+i)*.5,(n+o)*.5,c,t,t-Math.PI,true)});return s};var ot=function t(e,r,n,i){e.beginPath();e.moveTo(r+i,n);e.arc(r,n,i,0,Math.PI*2);return e};var at=function t(e,r,n,i,o){e.beginPath();e.rect(r,n,i,o);return e};var ut=function t(e,r,n,i,o){var a=e.createLinearGradient(r,n,i,o);var u={value:function t(){return a},addColorStop:function t(e,r){a.addColorStop(e,r);return u}};return u};function ft(c){var s=c.getContext("2d");if(c.__had_scale2_canvas__!=="YES"){c.__had_scale2_canvas__="YES";var t=c.clientWidth||c.getAttribute("width"),e=c.clientHeight||c.getAttribute("height");c.style.width=t+"px";c.style.height=e+"px";c.setAttribute("width",t*2);c.setAttribute("height",e*2);s.scale(2,2)}s.textBaseline="middle";s.textAlign="left";var u={"font-size":"16","font-family":"sans-serif","arc-start-cap":"butt","arc-end-cap":"butt"};var d={config:function t(){if(arguments.length===1){if(_typeof(arguments[0])!=="object")return s[arguments[0]];for(var e in arguments[0]){if(u[e])u[e]=arguments[0][e];else s[e]=arguments[0][e]}}else if(arguments.length===2){if(u[arguments[0]])u[arguments[0]]=arguments[1];else s[arguments[0]]=arguments[1]}return d},fillText:function t(e,r,n,i){s.save();nt(s,u,r,n,i||0).fillText(e,0,0);s.restore();return d},strokeText:function t(e,r,n,i){s.save();nt(s,u,r,n,i||0).strokeText(e,0,0);s.restore();return d},beginPath:function t(){s.beginPath();return d},closePath:function t(){s.closePath();return d},moveTo:function t(e,r){s.moveTo(e,r);return d},lineTo:function t(e,r){s.lineTo(e,r);return d},arc:function t(e,r,n,i,o){s.arc(e,r,n,i,i+o);return d},fill:function t(){s.fill();return d},stroke:function t(){s.stroke();return d},save:function t(){s.save();return d},restore:function t(){s.restore();return d},quadraticCurveTo:function t(e,r,n,i){s.quadraticCurveTo(e,r,n,i);return d},bezierCurveTo:function t(e,r,n,i,o,a){s.bezierCurveTo(e,r,n,i,o,a);return d},clearRect:function t(e,r,n,i){s.clearRect(e||0,r||0,n||c.getAttribute("width")/2,i||c.getAttribute("height")/2);return d},toDataURL:function t(){return c.toDataURL()},drawImage:function t(e,r,n,i,o,a,u,f,l){s.drawImage(e,r||0,n||0,i?i*2:c.getAttribute("width"),o?o*2:c.getAttribute("height"),a||0,u||0,f||c.getAttribute("width")/2,l||c.getAttribute("height")/2);return d},fillArc:function t(e,r,n,i,o,a){it(s,u,e,r,n,i,o,a).fill();return d},strokeArc:function t(e,r,n,i,o,a){it(s,u,e,r,n,i,o,a).stroke();return d},fillCircle:function t(e,r,n){ot(s,e,r,n).fill();return d},strokeCircle:function t(e,r,n){ot(s,e,r,n).stroke();return d},fillRect:function t(e,r,n,i){at(s,e,r,n,i).fill();return d},strokeRect:function t(e,r,n,i){at(s,e,r,n,i).stroke();return d},createLinearGradient:function t(e,r,n,i){return ut(s,e,r,n,i)},translate:function t(e,r){s.translate(e,r);return d},rotate:function t(e){s.rotate(e);return d},scale:function t(e,r){r=r||e;s.scale(e,r);return d}};return d}function lt(t,e){if(t==="textAlign"){return{left:"start",right:"end",center:"middle"}[e]||e}return e}var ct=function t(e,r,n,i,o){if(!y(e[0]))throw new Error("Target empty!");if(e[0].nodeName.toLowerCase()!=="text")throw new Error("Need a <text> !");e.attr("dy",{top:r["font-size"]*.5,middle:0,bottom:-r["font-size"]*.5}[r.textBaseline]).css({"text-anchor":r.textAlign,"dominant-baseline":"central","font-size":r["font-size"]+"px","font-family":r["font-family"]}).attr({x:n,y:i});return{transform:"rotate("+o*180/Math.PI+","+n+","+i+")"}};var st=function t(h,v,e,r,p,g,n,i){if(h[0].nodeName.toLowerCase()!=="path")throw new Error("Need a <path> !");rt(n,i,e,r,p,g,function(t,e,r,n,i,o,a,u,f,l,c){var s=e-t>Math.PI?1:0,d="M"+r+" "+n;if(c<0)c=-c;d+="A"+p+" "+p+" 0 "+s+" 1 "+a+" "+u;if(v["arc-end-cap"]!="round")d+="L"+f+" "+l;else d+="A"+c+" "+c+" "+" 0 1 0 "+f+" "+l;d+="A"+g+" "+g+" 0 "+s+" 0 "+i+" "+o;if(v["arc-start-cap"]!="round")d+="L"+r+" "+n;else d+="A"+c+" "+c+" "+" 0 1 0 "+r+" "+n;h.attr("d",d)});return h};var dt=function t(e,r,n,i){if(e[0].nodeName.toLowerCase()!=="circle")throw new Error("Need a <circle> !");e.attr({cx:r,cy:n,r:i});return e};var ht=function t(e,r){if(e[0].nodeName.toLowerCase()!=="path")throw new Error("Need a <path> !");e.attr("d",r);return e};var vt=function t(e,r,n,i,o){if(e[0].nodeName.toLowerCase()!=="rect")throw new Error("Need a <rect> !");e.attr({x:r,y:n,width:i,height:o});return e};var pt=function t(e){var r=e.getElementsByTagName("defs");if(r.length<=0){r=[x("<defs>","SVG")];e.appendChild(r[0])}return r[0]};var gt=function t(e,r,n,i,o,a){var u=pt(r);var f="image2D-lg-"+(new Date).valueOf()+"-"+Math.random();var l=x('<linearGradient id="'+f+'" x1="'+n+'%" y1="'+i+'%" x2="'+o+'%" y2="'+a+'%"></linearGradient>');r.appendChild(l);var c={value:function t(){return"url(#"+f+")"},addColorStop:function t(e,r){l.appendChild(x('<stop offset="'+e*100+'%" style="stop-color:'+r+';" />'));return c}};return c};function wt(o,t){var u=void 0;if(t)u=_(t,o);var f={fillStyle:"#000",strokeStyle:"#000",lineWidth:1,textAlign:"start",textBaseline:"middle","font-size":"16","font-family":"sans-serif","arc-start-cap":"butt","arc-end-cap":"butt"};var l="",c=[];var e=[],s="";var d={config:function t(){if(arguments.length===1){if(_typeof(arguments[0])!=="object")return f[arguments[0]];for(var e in arguments[0]){f[e]=lt(e,arguments[0][e])}}else if(arguments.length===2)f[arguments[0]]=lt(arguments[0],arguments[1]);return d},bind:function t(e){u=_(e,o);return d},appendTo:function t(e){u.appendTo(e||o,o);return d},prependTo:function t(e){u.prependTo(e||o,o);return d},afterTo:function t(e){u.afterTo(e||o,o);return d},beforeTo:function t(e){u.beforeTo(e||o,o);return d},beginPath:function t(){l="";c=[];return d},closePath:function t(){l+="Z";return d},moveTo:function t(e,r){l+="M"+e+" "+r;c=[e,r];return d},lineTo:function t(e,r){l+=(l==""?"M":"L")+e+" "+r;c=[e,r];return d},arc:function t(e,r,n,i,o){var a=T(e,r,i,e+n,r);var u=T(e,r,i+o,e+n,r);i=i/Math.PI*180;o=o/Math.PI*180;if(l==""){l+="M"+a[0]+","+a[1]}else if(a[0]!=c[0]||a[1]!=c[1]){l+="L"+a[0]+","+a[1]}l+="A"+n+","+n+" 0 "+(o>180||o<-180?1:0)+","+(o>0?1:0)+" "+u[0]+","+u[1];return d},fill:function t(){ht(u,l).attr("transform",s).attr("fill",f.fillStyle);return d},stroke:function t(){ht(u,l).attr("transform",s).attr({"stroke-width":f.lineWidth,stroke:f.strokeStyle,fill:"none"});return d},save:function t(){e.push(s);return d},restore:function t(){if(e.length>0)s=e.pop();return d},quadraticCurveTo:function t(e,r,n,i){l+="Q"+e+" "+r+","+n+" "+i;return d},bezierCurveTo:function t(e,r,n,i,o,a){l+="C"+e+" "+r+","+n+" "+i+","+o+" "+a;return d},fillText:function t(e,r,n,i){var o=ct(u,f,r,n,i||0);u.attr("transform",s+o.transform).attr("fill",f.fillStyle)[0].textContent=e;return d},strokeText:function t(e,r,n,i){var o=ct(u,f,r,n,i||0);u.attr("transform",s+o.transform).attr({stroke:f.strokeStyle,fill:"none"})[0].textContent=e;return d},fillArc:function t(e,r,n,i,o,a){st(u,f,e,r,n,i,o,a).attr("transform",s).attr("fill",f.fillStyle);return d},strokeArc:function t(e,r,n,i,o,a){st(u,f,e,r,n,i,o,a).attr("transform",s).attr({"stroke-width":f.lineWidth,stroke:f.strokeStyle,fill:"none"});return d},fillCircle:function t(e,r,n){dt(u,e,r,n).attr("transform",s).attr("fill",f.fillStyle);return d},strokeCircle:function t(e,r,n){dt(u,e,r,n).attr("transform",s).attr({"stroke-width":f.lineWidth,stroke:f.strokeStyle,fill:"none"});return d},fillRect:function t(e,r,n,i){vt(u,e,r,n,i).attr("transform",s).attr("fill",f.fillStyle);return d},strokeRect:function t(e,r,n,i){vt(u,e,r,n,i).attr("transform",s).attr({"stroke-width":f.lineWidth,stroke:f.strokeStyle,fill:"none"});return d},createLinearGradient:function t(e,r,n,i){return gt(u,o,e,r,n,i)},translate:function t(e,r){s+=" translate("+e+","+r+")";return d},rotate:function t(e){s+=" rotate("+e/Math.PI*180+")";return d},scale:function t(e,r){r=r||e;s+=" scale("+e+","+r+")";return d}};return d}function yt(){if(!y(this[0]))throw new Error("Target empty!");var t=this[0],e=t.nodeName.toLowerCase();if(e==="canvas")return ft(t);if(e==="svg")return wt(t,arguments[0]);throw new Error("Painter is not a function!")}var mt=function t(e){return e&&e.constructor===CanvasRenderingContext2D};function bt(){if(!y(this[0]))throw new Error("Target empty!");if(this[0].nodeName.toLowerCase()!=="canvas")throw new Error("Layer is not a function!");var r=this.painter(),n={},i=[];var o=this[0].clientWidth,a=this[0].clientHeight;var u={painter:function t(e){if(!n[e]||!mt(n[e].painter)){n[e]={visible:true};n[e].canvas=document.createElement("canvas");n[e].canvas.setAttribute("width",o);n[e].canvas.setAttribute("height",a);n[e].painter=_(n[e].canvas).painter();i.push(e)}return n[e].painter},delete:function t(e){for(var r=0;r<i.length;r++){if(i[r]===e){i.splice(r,1);break}}delete n[e];return u},update:function t(){r.clearRect(0,0,o,a);r.save();for(var e=0;e<i.length;e++){if(n[i[e]].visible)r.drawImage(n[i[e]].canvas,0,0,o,a,0,0,o,a)}r.restore();return u},hidden:function t(e){n[e].visible=false;return u},show:function t(e){n[e].visible=true;return u}};return u}_.extend({treeLayout:p,pieLayout:w,Matrix4:A,rotate:T,move:d,scale:h,dot:v,animation:I,cardinal:B});_.prototype.extend({appendTo:z,prependTo:D,afterTo:O,beforeTo:H,remove:G,filter:q,text:$,css:W,attr:Y,datum:X,data:Q,enter:Z,exit:J,loop:K,bind:tt,position:et,painter:yt,layer:bt});_.fn=_.prototype;if((typeof module==="undefined"?"undefined":_typeof(module))==="object"&&_typeof(module.exports)==="object"){module.exports=_}else{var xt=window.image2D,_t=window.$$;_.noConflict=function(t){if(window.$$===_){window.$$=_t}if(t&&window.image2D===_){window.image2D=xt}return _};window.image2D=window.$$=_}})();
\No newline at end of file