better names for elements of a linked graph

pull/1/head
Michael Peter Christen 13 years ago
parent 0cc0290978
commit aba9b1bfa0

@ -135,10 +135,10 @@ public class WebStructurePicture_p {
final int cyc) { final int cyc) {
// returns the number of nodes that had been placed // returns the number of nodes that had been placed
assert centerhost != null; assert centerhost != null;
final GraphPlotter.coordinate center = graph.getPoint(centerhost); final GraphPlotter.Point center = graph.getNode(centerhost);
int mynodes = 0; int mynodes = 0;
if (center == null) { if (center == null) {
graph.addPoint(centerhost, x, y, nextlayer); graph.addNode(centerhost, x, y, nextlayer);
maxnodes--; maxnodes--;
mynodes++; mynodes++;
} }
@ -165,13 +165,13 @@ public class WebStructurePicture_p {
maxtargetrefs = Math.max(targetrefs, maxtargetrefs); maxtargetrefs = Math.max(targetrefs, maxtargetrefs);
maxthisrefs = Math.max(thisrefs, maxthisrefs); maxthisrefs = Math.max(thisrefs, maxthisrefs);
targets.add(new String[] {targethash, targethost}); targets.add(new String[] {targethash, targethost});
if (graph.getPoint(targethost) != null) continue; if (graph.getNode(targethost) != null) continue;
// set a new point. It is placed on a circle around the host point // set a new point. It is placed on a circle around the host point
final double angle = ((Base64Order.enhancedCoder.cardinal((targethash + "____").getBytes()) / maxlongd) + (cyc / 360.0d)) * 2.0d * Math.PI; final double angle = ((Base64Order.enhancedCoder.cardinal((targethash + "____").getBytes()) / maxlongd) + (cyc / 360.0d)) * 2.0d * Math.PI;
//System.out.println("ANGLE = " + angle); //System.out.println("ANGLE = " + angle);
rr = radius * 0.25 * (1 - targetrefs / (double) maxtargetrefs); rr = radius * 0.25 * (1 - targetrefs / (double) maxtargetrefs);
re = radius * 0.5 * (thisrefs / (double) maxthisrefs); re = radius * 0.5 * (thisrefs / (double) maxthisrefs);
graph.addPoint(targethost, x + (radius - rr - re) * Math.cos(angle), y + (radius - rr - re) * Math.sin(angle), nextlayer); graph.addNode(targethost, x + (radius - rr - re) * Math.cos(angle), y + (radius - rr - re) * Math.sin(angle), nextlayer);
maxnodes--; maxnodes--;
mynodes++; mynodes++;
} }
@ -183,12 +183,12 @@ public class WebStructurePicture_p {
target = j.next(); target = j.next();
targethash = target[0]; targethash = target[0];
targethost = target[1]; targethost = target[1];
final GraphPlotter.coordinate c = graph.getPoint(targethost); final GraphPlotter.Point c = graph.getNode(targethost);
assert c != null; assert c != null;
nextnodes = ((maxnodes <= 0) || (System.currentTimeMillis() >= timeout)) ? 0 : place(graph, structure, targethash, targethost, maxnodes, timeout, c.x, c.y, nextlayer, maxlayer, cyc); nextnodes = ((maxnodes <= 0) || (System.currentTimeMillis() >= timeout)) ? 0 : place(graph, structure, targethash, targethost, maxnodes, timeout, c.x, c.y, nextlayer, maxlayer, cyc);
mynodes += nextnodes; mynodes += nextnodes;
maxnodes -= nextnodes; maxnodes -= nextnodes;
graph.setBorder(centerhost, targethost); graph.setEdge(centerhost, targethost);
} }
return mynodes; return mynodes;
} }

