UNPKG

@antv/g6

Version:

graph visualization frame work

2 lines 18.1 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@antv/g6")):"function"==typeof define&&define.amd?define(["@antv/g6"],e):"object"==typeof exports?exports.G6Plugins=e(require("@antv/g6")):t.G6Plugins=e(t.G6)}(window,function(t){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(i,r,function(e){return t[e]}.bind(null,r));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=80)}({12:function(t,e){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports=function(t){var e=void 0===t?"undefined":n(t);return null!==t&&"object"===e||"function"===e}},14:function(t,e){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports=function(t){return"object"===(void 0===t?"undefined":n(t))&&null!==t}},15:function(t,e,n){var i=n(14),r=n(4);t.exports=function(t){if(!i(t)||!r(t,"Object"))return!1;if(null===Object.getPrototypeOf(t))return!0;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}},16:function(t,e){t.exports=function(t,e){if(t["_wrap_"+e])return t["_wrap_"+e];var n=function(n){t[e](n)};return t["_wrap_"+e]=n,n}},17:function(t,e,n){var i=n(4);t.exports=function(t){return i(t,"String")}},2:function(t,e,n){var i=n(15),r=n(3),o=5;function a(t,e,n,s){for(var c in n=n||0,s=s||o,e)if(e.hasOwnProperty(c)){var u=e[c];null!==u&&i(u)?(i(t[c])||(t[c]={}),n<s?a(t[c],u,n+1,s):t[c]=e[c]):r(u)?(t[c]=[],t[c]=t[c].concat(u)):void 0!==u&&(t[c]=u)}}t.exports=function(){for(var t=new Array(arguments.length),e=t.length,n=0;n<e;n++)t[n]=arguments[n];for(var i=t[0],r=1;r<e;r++)a(i,t[r]);return i}},21:function(t,e){var n=document.createElement("table"),i=document.createElement("tr"),r=/^\s*<(\w+|!)[^>]*>/,o={tr:document.createElement("tbody"),tbody:n,thead:n,tfoot:n,td:i,th:i,"*":document.createElement("div")};t.exports=function(t){var e=r.test(t)&&RegExp.$1;e in o||(e="*");var n=o[e];t=t.replace(/(^\s*)|(\s*$)/g,""),n.innerHTML=""+t;var i=n.childNodes[0];return n.removeChild(i),i}},26:function(t,e){t.exports=function(t){return null===t||void 0===t}},3:function(t,e,n){var i=n(4),r=Array.isArray?Array.isArray:function(t){return i(t,"Array")};t.exports=r},39:function(t,e,n){function i(t,e,n){var i=t.x-e.x,r=t.y-e.y;return!n||Math.abs(i)>n||Math.abs(r)>n?Math.sqrt(i*i+r*r):n}function r(t,e){var n=(e.source.y-e.target.y)/(e.source.x-e.target.x),i=(n*n*e.source.x+n*(t.y-e.source.y)+t.x)/(n*n+1);return{x:i,y:n*(i-e.source.x)+e.source.y}}var o=function(t){function e(){return t.apply(this,arguments)||this}!function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}(e,t);var n=e.prototype;return n.getDefaultCfgs=function(){return{edgeBundles:[],edgePoints:[],K:.1,lambda:.1,divisions:1,divRate:2,cycles:6,iterations:90,iterRate:.6666667,bundleThreshold:.6,eps:1e-6,onLayoutEnd:function(){},onTick:function(){}}},n.init=function(){var t=this.get("graph"),e=this.get("onTick");this.set("tick",function(){e&&e(),t.refreshPositions()})},n.bundling=function(t){var e=this;if(e.set("data",t),!e.isTicking()){var n=t.edges,i=t.nodes,r=new Map,o=!1;if(i.forEach(function(t){null!==t.x&&null!==!t.y&&void 0!==t.x&&void 0!==!t.y||(o=!0),r.set(t.id,t)}),o)throw new Error("please layout the graph or assign x and y for nodes first");e.set("nodeIdMap",r);var a=e.get("divisions"),s=e.get("divRate"),c=e.divideEdges(a);e.set("edgePoints",c);var u=e.getEdgeBundles();e.set("edgeBundles",u);for(var g=e.get("cycles"),h=e.get("iterations"),f=e.get("iterRate"),d=e.get("lambda"),p=0;p<g;p++){for(var l=function(t){var i=[];n.forEach(function(t,n){if(t.source!==t.target){var o=r.get(t.source),s=r.get(t.target);i[n]=e.getEdgeForces({source:o,target:s},n,a,d);for(var u=0;u<a+1;u++)c[n][u].x+=i[n][u].x,c[n][u].y+=i[n][u].y}})},y=0;y<h;y++)l();d/=2,a*=s,h*=f,c=e.divideEdges(a),e.set("edgePoints",c)}n.forEach(function(t,e){t.source!==t.target&&(t.shape="polyline",t.controlPoints=c[e].slice(1,c[e].length-1))}),e.get("graph").refresh()}},n.updateBundling=function(t){var e=this,n=t.data;n&&e.set("data",n),e.get("ticking")&&e.set("ticking",!1),Object.keys(t).forEach(function(n){e.set(n,t[n])}),t.onTick&&e.set("tick",function(){t.onTick(),e.graph.refresh()}),e.bundling(n)},n.divideEdges=function(t){var e=this,n=e.get("data").edges,r=e.get("nodeIdMap"),o=e.get("edgePoints");return o&&void 0!==o||(o=[]),n.forEach(function(n,a){o[a]&&void 0!==o[a]||(o[a]=[]);var s=r.get(n.source),c=r.get(n.target);if(1===t)o[a].push({x:s.x,y:s.y}),o[a].push({x:.5*(s.x+c.x),y:.5*(s.y+c.y)}),o[a].push({x:c.x,y:c.y});else{var u=(o[a]&&o[a]!==[]?e.getEdgeLength(o[a]):i(s,c))/(t+1),g=u,h=[{x:s.x,y:s.y}];o[a].forEach(function(t,e){if(0!==e){for(var n=i(t,o[a][e-1]);n>g;){var r=g/n,s={x:o[a][e-1].x,y:o[a][e-1].y};s.x+=r*(t.x-o[a][e-1].x),s.y+=r*(t.y-o[a][e-1].y),h.push(s),n-=g,g=u}g-=n}}),h.push({x:c.x,y:c.y}),o[a]=h}}),o},n.getEdgeLength=function(t){var e=0;return t.forEach(function(n,r){0!==r&&(e+=i(n,t[r-1]))}),e},n.getEdgeBundles=function(){var t=this,e=t.get("data").edges,n=t.get("bundleThreshold"),i=t.get("nodeIdMap"),r=t.get("edgeBundles");return r||(r=[]),e.forEach(function(t,e){r[e]&&void 0!==r[e]||(r[e]=[])}),e.forEach(function(o,a){var s=i.get(o.source),c=i.get(o.target);e.forEach(function(e,o){if(!(o<=a)){var u=i.get(e.source),g=i.get(e.target);t.getBundleScore({source:s,target:c},{source:u,target:g})>=n&&(r[a].push(o),r[o].push(a))}})}),r},n.getBundleScore=function(t,e){return t.vx=t.target.x-t.source.x,t.vy=t.target.y-t.source.y,e.vx=e.target.x-e.source.x,e.vy=e.target.y-e.source.y,t.length=i({x:t.source.x,y:t.source.y},{x:t.target.x,y:t.target.y}),e.length=i({x:e.source.x,y:e.source.y},{x:e.target.x,y:e.target.y}),this.getAngleScore(t,e)*this.getScaleScore(t,e)*this.getPosisionScore(t,e)*this.getVisibilityScore(t,e)},n.getAngleScore=function(t,e){return function(t,e){return t.x*e.x+t.y*e.y}({x:t.vx,y:t.vy},{x:e.vx,y:e.vy})/(t.length*e.length)},n.getScaleScore=function(t,e){var n=(t.length+e.length)/2;return 2/(n/Math.min(t.length,e.length)+Math.max(t.length,e.length)/n)},n.getPosisionScore=function(t,e){var n=(t.length+e.length)/2;return n/(n+i({x:(t.source.x+t.target.x)/2,y:(t.source.y+t.target.y)/2},{x:(e.source.x+e.target.x)/2,y:(e.source.y+e.target.y)/2}))},n.getVisibilityScore=function(t,e){var n=this.getEdgeVisibility(t,e),i=this.getEdgeVisibility(e,t);return n<i?n:i},n.getEdgeVisibility=function(t,e){var n=r(e.source,t),o=r(e.target,t),a={x:(n.x+o.x)/2,y:(n.y+o.y)/2},s={x:(t.source.x+t.target.x)/2,y:(t.source.y+t.target.y)/2};return Math.max(0,1-2*i(a,s)/i(n,o))},n.getEdgeForces=function(t,e,n,r){for(var o=this.get("edgePoints"),a=this.get("K")/(i(t.source,t.target)*(n+1)),s=[{x:0,y:0}],c=1;c<n;c++){var u={x:0,y:0},g=this.getSpringForce({pre:o[e][c-1],cur:o[e][c],next:o[e][c+1]},a),h=this.getElectrostaticForce(c,e);u.x=r*(g.x+h.x),u.y=r*(g.y+h.y),s.push(u)}return s.push({x:0,y:0}),s},n.getSpringForce=function(t,e){var n=t.pre.x+t.next.x-2*t.cur.x,i=t.pre.y+t.next.y-2*t.cur.y;return{x:n*=e,y:i*=e}},n.getElectrostaticForce=function(t,e){var n=this.get("eps"),r=this.get("edgeBundles"),o=this.get("edgePoints"),a={x:0,y:0};return r[e].forEach(function(r){var s={x:o[r][t].x-o[e][t].x,y:o[r][t].y-o[e][t].y};if(Math.abs(s.x)>n||Math.abs(s.y)>n){var c=1/i(o[r][t],o[e][t]);a.x+=s.x*c,a.y+=s.y*c}}),a},n.isTicking=function(){return this.get("ticking")},n.getSimulation=function(){return this.get("forceSimulation")},n.destroy=function(){this.get("ticking")&&this.getSimulation().stop(),t.prototype.destroy.call(this)},e}(n(8));t.exports=o},4:function(t,e){var n={}.toString;t.exports=function(t,e){return n.call(t)==="[object "+e+"]"}},40:function(t,e,n){var i=n(8),r=n(9),o=function(t){function e(){return t.apply(this,arguments)||this}!function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}(e,t);var n=e.prototype;return n.getDefaultCfgs=function(){return{createDOM:!0,container:null,className:"g6-analyzer-menu",getContent:null,onShow:function(){},onHide:function(){}}},n.getEvents=function(){return{contextmenu:"onMenuShow"}},n.init=function(){if(this.get("createDOM")){var t=document.createElement("div");t.className=this.get("className"),r(t,{visibility:"hidden"});var e=this.get("container");e||(e=this.get("graph").get("container")),e.appendChild(t),this.set("menu",t)}},n.onMenuShow=function(t){var e=this,n=this.get("menu"),i=this.get("getContent"),o=this.get("onShow");if(i&&(n.innerHTML=i(t)),n){var a=this.get("graph"),s=a.get("width"),c=a.get("height"),u=n.getBoundingClientRect(),g=t.canvasX,h=t.canvasY;g+u.width>s&&(g=s-u.width,t.canvasX=g),h+u.height>c&&(h=c-u.height,t.canvasY=h),o&&!1===o(t)||r(n,{top:h,left:g,visibility:"visible"})}else o(t);var f=function(){e.onMenuHide()};document.body.addEventListener("click",f),this.set("handler",f)},n.onMenuHide=function(){var t=this.get("menu");!1!==this.get("onHide")()&&(t&&r(t,{visibility:"hidden"}),document.body.removeEventListener("click",this.get("handler")))},n.destroy=function(){var t=this.get("menu"),e=this.get("handler");t&&t.parentNode.removeChild(t),e&&document.body.removeEventListener("click",e)},e}(i);t.exports=o},41:function(t,e,n){var i=n(8),r=n(21),o=n(9),a=function(t){function e(){return t.apply(this,arguments)||this}!function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}(e,t);var n=e.prototype;return n.init=function(){var t=this.get("graph"),e=t.get("minZoom"),n=t.get("container"),i=t.get("canvas").get("el"),a=t.get("width"),s=t.get("height"),c=r('<div style="position: absolute; left:0;top:0;right:0;bottom:0;overflow: hidden;z-index: -1;"></div>'),u=r('<div class="g6-grid" style="position:absolute;transform-origin: 0% 0% 0px; background-image: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PHBhdHRlcm4gaWQ9ImdyaWQiIHdpZHRoPSI0MCIgaGVpZ2h0PSI0MCIgcGF0dGVyblVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+PHBhdGggZD0iTSAwIDEwIEwgNDAgMTAgTSAxMCAwIEwgMTAgNDAgTSAwIDIwIEwgNDAgMjAgTSAyMCAwIEwgMjAgNDAgTSAwIDMwIEwgNDAgMzAgTSAzMCAwIEwgMzAgNDAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2UwZTBlMCIgb3BhY2l0eT0iMC4yIiBzdHJva2Utd2lkdGg9IjEiLz48cGF0aCBkPSJNIDQwIDAgTCAwIDAgMCA0MCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZTBlMGUwIiBzdHJva2Utd2lkdGg9IjEiLz48L3BhdHRlcm4+PC9kZWZzPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JpZCkiLz48L3N2Zz4=)"></div>');c.appendChild(u),o(u,{width:a/e+"px",height:s/e+"px",left:0,top:0}),n.insertBefore(c,i),this.set("container",c),this.set("gridContainer",u)},n.getEvents=function(){return{viewportchange:"updateGrid"}},n.updateGrid=function(t){var e=this.get("gridContainer"),n=t.matrix,i="matrix("+n[0]+","+n[1]+","+n[3]+","+n[4]+",0,0)";o(e,{transform:i})},n.getContainer=function(){return this.get("container")},n.destroy=function(){this.get("graph").get("container").removeChild(this.get("container"))},e}(i);t.exports=a},42:function(e,n){e.exports=t},43:function(t,e,n){function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t}).apply(this,arguments)}var r=n(42).G,o=n(8),a=n(17),s=n(26),c=n(21),u=n(9),g=n(7),h=Math.max,f=function(t){function e(){return t.apply(this,arguments)||this}!function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}(e,t);var n=e.prototype;return n.init=function(){this.initContainer()},n.getDefaultCfgs=function(){return{container:null,className:"g6-minimap",viewportClassName:"g6-minimap-viewport",type:"default",size:[200,120],delegateStyle:{fill:"#40a9ff",stroke:"#096dd9"},refresh:!0}},n.getEvents=function(){return{beforepaint:"updateCanvas",beforeanimate:"disableRefresh",afteranimate:"enableRefresh",viewportchange:"disableOneRefresh"}},n.disableRefresh=function(){this.set("refresh",!1)},n.enableRefresh=function(){this.set("refresh",!0),this.updateCanvas()},n.disableOneRefresh=function(){this.set("viewportChange",!0)},n.initContainer=function(){var t=this.get("graph"),e=this.get("size"),n=this.get("className"),i=this.get("container"),o=c('<div class="'+n+'" style="width:'+e[0]+"px; height:"+e[1]+'px"></div>');a(i)&&(i=document.getElementById(i)),i?i.appendChild(o):t.get("container").appendChild(o),this.set("container",o);var s=c('<div class="g6-minimap-container"></div>');o.appendChild(s);var u=new r.Canvas({containerDOM:s,width:e[0],height:e[1],pixelRatio:t.get("pixelRatio")});this.set("canvas",u),this.updateCanvas()},n.initViewport=function(){var t,e,n,i,r,o,a,g=this,h=this._cfgs,f=h.size,d=h.graph,p=this.get("canvas").get("containerDOM"),l=c('<div class="'+h.viewportClassName+'" style="position:absolute;left:0;top:0;box-sizing:border-box;border: 2px solid #1980ff"></div>');p.addEventListener("mousedown",function(s){if(h.refresh=!1,s.target===l){var c=l.style;i=parseInt(c.left,10),r=parseInt(c.top,10),o=parseInt(c.width,10),a=parseInt(c.height,10),o>=f[0]||a>=f[1]||(n=!0,t=s.clientX,e=s.clientY)}},!1),p.addEventListener("mousemove",function(c){if(n&&!s(c.clientX)&&!s(c.clientY)){var h=t-c.clientX,p=e-c.clientY;i-h<0?h=i:i-h+o>f[0]&&(h=i+o-f[0]),r-p<0?p=r:r-p+a>f[1]&&(p=r+a-f[1]),u(l,{left:(i-=h)+"px",top:(r-=p)+"px"});var y=g.get("ratio");d.translate(h/y,p/y),t=c.clientX,e=c.clientY}},!1),p.addEventListener("mouseleave",function(){n=!1,h.refresh=!0},!1),p.addEventListener("mouseup",function(){n=!1,h.refresh=!0},!1),this.set("viewport",l),p.appendChild(l)},n.updateCanvas=function(){if(this.get("refresh")){this.get("viewportChange")&&(this.set("viewportChange",!1),this._updateViewport());var t=this.get("size"),e=this.get("graph"),n=this.get("canvas");switch(this.get("type")){case"default":this._updateGraphShapes();break;case"keyShape":this._updateKeyShapes();break;case"delegate":this._updateDelegateShapes();break;default:this._updateGraphShapes()}var i=n.getBBox(),r=h(i.width,e.get("width")),o=h(i.height,e.get("height")),a=n.get("pixelRatio"),s=Math.min(t[0]/r,t[1]/o);n.resetMatrix();var c=-(i.minX>0?0:i.minX),u=-(i.minY>0?0:i.minY);n.translate(c,u),n.scale(s*a,s*a);var g=(t[0]-r*s)/2,f=(t[1]-o*s)/2;n.translate(g*a,f*a),n.draw(),this.set("ratio",s),this.set("dx",g+c*s),this.set("dy",f+u*s),this._updateViewport()}},n._updateKeyShapes=function(){var t=this._cfgs.graph,e=this.get("canvas"),n=e.get("children")[0];n||(n=e.addGroup()).setMatrix(t.get("group").getMatrix());var i=t.getNodes();n.clear(),this._getGraphEdgeKeyShape(n),g(i,function(t){if(t.isVisible()){var e=n.addGroup();e.setMatrix(t.get("group").attr("matrix")),e.add(t.get("keyShape").clone())}})},n._updateGraphShapes=function(){var t=this.get("graph"),e=this.get("canvas"),n=t.get("group").clone();n.resetMatrix(),e.get("children")[0]=n},n._updateDelegateShapes=function(){var t=this._cfgs.graph,e=this.get("canvas"),n=e.get("children")[0]||e.addGroup(),r=this.get("delegateStyle");n.clear(),this._getGraphEdgeKeyShape(n),g(t.getNodes(),function(t){if(t.isVisible()){var e=t.getBBox();n.addShape("rect",{attrs:i({x:e.minX,y:e.minY,width:e.width,height:e.height},r)})}})},n._getGraphEdgeKeyShape=function(t){var e=this.get("graph");g(e.getEdges(),function(e){e.isVisible()&&t.add(e.get("keyShape").clone())})},n._updateViewport=function(){var t=this.get("ratio"),e=this.get("dx"),n=this.get("dy"),i=this.get("graph"),r=this.get("size"),o=i.get("width"),a=i.get("height"),s=i.getPointByCanvas(0,0),c=i.getPointByCanvas(o,a),g=this.get("viewport");g||this.initViewport();var h=(c.x-s.x)*t,f=(c.y-s.y)*t,d=s.x*t+e,p=s.y*t+n;h>r[0]&&(h=r[0]),f>r[1]&&(f=r[1]),this.set("ratio",t),u(g,{left:d>0?d+"px":0,top:p>0?p+"px":0,width:h+"px",height:f+"px"})},n.getCanvas=function(){return this.get("canvas")},n.getViewport=function(){return this.get("viewport")},n.getContainer=function(){return this.get("container")},n.destroy=function(){this.get("canvas").destroy();var t=this.get("container");t.parentNode.removeChild(t)},e}(o);t.exports=f},7:function(t,e,n){var i=n(12),r=n(3);t.exports=function(t,e){if(t)if(r(t))for(var n=0,o=t.length;n<o&&!1!==e(t[n],n);n++);else if(i(t))for(var a in t)if(t.hasOwnProperty(a)&&!1===e(t[a],a))break}},8:function(t,e,n){var i=n(2),r=n(7),o=n(16),a=function(){function t(t){this._cfgs=i(this.getDefaultCfgs(),t)}var e=t.prototype;return e.getDefaultCfgs=function(){return{}},e.initPlugin=function(t){var e=this;e.set("graph",t);var n=e.getEvents(),i={};r(n,function(n,r){var a=o(e,n);i[r]=a,t.on(r,a)}),this._events=i,this.init()},e.init=function(){},e.getEvents=function(){return{}},e.get=function(t){return this._cfgs[t]},e.set=function(t,e){this._cfgs[t]=e},e.destroy=function(){},e.destroyPlugin=function(){this.destroy();var t=this.get("graph"),e=this._events;r(e,function(e,n){t.off(n,e)}),this._events=null,this._cfgs=null,this.destroyed=!0},t}();t.exports=a},80:function(t,e,n){var i={Minimap:n(43),Grid:n(41),Menu:n(40),Bundling:n(39)};t.exports=i},9:function(t,e){t.exports=function(t,e){if(t)for(var n in e)e.hasOwnProperty(n)&&(t.style[n]=e[n]);return t}}})}); //# sourceMappingURL=g6Plugins.js.map