animated network graphic!

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6939 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent d7767e7589
commit 2b4f8f6c06

@ -8,6 +8,24 @@
float: left; float: left;
} }
</style> </style>
<script type="text/javascript">
imgname = "NetworkPicture.png?width=768&height=576&bgcolor=FFFFFF&coronaangle=";
i = 0;
imagearray = new Array(4);
for (j = 0; j < 4; j++) {
imagearray[j] = new Image(768, 576);
angle = j * 90;
imagearray[j].src = imgname + angle;
}
setTimeout("doanimation()", 1000);
function doanimation() {
document.getElementById("NetworkPicture").src = imagearray[i].src;
i++;
if (i == 4) { i = 0; }
setTimeout("doanimation()", 100);
}
</script>
</head> </head>
<body id="Network"> <body id="Network">
@ -187,7 +205,7 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
</div> </div>
<div class="left"><p> <div class="left"><p>
<a href="NetworkPicture.png?width=768&amp;height=576&amp;bgcolor=FFFFFF"><img src="NetworkPicture.png?width=768&amp;height=576&amp;bgcolor=FFFFFF" alt="The yacy Network" /></a> <a href="NetworkPicture.png?width=768&height=576&bgcolor=FFFFFF"><img id="NetworkPicture" src="NetworkPicture.png?width=768&height=576&bgcolor=FFFFFF&coronaangle=0" alt="The YaCy Network" /></a>
</p></div> </p></div>
<div class="left"> <div class="left">
Your Peer: Your Peer:
@ -232,7 +250,7 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
</tr> </tr>
</table> </table>
</div> </div>
<div class="left"><p> <div class="left">
<table border="0"> <table border="0">
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
@ -264,7 +282,13 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
<td>:</td> <td>:</td>
<td>this peer</td> <td>this peer</td>
</tr> </tr>
</table></p> <tr>
<td style="background-color:#AAAAAA">&nbsp;</td>
<td>waves</td>
<td>:</td>
<td>crawling activity</td>
</tr>
</table>
</div> </div>
:: ::

@ -37,6 +37,7 @@ public class NetworkPicture {
public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static RasterPlotter respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
final boolean authorized = sb.adminAuthenticated(header) >= 2;
int width = 768; int width = 768;
int height = 576; int height = 576;
@ -45,6 +46,7 @@ public class NetworkPicture {
int maxCount = 1000; int maxCount = 1000;
String bgcolor = NetworkGraph.COL_BACKGROUND; String bgcolor = NetworkGraph.COL_BACKGROUND;
boolean corona = true; boolean corona = true;
int coronaangle = 0;
if (post != null) { if (post != null) {
width = post.getInt("width", 768); width = post.getInt("width", 768);
@ -53,6 +55,7 @@ public class NetworkPicture {
potentialLimit = post.getInt("pol", 1440); potentialLimit = post.getInt("pol", 1440);
maxCount = post.getInt("max", 1000); maxCount = post.getInt("max", 1000);
corona = post.get("corona", "true").equals("true"); corona = post.get("corona", "true").equals("true");
coronaangle = (corona) ? post.getInt("coronaangle", 0) : -1;
bgcolor = post.get("bgcolor", bgcolor); bgcolor = post.get("bgcolor", bgcolor);
} }
@ -61,10 +64,14 @@ public class NetworkPicture {
if (width > 1920) width = 1920; if (width > 1920) width = 1920;
if (height < 240) height = 240; if (height < 240) height = 240;
if (height > 1920) height = 1920; if (height > 1920) height = 1920;
if (!authorized) {
width = Math.min(768, width);
height = Math.min(576, height);
}
if (passiveLimit > 1000000) passiveLimit = 1000000; if (passiveLimit > 1000000) passiveLimit = 1000000;
if (potentialLimit > 1000000) potentialLimit = 1000000; if (potentialLimit > 1000000) potentialLimit = 1000000;
if (maxCount > 10000) maxCount = 10000; if (maxCount > 10000) maxCount = 10000;
return NetworkGraph.getNetworkPicture(sb.peers, 10000, width, height, passiveLimit, potentialLimit, maxCount, corona, env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig("network.unit.description", "unspecified"), bgcolor); return NetworkGraph.getNetworkPicture(sb.peers, 10000, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), env.getConfig("network.unit.description", "unspecified"), bgcolor);
} }
} }

