From 91a86f0b06d9ce13c15e9fdefb6ced086965afb6 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Tue, 17 Apr 2012 11:46:14 +0200 Subject: [PATCH] fixed to network graph testing --- htroot/WebStructurePicture_p.java | 4 +-- .../net/yacy/visualization/GraphPlotter.java | 31 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/htroot/WebStructurePicture_p.java b/htroot/WebStructurePicture_p.java index e95751002..0e285d8d9 100644 --- a/htroot/WebStructurePicture_p.java +++ b/htroot/WebStructurePicture_p.java @@ -119,12 +119,12 @@ public class WebStructurePicture_p { // apply physics to it to get a better shape if (post != null && post.containsKey("pa")) { - // test with: http://localhost:8090/WebStructurePicture_p.png?pa=10&ral=0.7&raa=0.001&rar=0.0002&rel=0.25&rea=0.1&rer=0.0001 + // test with: http://localhost:8090/WebStructurePicture_p.png?pa=1&ral=0.7&raa=0.5&rar=2&rel=0.5&rea=1&rer=2 GraphPlotter.Ribbon rAll = new GraphPlotter.Ribbon(post.getFloat("ral", 0.1f), post.getFloat("raa", 0.1f), post.getFloat("rar", 0.1f)); GraphPlotter.Ribbon rEdge = new GraphPlotter.Ribbon(post.getFloat("rel", 0.05f), post.getFloat("rea", 0.1f), post.getFloat("rer", 0.1f)); for (int i = 0; i < post.getInt("pa", 1); i++) graph = graph.physics(rAll, rEdge); } - + // draw the graph graphPicture = graph.draw(width, height, 40, 40, 16, 16, color_back, color_dot, color_line, color_lineend, color_text); } diff --git a/source/net/yacy/visualization/GraphPlotter.java b/source/net/yacy/visualization/GraphPlotter.java index fbbed9532..032fa8f5d 100644 --- a/source/net/yacy/visualization/GraphPlotter.java +++ b/source/net/yacy/visualization/GraphPlotter.java @@ -60,6 +60,7 @@ public class GraphPlotter implements Cloneable { this.bottommost = 1.0; } + @Override public Object clone() { GraphPlotter g = new GraphPlotter(); g.nodes.putAll(this.nodes); @@ -70,7 +71,7 @@ public class GraphPlotter implements Cloneable { g.bottommost = this.bottommost; return g; } - + public static class Ribbon { double length, attraction, repulsion; public Ribbon(double length, double attraction, double repulsion) { @@ -94,7 +95,8 @@ public class GraphPlotter implements Cloneable { this.y = y; this.layer = layer; } - + + @Override public Object clone() { return new Point(this.x, this.y, this.layer); } @@ -102,7 +104,7 @@ public class GraphPlotter implements Cloneable { private final static double p2 = Math.PI / 2.0; private final static double p23 = p2 * 3.0; - + public static void force(Point calcPoint, Point currentPoint, Point otherPoint, Ribbon r) { double dx = otherPoint.x - currentPoint.x; double dy = otherPoint.y - currentPoint.y; @@ -113,18 +115,19 @@ public class GraphPlotter implements Cloneable { double f = attraction ? r.attraction * (d - r.length) * (d - r.length) : - r.repulsion * (r.length - d) * (r.length - d); // the force double x1 = Math.cos(a) * f; double y1 = Math.sin(a) * f; - assert !(attraction && a < Math.PI) || y1 > 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; - assert !(!attraction && a < Math.PI) || y1 < 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; - assert !(attraction && a > Math.PI) || y1 < 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; - assert !(!attraction && a > Math.PI) || y1 > 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; - assert !(attraction && (a < p2 || a > p23)) || x1 > 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; - assert !(!attraction && (a < p2 || a > p23)) || x1 < 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; - assert !(attraction && !(a < p2 || a > p23)) || x1 < 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; - assert !(!attraction && !(a < p2 || a > p23)) || x1 > 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; + // verify calculation + assert !(attraction && a < Math.PI) || y1 >= 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; + assert !(!attraction && a < Math.PI) || y1 <= 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; + assert !(attraction && a > Math.PI) || y1 <= 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; + assert !(!attraction && a > Math.PI) || y1 >= 0 : "attraction = " + attraction + ", a = " + a + ", y1 = " + y1; + assert !(attraction && (a < p2 || a > p23)) || x1 >= 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; + assert !(!attraction && (a < p2 || a > p23)) || x1 <= 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; + assert !(attraction && !(a < p2 || a > p23)) || x1 <= 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; + assert !(!attraction && !(a < p2 || a > p23)) || x1 >= 0 : "attraction = " + attraction + ", a = " + a + ", x1 = " + x1; calcPoint.x += x1; calcPoint.y += y1; } - + public GraphPlotter physics(Ribbon all, Ribbon edges) { GraphPlotter g = new GraphPlotter(); // compute force for every node @@ -151,7 +154,7 @@ public class GraphPlotter implements Cloneable { g.edges.addAll(this.edges); return g; } - + public Point getNode(final String node) { return this.nodes.get(node); } @@ -190,7 +193,7 @@ public class GraphPlotter implements Cloneable { assert to != null; this.edges.add(fromNode + "$" + toNode); } - + public Collection getEdges(final String node, boolean start) { Collection c = new ArrayList(); if (start) {