Plumb link labels through to layout

This commit is contained in:
Ian Gulliver
2019-07-10 17:17:17 +00:00
parent 75bc85919c
commit 245bbb86f4
5 changed files with 35 additions and 17 deletions

View File

@@ -7,8 +7,14 @@ class GraphLink {
this.to = nodesByLabel.get(this.toLabel);
for (let from of this.from) {
for (let to of this.to) {
from.links.push(to);
to.linksIn.push(from);
from.links.push({
to: to,
label: this.label,
});
to.linksIn.push({
from: from,
label: this.label,
});
}
}
}

View File

@@ -15,8 +15,8 @@ class GraphNode {
}
++this.pageRank;
visited.add(this);
for (let to of this.links) {
to.incPageRank(visited);
for (let link of this.links) {
link.to.incPageRank(visited);
}
visited.delete(this);
}
@@ -28,11 +28,11 @@ class GraphNode {
}
this.subgraph = subgraph;
nodes.delete(this);
for (let to of this.links) {
to.setSubgraph(subgraph, nodes);
for (let link of this.links) {
link.to.setSubgraph(subgraph, nodes);
}
for (let from of this.linksIn) {
from.setSubgraph(subgraph, nodes);
for (let link of this.linksIn) {
link.from.setSubgraph(subgraph, nodes);
}
for (let group of this.groups) {
for (let node of group.nodes) {
@@ -76,11 +76,11 @@ class GraphNode {
}
}
for (let to of this.links) {
for (let link of this.links) {
// Stronger affinity for links
// Prefer to move toward the target instance
this.addAffinity(to, d => d <= 2 ? -INF : d * 11);
to.addAffinity(this, d => d <= 2 ? -INF : d * 9);
this.addAffinity(link.to, d => d <= 2 ? -INF : d * 11);
link.to.addAffinity(this, d => d <= 2 ? -INF : d * 9);
}
// Affinity for groups

View File

@@ -212,10 +212,11 @@ class Layout {
drawLinks() {
let links = [];
for (let from of this.nodes_) {
for (let to of from.links) {
for (let link of from.links) {
links.push({
from: from,
to: to,
to: link.to,
label: link.label,
});
}
}
@@ -227,9 +228,13 @@ class Layout {
for (let link of links) {
this.links_.push(
new LayoutLink(link.from, link.to,
new LayoutLink(link.from, link.to, link.label,
this.nodesByPos_, this.linksByPos_));
}
for (let link of this.links_) {
link.drawLabel();
}
}
distance(a, b) {

View File

@@ -1,7 +1,8 @@
class LayoutLink {
constructor(from, to, nodesByPos, linksByPos) {
constructor(from, to, label, nodesByPos, linksByPos) {
this.from_ = from;
this.to_ = to;
this.label_ = label;
this.nodesByPos_ = nodesByPos;
this.linksByPos_ = linksByPos;
this.bfs();
@@ -178,6 +179,9 @@ class LayoutLink {
return (this.getOutPoint(from, to) + 4) % 8;
}
drawLabel() {
}
getSteps() {
let steps = [];

View File

@@ -10,8 +10,11 @@ class LayoutNode {
resolveLinks(nodesByGraphNode) {
this.links = [];
for (let to of this.graphNode_.links) {
this.links.push(nodesByGraphNode.get(to));
for (let link of this.graphNode_.links) {
this.links.push({
to: nodesByGraphNode.get(link.to),
label: link.label,
});
}
}