From aba9b1bfa0ca4c35efd18287f72d32e0e45565f7 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Mon, 27 Feb 2012 21:27:17 +0100 Subject: [PATCH] better names for elements of a linked graph --- htroot/WebStructurePicture_p.java | 12 ++-- .../net/yacy/visualization/GraphPlotter.java | 64 +++++++++---------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/htroot/WebStructurePicture_p.java b/htroot/WebStructurePicture_p.java index bff661a28..4ef7594af 100644 --- a/htroot/WebStructurePicture_p.java +++ b/htroot/WebStructurePicture_p.java @@ -135,10 +135,10 @@ public class WebStructurePicture_p { final int cyc) { // returns the number of nodes that had been placed assert centerhost != null; - final GraphPlotter.coordinate center = graph.getPoint(centerhost); + final GraphPlotter.Point center = graph.getNode(centerhost); int mynodes = 0; if (center == null) { - graph.addPoint(centerhost, x, y, nextlayer); + graph.addNode(centerhost, x, y, nextlayer); maxnodes--; mynodes++; } @@ -165,13 +165,13 @@ public class WebStructurePicture_p { maxtargetrefs = Math.max(targetrefs, maxtargetrefs); maxthisrefs = Math.max(thisrefs, maxthisrefs); 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 final double angle = ((Base64Order.enhancedCoder.cardinal((targethash + "____").getBytes()) / maxlongd) + (cyc / 360.0d)) * 2.0d * Math.PI; //System.out.println("ANGLE = " + angle); rr = radius * 0.25 * (1 - targetrefs / (double) maxtargetrefs); 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--; mynodes++; } @@ -183,12 +183,12 @@ public class WebStructurePicture_p { target = j.next(); targethash = target[0]; targethost = target[1]; - final GraphPlotter.coordinate c = graph.getPoint(targethost); + final GraphPlotter.Point c = graph.getNode(targethost); assert c != null; nextnodes = ((maxnodes <= 0) || (System.currentTimeMillis() >= timeout)) ? 0 : place(graph, structure, targethash, targethost, maxnodes, timeout, c.x, c.y, nextlayer, maxlayer, cyc); mynodes += nextnodes; maxnodes -= nextnodes; - graph.setBorder(centerhost, targethost); + graph.setEdge(centerhost, targethost); } return mynodes; } diff --git a/source/net/yacy/visualization/GraphPlotter.java b/source/net/yacy/visualization/GraphPlotter.java index 3fb122f18..6324f87ef 100644 --- a/source/net/yacy/visualization/GraphPlotter.java +++ b/source/net/yacy/visualization/GraphPlotter.java @@ -45,35 +45,35 @@ public class GraphPlotter { // a ymageGraph is a set of points and borders between the points // to reference the points, they must all have a nickname - private final Map points; - private final Set borders; + private final Map nodes; // the interconnected objects + private final Set edges; // the links that connect pairs of vertices private double leftmost, rightmost, topmost, bottommost; public GraphPlotter() { - this.points = new HashMap(); - this.borders = new HashSet(); + this.nodes = new HashMap(); + this.edges = new HashSet(); this.leftmost = 1.0; this.rightmost = -1.0; this.topmost = -1.0; this.bottommost = 1.0; } - public coordinate getPoint(final String name) { - return this.points.get(name); + public Point getNode(final String node) { + return this.nodes.get(node); } - public coordinate[] getBorder(final String name) { - final int p = name.indexOf('$',0); + public Point[] getEdge(final String edge) { + final int p = edge.indexOf('$',0); if (p < 0) return null; - final coordinate from = getPoint(name.substring(0, p)); - final coordinate to = getPoint(name.substring(p + 1)); + final Point from = getNode(edge.substring(0, p)); + final Point to = getNode(edge.substring(p + 1)); 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) { - final coordinate newc = new coordinate(x, y, layer); - final coordinate oldc = this.points.put(name, newc); + public Point addNode(final String node, final double x, final double y, final int layer) { + final Point newc = new Point(x, y, layer); + final Point oldc = this.nodes.put(node, newc); assert oldc == null; // all add shall be unique if (x > this.rightmost) this.rightmost = x; if (x < this.leftmost) this.leftmost = x; @@ -82,22 +82,22 @@ public class GraphPlotter { return newc; } - public boolean hasBorder(final String fromPoint, final String toPoint) { - return this.borders.contains(fromPoint + "-" + toPoint); + public boolean hasEdge(final String fromNode, final String toNode) { + return this.edges.contains(fromNode + "-" + toNode); } - public void setBorder(final String fromPoint, final String toPoint) { - final coordinate from = this.points.get(fromPoint); - final coordinate to = this.points.get(toPoint); + public void setEdge(final String fromNode, final String toNode) { + final Point from = this.nodes.get(fromNode); + final Point to = this.nodes.get(toNode); assert from != 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 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 y >= -1; @@ -110,17 +110,17 @@ public class GraphPlotter { public void print() { // for debug purpose: print out all coordinates - final Iterator> i = this.points.entrySet().iterator(); - Map.Entry entry; + final Iterator> i = this.nodes.entrySet().iterator(); + Map.Entry entry; String name; - coordinate c; + Point c; while (i.hasNext()) { entry = i.next(); name = entry.getKey(); c = entry.getValue(); System.out.println("point(" + c.x + ", " + c.y + ", " + c.layer + ") [" + name + "]"); } - final Iterator j = this.borders.iterator(); + final Iterator j = this.edges.iterator(); while (j.hasNext()) { 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); // draw dots and names - final Iterator> i = this.points.entrySet().iterator(); - Map.Entry entry; + final Iterator> i = this.nodes.entrySet().iterator(); + Map.Entry entry; String name; - coordinate c; + Point c; int x, y; while (i.hasNext()) { entry = i.next(); @@ -164,12 +164,12 @@ public class GraphPlotter { } // draw lines - final Iterator j = this.borders.iterator(); - coordinate[] border; + final Iterator j = this.edges.iterator(); + Point[] border; image.setColor(color_line); int x0, x1, y0, y1; while (j.hasNext()) { - border = getBorder(j.next()); + border = getEdge(j.next()); if (border == null) continue; if (xfactor == 0.0) { x0 = width / 2;