imagePainter may now paint arbitrary large circles; small update to network graphics

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@906 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent be8e95d86a
commit aae5af9686

@ -60,6 +60,8 @@ import de.anomic.yacy.yacySeed;
public class NetworkPicture {
private static int shortestName = 10;
private static int longestName = 12;
public static BufferedImage respond(httpHeader header, serverObjects post, serverSwitch env) {
@ -71,7 +73,12 @@ public class NetworkPicture {
height = post.getInt("height", 420);
}
int radius = Math.min(width, height) / 5;
int innerradius = Math.min(width, height) / 5;
int outerradius = innerradius + innerradius * yacyCore.seedDB.sizeConnected() / 100;
if (outerradius > innerradius * 2) outerradius = innerradius * 2;
shortestName = 10;
longestName = 12;
ImagePainter img = new ImagePainter(width, height, ImagePainter.TRANSPARENT);
img.setMode(ImagePainter.MODE_ADD);
@ -82,8 +89,7 @@ public class NetworkPicture {
// draw network circle
img.setColor("004020");
img.arc(width / 2, height / 2, radius - 20, radius + 20, 0, 360);
img.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 0, 360);
//System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance);
//System.out.println("Seed Minimum distance is " + yacySeed.minDHTNumber);
@ -100,7 +106,7 @@ public class NetworkPicture {
while (e.hasMoreElements() && count < maxCount) {
seed = (yacySeed) e.nextElement();
if (seed != null) {
drawPeer(img, width / 2, height / 2, radius, seed, "000040", "B0FFB0");
drawPeer(img, width / 2, height / 2, innerradius, outerradius, seed, "000040", "B0FFB0");
count++;
}
}
@ -114,7 +120,7 @@ public class NetworkPicture {
if (seed != null) {
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenTime()) / 1000 / 60);
if (lastseen > 120) break; // we have enough, this list is sorted so we don't miss anything
drawPeer(img, width / 2, height / 2, radius, seed, "101010", "802000");
drawPeer(img, width / 2, height / 2, innerradius, outerradius, seed, "101010", "802000");
count++;
}
}
@ -128,14 +134,14 @@ public class NetworkPicture {
if (seed != null) {
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenTime()) / 1000 / 60);
if (lastseen > 120) break; // we have enough, this list is sorted so we don't miss anything
drawPeer(img, width / 2, height / 2, radius, seed, "202000", "A0A000");
drawPeer(img, width / 2, height / 2, innerradius, outerradius, seed, "202000", "A0A000");
count++;
}
}
totalCount += count;
// draw my own peer
drawPeer(img, width / 2, height / 2, radius, yacyCore.seedDB.mySeed, "800000", "FFFFFF");
drawPeer(img, width / 2, height / 2, innerradius, outerradius, yacyCore.seedDB.mySeed, "800000", "FFFFFF");
// draw description
img.setColor("FFFFFF");
@ -146,17 +152,21 @@ public class NetworkPicture {
return img.toImage(true);
}
private static void drawPeer(ImagePainter img, int x, int y, int radius, yacySeed seed, String colorDot, String colorText) {
private static void drawPeer(ImagePainter img, int x, int y, int innerradius, int outerradius, yacySeed seed, String colorDot, String colorText) {
String name = seed.getName().toUpperCase();
if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length();
int angle = (int) ((long) 360 * (seed.dhtDistance() / (yacySeed.maxDHTDistance / (long) 10000)) / (long) 10000);
//System.out.println("Seed " + seed.hash + " has distance " + seed.dhtDistance() + ", angle = " + angle);
int linelength = radius + 60 + (Math.abs(seed.hash.hashCode()) % (radius / 2));
int linelength = 20 + outerradius * (20 * (name.length() - shortestName) / (longestName - shortestName) + (Math.abs(seed.hash.hashCode()) % 20)) / 60;
if (linelength > outerradius) linelength = outerradius;
int dotsize = 6 + 2 * (int) (seed.getLinkCount() / 500000L);
if (dotsize > 18) dotsize = 18;
img.setColor(colorDot);
img.arcDot(x, y, radius, dotsize, angle);
img.arcDot(x, y, innerradius, dotsize, angle);
img.setColor(colorText);
img.arcLine(x, y, radius + 18, linelength, angle);
img.arcPrint(x, y, linelength, angle, seed.getName().toUpperCase());
img.arcLine(x, y, innerradius + 18, innerradius + linelength, angle);
img.arcPrint(x, y, innerradius + linelength, angle, name);
}
}

