/*! * micro-graph. * https://www.github.com/ryansmith94/Graph * * Copyright 2013, ryansmith94 and contributors. * Released under the MIT license. * https://github.com/ryansmith94/Graph/blob/master/license.md * * Version 1.0.3. */ !function(a){"use strict";var b={parentsKey:"parents",childrenKey:"children"},c=function(a,b,c){return a.forEach(function(a){a[b]=a[b].concat(c)}),a},d=function(a,b,c,d){return function e(a,d){var f=[],g=d>0||void 0===d?e:function(){return[]};return a.forEach(function(a){f=a[b].filter(c),f=f.concat(g(a[b],d&&d-1))}),f}(a,d)},e=function(a,b,c){return a.forEach(function(a){c.forEach(function(c){a[b].splice(a[b].indexOf(c),1)})}),a},f=function(a){return"[object Array]"!==Object.prototype.toString.call(a)?[a]:a},g=function(){return!0},h=function(a,i){var j=this;return a=f(a),i=i||b,b=i,j.children=function(b,c){return new h(d(a,i.childrenKey,b||g,c),i)},j.parents=function(b,c){return new h(d(a,i.parentsKey,b||g,c),i)},j.addChildren=function(b){return c(a,i.childrenKey,c(f(b),i.parentsKey,a)),j},j.addParents=function(b){return c(a,i.parentsKey,c(f(b),i.childrenKey,a)),j},j.removeChildren=function(b){return e(a,i.childrenKey,e(f(b),i.parentsKey,a)),j},j.removeParents=function(b){return e(a,i.parentsKey,e(f(b),i.childrenKey,a)),j},j.filter=function(b){return new h(a.filter(b||g),i)},j.nodes=function(){return a},j},i=function(a,b){return new h(a,b)};"function"==typeof a.define?a.define("graph",[],function(){return i}):a.graph=i}(this);