You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
509 lines
27 KiB
509 lines
27 KiB
![]()
14 years ago
|
// NetworkGraph.java
|
||
![]()
20 years ago
|
// -----------------------
|
||
|
// part of YaCy
|
||
![]()
17 years ago
|
// (C) by Michael Peter Christen; mc@yacy.net
|
||
![]()
20 years ago
|
// first published on http://www.anomic.de
|
||
|
// Frankfurt, Germany, 2005
|
||
|
// Created 08.10.2005
|
||
|
//
|
||
![]()
19 years ago
|
// $LastChangedDate$
|
||
|
// $LastChangedRevision$
|
||
|
// $LastChangedBy$
|
||
![]()
20 years ago
|
//
|
||
|
// This program is free software; you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation; either version 2 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
|
||
![]()
14 years ago
|
package net.yacy.peers.graphics;
|
||
![]()
20 years ago
|
|
||
![]()
18 years ago
|
import java.awt.Color;
|
||
|
import java.awt.Graphics2D;
|
||
![]()
18 years ago
|
import java.awt.RenderingHints;
|
||
![]()
18 years ago
|
import java.awt.image.BufferedImage;
|
||
![]()
19 years ago
|
import java.util.Date;
|
||
|
import java.util.Iterator;
|
||
|
|
||
![]()
14 years ago
|
import net.yacy.cora.document.ASCII;
|
||
![]()
15 years ago
|
import net.yacy.cora.document.Hit;
|
||
![]()
14 years ago
|
import net.yacy.cora.document.UTF8;
|
||
![]()
15 years ago
|
import net.yacy.kelondro.logging.Log;
|
||
![]()
14 years ago
|
import net.yacy.peers.yacyChannel;
|
||
|
import net.yacy.peers.yacySearch;
|
||
|
import net.yacy.peers.yacySeed;
|
||
|
import net.yacy.peers.yacySeedDB;
|
||
|
import net.yacy.peers.dht.FlatWordPartitionScheme;
|
||
|
import net.yacy.search.Switchboard;
|
||
|
import net.yacy.search.SwitchboardConstants;
|
||
|
import net.yacy.search.query.QueryParams;
|
||
|
import net.yacy.search.query.SearchEvent;
|
||
|
import net.yacy.search.query.SearchEventCache;
|
||
![]()
16 years ago
|
import net.yacy.visualization.PrintTool;
|
||
|
import net.yacy.visualization.RasterPlotter;
|
||
![]()
20 years ago
|
|
||
![]()
16 years ago
|
public class NetworkGraph {
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
private static int shortestName = 10;
|
||
|
private static int longestName = 12;
|
||
![]()
19 years ago
|
|
||
![]()
18 years ago
|
public static final String COL_BACKGROUND = "FFFFFF";
|
||
|
private static final String COL_DHTCIRCLE = "006020";
|
||
|
private static final String COL_HEADLINE = "FFFFFF";
|
||
|
private static final String COL_ACTIVE_DOT = "000044";
|
||
|
private static final String COL_ACTIVE_LINE = "335544";
|
||
|
private static final String COL_ACTIVE_TEXT = "66AA88";
|
||
|
private static final String COL_PASSIVE_DOT = "221111";
|
||
|
private static final String COL_PASSIVE_LINE = "443333";
|
||
|
private static final String COL_PASSIVE_TEXT = "663333";
|
||
|
private static final String COL_POTENTIAL_DOT = "002200";
|
||
|
private static final String COL_POTENTIAL_LINE = "224422";
|
||
|
private static final String COL_POTENTIAL_TEXT = "336633";
|
||
![]()
15 years ago
|
private static final String COL_MYPEER_DOT = "FF0000";
|
||
|
private static final String COL_MYPEER_LINE = "FFAAAA";
|
||
|
private static final String COL_MYPEER_TEXT = "FFCCCC";
|
||
|
private static final String COL_DHTOUT = "440000";
|
||
![]()
15 years ago
|
private static final String COL_DHTIN = "008800";
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
private static final String COL_BORDER = "000000";
|
||
|
private static final String COL_NORMAL_TEXT = "000000";
|
||
|
private static final String COL_LOAD_BG = "F7F7F7";
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
public static class CircleThreadPiece {
|
||
|
private final String pieceName;
|
||
|
private final Color color;
|
||
|
private long execTime = 0;
|
||
![]()
18 years ago
|
private float fraction = 0;
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
public CircleThreadPiece(final String pieceName, final Color color) {
|
||
![]()
18 years ago
|
this.pieceName = pieceName;
|
||
|
this.color = color;
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
public int getAngle() { return Math.round(360f*this.fraction); }
|
||
|
public int getFractionPercent() { return Math.round(100f*this.fraction); }
|
||
![]()
18 years ago
|
public Color getColor() { return this.color; }
|
||
|
public long getExecTime() { return this.execTime; }
|
||
|
public String getPieceName() { return this.pieceName; }
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
public void addExecTime(final long execTime) { this.execTime += execTime; }
|
||
![]()
18 years ago
|
public void reset() {
|
||
|
this.execTime = 0;
|
||
![]()
18 years ago
|
this.fraction = 0;
|
||
![]()
18 years ago
|
}
|
||
![]()
17 years ago
|
public void setExecTime(final long execTime) { this.execTime = execTime; }
|
||
|
public void setFraction(final long totalBusyTime) {
|
||
![]()
18 years ago
|
this.fraction = (float)this.execTime / (float)totalBusyTime;
|
||
![]()
18 years ago
|
}
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
15 years ago
|
private static final int LEGEND_BOX_SIZE = 10;
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
private static BufferedImage peerloadPicture = null;
|
||
|
private static long peerloadPictureDate = 0;
|
||
![]()
19 years ago
|
|
||
![]()
14 years ago
|
private static RasterPlotter bannerPicture = null;
|
||
|
private static BufferedImage logo = null;
|
||
|
private static long bannerPictureDate = 0;
|
||
![]()
18 years ago
|
|
||
![]()
14 years ago
|
public static RasterPlotter getSearchEventPicture(final yacySeedDB seedDB, final String eventID, final int coronaangle, final int cyc) {
|
||
![]()
16 years ago
|
final SearchEvent event = SearchEventCache.getEvent(eventID);
|
||
![]()
18 years ago
|
if (event == null) return null;
|
||
![]()
17 years ago
|
final yacySearch[] primarySearches = event.getPrimarySearchThreads();
|
||
|
final yacySearch[] secondarySearches = event.getSecondarySearchThreads();
|
||
![]()
19 years ago
|
if (primarySearches == null) return null; // this was a local search and there are no threads
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// get a copy of a recent network picture
|
||
![]()
14 years ago
|
final RasterPlotter eventPicture = getNetworkPicture(seedDB, 120000, 640, 480, 300, 300, 1000, coronaangle, -1, Switchboard.getSwitchboard().getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"), Switchboard.getSwitchboard().getConfig("network.unit.description", "unspecified"), COL_BACKGROUND, cyc);
|
||
![]()
18 years ago
|
//if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
|
||
![]()
19 years ago
|
// TODO: fix cloning of ymageMatrix pictures
|
||
![]()
14 years ago
|
|
||
![]()
20 years ago
|
// get dimensions
|
||
![]()
17 years ago
|
final int cr = Math.min(eventPicture.getWidth(), eventPicture.getHeight()) / 5 - 20;
|
||
|
final int cx = eventPicture.getWidth() / 2;
|
||
![]()
15 years ago
|
final int cy = eventPicture.getHeight() / 2 + 20;
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
int angle;
|
||
![]()
19 years ago
|
|
||
![]()
19 years ago
|
// draw in the primary search peers
|
||
![]()
14 years ago
|
for (final yacySearch primarySearche : primarySearches) {
|
||
|
if (primarySearche == null) continue;
|
||
|
eventPicture.setColor((primarySearche.isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN);
|
||
![]()
14 years ago
|
angle = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(primarySearche.target().hash), null)) / ((double) Long.MAX_VALUE)));
|
||
![]()
14 years ago
|
eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false);
|
||
![]()
20 years ago
|
}
|
||
![]()
19 years ago
|
|
||
![]()
19 years ago
|
// draw in the secondary search peers
|
||
|
if (secondarySearches != null) {
|
||
![]()
14 years ago
|
for (final yacySearch secondarySearche : secondarySearches) {
|
||
|
if (secondarySearche == null) continue;
|
||
|
eventPicture.setColor((secondarySearche.isAlive()) ? RasterPlotter.RED : RasterPlotter.GREEN);
|
||
![]()
14 years ago
|
angle = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(UTF8.getBytes(secondarySearche.target().hash), null)) / ((double) Long.MAX_VALUE)));
|
||
![]()
14 years ago
|
eventPicture.arcLine(cx, cy, cr - 10, cr, angle - 1, true, null, null, -1, -1, -1, false);
|
||
|
eventPicture.arcLine(cx, cy, cr - 10, cr, angle + 1, true, null, null, -1, -1, -1, false);
|
||
![]()
19 years ago
|
}
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
20 years ago
|
// draw in the search target
|
||
![]()
16 years ago
|
final QueryParams query = event.getQuery();
|
||
![]()
16 years ago
|
final Iterator<byte[]> i = query.queryHashes.iterator();
|
||
![]()
16 years ago
|
eventPicture.setColor(RasterPlotter.GREY);
|
||
![]()
20 years ago
|
while (i.hasNext()) {
|
||
![]()
14 years ago
|
final long[] positions = seedDB.scheme.dhtPositions(i.next());
|
||
|
for (final long position : positions) {
|
||
![]()
14 years ago
|
angle = cyc + (int) (360.0 * (((double) position) / ((double) Long.MAX_VALUE)));
|
||
![]()
14 years ago
|
eventPicture.arcLine(cx, cy, cr - 20, cr, angle, true, null, null, -1, -1, -1, false);
|
||
![]()
16 years ago
|
}
|
||
![]()
20 years ago
|
}
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
return eventPicture;
|
||
|
}
|
||
![]()
19 years ago
|
|
||
![]()
14 years ago
|
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 long communicationTimeout, final String networkName, final String networkTitle, final String bgcolor, final int cyc) {
|
||
|
return drawNetworkPicture(seedDB, width, height, passiveLimit, potentialLimit, maxCount, coronaangle, communicationTimeout, networkName, networkTitle, bgcolor, cyc);
|
||
![]()
20 years ago
|
}
|
||
![]()
19 years ago
|
|
||
![]()
14 years ago
|
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 long communicationTimeout,
|
||
![]()
14 years ago
|
final String networkName, final String networkTitle, final String color_back,
|
||
|
final int cyc) {
|
||
![]()
19 years ago
|
|
||
![]()
14 years ago
|
final RasterPlotter.DrawMode drawMode = (RasterPlotter.darkColor(color_back)) ? RasterPlotter.DrawMode.MODE_ADD : RasterPlotter.DrawMode.MODE_SUB;
|
||
|
final RasterPlotter networkPicture = new RasterPlotter(width, height, drawMode, color_back);
|
||
![]()
15 years ago
|
if (seedDB == null) return networkPicture; // no other peers known
|
||
![]()
14 years ago
|
|
||
|
final int maxradius = Math.min(width, height) / 2;
|
||
|
final int innerradius = maxradius * 4 / 10;
|
||
![]()
14 years ago
|
final int outerradius = maxradius - 20;
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// draw network circle
|
||
![]()
19 years ago
|
networkPicture.setColor(COL_DHTCIRCLE);
|
||
![]()
14 years ago
|
networkPicture.arc(width / 2, height / 2, innerradius - 20, innerradius + 20, 100);
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
//System.out.println("Seed Maximum distance is " + yacySeed.maxDHTDistance);
|
||
|
//System.out.println("Seed Minimum distance is " + yacySeed.minDHTNumber);
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
yacySeed seed;
|
||
|
long lastseen;
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// draw connected senior and principals
|
||
|
int count = 0;
|
||
|
int totalCount = 0;
|
||
![]()
17 years ago
|
Iterator<yacySeed> e = seedDB.seedsConnected(true, false, null, (float) 0.0);
|
||
![]()
18 years ago
|
while (e.hasNext() && count < maxCount) {
|
||
![]()
17 years ago
|
seed = e.next();
|
||
![]()
15 years ago
|
if (seed == null) {
|
||
|
Log.logWarning("NetworkGraph", "connected seed == null");
|
||
|
continue;
|
||
![]()
20 years ago
|
}
|
||
![]()
15 years ago
|
//Log.logInfo("NetworkGraph", "drawing peer " + seed.getName());
|
||
![]()
14 years ago
|
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_ACTIVE_DOT, COL_ACTIVE_LINE, COL_ACTIVE_TEXT, coronaangle, cyc);
|
||
![]()
15 years ago
|
count++;
|
||
![]()
20 years ago
|
}
|
||
|
totalCount += count;
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// draw disconnected senior and principals that have been seen lately
|
||
|
count = 0;
|
||
![]()
17 years ago
|
e = seedDB.seedsSortedDisconnected(false, yacySeed.LASTSEEN);
|
||
![]()
18 years ago
|
while (e.hasNext() && count < maxCount) {
|
||
![]()
17 years ago
|
seed = e.next();
|
||
![]()
15 years ago
|
if (seed == null) {
|
||
|
Log.logWarning("NetworkGraph", "disconnected seed == null");
|
||
|
continue;
|
||
![]()
20 years ago
|
}
|
||
![]()
15 years ago
|
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
|
||
|
}
|
||
![]()
14 years ago
|
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_PASSIVE_DOT, COL_PASSIVE_LINE, COL_PASSIVE_TEXT, coronaangle, cyc);
|
||
![]()
15 years ago
|
count++;
|
||
![]()
20 years ago
|
}
|
||
|
totalCount += count;
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// draw juniors that have been seen lately
|
||
|
count = 0;
|
||
![]()
17 years ago
|
e = seedDB.seedsSortedPotential(false, yacySeed.LASTSEEN);
|
||
![]()
18 years ago
|
while (e.hasNext() && count < maxCount) {
|
||
![]()
17 years ago
|
seed = e.next();
|
||
![]()
15 years ago
|
if (seed == null) {
|
||
|
Log.logWarning("NetworkGraph", "potential seed == null");
|
||
|
continue;
|
||
|
}
|
||
|
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
|
||
![]()
20 years ago
|
}
|
||
![]()
14 years ago
|
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seed, COL_POTENTIAL_DOT, COL_POTENTIAL_LINE, COL_POTENTIAL_TEXT, coronaangle, cyc);
|
||
![]()
15 years ago
|
count++;
|
||
![]()
20 years ago
|
}
|
||
|
totalCount += count;
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// draw my own peer
|
||
![]()
14 years ago
|
drawNetworkPicturePeer(networkPicture, width / 2, height / 2, innerradius, outerradius, seedDB.mySeed(), COL_MYPEER_DOT, COL_MYPEER_LINE, COL_MYPEER_TEXT, coronaangle, cyc);
|
||
![]()
19 years ago
|
|
||
![]()
15 years ago
|
// draw DHT activity
|
||
![]()
15 years ago
|
if (communicationTimeout >= 0) {
|
||
![]()
14 years ago
|
final Date horizon = new Date(System.currentTimeMillis() - communicationTimeout);
|
||
|
for (final Hit event: yacyChannel.channels(yacyChannel.DHTRECEIVE)) {
|
||
![]()
15 years ago
|
if (event == null || event.getPubDate() == null) continue;
|
||
![]()
15 years ago
|
if (event.getPubDate().after(horizon)) {
|
||
|
//System.out.println("*** NETWORK-DHTRECEIVE: " + event.getLink());
|
||
![]()
14 years ago
|
drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTIN, coronaangle, false, cyc);
|
||
![]()
15 years ago
|
}
|
||
|
}
|
||
![]()
14 years ago
|
for (final Hit event: yacyChannel.channels(yacyChannel.DHTSEND)) {
|
||
![]()
15 years ago
|
if (event == null || event.getPubDate() == null) continue;
|
||
![]()
15 years ago
|
if (event.getPubDate().after(horizon)) {
|
||
|
//System.out.println("*** NETWORK-DHTSEND: " + event.getLink());
|
||
![]()
14 years ago
|
drawNetworkPictureDHT(networkPicture, width / 2, height / 2, innerradius, seedDB.mySeed(), seedDB.get(event.getLink()), COL_DHTOUT, coronaangle, true, cyc);
|
||
![]()
15 years ago
|
}
|
||
|
}
|
||
![]()
14 years ago
|
}
|
||
|
|
||
![]()
20 years ago
|
// draw description
|
||
![]()
19 years ago
|
networkPicture.setColor(COL_HEADLINE);
|
||
![]()
14 years ago
|
PrintTool.print(networkPicture, 2, 6, 0, "YACY NETWORK '" + networkName.toUpperCase() + "'", -1);
|
||
|
PrintTool.print(networkPicture, 2, 14, 0, networkTitle.toUpperCase(), -1);
|
||
|
PrintTool.print(networkPicture, width - 2, 6, 0, "SNAPSHOT FROM " + new Date().toString().toUpperCase(), 1);
|
||
|
PrintTool.print(networkPicture, width - 2, 14, 0, "DRAWING OF " + totalCount + " SELECTED PEERS", 1);
|
||
![]()
14 years ago
|
|
||
![]()
15 years ago
|
return networkPicture;
|
||
![]()
20 years ago
|
}
|
||
![]()
19 years ago
|
|
||
![]()
14 years ago
|
private static void drawNetworkPictureDHT(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final yacySeed mySeed, final yacySeed otherSeed, final String colorLine, final int coronaangle, final boolean out, final int cyc) {
|
||
|
final int angleMy = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(mySeed.hash), null)) / ((double) Long.MAX_VALUE)));
|
||
|
final int angleOther = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(otherSeed.hash), null)) / ((double) Long.MAX_VALUE)));
|
||
![]()
15 years ago
|
// draw line
|
||
![]()
14 years ago
|
img.arcLine(centerX, centerY, innerradius, innerradius - 20, angleMy, !out,
|
||
|
colorLine, null, 12, (coronaangle < 0) ? -1 : coronaangle / 30, 2, true);
|
||
|
img.arcLine(centerX, centerY, innerradius, innerradius - 20, angleOther, out,
|
||
|
colorLine, null, 12, (coronaangle < 0) ? -1 : coronaangle / 30, 2, true);
|
||
|
img.arcConnect(centerX, centerY, innerradius - 20, angleMy, angleOther, out,
|
||
|
colorLine, 100, null, 100, 12, (coronaangle < 0) ? -1 : coronaangle / 30, 2, true);
|
||
![]()
15 years ago
|
}
|
||
![]()
14 years ago
|
|
||
![]()
14 years ago
|
private static void drawNetworkPicturePeer(
|
||
|
final RasterPlotter img, final int centerX, final int centerY,
|
||
|
final int innerradius, final int outerradius,
|
||
|
final yacySeed seed,
|
||
|
final String colorDot, final String colorLine, final String colorText,
|
||
![]()
14 years ago
|
final int coronaangle,
|
||
|
final int cyc) {
|
||
![]()
17 years ago
|
final String name = seed.getName().toUpperCase() /*+ ":" + seed.hash + ":" + (((double) ((int) (100 * (((double) yacySeed.dhtPosition(seed.hash)) / ((double) yacySeed.maxDHTDistance))))) / 100.0)*/;
|
||
![]()
20 years ago
|
if (name.length() < shortestName) shortestName = name.length();
|
||
|
if (name.length() > longestName) longestName = name.length();
|
||
![]()
14 years ago
|
final int angle = cyc + (int) (360.0 * (((double) FlatWordPartitionScheme.std.dhtPosition(ASCII.getBytes(seed.hash), null)) / ((double) Long.MAX_VALUE)));
|
||
![]()
20 years ago
|
//System.out.println("Seed " + seed.hash + " has distance " + seed.dhtDistance() + ", angle = " + angle);
|
||
![]()
17 years ago
|
int linelength = 20 + outerradius * (20 * (name.length() - shortestName) / (longestName - shortestName) + Math.abs(seed.hash.hashCode() % 20)) / 60;
|
||
![]()
20 years ago
|
if (linelength > outerradius) linelength = outerradius;
|
||
![]()
17 years ago
|
int dotsize = 4 + (int) (seed.getLinkCount() / 2000000L);
|
||
![]()
19 years ago
|
if (dotsize > 18) dotsize = 18;
|
||
![]()
20 years ago
|
// draw dot
|
||
|
img.setColor(colorDot);
|
||
![]()
15 years ago
|
img.arcDot(centerX, centerY, innerradius, angle, dotsize);
|
||
![]()
20 years ago
|
// draw line to text
|
||
![]()
14 years ago
|
img.arcLine(centerX, centerY, innerradius + 18, innerradius + linelength, angle, true, colorLine, "444444", 12, coronaangle / 30, 0, true);
|
||
![]()
20 years ago
|
// draw text
|
||
|
img.setColor(colorText);
|
||
![]()
15 years ago
|
PrintTool.arcPrint(img, centerX, centerY, innerradius + linelength, angle, name);
|
||
![]()
19 years ago
|
|
||
![]()
20 years ago
|
// draw corona around dot for crawling activity
|
||
![]()
14 years ago
|
final int ppmx = seed.getPPM() / 30;
|
||
![]()
15 years ago
|
if (coronaangle >= 0 && ppmx > 0) {
|
||
|
drawCorona(img, centerX, centerY, innerradius, angle, dotsize, ppmx, coronaangle, true, false, 24, 24, 24); // color = 0..63
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
15 years ago
|
// draw corona around dot for query activity
|
||
![]()
14 years ago
|
final int qphx = ((int) (seed.getQPM() * 4.0));
|
||
![]()
15 years ago
|
if (coronaangle >= 0 && qphx > 0) {
|
||
|
drawCorona(img, centerX, centerY, innerradius, angle, dotsize, qphx, coronaangle, false, true, 8, 62, 8); // color = 0..63
|
||
|
}
|
||
|
}
|
||
![]()
14 years ago
|
|
||
|
private static void drawCorona(final RasterPlotter img, final int centerX, final int centerY, final int innerradius, final int angle, final int dotsize, int strength, final int coronaangle, final boolean inside, final boolean split, final int r, final int g, final int b) {
|
||
|
final double ca = Math.PI * 2.0 * (coronaangle) / 360.0;
|
||
![]()
15 years ago
|
if (strength > 4) strength = 4;
|
||
|
// draw a wave around crawling peers
|
||
|
double wave;
|
||
|
final int waveradius = innerradius / 2;
|
||
![]()
14 years ago
|
final int segments = 72;
|
||
![]()
15 years ago
|
for (int radius = 0; radius < waveradius; radius++) {
|
||
![]()
14 years ago
|
wave = ((double) (waveradius - radius) * strength) * (1.0 + Math.sin(Math.PI * 16 * radius / waveradius + ((inside) ? ca : -ca))) / 2.0 / waveradius;
|
||
![]()
15 years ago
|
img.setColor(((((long) (r * wave)) & 0xff) << 16) | (((long) ((g * wave)) & 0xff) << 8) | ((((long) (b * wave))) & 0xff));
|
||
|
if (split) {
|
||
|
for (int i = 0; i < segments; i++) {
|
||
![]()
14 years ago
|
final int a = (coronaangle + 360 * i) / segments;
|
||
![]()
15 years ago
|
img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, a, a + 180/segments);
|
||
|
}
|
||
|
} else {
|
||
![]()
14 years ago
|
img.arcArc(centerX, centerY, innerradius, angle, dotsize + radius, dotsize + radius, 100);
|
||
![]()
20 years ago
|
}
|
||
|
}
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
public static BufferedImage getPeerLoadPicture(final long maxAge, final int width, final int height, final CircleThreadPiece[] pieces, final CircleThreadPiece fillRest) {
|
||
![]()
18 years ago
|
if ((peerloadPicture == null) || ((System.currentTimeMillis() - peerloadPictureDate) > maxAge)) {
|
||
![]()
18 years ago
|
drawPeerLoadPicture(width, height, pieces, fillRest);
|
||
![]()
18 years ago
|
}
|
||
|
return peerloadPicture;
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
private static void drawPeerLoadPicture(final int width, final int height, final CircleThreadPiece[] pieces, final CircleThreadPiece fillRest) {
|
||
![]()
18 years ago
|
//prepare image
|
||
|
peerloadPicture = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
|
||
![]()
17 years ago
|
final Graphics2D g = peerloadPicture.createGraphics();
|
||
![]()
17 years ago
|
g.setBackground(Color.decode("0x"+COL_LOAD_BG));
|
||
![]()
18 years ago
|
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||
|
g.clearRect(0,0,width,height);
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
final int circ_w = Math.min(width,height)-20; //width of the circle (r*2)
|
||
|
final int circ_x = width-circ_w-10; //x-coordinate of circle-left
|
||
|
final int circ_y = 10; //y-coordinate of circle-top
|
||
![]()
18 years ago
|
int curr_angle = 0; //remember current angle
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
int i;
|
||
|
for (i=0; i<pieces.length; i++) {
|
||
|
// draw the piece
|
||
|
g.setColor(pieces[i].getColor());
|
||
![]()
18 years ago
|
g.fillArc(circ_x, circ_y, circ_w, circ_w, curr_angle, pieces[i].getAngle());
|
||
|
curr_angle += pieces[i].getAngle();
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
// draw it's legend line
|
||
![]()
18 years ago
|
drawLegendLine(g, 5, height - 5 - 15 * i, pieces[i].getPieceName()+" ("+pieces[i].getFractionPercent()+" %)", pieces[i].getColor());
|
||
![]()
18 years ago
|
}
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
// fill the rest
|
||
|
g.setColor(fillRest.getColor());
|
||
![]()
18 years ago
|
//FIXME: better method to avoid gaps on rounding-differences?
|
||
![]()
18 years ago
|
g.fillArc(circ_x, circ_y, circ_w, circ_w, curr_angle, 360 - curr_angle);
|
||
|
drawLegendLine(g, 5, height - 5 - 15 * i, fillRest.getPieceName()+" ("+fillRest.getFractionPercent()+" %)", fillRest.getColor());
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
//draw border around the circle
|
||
![]()
17 years ago
|
g.setColor(Color.decode("0x"+COL_BORDER));
|
||
![]()
18 years ago
|
g.drawArc(circ_x, circ_y, circ_w, circ_w, 0, 360);
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
peerloadPictureDate = System.currentTimeMillis();
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
private static void drawLegendLine(final Graphics2D g, final int x, final int y, final String caption, final Color item_color) {
|
||
![]()
18 years ago
|
g.setColor(item_color);
|
||
|
g.fillRect(x, y-LEGEND_BOX_SIZE, LEGEND_BOX_SIZE, LEGEND_BOX_SIZE);
|
||
![]()
17 years ago
|
g.setColor(Color.decode("0x"+COL_BORDER));
|
||
![]()
18 years ago
|
g.drawRect(x, y-LEGEND_BOX_SIZE, LEGEND_BOX_SIZE, LEGEND_BOX_SIZE);
|
||
![]()
14 years ago
|
|
||
![]()
17 years ago
|
g.setColor(Color.decode("0x"+COL_NORMAL_TEXT));
|
||
![]()
18 years ago
|
g.drawChars(caption.toCharArray(), 0, caption.length(), x+LEGEND_BOX_SIZE+5,y);
|
||
|
}
|
||
![]()
19 years ago
|
|
||
![]()
16 years ago
|
public static RasterPlotter getBannerPicture(final long maxAge, final int width, final int height, final String bgcolor, final String textcolor, final String bordercolor, final String name, final long links, final long words, final String type, final int ppm, final String network, final int peers, final long nlinks, final long nwords, final double nqph, final long nppm) {
|
||
![]()
18 years ago
|
if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) {
|
||
![]()
18 years ago
|
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, peers, nlinks, nwords, nqph, nppm, logo);
|
||
![]()
18 years ago
|
}
|
||
|
return bannerPicture;
|
||
![]()
14 years ago
|
}
|
||
|
|
||
![]()
16 years ago
|
public static RasterPlotter getBannerPicture(final long maxAge, final int width, final int height, final String bgcolor, final String textcolor, final String bordercolor, final String name, final long links, final long words, final String type, final int ppm, final String network, final int peers, final long nlinks, final long nwords, final double nqph, final long nppm, final BufferedImage newLogo) {
|
||
![]()
18 years ago
|
if ((bannerPicture == null) || ((System.currentTimeMillis() - bannerPictureDate) > maxAge)) {
|
||
![]()
18 years ago
|
drawBannerPicture(width, height, bgcolor, textcolor, bordercolor, name, links, words, type, ppm, network, peers, nlinks, nwords, nqph, nppm, newLogo);
|
||
![]()
18 years ago
|
}
|
||
![]()
18 years ago
|
return bannerPicture;
|
||
|
}
|
||
|
|
||
![]()
17 years ago
|
private static void drawBannerPicture(final int width, final int height, final String bgcolor, final String textcolor, final String bordercolor, final String name, final long links, final long words, final String type, final int ppm, final String network, final int peers, final long nlinks, final long nwords, final double nqph, final long nppm, final BufferedImage newLogo) {
|
||
![]()
18 years ago
|
|
||
![]()
17 years ago
|
final int exprlength = 19;
|
||
![]()
18 years ago
|
logo = newLogo;
|
||
![]()
15 years ago
|
bannerPicture = new RasterPlotter(width, height, RasterPlotter.DrawMode.MODE_REPLACE, bgcolor);
|
||
![]()
18 years ago
|
|
||
|
// draw description
|
||
|
bannerPicture.setColor(textcolor);
|
||
![]()
16 years ago
|
PrintTool.print(bannerPicture, 100, 12, 0, "PEER: " + addTrailingBlanks(name, exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 100, 22, 0, "LINKS: " + addBlanksAndDots(links, exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 100, 32, 0, "WORDS: " + addBlanksAndDots(words, exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 100, 42, 0, "TYPE: " + addTrailingBlanks(type, exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 100, 52, 0, "SPEED: " + addTrailingBlanks(ppm + " PAGES/MINUTE", exprlength), -1);
|
||
|
|
||
|
PrintTool.print(bannerPicture, 285, 12, 0, "NETWORK: " + addTrailingBlanks(network + " [" + peers + "]", exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 285, 22, 0, "LINKS: " + addBlanksAndDots(nlinks, exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 285, 32, 0, "WORDS: " + addBlanksAndDots(nwords, exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 285, 42, 0, "QUERIES: " + addTrailingBlanks(nqph + " QUERIES/HOUR", exprlength), -1);
|
||
|
PrintTool.print(bannerPicture, 285, 52, 0, "SPEED: " + addTrailingBlanks(nppm + " PAGES/MINUTE", exprlength), -1);
|
||
![]()
18 years ago
|
|
||
![]()
18 years ago
|
if (logo != null) {
|
||
![]()
17 years ago
|
final int x = (100/2 - logo.getWidth()/2);
|
||
|
final int y = (height/2 - logo.getHeight()/2);
|
||
![]()
15 years ago
|
bannerPicture.insertBitmap(logo, x, y, 0, 0, RasterPlotter.FilterMode.FILTER_ANTIALIASING);
|
||
![]()
18 years ago
|
}
|
||
|
|
||
![]()
18 years ago
|
if (!bordercolor.equals("")) {
|
||
|
bannerPicture.setColor(bordercolor);
|
||
![]()
15 years ago
|
bannerPicture.line(0, 0, 0, height-1, 100);
|
||
|
bannerPicture.line(0, 0, width-1, 0, 100);
|
||
|
bannerPicture.line(width-1, 0, width-1, height-1, 100);
|
||
|
bannerPicture.line(0, height-1, width-1, height-1, 100);
|
||
![]()
18 years ago
|
}
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
// set timestamp
|
||
![]()
18 years ago
|
bannerPictureDate = System.currentTimeMillis();
|
||
|
}
|
||
![]()
14 years ago
|
|
||
![]()
18 years ago
|
public static boolean logoIsLoaded() {
|
||
|
if (logo == null) {
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
![]()
18 years ago
|
|
||
![]()
17 years ago
|
private static String addBlanksAndDots(final long input, final int length) {
|
||
![]()
16 years ago
|
return addBlanksAndDots(Long.toString(input), length);
|
||
![]()
18 years ago
|
}
|
||
|
|
||
![]()
17 years ago
|
private static String addBlanksAndDots(String input, final int length) {
|
||
![]()
18 years ago
|
input = addDots(input);
|
||
|
input = addTrailingBlanks(input,length);
|
||
|
return input;
|
||
|
}
|
||
|
|
||
|
private static String addDots(String word) {
|
||
|
String tmp = "";
|
||
|
int len = word.length();
|
||
![]()
18 years ago
|
if (len > 3) {
|
||
|
while(len > 3) {
|
||
|
if(tmp.equals("")) {
|
||
|
tmp = word.substring(len-3,len);
|
||
|
} else {
|
||
|
tmp = word.substring(len-3,len) + "." + tmp;
|
||
|
}
|
||
|
word = word.substring(0,len-3);
|
||
|
len = word.length();
|
||
![]()
18 years ago
|
}
|
||
![]()
18 years ago
|
word = word + "." + tmp;
|
||
![]()
18 years ago
|
}
|
||
|
return word;
|
||
|
}
|
||
|
|
||
|
private static String addTrailingBlanks(String word, int length) {
|
||
|
if (length > word.length()) {
|
||
|
String blanks = "";
|
||
|
length = length - word.length();
|
||
|
int i = 0;
|
||
|
while(i++ < length) {
|
||
|
blanks += " ";
|
||
|
}
|
||
|
word = blanks + word;
|
||
|
}
|
||
|
return word;
|
||
![]()
18 years ago
|
}
|
||
|
|
||
![]()
19 years ago
|
}
|