@ -45,35 +45,35 @@ public class GraphPlotter {
// a ymageGraph is a set of points and borders between the points // a ymageGraph is a set of points and borders between the points
// to reference the points, they must all have a nickname // to reference the points, they must all have a nickname
private final Map<String, coordinate> points; private final Map<String, Point> nodes; // the interconnected objects
private final Set<String> borders; private final Set<String> edges; // the links that connect pairs of vertices
private double leftmost, rightmost, topmost, bottommost; private double leftmost, rightmost, topmost, bottommost;
public GraphPlotter() { public GraphPlotter() {
this.points = new HashMap<String, coordinate>(); this.nodes = new HashMap<String, Point>();
this.borders = new HashSet<String>(); this.edges = new HashSet<String>();
this.leftmost = 1.0; this.leftmost = 1.0;
this.rightmost = -1.0; this.rightmost = -1.0;
this.topmost = -1.0; this.topmost = -1.0;
this.bottommost = 1.0; this.bottommost = 1.0;
} }
public coordinate getPoint(final String name) { public Point getNode(final String node) {
return this.points.get(name); return this.nodes.get(node);
} }
public coordinate[] getBorder(final String name) { public Point[] getEdge(final String edge) {
final int p = name.indexOf('$',0); final int p = edge.indexOf('$',0);
if (p < 0) return null; if (p < 0) return null;
final coordinate from = getPoint(name.substring(0, p)); final Point from = getNode(edge.substring(0, p));
final coordinate to = getPoint(name.substring(p + 1)); final Point to = getNode(edge.substring(p + 1));
if ((from == null) || (to == null)) return null; if ((from == null) || (to == null)) return null;
return new coordinate[] {from, to}; return new Point[] {from, to};
} }
public coordinate addPoint(final String name, final double x, final double y, final int layer) { public Point addNode(final String node, final double x, final double y, final int layer) {
final coordinate newc = new coordinate(x, y, layer); final Point newc = new Point(x, y, layer);
final coordinate oldc = this.points.put(name, newc); final Point oldc = this.nodes.put(node, newc);
assert oldc == null; // all add shall be unique assert oldc == null; // all add shall be unique
if (x > this.rightmost) this.rightmost = x; if (x > this.rightmost) this.rightmost = x;
if (x < this.leftmost) this.leftmost = x; if (x < this.leftmost) this.leftmost = x;
@ -82,22 +82,22 @@ public class GraphPlotter {
return newc; return newc;
} }
public boolean hasBorder(final String fromPoint, final String toPoint) { public boolean hasEdge(final String fromNode, final String toNode) {
return this.borders.contains(fromPoint + "-" + toPoint); return this.edges.contains(fromNode + "-" + toNode);
} }
public void setBorder(final String fromPoint, final String toPoint) { public void setEdge(final String fromNode, final String toNode) {
final coordinate from = this.points.get(fromPoint); final Point from = this.nodes.get(fromNode);
final coordinate to = this.points.get(toPoint); final Point to = this.nodes.get(toNode);
assert from != null; assert from != null;
assert to != null; assert to != null;
this.borders.add(fromPoint + "$" + toPoint); this.edges.add(fromNode + "$" + toNode);
} }
public static class coordinate { public static class Point {
public double x, y; public double x, y;
public int layer; public int layer;
public coordinate(final double x, final double y, final int layer) { public Point(final double x, final double y, final int layer) {
assert x >= -1; assert x >= -1;
assert x <= 1; assert x <= 1;
assert y >= -1; assert y >= -1;
@ -110,17 +110,17 @@ public class GraphPlotter {
public void print() { public void print() {
// for debug purpose: print out all coordinates // for debug purpose: print out all coordinates
final Iterator<Map.Entry<String, coordinate>> i = this.points.entrySet().iterator(); final Iterator<Map.Entry<String, Point>> i = this.nodes.entrySet().iterator();
Map.Entry<String, coordinate> entry; Map.Entry<String, Point> entry;
String name; String name;
coordinate c; Point c;
while (i.hasNext()) { while (i.hasNext()) {
entry = i.next(); entry = i.next();
name = entry.getKey(); name = entry.getKey();
c = entry.getValue(); c = entry.getValue();
System.out.println("point(" + c.x + ", " + c.y + ", " + c.layer + ") [" + name + "]"); System.out.println("point(" + c.x + ", " + c.y + ", " + c.layer + ") [" + name + "]");
} }
final Iterator<String> j = this.borders.iterator(); final Iterator<String> j = this.edges.iterator();
while (j.hasNext()) { while (j.hasNext()) {
System.out.println("border(" + j.next() + ")"); System.out.println("border(" + j.next() + ")");
} }
@ -146,10 +146,10 @@ public class GraphPlotter {
final double yfactor = ((this.topmost - this.bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (this.topmost - this.bottommost); final double yfactor = ((this.topmost - this.bottommost) == 0.0) ? 0.0 : (height - topborder - bottomborder) / (this.topmost - this.bottommost);
// draw dots and names // draw dots and names
final Iterator<Map.Entry<String, coordinate>> i = this.points.entrySet().iterator(); final Iterator<Map.Entry<String, Point>> i = this.nodes.entrySet().iterator();
Map.Entry<String, coordinate> entry; Map.Entry<String, Point> entry;
String name; String name;
coordinate c; Point c;
int x, y; int x, y;
while (i.hasNext()) { while (i.hasNext()) {
entry = i.next(); entry = i.next();
@ -164,12 +164,12 @@ public class GraphPlotter {
} }
// draw lines // draw lines
final Iterator<String> j = this.borders.iterator(); final Iterator<String> j = this.edges.iterator();
coordinate[] border; Point[] border;
image.setColor(color_line); image.setColor(color_line);
int x0, x1, y0, y1; int x0, x1, y0, y1;
while (j.hasNext()) { while (j.hasNext()) {
border = getBorder(j.next()); border = getEdge(j.next());
if (border == null) continue; if (border == null) continue;
if (xfactor == 0.0) { if (xfactor == 0.0) {
x0 = width / 2; x0 = width / 2;

Loading…
Cancel
Save