Team Ai
Apppublic

gbehem/Data_Visualization_Project_RQ2

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
graphlib-C3L5jDqv.js2 linesDownload Raw Back to assets
1import{y as v}from"./_Uint8Array-C0aUZfE0.js";import{_ as c,d as w,t as N}from"./isArrayLikeObject-Dx6-QZGQ.js";import{m as u}from"./_baseIsEqual-EYp9AUJI.js";import{t as E}from"./_baseUniq-Gs_9sAsL.js";import{i as p,n as _,o as a,r as g,t as L}from"./reduce-B_JYXBwk.js";import{t as j}from"./_baseFlatten-Be7p_si8.js";import{t as b}from"./isEmpty-CfmnKtgL.js";var D=w(function(t){return E(j(t,1,N,!0))}),P="\0",d="\0",C="",m=class{constructor(t={}){this._isDirected=Object.prototype.hasOwnProperty.call(t,"directed")?t.directed:!0,this._isMultigraph=Object.prototype.hasOwnProperty.call(t,"multigraph")?t.multigraph:!1,this._isCompound=Object.prototype.hasOwnProperty.call(t,"compound")?t.compound:!1,this._label=void 0,this._defaultNodeLabelFn=c(void 0),this._defaultEdgeLabelFn=c(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[d]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return v(t)||(t=c(t)),this._defaultNodeLabelFn=t,this}nodeCount(){return this._nodeCount}nodes(){return u(this._nodes)}sources(){var t=this;return p(this.nodes(),function(e){return b(t._in[e])})}sinks(){var t=this;return p(this.nodes(),function(e){return b(t._out[e])})}setNodes(t,e){var s=arguments,r=this;return a(t,function(n){s.length>1?r.setNode(n,e):r.setNode(n)}),this}setNode(t,e){return Object.prototype.hasOwnProperty.call(this._nodes,t)?(arguments.length>1&&(this._nodes[t]=e),this):(this._nodes[t]=arguments.length>1?e:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]=d,this._children[t]={},this._children[d][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return Object.prototype.hasOwnProperty.call(this._nodes,t)}removeNode(t){if(Object.prototype.hasOwnProperty.call(this._nodes,t)){var e=s=>this.removeEdge(this._edgeObjs[s]);delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],a(this.children(t),s=>{this.setParent(s)}),delete this._children[t]),a(u(this._in[t]),e),delete this._in[t],delete this._preds[t],a(u(this._out[t]),e),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,e){if(!this._isCompound)throw Error("Cannot set parent in a non-compound graph");if(_(e))e=d;else{e+="";for(var s=e;!_(s);s=this.parent(s))if(s===t)throw Error("Setting "+e+" as parent of "+t+" would create a cycle");this.setNode(e)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=e,this._children[e][t]=!0,this}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}parent(t){if(this._isCompound){var e=this._parent[t];if(e!==d)return e}}children(t){if(_(t)&&(t=d),this._isCompound){var e=this._children[t];if(e)return u(e)}else{if(t===d)return this.nodes();if(this.hasNode(t))return[]}}predecessors(t){var e=this._preds[t];if(e)return u(e)}successors(t){var e=this._sucs[t];if(e)return u(e)}neighbors(t){var e=this.predecessors(t);if(e)return D(e,this.successors(t))}isLeaf(t){return(this.isDirected()?this.successors(t):this.neighbors(t)).length===0}filterNodes(t){var e=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});e.setGraph(this.graph());var s=this;a(this._nodes,function(i,h){t(h)&&e.setNode(h,i)}),a(this._edgeObjs,function(i){e.hasNode(i.v)&&e.hasNode(i.w)&&e.setEdge(i,s.edge(i))});var r={};function n(i){var h=s.parent(i);return h===void 0||e.hasNode(h)?(r[i]=h,h):h in r?r[h]:n(h)}return this._isCompound&&a(e.nodes(),function(i){e.setParent(i,n(i))}),e}setDefaultEdgeLabel(t){return v(t)||(t=c(t)),this._defaultEdgeLabelFn=t,this}edgeCount(){return this._edgeCount}edges(){return g(this._edgeObjs)}setPath(t,e){var s=this,r=arguments;return L(t,function(n,i){return r.length>1?s.setEdge(n,i,e):s.setEdge(n,i),i}),this}setEdge(){var t,e,s,r,n=!1,i=arguments[0];typeof i=="object"&&i&&"v"in i?(t=i.v,e=i.w,s=i.name,arguments.length===2&&(r=arguments[1],n=!0)):(t=i,e=arguments[1],s=arguments[3],arguments.length>2&&(r=arguments[2],n=!0)),t=""+t,e=""+e,_(s)||(s=""+s);var h=l(this._isDirected,t,e,s);if(Object.prototype.hasOwnProperty.call(this._edgeLabels,h))return n&&(this._edgeLabels[h]=r),this;if(!_(s)&&!this._isMultigraph)throw Error("Cannot set a named edge when isMultigraph = false");this.setNode(t),this.setNode(e),this._edgeLabels[h]=n?r:this._defaultEdgeLabelFn(t,e,s);var o=F(this._isDirected,t,e,s);return t=o.v,e=o.w,Object.freeze(o),this._edgeObjs[h]=o,O(this._preds[e],t),O(this._sucs[t],e),this._in[e][h]=o,this._out[t][h]=o,this._edgeCount++,this}edge(t,e,s){var r=arguments.length===1?f(this._isDirected,arguments[0]):l(this._isDirected,t,e,s);return this._edgeLabels[r]}hasEdge(t,e,s){var r=arguments.length===1?f(this._isDirected,arguments[0]):l(this._isDirected,t,e,s);return Object.prototype.hasOwnProperty.call(this._edgeLabels,r)}removeEdge(t,e,s){var r=arguments.length===1?f(this._isDirected,arguments[0]):l(this._isDirected,t,e,s),n=this._edgeObjs[r];return n&&(t=n.v,e=n.w,delete this._edgeLabels[r],delete this._edgeObjs[r],y(this._preds[e],t),y(this._sucs[t],e),delete this._in[e][r],delete this._out[t][r],this._edgeCount--),this}inEdges(t,e){var s=this._in[t];if(s){var r=g(s);return e?p(r,function(n){return n.v===e}):r}}outEdges(t,e){var s=this._out[t];if(s){var r=g(s);return e?p(r,function(n){return n.w===e}):r}}nodeEdges(t,e){var s=this.inEdges(t,e);if(s)return s.concat(this.outEdges(t,e))}};m.prototype._nodeCount=0,m.prototype._edgeCount=0;function O(t,e){t[e]?t[e]++:t[e]=1}function y(t,e){--t[e]||delete t[e]}function l(t,e,s,r){var n=""+e,i=""+s;if(!t&&n>i){var h=n;n=i,i=h}return n+C+i+C+(_(r)?P:r)}function F(t,e,s,r){var n=""+e,i=""+s;if(!t&&n>i){var h=n;n=i,i=h}var o={v:n,w:i};return r&&(o.name=r),o}function f(t,e){return l(t,e.v,e.w,e.name)}export{m as t};2