2016-05-27 23:59:01 +02:00
|
|
|
define(function () {
|
|
|
|
"use strict";
|
|
|
|
|
2015-07-08 00:36:57 +02:00
|
|
|
return function (filter) {
|
|
|
|
return function (data) {
|
2017-03-17 03:14:57 +01:00
|
|
|
var n = Object.create(data);
|
|
|
|
n.nodes = {};
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
for (var key in data.nodes) {
|
|
|
|
n.nodes[key] = data.nodes[key].filter(filter);
|
|
|
|
}
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
var filteredIds = new Set();
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
n.graph = {};
|
|
|
|
n.graph.nodes = data.graph.nodes.filter(function (d) {
|
|
|
|
var r;
|
|
|
|
if (d.node) {
|
|
|
|
r = filter(d.node);
|
|
|
|
} else {
|
|
|
|
r = filter({});
|
|
|
|
}
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
if (r) {
|
|
|
|
filteredIds.add(d.id);
|
|
|
|
}
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return r;
|
|
|
|
});
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
n.graph.links = data.graph.links.filter(function (d) {
|
|
|
|
return filteredIds.has(d.source.id) && filteredIds.has(d.target.id);
|
|
|
|
});
|
2015-07-08 00:36:57 +02:00
|
|
|
|
2017-03-17 03:14:57 +01:00
|
|
|
return n;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|