merge forcenet with wikimap, many refinements, incremental loading directly from api

This commit is contained in:
Michael Murtaugh
2019-07-09 17:31:52 +02:00
parent ad3e494d47
commit 5ac253c712
6 changed files with 1276 additions and 966 deletions

View File

@@ -74,13 +74,38 @@ export class ForceNet {
return (a < b) ? ("link_"+a+"_"+b) : ("link_"+b+"_"+a);
}
/*
link_key (p1, p2) {
return (p1.title < p2.title) ?
("link_"+p1.title+"_"+p2.title) :
("link_"+p2.title+"_"+p1.title);
}
*/
make_link (p1, p2) {
return (p1.title < p2.title) ?
{source: p1, target: p2 } :
{source: p2, target: p1 };
}
register_link (from_page, to_page) {
var lkey = this.link_key(from_page, to_page);
if (this.links[lkey] === undefined) {
this.links[lkey] = this.make_link(from_page, to_page);
}
}
get_symbol (d, def) {
return "symbols.svg#Main";
/*
for (var i=0, l=d.cats.length; i<l; i++) {
if (this.symbols[d.cats[i]]) {
return this.symbols[d.cats[i]];
}
}
return this.symbols.default || def;
*/
}
update_graph (graph) {
@@ -103,6 +128,8 @@ export class ForceNet {
var node = this.nodesg
.selectAll("g.page")
.data(graph.nodes, function (d) { return d.title });
node.exit().remove();
var that = this;
var node_enter = node.enter().append("g")
@@ -215,13 +242,26 @@ export class ForceNet {
if (d.source.active || d.target.active) {
return 1;
} else {
return 1;
// same as d3.force's defaultStrength
return 0.5 * (1 / Math.min(d.source.count, d.target.count));
// return 0.5 * (1 / Math.min(d.source.count, d.target.count));
}
});
this.simulation.alphaTarget(0.3).restart();
}
activate_linked_nodes (page, active) {
// deactivate linked links/nodes
for (let i=0, l=this.links.length; i<l; i++) {
let link = this.links[i];
if (link.source == page || link.target == page) {
link.active2 = active;
link.source.active2 = active;
link.target.active2 = active;
}
}
}
}