Affinity migration checkout

Issue #6
This commit is contained in:
Ian Gulliver
2019-07-13 03:41:36 +00:00
parent 2663c64bcd
commit aa9035749f
3 changed files with 23 additions and 19 deletions

View File

@@ -46,25 +46,6 @@ class GraphNode {
const INF = 999999;
for (let node of nodes) {
// Am I in any labeled groups that node is not?
// If so, preserve one space above the group
let labeled = new Set(Array.from(this.groups).filter(g => g.label != ''));
if (asymDifference(labeled, node.groups).size) {
node.addAffinity(this, (d, v) =>
(v[0] == 0 && v[1] > 0 && v[1] < 2) ? -INF : 0);
}
// Try to stack nodes with the same label
if (node.label == this.label) {
this.addAffinity(node, (d, v) => v[0] == 0 ? 200 : 500);
}
// Try to preserve pagerank left-to-right flow from initial positions
let rankSign = Math.sign(node.pageRank - this.pageRank);
if (rankSign != 0) {
this.addAffinity(node, (d, v) =>
[Math.sign(v[0]) == rankSign ? 0 : -1000, 0]);
}
}
for (let link of this.links) {

View File

@@ -5,6 +5,8 @@ class LayoutGroup {
this.nodes = new Set(nodes);
this.tension = 0;
this.label = this.graphGroup_ ? this.graphGroup_.label : null;
for (let node of nodes) {
node.groups.add(this);
}

View File

@@ -8,6 +8,7 @@ class LayoutNode {
this.affinity_ = [];
this.label = this.graphNode_.label;
this.pageRank = this.graphNode_.pageRank;
this.subgraph = this.graphNode_.subgraph;
this.nodesByPos_.set(this.pos, this);
@@ -46,6 +47,26 @@ class LayoutNode {
this.addAffinity(node, d => d <= 2 ? -INF : 0);
}
// Am I in any labeled groups that node is not?
// If so, preserve one space above the group
let labeled = new Set(Array.from(this.groups).filter(g => !!g.label));
if (asymDifference(labeled, node.groups).size) {
node.addAffinity(this, (d, v) =>
(v[0] == 0 && v[1] > 0 && v[1] < 2) ? -INF : 0);
}
// Try to stack nodes with the same label
if (node.label == this.label) {
this.addAffinity(node, (d, v) => v[0] == 0 ? 200 : 500);
}
// Try to preserve pagerank left-to-right flow from initial positions
let rankSign = Math.sign(node.pageRank - this.pageRank);
if (rankSign != 0) {
this.addAffinity(node, (d, v) =>
[Math.sign(v[0]) == rankSign ? 0 : -1000, 0]);
}
for (let group of this.groups) {
// Ensure groups do not overlap
if (group.nodes.has(node)) {