@ -93,10 +93,12 @@ public class ImagePainter {
0x000288A,0x0002884,0x0003C9E,0x0622086,0x0421084,0x0C2088C,0x0045440,0x1F8C63F
};
private static final int radiusPrecalc = 180;
private static HashSet crds = new HashSet();
private static ArrayList crc;
private static int[][][] circles = new int[radiusPrecalc][][];
//private static final int radiusPrecalc = 180;
//private static HashSet crds = new HashSet();
//private static ArrayList crc;
//private static int[][][] circles = new int[radiusPrecalc][][];
private static int[][][] circles = new int[0][][];
/*
static {
// calculate coordinates
int x, y;
@ -132,6 +134,7 @@ public class ImagePainter {
crc = null;
crds = null;
}
*/
private long[] grid; // one-dimensional arrays are much faster than two-dimensional
private int width, height;
@ -238,13 +241,70 @@ public class ImagePainter {
}
}
private static int[][] getCircleCoords(int radius) {
if ((radius - 1) < circles.length) return circles[radius - 1];
// read some lines from known circles
HashSet crds = new HashSet();
crds.add("0|0");
String co;
for (int i = Math.max(0, circles.length - 5); i < circles.length; i++) {
for (int j = 0; j < circles[i].length; j++) {
co = circles[i][j][0] + "|" + circles[i][j][1];
if (!(crds.contains(co))) crds.add(co);
}
}
// copy old circles into new array
int[][][] newCircles = new int[radius + 30][][];
System.arraycopy(circles, 0, newCircles, 0, circles.length);
// compute more lines in new circles
int x, y;
ArrayList crc;
for (int r = circles.length; r < newCircles.length; r++) {
crc = new ArrayList();
for (int a = 0; a <= 2 * (r + 1); a++) {
x = (int) ((r + 1) * Math.cos(Math.PI * a / (4 * (r + 1))));
y = (int) ((r + 1) * Math.sin(Math.PI * a / (4 * (r + 1))));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new int[]{x, y});
crds.add(co);
}
x = (int) ((r + 0.5) * Math.cos(Math.PI * a / (4 * (r + 1))));
y = (int) ((r + 0.5) * Math.sin(Math.PI * a / (4 * (r + 1))));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new int[]{x, y});
crds.add(co);
}
}
// put coordinates into array
//System.out.print("Radius " + r + " => " + crc.size() + " points: ");
newCircles[r] = new int[crc.size() - 1][];
for (int i = 0; i < crc.size() - 1; i++) {
newCircles[r][i] = (int[]) crc.get(i);
//System.out.print(circles[r][i][0] + "," +circles[r][i][1] + "; ");
}
//System.out.println();
}
crc = null;
crds = null;
// move newCircles to circles array
circles = newCircles;
newCircles = null;
// finally return wanted slice
return circles[radius - 1];
}
private void circle(int xc, int yc, int radius) {
if (radius == 0) {
plot(xc, yc);
} else {
int[][] c = circles[radius - 1];
int[][] c = getCircleCoords(radius);
int x, y;
for (int i = c.length - 1; i >= 0; i--) {
x = c[i][0];
@ -263,7 +323,7 @@ public class ImagePainter {
if (radius == 0) {
plot(xc, yc);
} else {
int[][] c = circles[radius - 1];
int[][] c = getCircleCoords(radius);
int q = c.length;
int[][] c4 = new int[q * 4][];
for (int i = 0; i < q; i++) {

Loading…
Cancel
Save