Skip to content

Commit e676f6a

Browse files
Prep v1.0.6 release
1 parent a5f8014 commit e676f6a

7 files changed

Lines changed: 99 additions & 11 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphlib",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"main": [
55
"dist/graphlib.core.js"
66
],

dist/graphlib.core.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,50 @@ Graph.prototype.neighbors = function(v) {
891891
}
892892
};
893893

894+
Graph.prototype.filterNodes = function(filter) {
895+
var copy = new this.constructor({
896+
directed: this._isDirected,
897+
multigraph: this._isMultigraph,
898+
compound: this._isCompound
899+
});
900+
901+
copy.setGraph(this.graph());
902+
903+
_.each(this._nodes, function(value, v) {
904+
if (filter(v)) {
905+
copy.setNode(v, value);
906+
}
907+
}, this);
908+
909+
_.each(this._edgeObjs, function(e) {
910+
if (copy.hasNode(e.v) && copy.hasNode(e.w)) {
911+
copy.setEdge(e, this.edge(e));
912+
}
913+
}, this);
914+
915+
var self = this;
916+
var parents = {};
917+
function findParent(v) {
918+
var parent = self.parent(v);
919+
if (parent === undefined || copy.hasNode(parent)) {
920+
parents[v] = parent;
921+
return parent;
922+
} else if (parent in parents) {
923+
return parents[parent];
924+
} else {
925+
return findParent(parent);
926+
}
927+
}
928+
929+
if (this._isCompound) {
930+
_.each(copy.nodes(), function(v) {
931+
copy.setParent(v, findParent(v));
932+
});
933+
}
934+
935+
return copy;
936+
};
937+
894938
/* === Edge functions ========== */
895939

896940
Graph.prototype.setDefaultEdgeLabel = function(newDefault) {
@@ -1183,6 +1227,6 @@ if (!lodash) {
11831227
module.exports = lodash;
11841228

11851229
},{"lodash":undefined}],21:[function(require,module,exports){
1186-
module.exports = '1.0.5';
1230+
module.exports = '1.0.6';
11871231

11881232
},{}]},{},[1]);

dist/graphlib.core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/graphlib.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,50 @@ Graph.prototype.neighbors = function(v) {
891891
}
892892
};
893893

894+
Graph.prototype.filterNodes = function(filter) {
895+
var copy = new this.constructor({
896+
directed: this._isDirected,
897+
multigraph: this._isMultigraph,
898+
compound: this._isCompound
899+
});
900+
901+
copy.setGraph(this.graph());
902+
903+
_.each(this._nodes, function(value, v) {
904+
if (filter(v)) {
905+
copy.setNode(v, value);
906+
}
907+
}, this);
908+
909+
_.each(this._edgeObjs, function(e) {
910+
if (copy.hasNode(e.v) && copy.hasNode(e.w)) {
911+
copy.setEdge(e, this.edge(e));
912+
}
913+
}, this);
914+
915+
var self = this;
916+
var parents = {};
917+
function findParent(v) {
918+
var parent = self.parent(v);
919+
if (parent === undefined || copy.hasNode(parent)) {
920+
parents[v] = parent;
921+
return parent;
922+
} else if (parent in parents) {
923+
return parents[parent];
924+
} else {
925+
return findParent(parent);
926+
}
927+
}
928+
929+
if (this._isCompound) {
930+
_.each(copy.nodes(), function(v) {
931+
copy.setParent(v, findParent(v));
932+
});
933+
}
934+
935+
return copy;
936+
};
937+
894938
/* === Edge functions ========== */
895939

896940
Graph.prototype.setDefaultEdgeLabel = function(newDefault) {
@@ -1183,7 +1227,7 @@ if (!lodash) {
11831227
module.exports = lodash;
11841228

11851229
},{"lodash":22}],21:[function(require,module,exports){
1186-
module.exports = '1.0.5';
1230+
module.exports = '1.0.6';
11871231

11881232
},{}],22:[function(require,module,exports){
11891233
(function (global){

dist/graphlib.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = '1.0.6-pre';
1+
module.exports = '1.0.6';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphlib",
3-
"version": "1.0.6-pre",
3+
"version": "1.0.6",
44
"description": "A directed and undirected multi-graph library",
55
"author": "Chris Pettitt <cpettitt@gmail.com>",
66
"main": "index.js",
@@ -36,4 +36,4 @@
3636
"url": "https://github.com/cpettitt/graphlib.git"
3737
},
3838
"license": "MIT"
39-
}
39+
}

0 commit comments

Comments
 (0)