@ -40,7 +40,7 @@ public class SearchEventPicture {
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
final String eventID = header.get("event", SearchEventCache.lastEventID); final String eventID = header.get("event", SearchEventCache.lastEventID);
if (eventID == null) return null; if (eventID == null) return null;
final RasterPlotter yp = NetworkGraph.getSearchEventPicture(sb.peers, eventID); final RasterPlotter yp = NetworkGraph.getSearchEventPicture(sb.peers, eventID, 0);
if (yp == null) return new RasterPlotter(1, 1, RasterPlotter.MODE_SUB, "000000"); // empty image if (yp == null) return new RasterPlotter(1, 1, RasterPlotter.MODE_SUB, "000000"); // empty image
return yp; return yp;

@ -101,19 +101,16 @@ public class NetworkGraph {
} }
} }
private static final int LEGEND_BOX_SIZE = 10; private static final int LEGEND_BOX_SIZE = 10;
private static RasterPlotter networkPicture = null;
private static long networkPictureDate = 0;
private static BufferedImage peerloadPicture = null; private static BufferedImage peerloadPicture = null;
private static long peerloadPictureDate = 0; private static long peerloadPictureDate = 0;
private static RasterPlotter bannerPicture = null; // [MN] private static RasterPlotter bannerPicture = null; // [MN]
private static BufferedImage logo = null; // [MN] private static BufferedImage logo = null; // [MN]
private static long bannerPictureDate = 0; // [MN] private static long bannerPictureDate = 0; // [MN]
public static RasterPlotter getSearchEventPicture(final yacySeedDB seedDB, final String eventID) { public static RasterPlotter getSearchEventPicture(final yacySeedDB seedDB, final String eventID, final int coronaangle) {
final SearchEvent event = SearchEventCache.getEvent(eventID); final SearchEvent event = SearchEventCache.getEvent(eventID);
if (event == null) return null; if (event == null) return null;
final yacySearch[] primarySearches = event.getPrimarySearchThreads(); final yacySearch[] primarySearches = event.getPrimarySearchThreads();
@ -121,7 +118,7 @@ public class NetworkGraph {
if (primarySearches == null) return null; // this was a local search and there are no threads if (primarySearches == null) return null; // this was a local search and there are no threads
// get a copy of a recent network picture // get a copy of a recent network picture
final RasterPlotter eventPicture = getNetworkPicture(seedDB, 120000, 640, 480, 300, 300, 1000, true, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), Switchboard.getSwitchboard().getConfig("network.unit.description", "unspecified"), COL_BACKGROUND); final RasterPlotter eventPicture = getNetworkPicture(seedDB, 120000, 640, 480, 300, 300, 1000, coronaangle, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), Switchboard.getSwitchboard().getConfig("network.unit.description", "unspecified"), COL_BACKGROUND);
//if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture); //if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
// TODO: fix cloning of ymageMatrix pictures // TODO: fix cloning of ymageMatrix pictures
@ -164,23 +161,19 @@ public class NetworkGraph {
return eventPicture; return eventPicture;
} }
public static RasterPlotter getNetworkPicture(final yacySeedDB seedDB, final long maxAge, final int width, final int height, final int passiveLimit, final int potentialLimit, final int maxCount, final boolean corona, final String networkName, final String networkTitle, final String bgcolor) { public static RasterPlotter getNetworkPicture(final yacySeedDB seedDB, final long maxAge, final int width, final int height, final int passiveLimit, final int potentialLimit, final int maxCount, final int coronaangle, final String networkName, final String networkTitle, final String bgcolor) {
if ((networkPicture == null) || ((System.currentTimeMillis() - networkPictureDate) > maxAge)) { return drawNetworkPicture(seedDB, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, networkName, networkTitle, bgcolor);
drawNetworkPicture(seedDB, width, height, passiveLimit, potentialLimit, maxCount, corona, networkName, networkTitle, bgcolor);
}
return networkPicture;
} }
private static void drawNetworkPicture(final yacySeedDB seedDB, final int width, final int height, final int passiveLimit, final int potentialLimit, final int maxCount, final boolean corona, final String networkName, final String networkTitle, final String bgcolor) { private static RasterPlotter drawNetworkPicture(final yacySeedDB seedDB, final int width, final int height, final int passiveLimit, final int potentialLimit, final int maxCount, final int coronaangle, final String networkName, final String networkTitle, final String bgcolor) {
if (seedDB == null) return; // no other peers known RasterPlotter networkPicture = new RasterPlotter(width, height, (bgcolor.equals("000000")) ? RasterPlotter.MODE_ADD : RasterPlotter.MODE_SUB, bgcolor);
if (seedDB == null) return networkPicture; // no other peers known
final int innerradius = Math.min(width, height) / 5; final int innerradius = Math.min(width, height) / 5;
int outerradius = innerradius + innerradius * seedDB.sizeConnected() / 100; int outerradius = innerradius + innerradius * seedDB.sizeConnected() / 100;
if (outerradius > innerradius * 2) outerradius = innerradius * 2; if (outerradius > innerradius * 2) outerradius = innerradius * 2;
networkPicture = new RasterPlotter(width, height, (bgcolor.equals("000000")) ? RasterPlotter.MODE_ADD : RasterPlotter.MODE_SUB, bgcolor);
// draw network circle // draw network circle
networkPicture.setColor(COL_DHTCIRCLE); networkPicture.setColor(COL_DHTCIRCLE);
networkPicture.arc(width / 2, height / 2 + 20, innerradius - 20, innerradius + 20, 0, 360); networkPicture.arc(width / 2, height / 2 + 20, innerradius - 20, innerradius + 20, 0, 360);
@ -199,7 +192,7 @@ public class NetworkGraph {
while (e.hasNext() && count < maxCount) { while (e.hasNext() && count < maxCount) {
seed = e.next(); seed = e.next();
if (seed != null) { if (seed != null) {
drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seed, COL_ACTIVE_DOT, COL_ACTIVE_LINE, COL_ACTIVE_TEXT, corona); drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seed, COL_ACTIVE_DOT, COL_ACTIVE_LINE, COL_ACTIVE_TEXT, coronaangle);
count++; count++;
} }
} }
@ -213,7 +206,7 @@ public class NetworkGraph {
if (seed != null) { if (seed != null) {
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60); lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60);
if (lastseen > passiveLimit) break; // we have enough, this list is sorted so we don't miss anything if (lastseen > passiveLimit) break; // we have enough, this list is sorted so we don't miss anything
drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seed, COL_PASSIVE_DOT, COL_PASSIVE_LINE, COL_PASSIVE_TEXT, corona); drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seed, COL_PASSIVE_DOT, COL_PASSIVE_LINE, COL_PASSIVE_TEXT, coronaangle);
count++; count++;
} }
} }
@ -227,14 +220,14 @@ public class NetworkGraph {
if (seed != null) { if (seed != null) {
lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60); lastseen = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 1000 / 60);
if (lastseen > potentialLimit) break; // we have enough, this list is sorted so we don't miss anything if (lastseen > potentialLimit) break; // we have enough, this list is sorted so we don't miss anything
drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seed, COL_POTENTIAL_DOT, COL_POTENTIAL_LINE, COL_POTENTIAL_TEXT, corona); drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seed, COL_POTENTIAL_DOT, COL_POTENTIAL_LINE, COL_POTENTIAL_TEXT, coronaangle);
count++; count++;
} }
} }
totalCount += count; totalCount += count;
// draw my own peer // draw my own peer
drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seedDB.mySeed(), COL_WE_DOT, COL_WE_LINE, COL_WE_TEXT, corona); drawNetworkPicturePeer(networkPicture, width / 2, height / 2 + 20, innerradius, outerradius, seedDB.mySeed(), COL_WE_DOT, COL_WE_LINE, COL_WE_TEXT, coronaangle);
// draw description // draw description
networkPicture.setColor(COL_HEADLINE); networkPicture.setColor(COL_HEADLINE);
@ -243,11 +236,10 @@ public class NetworkGraph {
PrintTool.print(networkPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1); PrintTool.print(networkPicture, width - 2, 8, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
PrintTool.print(networkPicture, width - 2, 16, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", 1); PrintTool.print(networkPicture, width - 2, 16, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", 1);
// set timestamp return networkPicture;
networkPictureDate = System.currentTimeMillis();
} }
private static void drawNetworkPicturePeer(final RasterPlotter img, final int x, final int y, final int innerradius, final int outerradius, final yacySeed seed, final String colorDot, final String colorLine, final String colorText, final boolean corona) { private static void drawNetworkPicturePeer(final RasterPlotter img, final int x, final int y, final int innerradius, final int outerradius, final yacySeed seed, final String colorDot, final String colorLine, final String colorText, final int coronaangle) {
final String name = seed.getName().toUpperCase() /*+ ":" + seed.hash + ":" + (((double) ((int) (100 * (((double) yacySeed.dhtPosition(seed.hash)) / ((double) yacySeed.maxDHTDistance))))) / 100.0)*/; final String name = seed.getName().toUpperCase() /*+ ":" + seed.hash + ":" + (((double) ((int) (100 * (((double) yacySeed.dhtPosition(seed.hash)) / ((double) yacySeed.maxDHTDistance))))) / 100.0)*/;
if (name.length() < shortestName) shortestName = name.length(); if (name.length() < shortestName) shortestName = name.length();
if (name.length() > longestName) longestName = name.length(); if (name.length() > longestName) longestName = name.length();
@ -269,7 +261,8 @@ public class NetworkGraph {
// draw corona around dot for crawling activity // draw corona around dot for crawling activity
int ppm20 = seed.getPPM() / 20; int ppm20 = seed.getPPM() / 20;
if ((corona) && (ppm20 > 0)) { if (coronaangle >= 0 && ppm20 > 0) {
double ca = Math.PI * 2.0 * ((double) coronaangle) / 360.0;
if (ppm20 > 3) ppm20 = 3; if (ppm20 > 3) ppm20 = 3;
// draw a wave around crawling peers // draw a wave around crawling peers
long strength; long strength;
@ -277,7 +270,7 @@ public class NetworkGraph {
img.arcArc(x, y, innerradius, angle, dotsize + 1, dotsize + 1, 0, 360); img.arcArc(x, y, innerradius, angle, dotsize + 1, dotsize + 1, 0, 360);
final int waveradius = innerradius / 2; final int waveradius = innerradius / 2;
for (int r = 0; r < waveradius; r++) { for (int r = 0; r < waveradius; r++) {
strength = (waveradius - r) * (long) (0x08 * ppm20 * (1.0 + Math.sin(Math.PI * 16 * r / waveradius))) / waveradius; strength = (waveradius - r) * (long) (0x08 * ppm20 * (1.0 + Math.sin(ca + Math.PI * 16 * r / waveradius))) / waveradius;
//System.out.println("r = " + r + ", Strength = " + strength); //System.out.println("r = " + r + ", Strength = " + strength);
img.setColor((strength << 16) | (strength << 8) | strength); img.setColor((strength << 16) | (strength << 8) | strength);
img.arcArc(x, y, innerradius, angle, dotsize + r, dotsize + r, 0, 360); img.arcArc(x, y, innerradius, angle, dotsize + r, dotsize + r, 0, 360);

Loading…
Cancel
Save