basb-cli
Version:
Blog as Second Brain!
2 lines (1 loc) • 6.1 kB
JavaScript
import{A as e,b as t,b8 as n,aY as d,bm as a,c as s,aP as o,D as i,bj as r,aM as h}from"./index.js";import{l as u}from"./linkSeriesData.js";function g(e){return"_EC_"+e}var p=function(){function e(e){this.type="graph",this.nodes=[],this.edges=[],this._nodesMap={},this._edgesMap={},this._directed=e||!1}return e.prototype.isDirected=function(){return this._directed},e.prototype.addNode=function(e,t){e=null==e?""+t:""+e;var n=this._nodesMap;if(!n[g(e)]){var d=new c(e,t);return d.hostGraph=this,this.nodes.push(d),n[g(e)]=d,d}console.error("Graph nodes have duplicate name or id")},e.prototype.getNodeByIndex=function(e){var t=this.data.getRawIndex(e);return this.nodes[t]},e.prototype.getNodeById=function(e){return this._nodesMap[g(e)]},e.prototype.addEdge=function(e,n,d){var a=this._nodesMap,s=this._edgesMap;if(t(e)&&(e=this.nodes[e]),t(n)&&(n=this.nodes[n]),e instanceof c||(e=a[g(e)]),n instanceof c||(n=a[g(n)]),e&&n){var o=e.id+"-"+n.id,i=new f(e,n,d);return i.hostGraph=this,this._directed&&(e.outEdges.push(i),n.inEdges.push(i)),e.edges.push(i),e!==n&&n.edges.push(i),this.edges.push(i),s[o]=i,i}},e.prototype.getEdgeByIndex=function(e){var t=this.edgeData.getRawIndex(e);return this.edges[t]},e.prototype.getEdge=function(e,t){e instanceof c&&(e=e.id),t instanceof c&&(t=t.id);var n=this._edgesMap;return this._directed?n[e+"-"+t]:n[e+"-"+t]||n[t+"-"+e]},e.prototype.eachNode=function(e,t){for(var n=this.nodes,d=n.length,a=0;a<d;a++)n[a].dataIndex>=0&&e.call(t,n[a],a)},e.prototype.eachEdge=function(e,t){for(var n=this.edges,d=n.length,a=0;a<d;a++)n[a].dataIndex>=0&&n[a].node1.dataIndex>=0&&n[a].node2.dataIndex>=0&&e.call(t,n[a],a)},e.prototype.breadthFirstTraverse=function(e,t,n,d){if(t instanceof c||(t=this._nodesMap[g(t)]),t){for(var a="out"===n?"outEdges":"in"===n?"inEdges":"edges",s=0;s<this.nodes.length;s++)this.nodes[s].__visited=!1;if(!e.call(d,t,null))for(var o=[t];o.length;){var i=o.shift(),r=i[a];for(s=0;s<r.length;s++){var h=r[s],u=h.node1===i?h.node2:h.node1;if(!u.__visited){if(e.call(d,u,i))return;o.push(u),u.__visited=!0}}}}},e.prototype.update=function(){for(var e=this.data,t=this.edgeData,n=this.nodes,d=this.edges,a=0,s=n.length;a<s;a++)n[a].dataIndex=-1;for(a=0,s=e.count();a<s;a++)n[e.getRawIndex(a)].dataIndex=a;t.filterSelf((function(e){var n=d[t.getRawIndex(e)];return n.node1.dataIndex>=0&&n.node2.dataIndex>=0}));for(a=0,s=d.length;a<s;a++)d[a].dataIndex=-1;for(a=0,s=t.count();a<s;a++)d[t.getRawIndex(a)].dataIndex=a},e.prototype.clone=function(){for(var t=new e(this._directed),n=this.nodes,d=this.edges,a=0;a<n.length;a++)t.addNode(n[a].id,n[a].dataIndex);for(a=0;a<d.length;a++){var s=d[a];t.addEdge(s.node1.id,s.node2.id,s.dataIndex)}return t},e}(),c=function(){function e(e,t){this.inEdges=[],this.outEdges=[],this.edges=[],this.dataIndex=-1,this.id=null==e?"":e,this.dataIndex=null==t?-1:t}return e.prototype.degree=function(){return this.edges.length},e.prototype.inDegree=function(){return this.inEdges.length},e.prototype.outDegree=function(){return this.outEdges.length},e.prototype.getModel=function(e){if(!(this.dataIndex<0))return this.hostGraph.data.getItemModel(this.dataIndex).getModel(e)},e.prototype.getAdjacentDataIndices=function(){for(var e={edge:[],node:[]},t=0;t<this.edges.length;t++){var n=this.edges[t];n.dataIndex<0||(e.edge.push(n.dataIndex),e.node.push(n.node1.dataIndex,n.node2.dataIndex))}return e},e.prototype.getTrajectoryDataIndices=function(){for(var e=n(),t=n(),d=0;d<this.edges.length;d++){var a=this.edges[d];if(!(a.dataIndex<0)){e.set(a.dataIndex,!0);for(var s=[a.node1],o=[a.node2],i=0;i<s.length;){var r=s[i];i++,t.set(r.dataIndex,!0);for(var h=0;h<r.inEdges.length;h++)e.set(r.inEdges[h].dataIndex,!0),s.push(r.inEdges[h].node1)}for(i=0;i<o.length;){var u=o[i];i++,t.set(u.dataIndex,!0);for(h=0;h<u.outEdges.length;h++)e.set(u.outEdges[h].dataIndex,!0),o.push(u.outEdges[h].node2)}}}return{edge:e.keys(),node:t.keys()}},e}(),f=function(){function e(e,t,n){this.dataIndex=-1,this.node1=e,this.node2=t,this.dataIndex=null==n?-1:n}return e.prototype.getModel=function(e){if(!(this.dataIndex<0))return this.hostGraph.edgeData.getItemModel(this.dataIndex).getModel(e)},e.prototype.getAdjacentDataIndices=function(){return{edge:[this.dataIndex],node:[this.node1.dataIndex,this.node2.dataIndex]}},e.prototype.getTrajectoryDataIndices=function(){var e=n(),t=n();e.set(this.dataIndex,!0);for(var d=[this.node1],a=[this.node2],s=0;s<d.length;){var o=d[s];s++,t.set(o.dataIndex,!0);for(var i=0;i<o.inEdges.length;i++)e.set(o.inEdges[i].dataIndex,!0),d.push(o.inEdges[i].node1)}for(s=0;s<a.length;){var r=a[s];s++,t.set(r.dataIndex,!0);for(i=0;i<r.outEdges.length;i++)e.set(r.outEdges[i].dataIndex,!0),a.push(r.outEdges[i].node2)}return{edge:e.keys(),node:t.keys()}},e}();function l(e,t){return{getValue:function(n){var d=this[e][t];return d.getStore().get(d.getDimensionIndex(n||"value"),this.dataIndex)},setVisual:function(n,d){this.dataIndex>=0&&this[e][t].setItemVisual(this.dataIndex,n,d)},getVisual:function(n){return this[e][t].getItemVisual(this.dataIndex,n)},setLayout:function(n,d){this.dataIndex>=0&&this[e][t].setItemLayout(this.dataIndex,n,d)},getLayout:function(){return this[e][t].getItemLayout(this.dataIndex)},getGraphicEl:function(){return this[e][t].getItemGraphicEl(this.dataIndex)},getRawIndex:function(){return this[e][t].getRawIndex(this.dataIndex)}}}function I(e,t,n,g,c){for(var f=new p(g),l=0;l<e.length;l++)f.addNode(d(e[l].id,e[l].name,l),l);var I=[],x=[],v=0;for(l=0;l<t.length;l++){var y=t[l],E=y.source,_=y.target;f.addEdge(E,_,v)&&(x.push(y),I.push(d(a(y.id,null),E+" > "+_)),v++)}var m,D=n.get("coordinateSystem");if("cartesian2d"===D||"polar"===D)m=s(e,n);else{var M=o.get(D),w=M&&M.dimensions||[];i(w,"value")<0&&w.concat(["value"]);var G=r(e,{coordDimensions:w,encodeDefine:n.getEncode()}).dimensions;(m=new h(G,n)).initData(e)}var j=new h(["value"],n);return j.initData(x,I),c&&c(m,j),u({mainData:m,struct:f,structAttr:"graph",datas:{node:m,edge:j},datasAttr:{node:"data",edge:"edgeData"}}),f.update(),f}e(c,l("hostGraph","data")),e(f,l("hostGraph","edgeData"));export{I as c};