Commit d70fee75 authored by S Anand's avatar S Anand

BUG: G.network.force filter_links should work before draw. Fixes #21

parent a238a70b
......@@ -317,12 +317,26 @@ _G_network.force = function() {
// Apply all link filters, and remove links to non-existent nodes
function filter_links() {
for (var links=[], i=0, link; link=data.links[i]; i++)
if (link.source.id in node_ids && link.target.id in node_ids)
links.push(link)
for (var ns in link_filter)
links = links.filter(link_filter[ns])
return links
var filtered_links = [],
i = 0,
link
if (links.length) {
// If we've already called .draw(), the links are resolved into objects.
// In that case, .source is an object whose .id is the node id
if (typeof links[0].source == 'object') {
for (; link=links[i]; i++)
if (link.source.id in node_ids && link.target.id in node_ids)
filtered_links.push(link)
} else {
// If we haven't called .draw() yet, the links are node IDs themselves
for (; link=links[i]; i++)
if (nodes[link.source].id in node_ids && nodes[link.target].id in node_ids)
filtered_links.push(link)
}
for (var ns in link_filter)
filtered_links = filtered_links.filter(link_filter[ns])
}
return filtered_links
}
// Filters links based on fn(link)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment