
skeleton.lib.vivagraph.min.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crawloverview-plugin Show documentation
Show all versions of crawloverview-plugin Show documentation
Generates an HTML report with a snapshot overview of what is crawled.
var Viva=Viva||{};Viva.Graph=Viva.Graph||{},"undefined"!=typeof module&&module.exports&&(module.exports=Viva),Viva.Graph.version="0.4.1",Viva.lazyExtend=function(e,t){var n;if(e||(e={}),t)for(n in t)if(t.hasOwnProperty(n)){var r=e.hasOwnProperty(n),i=typeof t[n],o=!r||typeof e[n]!==i;o?e[n]=t[n]:"object"===i&&(e[n]=Viva.lazyExtend(e[n],t[n]))}return e},Viva.random=function(){function e(){var e=4022871197,t=function(t){var n;for(t=""+t,n=0;t.length>n;n++){e+=t.charCodeAt(n);var r=.02519603282416938*e;e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=4294967296*r}return 2.3283064365386963e-10*(e>>>0)};return t.version="Mash 0.9",t}function t(t){return function(t){var n,r,i=0,o=58,a=119,u=178,s=[],c=e();for(0===t.length&&(t=[+new Date]),n=0;256>n;n++)s[n]=c(" "),s[n]-=4.76837158203125e-7*c(" "),0>s[n]&&(s[n]+=1);for(r=0;t.length>r;r++)for(n=0;256>n;n++)s[n]-=c(t[r]),s[n]-=4.76837158203125e-7*c(t[r]),0>s[n]&&(s[n]+=1);c=null;var f=function(){var e;return i=255&i+1,o=255&o+1,a=255&a+1,u=255&u+1,e=s[i]-s[o],0>e&&(e+=1),e-=s[a],0>e&&(e+=1),e-=s[u],0>e&&(e+=1),s[i]=e,e};return f.uint32=function(){return 4294967296*f()>>>0},f.fract53=f,f.version="LFIB4 0.9",f.args=t,f}(t)}var n=new t(Array.prototype.slice.call(arguments));return{next:function(e){return Math.floor(n()*e)},nextDouble:function(){return n()}}},Viva.randomIterator=function(e,t){return t=t||Viva.random(),{forEach:function(n){var r,i,o;for(r=e.length-1;r>0;--r)i=t.next(r+1),o=e[i],e[i]=e[r],e[r]=o,n(o);e.length&&n(e[0])},shuffle:function(){var n,r,i;for(n=e.length-1;n>0;--n)r=t.next(n+1),i=e[r],e[r]=e[n],e[n]=i;return e}}},Viva.BrowserInfo=function(){if("undefined"==typeof window||!window.hasOwnProperty("navigator"))return{browser:"",version:"0"};var e=window.navigator.userAgent.toLowerCase(),t=/(webkit)[ \/]([\w.]+)/,n=/(opera)(?:.*version)?[ \/]([\w.]+)/,r=/(msie) ([\w.]+)/,i=/(mozilla)(?:.*? rv:([\w.]+))?/,o=t.exec(e)||n.exec(e)||r.exec(e)||0>e.indexOf("compatible")&&i.exec(e)||[];return{browser:o[1]||"",version:o[2]||"0"}}(),Viva.Graph.Utils=Viva.Graph.Utils||{},Viva.Graph.Utils.indexOfElementInArray=function(e,t){if(t.indexOf)return t.indexOf(e);var n,r=t.length;for(n=0;r>n;n+=1)if(t.hasOwnProperty(n)&&t[n]===e)return n;return-1},Viva.Graph.Utils=Viva.Graph.Utils||{},Viva.Graph.Utils.getDimension=function(e){if(!e)throw{message:"Cannot get dimensions of undefined container"};var t=e.clientWidth,n=e.clientHeight;return{left:0,top:0,width:t,height:n}},Viva.Graph.Utils.findElementPosition=function(e){var t=0,n=0;if(e.offsetParent)do t+=e.offsetLeft,n+=e.offsetTop;while(null!==(e=e.offsetParent));return[t,n]},Viva.Graph.Utils=Viva.Graph.Utils||{},Viva.Graph.Utils.events=function(e){var t=function(e){var t={};return e.fire=function(e,n){var r,i,o,a;if("string"!=typeof e)throw"Only strings can be used as even type";if(t.hasOwnProperty(e))for(r=t[e],a=0;r.length>a;++a)o=r[a],i=o.method,i(n);return this},e.addEventListener=function(e,n){if("function"!=typeof n)throw"Only functions allowed to be callbacks";var r={method:n};return t.hasOwnProperty(e)?t[e].push(r):t[e]=[r],this},e.removeEventListener=function(e,n){if("function"!=typeof n)throw"Only functions allowed to be callbacks";if(t.hasOwnProperty(e)){var r,i=t[e];for(r=0;i.length>r;++r)if(i[r].callback===n){i.splice(r);break}}return this},e.removeAllListeners=function(){var e;for(e in t)t.hasOwnProperty(e)&&delete t[e]},e};return{on:function(t,n){return e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,n),this},stop:function(t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent&&e.detachEvent("on"+t,n)},extend:function(){return t(e)}}},Viva.Graph.Utils=Viva.Graph.Utils||{},Viva.Graph.Utils.dragndrop=function(e){var t,n,r,i,o,a,u,s=Viva.Graph.Utils.events(window.document),c=Viva.Graph.Utils.events(e),f=Viva.Graph.Utils.findElementPosition,l=0,d=0,h=!1,p=0,v=function(e){var t=0,n=0;return e=e||window.event,e.pageX||e.pageY?(t=e.pageX,n=e.pageY):(e.clientX||e.clientY)&&(t=e.clientX+window.document.body.scrollLeft+window.document.documentElement.scrollLeft,n=e.clientY+window.document.body.scrollTop+window.document.documentElement.scrollTop),[t,n]},m=function(e,t,r){n&&n(e,{x:t-l,y:r-d}),l=t,d=r},g=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},y=function(e){e.preventDefault&&e.preventDefault()},x=function(e){return g(e),!1},w=function(e){e=e||window.event,m(e,e.clientX,e.clientY)},V=function(e){if(e=e||window.event,h)return g(e),!1;var n=1===e.button&&null!==window.event||0===e.button;return n?(l=e.clientX,d=e.clientY,u=e.target||e.srcElement,t&&t(e,{x:l,y:d}),s.on("mousemove",w),s.on("mouseup",b),g(e),o=window.document.onselectstart,a=window.document.ondragstart,window.document.onselectstart=x,u.ondragstart=x,!1):void 0},b=function(e){e=e||window.event,s.stop("mousemove",w),s.stop("mouseup",b),window.document.onselectstart=o,u.ondragstart=a,u=null,r&&r(e)},E=function(t){if("function"==typeof i){t=t||window.event,t.preventDefault&&t.preventDefault(),t.returnValue=!1;var n,r=v(t),o=f(e),a={x:r[0]-o[0],y:r[1]-o[1]};n=t.wheelDelta?t.wheelDelta/360:t.detail/-9,i(t,n,a)}},G=function(t){!i&&t?"webkit"===Viva.BrowserInfo.browser?e.addEventListener("mousewheel",E,!1):e.addEventListener("DOMMouseScroll",E,!1):i&&!t&&("webkit"===Viva.BrowserInfo.browser?e.removeEventListener("mousewheel",E,!1):e.removeEventListener("DOMMouseScroll",E,!1)),i=t},P=function(e,t){return(e.clientX-t.clientX)*(e.clientX-t.clientX)+(e.clientY-t.clientY)*(e.clientY-t.clientY)},N=function(e){if(1===e.touches.length){g(e);var t=e.touches[0];m(e,t.clientX,t.clientY)}else if(2===e.touches.length){var n=P(e.touches[0],e.touches[1]),r=0;p>n?r=-1:n>p&&(r=1),i(e,r,{x:e.touches[0].clientX,y:e.touches[0].clientY}),p=n,g(e),y(e)}},_=function(e){h=!1,s.stop("touchmove",N),s.stop("touchend",_),s.stop("touchcancel",_),u=null,r&&r(e)},L=function(e,n){g(e),y(e),l=n.clientX,d=n.clientY,u=e.target||e.srcElement,t&&t(e,{x:l,y:d}),h||(h=!0,s.on("touchmove",N),s.on("touchend",_),s.on("touchcancel",_))},A=function(t){return console.log("Touch start for ",e),1===t.touches.length?L(t,t.touches[0]):(2===t.touches.length&&(g(t),y(t),p=P(t.touches[0],t.touches[1])),void 0)};return c.on("mousedown",V),c.on("touchstart",A),{onStart:function(e){return t=e,this},onDrag:function(e){return n=e,this},onStop:function(e){return r=e,this},onScroll:function(e){return G(e),this},release:function(){s.stop("mousemove",w),s.stop("mousedown",V),s.stop("mouseup",b),s.stop("touchmove",N),s.stop("touchend",_),s.stop("touchcancel",_),G(null)}}},Viva.Input=Viva.Input||{},Viva.Input.domInputManager=function(){return{bindDragNDrop:function(e,t){if(t){var n=Viva.Graph.Utils.dragndrop(e.ui);"function"==typeof t.onStart&&n.onStart(t.onStart),"function"==typeof t.onDrag&&n.onDrag(t.onDrag),"function"==typeof t.onStop&&n.onStop(t.onStop),e.events=n}else e.events&&(e.events.release(),e.events=null,delete e.events)}}},Viva.Graph.spatialIndex=function(e,t){var n,r,i=16;return"function"==typeof t?(r=t,n=function(t,n){var i=null;return e.forEachNode(function(e){return r(e,t,n)?(i=e,!0):void 0}),i}):"number"==typeof t&&(i=t,n=function(t,n){var r=null;return e.forEachNode(function(e){var o=e.position;return t>o.x-i&&o.x+i>t&&n>o.y-i&&o.y+i>n?(r=e,!0):void 0}),r}),{getNodeAt:n}},Viva.Graph.Utils=Viva.Graph.Utils||{},function(){var e,t,n=0,r=["ms","moz","webkit","o"];for(t="undefined"!=typeof window?window:"undefined"!=typeof global?global:{setTimeout:function(){},clearTimeout:function(){}},e=0;r.length>e&&!t.requestAnimationFrame;++e){var i=r[e];t.requestAnimationFrame=t[i+"RequestAnimationFrame"],t.cancelAnimationFrame=t[i+"CancelAnimationFrame"]||t[i+"CancelRequestAnimationFrame"]}t.requestAnimationFrame||(t.requestAnimationFrame=function(e){var r=(new Date).getTime(),i=Math.max(0,16-(r-n)),o=t.setTimeout(function(){e(r+i)},i);return n=r+i,o}),t.cancelAnimationFrame||(t.cancelAnimationFrame=function(e){t.clearTimeout(e)}),Viva.Graph.Utils.timer=function(e){var n,r=function(){t.cancelAnimationFrame(n),n=0},i=function(){n=t.requestAnimationFrame(i),e()||r()};return i(),{stop:r,restart:function(){n||i()}}}}(),Viva.Graph.geom=function(){return{intersect:function(e,t,n,r,i,o,a,u){var s,c,f,l,d,h,p,v,m,g,y,x,w,V={x:0,y:0};return s=r-t,f=e-n,d=n*t-e*r,m=s*i+f*o+d,g=s*a+f*u+d,0!==m&&0!==g&&m>=0==g>=4?null:(c=u-o,l=i-a,h=a*o-i*u,p=c*e+l*t+h,v=c*n+l*r+h,0!==p&&0!==v&&p>=0==v>=0?null:(y=s*l-c*f,0===y?null:(x=0>y?-y/2:y/2,x=0,w=f*h-l*d,V.x=(0>w?w-x:w+x)/y,w=c*d-s*h,V.y=(0>w?w-x:w+x)/y,V)))},intersectRect:function(e,t,n,r,i,o,a,u){return this.intersect(e,t,e,r,i,o,a,u)||this.intersect(e,r,n,r,i,o,a,u)||this.intersect(n,r,n,t,i,o,a,u)||this.intersect(n,t,e,t,i,o,a,u)},convexHull:function(e){var t=function(e,t){var n,r,i=function(t){var n=t.x-e.x,r=t.y-e.y,i=n>0?1:-1;return i*n*n/(n*n+r*r)},o=t.sort(function(e,t){return i(t)-i(e)}),a=o[0],u=i(a),s=a.x-e.x,c=a.y-e.y,f=s*s+c*c;for(r=1;o.length>r;++r){a=o[r];var l=i(a);l===u?(s=a.x-e.x,c=a.y-e.y,n=s*s+c*c,f>n?o.splice(r,1):o.splice(r-1,1)):u=l}return o},n=function(e,t,n){return 0>(n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x)};if(3>e.length)return e;var r,i=0;for(r=0;e.length>r;++r)e[r].ya.length)return a;var u=[];u.push(o),u.push(a[0]),u.push(a[1]);var s=u.length;for(r=2;a.length>r;++r){for(;!n(u[s-2],u[s-1],a[r]);)u.pop(),s-=1;u.push(a[r]),s+=1}return u}}},Viva.Graph.Rect=function(e,t,n,r){this.x1=e||0,this.y1=t||0,this.x2=n||0,this.y2=r||0},Viva.Graph.Point2d=function(e,t){this.x=e||0,this.y=t||0},Viva.Graph.Node=function(e){this.id=e,this.links=[],this.data=null},Viva.Graph.Link=function(e,t,n){this.fromId=e,this.toId=t,this.data=n},Viva.Graph.graph=function(){var e={},t=[],n=0,r=0,i=[],o=function(e){e.fire("changed",i)},a=function(){r+=1},u=function(e){r-=1,0===r&&i.length>0&&(o(e),i.length=0)},s=function(e,t){i.push({node:e,changeType:t})},c=function(e,t){i.push({link:e,changeType:t})},f=function(e){return e&&"object"==typeof e&&"number"==typeof e.length&&"function"==typeof e.splice&&!e.propertyIsEnumerable("length")},l={addNode:function(t,r){if(t===void 0)throw{message:"Invalid node identifier"};a();var i=this.getNode(t);if(i?s(i,"update"):(i=new Viva.Graph.Node(t),n++,s(i,"add")),r){var o,c=i.data||{},l=typeof r;if("string"===l||f(r)||"number"===l||"boolean"===l)c=r;else if("undefined"===l)c=null;else for(o in r)r.hasOwnProperty(o)&&(c[o]=r[o]);i.data=c}return e[t]=i,u(this),i},addLink:function(e,n,r){a();var i=this.getNode(e)||this.addNode(e),o=this.getNode(n)||this.addNode(n),s=new Viva.Graph.Link(e,n,r);return t.push(s),i.links.push(s),o.links.push(s),c(s,"add"),u(this),s},removeLink:function(e){if(!e)return!1;var n=Viva.Graph.Utils.indexOfElementInArray(e,t);if(0>n)return!1;a(),t.splice(n,1);var r=this.getNode(e.fromId),i=this.getNode(e.toId);return r&&(n=Viva.Graph.Utils.indexOfElementInArray(e,r.links),n>=0&&r.links.splice(n,1)),i&&(n=Viva.Graph.Utils.indexOfElementInArray(e,i.links),n>=0&&i.links.splice(n,1)),c(e,"remove"),u(this),!0},removeNode:function(t){var r=this.getNode(t);if(!r)return!1;for(a();r.links.length;){var i=r.links[0];this.removeLink(i)}e[t]=null,delete e[t],n--,s(r,"remove"),u(this)},getNode:function(t){return e[t]},getNodesCount:function(){return n},getLinksCount:function(){return t.length},getLinks:function(e){var t=this.getNode(e);return t?t.links:null},forEachNode:function(t){if("function"==typeof t){var n;for(n in e)if(e.hasOwnProperty(n)&&t(e[n]))return}},forEachLinkedNode:function(t,n,r){var i,o,a,u=this.getNode(t);if(u&&u.links&&"function"==typeof n)if(r)for(i=0;u.links.length>i;++i)o=u.links[i],o.fromId===t&&n(e[o.toId],o);else for(i=0;u.links.length>i;++i)o=u.links[i],a=o.fromId===t?o.toId:o.fromId,n(e[a],o)},forEachLink:function(e){var n;if("function"==typeof e)for(n=0;t.length>n;++n)e(t[n])},beginUpdate:function(){a()},endUpdate:function(){u(this)},clear:function(){var e=this;e.beginUpdate(),e.forEachNode(function(t){e.removeNode(t.id)}),e.endUpdate()},hasLink:function(e,t){var n,r=this.getNode(e);if(!r)return null;for(n=0;r.links.length>n;++n){var i=r.links[n];if(i.fromId===e&&i.toId===t)return i}return null}};return Viva.Graph.Utils.events(l).extend(),l},Viva.Graph.operations=function(){return{density:function(e){var t=e.getNodesCount();return 0===t?0/0:2*e.getLinksCount()/(t*(t-1))}}},Viva.Graph.Physics=Viva.Graph.Physics||{},Viva.Graph.Physics.Vector=function(e,t){this.x=e||0,this.y=t||0},Viva.Graph.Physics.Vector.prototype={multiply:function(e){return new Viva.Graph.Physics.Vector(this.x*e,this.y*e)}},Viva.Graph.Physics.Point=function(e,t){this.x=e||0,this.y=t||0},Viva.Graph.Physics.Point.prototype={add:function(e){return new Viva.Graph.Physics.Point(this.x+e.x,this.y+e.y)}},Viva.Graph.Physics.Body=function(){this.mass=1,this.force=new Viva.Graph.Physics.Vector,this.velocity=new Viva.Graph.Physics.Vector,this.location=new Viva.Graph.Physics.Point,this.prevLocation=new Viva.Graph.Physics.Point},Viva.Graph.Physics.Body.prototype={loc:function(e){return e?(this.location.x=e.x,this.location.y=e.y,this):this.location},vel:function(e){return e?(this.velocity.x=e.x,this.velocity.y=e.y,this):this.velocity}},Viva.Graph.Physics.Spring=function(e,t,n,r,i){this.body1=e,this.body2=t,this.length=n,this.coeff=r,this.weight=i},Viva.Graph.Physics.QuadTreeNode=function(){this.centerOfMass=new Viva.Graph.Physics.Point,this.children=[],this.body=null,this.hasChildren=!1,this.x1=0,this.y1=0,this.x2=0,this.y2=0},Viva.Graph.Physics=Viva.Graph.Physics||{},Viva.Graph.Physics.eulerIntegrator=function(){return{integrate:function(e,t){var n,r=e.speedLimit,i=0,o=0,a=e.bodies.length;for(n=0;a>n;++n){var u=e.bodies[n],s=t/u.mass;u.velocity.x+=s*u.force.x,u.velocity.y+=s*u.force.y;var c=u.velocity.x,f=u.velocity.y,l=Math.sqrt(c*c+f*f);l>r&&(u.velocity.x=r*c/l,u.velocity.y=r*f/l),i=t*u.velocity.x,o=t*u.velocity.y,u.location.x+=i,u.location.y+=o}return i*i+o*o}}},Viva.Graph.Physics.nbodyForce=function(e){function t(e,t){this.node=e,this.body=t}function n(){this.stack=[],this.popIdx=0}e=Viva.lazyExtend(e||{gravity:-1,theta:.8}),n.prototype={isEmpty:function(){return 0===this.popIdx},push:function(e,n){var r=this.stack[this.popIdx];r?(r.node=e,r.body=n):this.stack[this.popIdx]=new t(e,n),++this.popIdx},pop:function(){return this.popIdx>0?this.stack[--this.popIdx]:void 0},reset:function(){this.popIdx=0}};var r=e.gravity,i=[],o=new n,a=e.theta,u=Viva.random("5f4dcc3b5aa765d61d8327deb882cf99",75,20,63,108,65,76,65,72),s=function(){this.body=null,this.quads=[],this.mass=0,this.massX=0,this.massY=0,this.left=0,this.top=0,this.bottom=0,this.right=0,this.isInternal=!1},c=[],f=0,l=function(){var e;return c[f]?(e=c[f],e.quads[0]=null,e.quads[1]=null,e.quads[2]=null,e.quads[3]=null,e.body=null,e.mass=e.massX=e.massY=0,e.left=e.right=e.top=e.bottom=0,e.isInternal=!1):(e=new s,c[f]=e),++f,e},d=l(),h=function(e,t){var n=Math.abs(e.x-t.x),r=Math.abs(e.y-t.y);return.01>n&&.01>r},p=function(e){for(o.reset(),o.push(d,e);!o.isEmpty();){var t=o.pop(),n=t.node,r=t.body;if(n.isInternal){var i=r.location.x,a=r.location.y;n.mass=n.mass+r.mass,n.massX=n.massX+r.mass*i,n.massY=n.massY+r.mass*a;var s=0,c=n.left,f=(n.right+c)/2,p=n.top,v=(n.bottom+p)/2;if(i>f){s+=1;var m=c;c=f,f+=f-m}if(a>v){s+=2;var g=p;p=v,v+=v-g}var y=n.quads[s];y||(y=l(),y.left=c,y.top=p,y.right=f,y.bottom=v,n.quads[s]=y),o.push(y,r)}else if(n.body){var x=n.body;if(n.body=null,n.isInternal=!0,h(x.location,r.location)){var w,V;do{var b=2*u.nextDouble()*Math.PI,E=.006*(n.right-n.left)*Math.cos(b),G=.006*(n.bottom-n.top)*Math.sin(b);w=x.location.x+E,V=x.location.y+G}while(n.left>w||w>n.right||n.top>V||V>n.bottom);x.location.x=w,x.location.y=V}o.push(n,x),o.push(n,r)}else n.body=r}},v=function(e){var t,n,o,s,c=i,f=1,l=0,h=1;for(c[0]=d;f;){var p=c[l],v=p.body;f-=1,l+=1,v&&v!==e?(n=v.location.x-e.location.x,o=v.location.y-e.location.y,s=Math.sqrt(n*n+o*o),0===s&&(n=(u.nextDouble()-.5)/50,o=(u.nextDouble()-.5)/50,s=Math.sqrt(n*n+o*o)),t=r*v.mass*e.mass/(s*s*s),e.force.x=e.force.x+t*n,e.force.y=e.force.y+t*o):(n=p.massX/p.mass-e.location.x,o=p.massY/p.mass-e.location.y,s=Math.sqrt(n*n+o*o),0===s&&(n=(u.nextDouble()-.5)/50,o=(u.nextDouble()-.5)/50,s=Math.sqrt(n*n+o*o)),a>(p.right-p.left)/s?(t=r*p.mass*e.mass/(s*s*s),e.force.x=e.force.x+t*n,e.force.y=e.force.y+t*o):(p.quads[0]&&(c[h]=p.quads[0],f+=1,h+=1),p.quads[1]&&(c[h]=p.quads[1],f+=1,h+=1),p.quads[2]&&(c[h]=p.quads[2],f+=1,h+=1),p.quads[3]&&(c[h]=p.quads[3],f+=1,h+=1)))}},m=function(e){var t,n=Number.MAX_VALUE,r=Number.MAX_VALUE,i=Number.MIN_VALUE,o=Number.MIN_VALUE,a=e.bodies,u=a.length;for(t=u;t--;){var s=a[t].location.x,c=a[t].location.y;n>s&&(n=s),s>i&&(i=s),r>c&&(r=c),c>o&&(o=c)}var h=i-n,v=o-r;for(h>v?o=r+h:i=n+v,f=0,d=l(),d.left=n,d.right=i,d.top=r,d.bottom=o,t=u;t--;)p(a[t],d)};return{insert:p,init:m,update:v,options:function(e){return e?("number"==typeof e.gravity&&(r=e.gravity),"number"==typeof e.theta&&(a=e.theta),this):{gravity:r,theta:a}}}},Viva.Graph.Physics.dragForce=function(e){e||(e={});var t={coeff:e.coeff||.01};return{init:function(){},update:function(e){e.force.x-=t.coeff*e.velocity.x,e.force.y-=t.coeff*e.velocity.y},options:function(e){return e?("number"==typeof e.coeff&&(t.coeff=e.coeff),this):t}}},Viva.Graph.Physics.springForce=function(e){e=Viva.lazyExtend(e,{length:50,coeff:22e-5});var t=Viva.random("Random number 4.","Chosen by fair dice roll");return{init:function(){},update:function(n){var r=n.body1,i=n.body2,o=0>n.length?e.length:n.length,a=i.location.x-r.location.x,u=i.location.y-r.location.y,s=Math.sqrt(a*a+u*u);0===s&&(a=(t.nextDouble()-.5)/50,u=(t.nextDouble()-.5)/50,s=Math.sqrt(a*a+u*u));var c=s-o,f=(!n.coeff||0>n.coeff?e.coeff:n.coeff)*c/s*n.weight;r.force.x+=f*a,r.force.y+=f*u,i.force.x+=-f*a,i.force.y+=-f*u},options:function(t){return t?("number"==typeof t.length&&(e.length=t.length),"number"==typeof t.coeff&&(e.coeff=t.coeff),this):e}}},Viva.Graph.Physics=Viva.Graph.Physics||{},Viva.Graph.Physics.forceSimulator=function(e){var t=e,n=[],r=[],i=[],o=[];return{speedLimit:1,bodies:n,accumulate:function(){var e,t,a;for(e=i.length;e--;)i[e].init(this);for(e=o.length;e--;)o[e].init(this);for(e=n.length;e--;)for(a=n[e],a.force.x=0,a.force.y=0,t=0;i.length>t;t++)i[t].update(a);for(e=0;r.length>e;++e)for(t=0;o.length>t;t++)o[t].update(r[e])},run:function(e){return this.accumulate(),t.integrate(this,e)},addBody:function(e){if(!e)throw{message:"Cannot add null body to force simulator"};return n.push(e),e},removeBody:function(e){if(!e)return!1;var t=Viva.Graph.Utils.indexOfElementInArray(e,n);return 0>t?!1:n.splice(t,1)},addSpring:function(e,t,n,i,o){if(!e||!t)throw{message:"Cannot add null spring to force simulator"};if("number"!=typeof n)throw{message:"Spring length should be a number"};o="number"==typeof o?o:1;var a=new Viva.Graph.Physics.Spring(e,t,n,i>=0?i:-1,o);return r.push(a),a},removeSpring:function(e){if(!e)return!1;var t=Viva.Graph.Utils.indexOfElementInArray(e,r);return 0>t?!1:r.splice(t,1)},addBodyForce:function(e){if(!e)throw{message:"Cannot add mighty (unknown) force to the simulator"};i.push(e)},addSpringForce:function(e){if(!e)throw{message:"Cannot add unknown force to the simulator"};o.push(e)}}},Viva.Graph.Layout=Viva.Graph.Layout||{},Viva.Graph.Layout.forceDirected=function(e,t){var n=.001;if(!e)throw{message:"Graph structure cannot be undefined"};t=Viva.lazyExtend(t,{springLength:80,springCoeff:2e-4,gravity:-1.2,theta:.8,dragCoeff:.02});var r=Viva.Graph.Physics.forceSimulator(Viva.Graph.Physics.eulerIntegrator()),i=Viva.Graph.Physics.nbodyForce({gravity:t.gravity,theta:t.theta}),o=Viva.Graph.Physics.springForce({length:t.springLength,coeff:t.springCoeff}),a=Viva.Graph.Physics.dragForce({coeff:t.dragCoeff}),u=new Viva.Graph.Rect,s=Viva.random("ted.com",103,114,101,97,116),c=function(n){var r=(u.x1+u.x2)/2,i=(u.y1+u.y2)/2,o=t.springLength;if(n.links&&n.links.length>0){var a=n.links[0],c=a.fromId!==n.id?e.getNode(a.fromId):e.getNode(a.toId);c.position&&(r=c.position.x,i=c.position.y)}return{x:r+s.next(o)-o/2,y:i+s.next(o)-o/2}},f=function(t){var n=t.force_directed_body;n.mass=1+e.getLinks(t.id).length/3},l=function(e){var t=e.force_directed_body;t||(e.position=e.position||c(e),t=new Viva.Graph.Physics.Body,e.force_directed_body=t,f(e),t.loc(e.position),r.addBody(t))},d=function(e){var t=e.force_directed_body;t&&(e.force_directed_body=null,delete e.force_directed_body,r.removeBody(t))},h=function(t){var n=e.getNode(t.fromId),i=e.getNode(t.toId);f(n),f(i),t.force_directed_spring=r.addSpring(n.force_directed_body,i.force_directed_body,-1,t.weight)},p=function(t){var n=t.force_directed_spring;if(n){var i=e.getNode(t.fromId),o=e.getNode(t.toId);i&&f(i),o&&f(o),t.force_directed_spring=null,delete t.force_directed_spring,r.removeSpring(n)}},v=function(e){for(var t=0;e.length>t;++t){var n=e[t];"add"===n.changeType?(n.node&&l(n.node),n.link&&h(n.link)):"remove"===n.changeType&&(n.node&&d(n.node),n.link&&p(n.link))}},m=function(){e.forEachNode(l),e.forEachLink(h),e.addEventListener("changed",v)},g=function(e){return e?e.isPinned||e.data&&e.data.isPinned:!0},y=function(){var t=Number.MAX_VALUE,n=Number.MAX_VALUE,r=Number.MIN_VALUE,i=Number.MIN_VALUE;0!==e.getNodesCount()&&(e.forEachNode(function(e){var o=e.force_directed_body;o&&(g(e)&&o.loc(e.position),e.position.x=o.location.x,e.position.y=o.location.y,t>e.position.x&&(t=e.position.x),e.position.x>r&&(r=e.position.x),n>e.position.y&&(n=e.position.y),e.position.y>i&&(i=e.position.y))}),u.x1=t,u.x2=r,u.y1=n,u.y2=i)};return r.addSpringForce(o),r.addBodyForce(i),r.addBodyForce(a),m(),{run:function(e){var t;for(e=e||50,t=0;e>t;++t)this.step()},step:function(){var e=r.run(20);return y(),n>e},getGraphRect:function(){return u},dispose:function(){e.removeEventListener("change",v)},springLength:function(e){return 1===arguments.length?(o.options({length:e}),this):o.options().length},springCoeff:function(e){return 1===arguments.length?(o.options({coeff:e}),this):o.options().coeff},gravity:function(e){return 1===arguments.length?(i.options({gravity:e}),this):i.options().gravity},theta:function(e){return 1===arguments.length?(i.options({theta:e}),this):i.options().theta},drag:function(e){return 1===arguments.length?(a.options({coeff:e}),this):a.options().coeff}}},Viva.Graph.Layout=Viva.Graph.Layout||{},Viva.Graph.Layout.constant=function(e,t){t=Viva.lazyExtend(t,{maxX:1024,maxY:1024,seed:"Deterministic randomness made me do this"});var n=Viva.random(t.seed),r=new Viva.Graph.Rect(Number.MAX_VALUE,Number.MAX_VALUE,Number.MIN_VALUE,Number.MIN_VALUE),i=function(){return new Viva.Graph.Point2d(n.next(t.maxX),n.next(t.maxY))},o=function(e,t){e.position.xt.x2&&(t.x2=e.position.x),e.position.yt.y2&&(t.y2=e.position.y)},a=function(e){e.hasOwnProperty("position")||(e.position=i(e)),o(e,r)},u=function(){0!==e.getNodesCount()&&(r.x1=Number.MAX_VALUE,r.y1=Number.MAX_VALUE,r.x2=Number.MIN_VALUE,r.y2=Number.MIN_VALUE,e.forEachNode(a))},s=function(e){for(var t=0;e.length>t;++t){var n=e[t];"add"===n.changeType&&n.node&&a(n.node)}};return{run:function(){this.step()},step:function(){return u(),!1},getGraphRect:function(){return r},dispose:function(){e.removeEventListener("change",s)},placeNode:function(e){return"function"==typeof e?(i=e,u(),this):i(e)}}},Viva.Graph.View=Viva.Graph.View||{},Viva.Graph.View.renderer=function(e,t){var n=30;t=t||{};var r,i,o,a,u=t.layout,s=t.graphics,c=t.container,f=!1,l=!0,d=0,h=0,p=!1,v=!1,m={x:0,y:0},g={offsetX:0,offsetY:0,scale:1},y=function(){c=c||window.document.body,u=u||Viva.Graph.Layout.forceDirected(e),s=s||Viva.Graph.View.svgGraphics(e,{container:c}),t.hasOwnProperty("renderLinks")||(t.renderLinks=!0),t.prerender=t.prerender||0,r=(s.inputManager||Viva.Input.domInputManager)(e,s)},x={x:0,y:0,node:null},w={x:0,y:0,node:null},V={x:0,y:0},b=Viva.Graph.Utils.events(window),E=Viva.Graph.Utils.events({}).extend(),G=function(t){var n=e.getNode(t.fromId),r=e.getNode(t.toId);n&&r&&(x.x=n.position.x,x.y=n.position.y,x.node=n,w.x=r.position.x,w.y=r.position.y,w.node=r,s.updateLinkPosition(t.ui,x,w))},P=function(e){V.x=e.position.x,V.y=e.position.y,s.updateNodePosition(e.ui,V)},N=function(){s.beginRender(),t.renderLinks&&!s.omitLinksRendering&&e.forEachLink(G),e.forEachNode(P),s.endRender()},_=function(){return p=u.step()&&!v,N(),!p},L=function(e){return i?(h+=e,void 0):(e?(h+=e,i=Viva.Graph.Utils.timer(function(){return _()},n)):(d=0,h=0,i=Viva.Graph.Utils.timer(_,n)),void 0)},A=function(){p=!1,i.restart()},I=function(){var e;if("number"==typeof t.prerender&&t.prerender>0)for(e=0;t.prerender>e;e+=1)u.step()},k=function(){var e=u.getGraphRect(),t=Viva.Graph.Utils.getDimension(c);m.x=m.y=0,g.offsetX=t.width/2-(e.x2+e.x1)/2,g.offsetY=t.height/2-(e.y2+e.y1)/2,s.graphCenterChanged(g.offsetX+m.x,g.offsetY+m.y),l=!1},T=function(e){var t=s.node(e);e.ui=t,s.initNode(t),P(e)},C=function(e){e.hasOwnProperty("ui")&&(s.releaseNode(e.ui),e.ui=null,delete e.ui)},M=function(e){var t=s.link(e);e.ui=t,s.initLink(t),s.omitLinksRendering||G(e)},S=function(e){e.hasOwnProperty("ui")&&(s.releaseLink(e.ui),e.ui=null,delete e.ui)},U=function(e){var t=!1;r.bindDragNDrop(e,{onStart:function(){t=e.isPinned,e.isPinned=!0,v=!0,A()},onDrag:function(t,n){e.position.x+=n.x/g.scale,e.position.y+=n.y/g.scale,v=!0,N()},onStop:function(){e.isPinned=t,v=!1}})},R=function(e){r.bindDragNDrop(e,null)},D=function(){s.init(c),e.forEachNode(T),t.renderLinks&&e.forEachLink(M)},F=function(){s.release(c)},O=function(t){var n=t.node;"add"===t.changeType?(T(n),U(n),l&&k()):"remove"===t.changeType?(R(n),C(n),0===e.getNodesCount()&&(l=!0)):"update"===t.changeType&&(R(n),C(n),T(n),U(n))},z=function(e){var n=e.link;if("add"===e.changeType)t.renderLinks&&M(n);else if("remove"===e.changeType)t.renderLinks&&S(n);else if("update"===e.changeType)throw"Update type is not implemented. TODO: Implement me!"},B=function(e){var t,n;for(t=0;e.length>t;t+=1)n=e[t],n.node?O(n):n.link&&z(n);A()},Y=function(){k(),_()},X=function(){a&&(a.release(),a=null)},q=function(){o&&(o.stop("changed",B),o=null)},W=function(){b.on("resize",Y),X(),a=Viva.Graph.Utils.dragndrop(c),a.onDrag(function(e,t){m.x+=t.x,m.y+=t.y,s.translateRel(t.x,t.y),N()}),a.onScroll(function(e,t,n){var r=Math.pow(1.4,0>t?-.2:.2);g.scale=s.scale(r,n),N(),E.fire("scale",g.scale)}),e.forEachNode(U),q(),o=Viva.Graph.Utils.events(e),o.on("changed",B)},j=function(){f=!1,q(),X(),b.stop("resize",Y),E.removeAllListeners(),i.stop(),e.forEachLink(function(e){t.renderLinks&&S(e)}),e.forEachNode(function(e){R(e),C(e)}),u.dispose(),F()};return{run:function(e){return f||(y(),I(),k(),D(),W(),f=!0),L(e),this},reset:function(){s.resetScale(),k(),g.scale=1},pause:function(){i.stop()},resume:function(){i.restart()},rerender:function(){return N(),this},dispose:function(){j()},on:function(e,t){return E.addEventListener(e,t),this},off:function(e,t){return E.removeEventListener(e,t),this}}},Viva.Graph.serializer=function(){var e=function(){if("undefined"==typeof JSON||!JSON.stringify||!JSON.parse)throw"JSON serializer is not defined."},t=function(e){return{id:e.id,data:e.data}},n=function(e){return{fromId:e.fromId,toId:e.toId,data:e.data}},r=function(e){return e},i=function(e){return e};return{storeToJSON:function(r,i,o){if(!r)throw"Graph is not defined";e(),i=i||t,o=o||n;var a={nodes:[],links:[]};return r.forEachNode(function(e){a.nodes.push(i(e))}),r.forEachLink(function(e){a.links.push(o(e))}),JSON.stringify(a)},loadFromJSON:function(t,n,o){if("string"!=typeof t)throw"String expected in loadFromJSON() method";e(),n=n||r,o=o||i;var a,u=JSON.parse(t),s=Viva.Graph.graph();if(!u||!u.nodes||!u.links)throw"Passed json string does not represent valid graph";for(a=0;u.nodes.length>a;++a){var c=n(u.nodes[a]);if(!c.hasOwnProperty("id"))throw"Graph node format is invalid. Node.id is missing";s.addNode(c.id,c.data)}for(a=0;u.links.length>a;++a){var f=o(u.links[a]);if(!f.hasOwnProperty("fromId")||!f.hasOwnProperty("toId"))throw"Graph link format is invalid. Both fromId and toId are required";s.addLink(f.fromId,f.toId,f.data)}return s}}},Viva.Graph.centrality=function(){var e=function(e,t,n){var r,i,o,a={},u=[],s={},c={},f=[t.id],l=function(e){c.hasOwnProperty(e.id)||(f.push(e.id),c[e.id]=i+1),c[e.id]===i+1&&(s[e.id]+=o,a[e.id].push(r))};for(e.forEachNode(function(e){a[e.id]=[],s[e.id]=0}),c[t.id]=0,s[t.id]=1;f.length;)r=f.shift(),i=c[r],o=s[r],u.push(r),e.forEachLinkedNode(r,l,n);return{S:u,P:a,sigma:s}},t=function(e,t,n){var r,i,o,a,u,s={},c=t.S;for(r=0;c.length>r;r+=1)s[c[r]]=0;for(;c.length;){for(i=c.pop(),o=(1+s[i])/t.sigma[i],a=t.P[i],r=0;a.length>r;r+=1)u=a[r],s[u]+=t.sigma[u]*o;i!==n&&(e[i]+=s[i])}},n=function(e){var t,n=[];for(t in e)e.hasOwnProperty(t)&&n.push({key:t,value:e[t]});return n.sort(function(e,t){return t.value-e.value})};return{betweennessCentrality:function(r){var i,o={};return r.forEachNode(function(e){o[e.id]=0}),r.forEachNode(function(n){i=e(r,n),t(o,i,n)}),n(o)},degreeCentrality:function(e,t){var n,r,i=[],o=[];if(t=(t||"both").toLowerCase(),"in"===t)n=function(e,t){var n,r=0;for(n=0;e.length>n;n+=1)r+=e[n].toId===t?1:0;return r};else if("out"===t)n=function(e,t){var n,r=0;for(n=0;e.length>n;n+=1)r+=e[n].fromId===t?1:0;return r};else{if("both"!==t)throw"Expected centrality degree kind is: in, out or both";n=function(e){return e.length}}e.forEachNode(function(t){var r=e.getLinks(t.id),o=n(r,t.id);i.hasOwnProperty(o)?i[o].push(t.id):i[o]=[t.id]});for(r in i)if(i.hasOwnProperty(r)){var a,u=i[r];if(u)for(a=0;u.length>a;++a)o.unshift({key:u[a],value:parseInt(r,10)})}return o}}},Viva.Graph.community=function(){return{slpa:function(e,t,n){var r=Viva.Graph._community.slpaAlgorithm(e,t,n);return r.run()}}},Viva.Graph._community={},Viva.Graph._community.slpaAlgorithm=function(e,t,n){t=t||100,n=n||.3;var r=Viva.random(1331782216905),i=Viva.random("Greeting goes to you, ","dear reader"),o=function(e,n){var r=[];return e.forEachUniqueWord(function(e,i){return i>n?(r.push({name:e,probability:i/t}),void 0):!0}),r},a=function(e){var t=[];return e.forEachNode(function(e){var n=Viva.Graph._community.occuranceMap(r);n.add(e.id),e.slpa={memory:n},t.push(e.id)}),t},u=function(e,n){var o,a=Viva.randomIterator(n,i),u=function(t){var n=e.getNode(t),i=Viva.Graph._community.occuranceMap(r);e.forEachLinkedNode(t,function(e){var t=e.slpa.memory.getRandomWord();i.add(t)});var o=i.getMostPopularFair();n.slpa.memory.add(o)};for(o=0;t-1>o;++o)a.forEach(u)},s=function(e){var r={};return e.forEachNode(function(e){var i,a=o(e.slpa.memory,n*t);for(i=0;a.length>i;++i){var u=a[i].name;r.hasOwnProperty(u)?r[u].push(e.id):r[u]=[e.id]}e.communities=a,e.slpa=null,delete e.slpa}),r};return{run:function(){var t=a(e);return u(e,t),s(e)}}},Viva.Graph._community.occuranceMap=function(e){e=e||Viva.random();var t={},n=[],r=!1,i=[],o=function(){var e;i.length=0;for(e in t)t.hasOwnProperty(e)&&i.push(e);i.sort(function(e,n){var r=t[n]-t[e];return r?r:n>e?-1:e>n?1:0})},a=function(){r&&(o(),r=!1)};return{add:function(e){e+="",t.hasOwnProperty(e)?t[e]+=1:t[e]=1,n.push(e),r=!0},getWordCount:function(e){return t[e]||0},getMostPopularFair:function(){if(1===n.length)return n[0];a();var r,o=0;for(r=1;i.length>r&&t[i[r-1]]===t[i[r]];++r)o+=1;return o+=1,i[e.next(o)]},getRandomWord:function(){if(0===n.length)throw"The occurance map is empty. Cannot get empty word";return n[e.next(n.length)]},forEachUniqueWord:function(e){if("function"!=typeof e)throw"Function callback is expected to enumerate all words";var n;for(a(),n=0;i.length>n;++n){var r=i[n],o=t[r],u=e(r,o);if(u)break}}}},Viva.Graph.generator=function(){return{complete:function(e){if(!e||1>e)throw{message:"At least two nodes expected for complete graph"};var t,n,r=Viva.Graph.graph();for(r.Name="Complete K"+e,t=0;e>t;++t)for(n=t+1;e>n;++n)t!==n&&r.addLink(t,n);return r},completeBipartite:function(e,t){if(!e||!t||0>e||0>t)throw{message:"Graph dimensions are invalid. Number of nodes in each partition should be greate than 0"};var n,r,i=Viva.Graph.graph();for(i.Name="Complete K "+e+","+t,n=0;e>n;++n)for(r=e;e+t>r;++r)i.addLink(n,r);
return i},ladder:function(e){if(!e||0>e)throw{message:"Invalid number of nodes"};var t,n=Viva.Graph.graph();for(n.Name="Ladder graph "+e,t=0;e-1>t;++t)n.addLink(t,t+1),n.addLink(e+t,e+t+1),n.addLink(t,e+t);return n.addLink(e-1,2*e-1),n},circularLadder:function(e){if(!e||0>e)throw{message:"Invalid number of nodes"};var t=this.ladder(e);return t.Name="Circular ladder graph "+e,t.addLink(0,e-1),t.addLink(e,2*e-1),t},grid:function(e,t){var n,r,i=Viva.Graph.graph();for(i.Name="Grid graph "+e+"x"+t,n=0;e>n;++n)for(r=0;t>r;++r){var o=n+r*e;n>0&&i.addLink(o,n-1+r*e),r>0&&i.addLink(o,n+(r-1)*e)}return i},path:function(e){if(!e||0>e)throw{message:"Invalid number of nodes"};var t,n=Viva.Graph.graph();for(n.Name="Path graph "+e,n.addNode(0),t=1;e>t;++t)n.addLink(t-1,t);return n},lollipop:function(e,t){if(!t||0>t||!e||0>e)throw{message:"Invalid number of nodes"};var n,r=this.complete(e);for(r.Name="Lollipop graph. Head x Path "+e+"x"+t,n=0;t>n;++n)r.addLink(e+n-1,e+n);return r},balancedBinTree:function(e){var t,n=Viva.Graph.graph(),r=Math.pow(2,e);for(n.Name="Balanced bin tree graph "+e,t=1;r>t;++t){var i=t,o=2*i,a=2*i+1;n.addLink(i,o),n.addLink(i,a)}return n},randomNoLinks:function(e){if(!e||0>e)throw{message:"Invalid number of nodes"};var t,n=Viva.Graph.graph();for(n.Name="Random graph, no Links: "+e,t=0;e>t;++t)n.addNode(t);return n}}},Viva.Graph.View=Viva.Graph.View||{},Viva.Graph.View.cssGraphics=function(){var e,t,n,r="OLD_IE",i=1,o=1,a=function(){var e,t,n=Viva.BrowserInfo.browser;switch(n){case"mozilla":e="Moz";break;case"webkit":e="webkit";break;case"opera":e="O";break;case"msie":if(t=Viva.BrowserInfo.version.split(".")[0],!(t>8))return r;e="ms"}return e?e+"Transform":null}(),u=function(){return a===r?function(e,t,n,r){var i=Math.cos(r),o=Math.sin(r);0>r&&(r=2*Math.PI+r),Math.PI/2>r?(e.style.left=t+"px",e.style.top=n+"px"):Math.PI>r?(e.style.left=t-e.clientWidth*Math.cos(Math.PI-r),e.style.top=n):Math.PI+Math.PI/2>r?(e.style.left=t-e.clientWidth*Math.cos(Math.PI-r),e.style.top=n+e.clientWidth*Math.sin(Math.PI-r)):(e.style.left=t,e.style.top=n+e.clientWidth*Math.sin(Math.PI-r)),e.style.filter='progid:DXImageTransform.Microsoft.Matrix(sizingMethod="auto expand",M11='+i+", M12="+-o+","+"M21="+o+", M22="+i+");"}:a?function(e,t,n,r){e.style.left=t+"px",e.style.top=n+"px",e.style[a]="rotate("+r+"rad)",e.style[a+"Origin"]="left"}:function(){}}(),s=function(){var e=window.document.createElement("div");return e.setAttribute("class","node"),e},c=function(e,t){e.style.left=t.x-5+"px",e.style.top=t.y-5+"px"},f=function(e,t,n){var r=t.x-n.x,i=t.y-n.y,o=Math.sqrt(r*r+i*i);e.style.height="1px",e.style.width=o+"px",u(e,n.x,n.y,Math.atan2(i,r))},l=function(){var e=window.document.createElement("div");return e.setAttribute("class","link"),e},d=function(){if(e){if(!a||a===r)throw"Not implemented. TODO: Implement OLD_IE Filter based transform";var u="matrix("+i+", 0, 0,"+o+","+t+","+n+")";e.style[a]=u}};return{node:function(e){return e&&"function"!=typeof e?s(e):(s=e,this)},link:function(e){return e&&"function"!=typeof e?l(e):(l=e,this)},inputManager:Viva.Input.domInputManager,graphCenterChanged:function(e,r){t=e,n=r,d()},translateRel:function(e,r){t+=e,n+=r,d()},scale:function(){return 1},resetScale:function(){return this},beginRender:function(){},endRender:function(){},placeNode:function(e){return c=e,this},placeLink:function(e){return f=e,this},init:function(t){e=t,d()},initLink:function(t){e.childElementCount>0?e.insertBefore(t,e.firstChild):e.appendChild(t)},releaseLink:function(t){e.removeChild(t)},initNode:function(t){e.appendChild(t)},releaseNode:function(t){e.removeChild(t)},updateNodePosition:function(e,t){c(e,t)},updateLinkPosition:function(e,t,n){f(e,t,n)}}},Viva.Graph.svg=function(e){var t="http://www.w3.org/2000/svg",n="http://www.w3.org/1999/xlink",r=e;return"string"==typeof e&&(r=window.document.createElementNS(t,e)),r.vivagraphAugmented?r:(r.vivagraphAugmented=!0,r.attr=function(e,t){return 2===arguments.length?(null!==t?r.setAttributeNS(null,e,t):r.removeAttributeNS(null,e),r):r.getAttributeNS(null,e)},r.append=function(e){var t=Viva.Graph.svg(e);return r.appendChild(t),t},r.text=function(e){return e!==void 0?(r.textContent=e,r):r.textContent},r.link=function(e){return arguments.length?(r.setAttributeNS(n,"xlink:href",e),r):r.getAttributeNS(n,"xlink:href")},r.children=function(e){var t,n,i=[],o=r.childNodes.length;if(void 0===e&&r.hasChildNodes())for(t=0;o>t;t++)i.push(Viva.Graph.svg(r.childNodes[t]));else if("string"==typeof e){var a="."===e[0],u="#"===e[0],s=!a&&!u;for(t=0;o>t;t++){var c=r.childNodes[t];if(1===c.nodeType){var f=c.attr("class"),l=c.attr("id"),d=c.nodeName;if(a&&f){for(f=f.replace(/\s+/g," ").split(" "),n=0;f.length>n;n++)if(a&&f[n]===e.substr(1)){i.push(Viva.Graph.svg(c));break}}else{if(u&&l===e.substr(1)){i.push(Viva.Graph.svg(c));break}s&&d===e&&i.push(Viva.Graph.svg(c))}i=i.concat(Viva.Graph.svg(c).children(e))}}if(u&&1===i.length)return i[0]}return i},r)},Viva.Graph.View=Viva.Graph.View||{},Viva.Graph.View.svgGraphics=function(){var e,t,n,r,i=1,o=function(){return Viva.Graph.svg("rect").attr("width",10).attr("height",10).attr("fill","#00a2e8")},a=function(e,t){e.attr("x",t.x-5).attr("y",t.y-5)},u=function(){return Viva.Graph.svg("line").attr("stroke","#999")},s=function(e,t,n){e.attr("x1",t.x).attr("y1",t.y).attr("x2",n.x).attr("y2",n.y)},c=function(e){e.fire("rescaled")},f=function(){if(e){var t="matrix("+i+", 0, 0,"+i+","+n+","+r+")";e.attr("transform",t)}},l={node:function(e){return e&&"function"!=typeof e?o(e):(o=e,this)},link:function(e){return e&&"function"!=typeof e?u(e):(u=e,this)},placeNode:function(e){return a=e,this},placeLink:function(e){return s=e,this},beginRender:function(){},endRender:function(){},graphCenterChanged:function(e,t){n=e,r=t,f()},inputManager:Viva.Input.domInputManager,translateRel:function(n,r){var i=t.createSVGPoint(),o=e.getCTM(),a=t.createSVGPoint().matrixTransform(o.inverse());i.x=n,i.y=r,i=i.matrixTransform(o.inverse()),i.x=(i.x-a.x)*o.a,i.y=(i.y-a.y)*o.d,o.e+=i.x,o.f+=i.y;var u="matrix("+o.a+", 0, 0,"+o.d+","+o.e+","+o.f+")";e.attr("transform",u)},scale:function(o,a){var u=t.createSVGPoint();u.x=a.x,u.y=a.y,u=u.matrixTransform(e.getCTM().inverse());var s=t.createSVGMatrix().translate(u.x,u.y).scale(o).translate(-u.x,-u.y),f=e.getCTM().multiply(s);i=f.a,n=f.e,r=f.f;var l="matrix("+f.a+", 0, 0,"+f.d+","+f.e+","+f.f+")";return e.attr("transform",l),c(this),i},resetScale:function(){i=1;var t="matrix(1, 0, 0, 1, 0, 0)";return e.attr("transform",t),c(this),this},init:function(n){t=Viva.Graph.svg("svg"),e=Viva.Graph.svg("g").attr("buffered-rendering","dynamic"),t.appendChild(e),n.appendChild(t),f()},release:function(e){t&&e&&e.removeChild(t)},initLink:function(t){t&&(e.childElementCount>0?e.insertBefore(t,e.firstChild):e.appendChild(t))},releaseLink:function(t){e.removeChild(t)},initNode:function(t){e.appendChild(t)},releaseNode:function(t){e.removeChild(t)},updateNodePosition:function(e,t){a(e,t)},updateLinkPosition:function(e,t,n){s(e,t,n)},getSvgRoot:function(){return t}};return Viva.Graph.Utils.events(l).extend(),l},Viva.Graph.View.svgNodeFactory=function(e){var t="#999",n=Viva.Graph.geom(),r=function(e){e.size={w:10,h:10},e.append("rect").attr("width",e.size.w).attr("height",e.size.h).attr("stroke","orange").attr("fill","orange")},i=function(e){return e.size};return{node:function(e){var t=Viva.Graph.svg("g");return r(t,e),t.nodeId=e.id,t},link:function(n){var r=e.getNode(n.fromId),i=r&&r.ui;if(i&&!i.linksContainer){var o=Viva.Graph.svg("path").attr("stroke",t);return i.linksContainer=o,o}return null},customContent:function(e,t){if("function"!=typeof e||"function"!=typeof t)throw"Two functions expected: contentCreator(nodeUI, node) and size(nodeUI)";r=e,i=t},placeNode:function(t,r){var o="",a=i(t);e.forEachLinkedNode(t.nodeId,function(e,u){if(e.position&&e.ui&&e.ui!==t&&u.fromId===t.nodeId){var s=i(e.ui),c=e.position,f=n.intersectRect(r.x-a.w/2,r.y-a.h/2,r.x+a.w/2,r.y+a.h/2,r.x,r.y,c.x,c.y)||r,l=n.intersectRect(c.x-s.w/2,c.y-s.h/2,c.x+s.w/2,c.y+s.h/2,c.x,c.y,r.x,r.y)||c;o+="M"+Math.round(f.x)+" "+Math.round(f.y)+"L"+Math.round(l.x)+" "+Math.round(l.y)}}),t.attr("transform","translate("+(r.x-a.w/2)+", "+(r.y-a.h/2)+")"),""!==o&&t.linksContainer&&t.linksContainer.attr("d",o)}}},Viva.Graph.webgl=function(e){var t=function(t,n){var r=e.createShader(n);if(e.shaderSource(r,t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){var i=e.getShaderInfoLog(r);throw window.alert(i),i}return r};return{createProgram:function(n,r){var i=e.createProgram(),o=t(n,e.VERTEX_SHADER),a=t(r,e.FRAGMENT_SHADER);if(e.attachShader(i,o),e.attachShader(i,a),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS)){var u=e.getShaderInfoLog(i);throw window.alert(u),u}return i},extendArray:function(e,t,n){if((t+1)*n>e.length){var r=new Float32Array(2*e.length*n);return r.set(e),r}return e},copyArrayPart:function(e,t,n,r){var i;for(i=0;r>i;++i)e[t+i]=e[n+i]},swapArrayPart:function(e,t,n,r){var i;for(i=0;r>i;++i){var o=e[t+i];e[t+i]=e[n+i],e[n+i]=o}},getLocations:function(t,n){var r,i={};for(r=0;n.length>r;++r){var o=n[r],a=-1;if(0===o.indexOf("a_")){if(a=e.getAttribLocation(t,o),-1===a)throw"Program doesn't have required attribute: "+o;i[o.slice(2)]=a}else{if(0!==o.indexOf("u_"))throw"Couldn't figure out your intent. All uniforms should start with 'u_' prefix, and attributes with 'a_'";if(a=e.getUniformLocation(t,o),null===a)throw"Program doesn't have required uniform: "+o;i[o.slice(2)]=a}}return i},context:e}},Viva.Graph.View.WebglUtils=function(){},Viva.Graph.View.WebglUtils.prototype.parseColor=function(e){var t=10414335;if("string"==typeof e&&e)if(4===e.length&&(e=e.replace(/([^#])/g,"$1$1")),9===e.length)t=parseInt(e.substr(1),16);else{if(7!==e.length)throw'Color expected in hex format with preceding "#". E.g. #00ff00. Got value: '+e;t=255|parseInt(e.substr(1),16)<<8}else"number"==typeof e&&(t=e);return t},Viva.Graph.View._webglUtil=new Viva.Graph.View.WebglUtils,Viva.Graph.View.webglLine=function(e){return{color:Viva.Graph.View._webglUtil.parseColor(e)}},Viva.Graph.View.webglSquare=function(e,t){return{size:"number"==typeof e?e:10,color:Viva.Graph.View._webglUtil.parseColor(t)}},Viva.Graph.View.webglImage=function(e,t){return{_texture:0,_offset:0,size:"number"==typeof e?e:32,src:t}},Viva.Graph.View.webglNodeProgram=function(){var e,t,n,r,i,o,a,u,s,c=4,f=3*Float32Array.BYTES_PER_ELEMENT+Uint32Array.BYTES_PER_ELEMENT,l=["precision mediump float;","varying vec4 color;","void main(void) {"," gl_FragColor = color;","}"].join("\n"),d=["attribute vec3 a_vertexPos;","attribute vec4 a_color;","uniform vec2 u_screenSize;","uniform mat4 u_transform;","varying vec4 color;","void main(void) {"," gl_Position = u_transform * vec4(a_vertexPos.xy/u_screenSize, 0, 1);"," gl_PointSize = a_vertexPos.z * u_transform[0][0];"," color = a_color.abgr;","}"].join("\n"),h=new ArrayBuffer(16*f),p=new Float32Array(h),v=new Uint32Array(h),m=0,g=function(){if((m+1)*f>=h.byteLength){var e=new ArrayBuffer(2*h.byteLength),t=new Float32Array(e),n=new Uint32Array(e);n.set(v),p=t,v=n,h=e}};return{load:function(o){t=o,i=Viva.Graph.webgl(o),e=i.createProgram(d,l),t.useProgram(e),r=i.getLocations(e,["a_vertexPos","a_color","u_screenSize","u_transform"]),t.enableVertexAttribArray(r.vertexPos),t.enableVertexAttribArray(r.color),n=t.createBuffer()},position:function(e,t){var n=e.id;p[n*c]=t.x,p[n*c+1]=t.y,p[n*c+2]=e.size,v[n*c+3]=e.color},updateTransform:function(e){s=!0,u=e},updateSize:function(e,t){o=e,a=t,s=!0},removeNode:function(e){m>0&&(m-=1),m>e.id&&m>0&&i.copyArrayPart(v,e.id*c,m*c,c)},createNode:function(){g(),m+=1},replaceProperties:function(){},render:function(){t.useProgram(e),t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,h,t.DYNAMIC_DRAW),s&&(s=!1,t.uniformMatrix4fv(r.transform,!1,u),t.uniform2f(r.screenSize,o,a)),t.vertexAttribPointer(r.vertexPos,3,t.FLOAT,!1,c*Float32Array.BYTES_PER_ELEMENT,0),t.vertexAttribPointer(r.color,4,t.UNSIGNED_BYTE,!0,c*Float32Array.BYTES_PER_ELEMENT,12),t.drawArrays(t.POINTS,0,m)}}},Viva.Graph.View.webglLinkProgram=function(){var e,t,n,r,i,o,a,u,s,c,f=6,l=2*(2*Float32Array.BYTES_PER_ELEMENT+Uint32Array.BYTES_PER_ELEMENT),d=["precision mediump float;","varying vec4 color;","void main(void) {"," gl_FragColor = color;","}"].join("\n"),h=["attribute vec2 a_vertexPos;","attribute vec4 a_color;","uniform vec2 u_screenSize;","uniform mat4 u_transform;","varying vec4 color;","void main(void) {"," gl_Position = u_transform * vec4(a_vertexPos/u_screenSize, 0.0, 1.0);"," color = a_color.abgr;","}"].join("\n"),p=0,v=new ArrayBuffer(16*l),m=new Float32Array(v),g=new Uint32Array(v),y=function(){if((p+1)*l>v.byteLength){var e=new ArrayBuffer(2*v.byteLength),t=new Float32Array(e),n=new Uint32Array(e);n.set(g),m=t,g=n,v=e}};return{load:function(o){t=o,r=Viva.Graph.webgl(o),e=r.createProgram(h,d),t.useProgram(e),i=r.getLocations(e,["a_vertexPos","a_color","u_screenSize","u_transform"]),t.enableVertexAttribArray(i.vertexPos),t.enableVertexAttribArray(i.color),n=t.createBuffer()},position:function(e,t,n){var r=e.id,i=r*f;m[i]=t.x,m[i+1]=t.y,g[i+2]=e.color,m[i+3]=n.x,m[i+4]=n.y,g[i+5]=e.color},createLink:function(e){y(),p+=1,o=e.id},removeLink:function(e){p>0&&(p-=1),p>e.id&&p>0&&r.copyArrayPart(g,e.id*f,p*f,f)},updateTransform:function(e){c=!0,s=e},updateSize:function(e,t){a=e,u=t,c=!0},render:function(){t.useProgram(e),t.bindBuffer(t.ARRAY_BUFFER,n),t.bufferData(t.ARRAY_BUFFER,v,t.DYNAMIC_DRAW),c&&(c=!1,t.uniformMatrix4fv(i.transform,!1,s),t.uniform2f(i.screenSize,a,u)),t.vertexAttribPointer(i.vertexPos,2,t.FLOAT,!1,3*Float32Array.BYTES_PER_ELEMENT,0),t.vertexAttribPointer(i.color,4,t.UNSIGNED_BYTE,!0,3*Float32Array.BYTES_PER_ELEMENT,8),t.drawArrays(t.LINES,0,2*p),o=p-1},bringToFront:function(e){o>e.id&&r.swapArrayPart(m,e.id*f,o*f,f),o>0&&(o-=1)},getFrontLinkId:function(){return o}}},Viva.Graph.View.Texture=function(e){this.canvas=window.document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.isDirty=!1,this.canvas.width=this.canvas.height=e},Viva.Graph.View.webglAtlas=function(e){var t,n,r=Math.sqrt(e||1024)<<0,i=r,o=1,a={},u=0,s=[],c=[],f=function(e){return 0===(e&e-1)},l=function(){var e=new Viva.Graph.View.Texture(r*i);s.push(e)},d=function(t){var n=t/e<<0,i=t%e,o=i/r<<0,a=i%r;return{textureNumber:n,row:o,col:a}},h=function(){n.isDirty=!0,u=0,t=null},p=function(){t&&(window.clearTimeout(t),u+=1,t=null),u>10?h():t=window.setTimeout(h,400)},v=function(e,t){var n=s[e.textureNumber].canvas,r=s[t.textureNumber].ctx,o=t.col*i,a=t.row*i;r.drawImage(n,e.col*i,e.row*i,i,i,o,a,i,i),s[e.textureNumber].isDirty=!0,s[t.textureNumber].isDirty=!0},m=function(e,t,n){var r=d(e),o={offset:e};r.textureNumber>=s.length&&l();var u=s[r.textureNumber];u.ctx.drawImage(t,r.col*i,r.row*i,i,i),c[e]=t.src,a[t.src]=o,u.isDirty=!0,n(o)};if(!f(e))throw"Tiles per texture should be power of two.";return n={isDirty:!1,clearDirty:function(){var e;for(this.isDirty=!1,e=0;s.length>e;++e)s[e].isDirty=!1},remove:function(e){var t=a[e];if(!t)return!1;if(delete a[e],o-=1,o===t.offset)return!0;var n=d(t.offset),r=d(o);v(r,n);var i=a[c[o]];return i.offset=t.offset,c[t.offset]=c[o],p(),!0},getTextures:function(){return s},getCoordinates:function(e){return a[e]},load:function(e,t){if(a.hasOwnProperty(e))t(a[e]);else{var n=new window.Image,r=o;o+=1,n.crossOrigin="anonymous",n.onload=function(){p(),m(r,n,t)},n.src=e}}}},Viva.Graph.View.webglImageNodeProgram=function(){var e,t,n,r,i,o,a,u,s,c,f=18,l=["precision mediump float;","varying vec4 color;","varying vec3 vTextureCoord;","uniform sampler2D u_sampler0;","uniform sampler2D u_sampler1;","uniform sampler2D u_sampler2;","uniform sampler2D u_sampler3;","void main(void) {"," if (vTextureCoord.z == 0.) {"," gl_FragColor = texture2D(u_sampler0, vTextureCoord.xy);"," } else if (vTextureCoord.z == 1.) {"," gl_FragColor = texture2D(u_sampler1, vTextureCoord.xy);"," } else if (vTextureCoord.z == 2.) {"," gl_FragColor = texture2D(u_sampler2, vTextureCoord.xy);"," } else if (vTextureCoord.z == 3.) {"," gl_FragColor = texture2D(u_sampler3, vTextureCoord.xy);"," } else { gl_FragColor = vec4(0, 1, 0, 1); }","}"].join("\n"),d=["attribute vec2 a_vertexPos;","attribute float a_customAttributes;","uniform vec2 u_screenSize;","uniform mat4 u_transform;","uniform float u_tilesPerTexture;","varying vec3 vTextureCoord;","void main(void) {"," gl_Position = u_transform * vec4(a_vertexPos/u_screenSize, 0, 1);","float corner = mod(a_customAttributes, 4.);","float tileIndex = mod(floor(a_customAttributes / 4.), u_tilesPerTexture);","float tilesPerRow = sqrt(u_tilesPerTexture);","float tileSize = 1./tilesPerRow;","float tileColumn = mod(tileIndex, tilesPerRow);","float tileRow = floor(tileIndex/tilesPerRow);","if(corner == 0.0) {"," vTextureCoord.xy = vec2(0, 1);","} else if(corner == 1.0) {"," vTextureCoord.xy = vec2(1, 1);","} else if(corner == 2.0) {"," vTextureCoord.xy = vec2(0, 0);","} else {"," vTextureCoord.xy = vec2(1, 0);","}","vTextureCoord *= tileSize;","vTextureCoord.x += tileColumn * tileSize;","vTextureCoord.y += tileRow * tileSize;","vTextureCoord.z = floor(floor(a_customAttributes / 4.)/u_tilesPerTexture);","}"].join("\n"),h=1024,p=0,v=new Float32Array(64),m=function(e,t){e.nativeObject&&n.deleteTexture(e.nativeObject);var r=n.createTexture();n.activeTexture(n["TEXTURE"+t]),n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e.canvas),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_NEAREST),n.generateMipmap(n.TEXTURE_2D),n.uniform1i(o["sampler"+t],t),e.nativeObject=r},g=function(){if(e.isDirty){var t,n=e.getTextures();for(t=0;n.length>t;++t)(n[t].isDirty||!n[t].nativeObject)&&m(n[t],t);e.clearDirty()}};return{load:function(a){n=a,i=Viva.Graph.webgl(a),e=new Viva.Graph.View.webglAtlas(h),t=i.createProgram(d,l),n.useProgram(t),o=i.getLocations(t,["a_vertexPos","a_customAttributes","u_screenSize","u_transform","u_sampler0","u_sampler1","u_sampler2","u_sampler3","u_tilesPerTexture"]),n.uniform1f(o.tilesPerTexture,h),n.enableVertexAttribArray(o.vertexPos),n.enableVertexAttribArray(o.customAttributes),r=n.createBuffer()},position:function(e,t){var n=e.id*f;v[n]=t.x-e.size,v[n+1]=t.y-e.size,v[n+2]=4*e._offset,v[n+3]=t.x+e.size,v[n+4]=t.y-e.size,v[n+5]=4*e._offset+1,v[n+6]=t.x-e.size,v[n+7]=t.y+e.size,v[n+8]=4*e._offset+2,v[n+9]=t.x-e.size,v[n+10]=t.y+e.size,v[n+11]=4*e._offset+2,v[n+12]=t.x+e.size,v[n+13]=t.y-e.size,v[n+14]=4*e._offset+1,v[n+15]=t.x+e.size,v[n+16]=t.y+e.size,v[n+17]=4*e._offset+3},createNode:function(t){v=i.extendArray(v,p,f),p+=1;var n=e.getCoordinates(t.src);n?t._offset=n.offset:(t._offset=0,e.load(t.src,function(e){t._offset=e.offset}))},removeNode:function(t){p>0&&(p-=1),p>t.id&&p>0&&(t.src&&e.remove(t.src),i.copyArrayPart(v,t.id*f,p*f,f))},replaceProperties:function(e,t){t._offset=e._offset},updateTransform:function(e){c=!0,s=e},updateSize:function(e,t){a=e,u=t,c=!0},render:function(){n.useProgram(t),n.bindBuffer(n.ARRAY_BUFFER,r),n.bufferData(n.ARRAY_BUFFER,v,n.DYNAMIC_DRAW),c&&(c=!1,n.uniformMatrix4fv(o.transform,!1,s),n.uniform2f(o.screenSize,a,u)),n.vertexAttribPointer(o.vertexPos,2,n.FLOAT,!1,3*Float32Array.BYTES_PER_ELEMENT,0),n.vertexAttribPointer(o.customAttributes,1,n.FLOAT,!1,3*Float32Array.BYTES_PER_ELEMENT,8),g(),n.drawArrays(n.TRIANGLES,0,6*p)}}},Viva.Graph.View=Viva.Graph.View||{},Viva.Graph.View.webglGraphics=function(e){e=Viva.lazyExtend(e,{enableBlending:!0,preserveDrawingBuffer:!1,clearColor:!1,clearColorValue:{r:1,g:1,b:1,a:1}});var t,n,r,i,o,a,u,s,c,f=0,l=0,d=[],h=[],p=Viva.Graph.View.webglLinkProgram(),v=Viva.Graph.View.webglNodeProgram(),m=function(){return Viva.Graph.View.webglSquare()},g=function(){return Viva.Graph.View.webglLine(3014898687)},y=function(){p.updateTransform(a),v.updateTransform(a)},x=function(){a=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]},w=function(){t&&n&&(i=n.width=Math.max(t.offsetWidth,1),o=n.height=Math.max(t.offsetHeight,1),r&&r.viewport(0,0,i,o),p&&p.updateSize(i/2,o/2),v&&v.updateSize(i/2,o/2))},V=function(e){var t=f++,n=m(e);return n.id=t,v.createNode(n),d[t]=e,n},b=function(e){var t=l++,n=g(e);return n.id=t,p.createLink(n),h[t]=e,n},E=function(e){e.fire("rescaled")},G={node:function(e){return e&&"function"!=typeof e?V(e):(m=e,this)},link:function(e){return e&&"function"!=typeof e?b(e):(g=e,this)},placeNode:function(e){return u=e,this},placeLink:function(e){return s=e,this},inputManager:Viva.Input.webglInputManager,beginRender:function(){},endRender:function(){l>0&&p.render(),f>0&&v.render()},bringLinkToFront:function(e){var t,n,r=p.getFrontLinkId();p.bringToFront(e),r>e.id&&(t=e.id,n=h[r],h[r]=h[t],h[r].ui.id=r,h[t]=n,h[t].ui.id=t)},graphCenterChanged:function(){w()},initLink:function(){},initNode:function(){},translateRel:function(e,t){a[12]+=2*a[0]*e/i/a[0],a[13]-=2*a[5]*t/o/a[5],y()},scale:function(e,t){var n=2*t.x/i-1,r=1-2*t.y/o;return n-=a[12],r-=a[13],a[12]+=n*(1-e),a[13]+=r*(1-e),a[0]*=e,a[5]*=e,y(),E(this),a[0]},resetScale:function(){return x(),r&&(w(),y()),this},init:function(a){var u={};if(e.preserveDrawingBuffer&&(u.preserveDrawingBuffer=!0),t=a,n=window.document.createElement("canvas"),w(),x(),t.appendChild(n),r=n.getContext("experimental-webgl",u),!r){var s="Could not initialize WebGL. Seems like the browser doesn't support it.";throw window.alert(s),s}if(e.enableBlending&&(r.blendFunc(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA),r.enable(r.BLEND)),e.clearColor){var f=e.clearColorValue;r.clearColor(f.r,f.g,f.b,f.a),this.beginRender=function(){r.clear(r.COLOR_BUFFER_BIT)}}p.load(r),p.updateSize(i/2,o/2),v.load(r),v.updateSize(i/2,o/2),y(),"function"==typeof c&&c(n)},release:function(e){n&&e&&e.removeChild(n)},isSupported:function(){var e=window.document.createElement("canvas"),t=e&&e.getContext&&e.getContext("experimental-webgl");return t},releaseLink:function(e){l>0&&(l-=1),p.removeLink(e);var t=e.id;if(l>t){if(0===l||l===t)return;h[t]=h[l],h[t].ui.id=t}},releaseNode:function(e){if(f>0&&(f-=1),v.removeNode(e),f>e.id){var t=e.id;if(0===f||f===t)return;var n=d[f],r=d[t];d[t]=n,d[t].ui.id=t,v.replaceProperties(r.ui,n.ui)}},updateNodePosition:function(e,t){t.y=-t.y,u&&u(e,t),v.position(e,t)},updateLinkPosition:function(e,t,n){t.y=-t.y,n.y=-n.y,s&&s(e,t,n),p.position(e,t,n)},getGraphicsRoot:function(e){return"function"==typeof e&&(n?e(n):c=e),n},setNodeProgram:function(e){if(!r&&e)v=e;else if(e)throw"Not implemented. Cannot swap shader on the fly... yet."},setLinkProgram:function(e){if(!r&&e)p=e;else if(e)throw"Not implemented. Cannot swap shader on the fly... yet."},getGraphCoordinates:function(e){return e.x=2*e.x/i-1,e.y=1-2*e.y/o,e.x=(e.x-a[12])/a[0],e.y=(e.y-a[13])/a[5],e.x*=i/2,e.y*=-o/2,e}};return Viva.Graph.Utils.events(G).extend(),G},Viva.Graph.webglInputEvents=function(e,t){if(e.webglInputEvents)return e.webglInputEvents;var n,r,i=function(e,t,n){if(e.ui&&e.ui.size){var r=e.position,i=e.ui.size;return t>r.x-i&&r.x+i>t&&n>r.y-i&&r.y+i>n}return!0},o=null,a=Viva.Graph.spatialIndex(t,i),u=[],s=[],c=[],f=[],l=[],d=[],h=[],p=Viva.Graph.Utils.events(window.document),v=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},m=function(e){return v(e),!1},g=function(e,t){var n,r;for(n=0;e.length>n;n+=1)if(r=e[n].apply(void 0,t))return!0},y=function(t){var i={x:0,y:0},y=null,x=+new Date,w=function(e){g(l,[y,e]),i.x=e.clientX,i.y=e.clientY},V=function(){p.stop("mousemove",w),p.stop("mouseup",V)},b=function(){r=t.getBoundingClientRect()};window.addEventListener("resize",b),b(),t.addEventListener("mousemove",function(t){if(!o){var n,c=!1;i.x=t.clientX-r.left,i.y=t.clientY-r.top,e.getGraphCoordinates(i),n=a.getNodeAt(i.x,i.y),n&&y!==n?(y=n,c=c||g(u,[y])):null===n&&y!==n&&(c=c||g(s,[y]),y=null),c&&v(t)}}),t.addEventListener("mousedown",function(t){var o,u=!1;i.x=t.clientX-r.left,i.y=t.clientY-r.top,e.getGraphCoordinates(i),o=[a.getNodeAt(i.x,i.y),t],o[0]?(u=g(c,o),p.on("mousemove",w),p.on("mouseup",V),n=window.document.onselectstart,window.document.onselectstart=m,y=o[0]):y=null,u&&v(t)}),t.addEventListener("mouseup",function(t){var o,u=+new Date;i.x=t.clientX-r.left,i.y=t.clientY-r.top,e.getGraphCoordinates(i),o=[a.getNodeAt(i.x,i.y),t],o[0]&&(window.document.onselectstart=n,400>u-x&&o[0]===y?g(h,o):g(d,o),x=u,g(f,o)&&v(t))})};return e.getGraphicsRoot(y),e.webglInputEvents={mouseEnter:function(e){return"function"==typeof e&&u.push(e),this},mouseLeave:function(e){return"function"==typeof e&&s.push(e),this},mouseDown:function(e){return"function"==typeof e&&c.push(e),this},mouseUp:function(e){return"function"==typeof e&&f.push(e),this},mouseMove:function(e){return"function"==typeof e&&l.push(e),this},click:function(e){return"function"==typeof e&&d.push(e),this},dblClick:function(e){return"function"==typeof e&&h.push(e),this},mouseCapture:function(e){o=e},releaseMouseCapture:function(){o=null}},e.webglInputEvents},Viva.Input=Viva.Input||{},Viva.Input.webglInputManager=function(e,t){var n=Viva.Graph.webglInputEvents(t,e),r=null,i={},o={x:0,y:0};return n.mouseDown(function(e,t){r=e,o.x=t.clientX,o.y=t.clientY,n.mouseCapture(r);var a=i[e.ui.id];return a&&a.onStart&&a.onStart(t,o),!0}).mouseUp(function(e){n.releaseMouseCapture(r),r=null;var t=i[e.ui.id];return t&&t.onStop&&t.onStop(),!0}).mouseMove(function(e,t){if(r){var n=i[r.ui.id];return n&&n.onDrag&&n.onDrag(t,{x:t.clientX-o.x,y:t.clientY-o.y}),o.x=t.clientX,o.y=t.clientY,!0}}),{bindDragNDrop:function(e,t){i[e.ui.id]=t}}};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy