Author: jflesch
Date: 2007-08-25 18:54:59 +0000 (Sat, 25 Aug 2007)
New Revision: 14879
Modified:
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java
trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphPanel.java
trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
Log:
Try to improve the graph with a force-based algorithm
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-08-25
16:15:52 UTC (rev 14878)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-08-25
18:54:59 UTC (rev 14879)
@@ -639,7 +639,7 @@
## Index web grapher
-thaw.plugin.indexWebGrapher=Toile d'indexes
+thaw.plugin.indexWebGrapher=Une tentative de repr?sentation de la toile des
indexes
thaw.plugin.indexWebGrapher.shortName=Toile d'indexes
thaw.plugin.indexWebGrapher.compute=Calculer
thaw.plugin.indexWebGrapher.computing=En cours ...
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-08-25 16:15:52 UTC
(rev 14878)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-08-25 18:54:59 UTC
(rev 14879)
@@ -657,7 +657,7 @@
## index web grapher
-thaw.plugin.indexWebGrapher=Index web grapher
+thaw.plugin.indexWebGrapher=An attempt to draw a graph of the index web
thaw.plugin.indexWebGrapher.shortName=Index web
thaw.plugin.indexWebGrapher.compute=Compute
thaw.plugin.indexWebGrapher.computing=Computing
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-08-25 16:15:52 UTC
(rev 14878)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-08-25 18:54:59 UTC
(rev 14879)
@@ -639,7 +639,7 @@
## Index web grapher
-thaw.plugin.indexWebGrapher=Toile d'indexes
+thaw.plugin.indexWebGrapher=Une tentative de repr\u00e9sentation de la toile
des indexes
thaw.plugin.indexWebGrapher.shortName=Toile d'indexes
thaw.plugin.indexWebGrapher.compute=Calculer
thaw.plugin.indexWebGrapher.computing=En cours ...
Modified: trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java 2007-08-25
16:15:52 UTC (rev 14878)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexWebGrapher.java 2007-08-25
18:54:59 UTC (rev 14879)
@@ -38,6 +38,7 @@
private JButton compute;
private JButton zoomIn;
private JButton zoomOut;
+ private JButton refresh;
private JProgressBar progressBar;
private Random random;
@@ -76,12 +77,14 @@
progressBar.setString(I18n.getMessage("thaw.plugin.indexWebGrapher.waiting"));
progressBar.setStringPainted(true);
- JPanel zoomPanel = new JPanel(new GridLayout(1, 2));
+ JPanel zoomPanel = new JPanel(new GridLayout(1, 3));
+ zoomPanel.add( (refresh = new JButton("",
thaw.gui.IconBox.minRefreshAction)) );
zoomPanel.add( (zoomOut = new JButton("-")) );
zoomPanel.add( (zoomIn = new JButton("+")) );
zoomOut.addActionListener(this);
zoomIn.addActionListener(this);
+ refresh.addActionListener(this);
southPanel.add(compute, BorderLayout.WEST);
southPanel.add(progressBar, BorderLayout.CENTER);
@@ -140,15 +143,26 @@
return thaw.gui.IconBox.web;
}
+ private GraphBuilder lastBuilder = null;
+
public void actionPerformed(ActionEvent e) {
if (e.getSource() == compute) {
- GraphBuilder builder = new GraphBuilder(this,
graphPanel, db);
- Thread th = new Thread(builder);
- th.start();
+ if (lastBuilder == null || lastBuilder.isFinished()) {
+ lastBuilder = new GraphBuilder(this,
graphPanel, db);
+ Thread th = new Thread(lastBuilder);
+ th.start();
+ } else {
+ if (!lastBuilder.fasterFlag())
+ lastBuilder.setFasterFlag(true);
+ else
+ lastBuilder.stop();
+ }
} else if (e.getSource() == zoomIn) {
graphPanel.zoomIn();
} else if (e.getSource() == zoomOut) {
graphPanel.zoomOut();
+ } else if (e.getSource() == refresh) {
+ graphPanel.refresh();
}
}
}
Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
2007-08-25 16:15:52 UTC (rev 14878)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphBuilder.java
2007-08-25 18:54:59 UTC (rev 14879)
@@ -19,14 +19,48 @@
private GraphPanel graphPanel;
private Hsqldb db;
+ private boolean faster;
+ private boolean finish;
+ private boolean stop;
+
public GraphBuilder(IndexWebGrapher plugin,
GraphPanel panel,
Hsqldb db) {
this.plugin = plugin;
this.graphPanel = panel;
this.db = db;
+ this.faster = false;
+ this.finish = false;
+ this.stop = false;
}
+ private class Refresher implements Runnable {
+ public Refresher() {
+
+ }
+
+ public void run() {
+ run(true);
+ }
+
+ public void run(boolean loop) {
+ do {
+
+ graphPanel.recomputeMinMax();
+ graphPanel.refresh();
+
+ try {
+ Thread.sleep(faster /* == separate
thread */ ? 5000 : 50 );
+ } catch(InterruptedException e) {
+ /* \_o< */
+ }
+
+ } while (loop && !stop && !finish);
+ }
+
+ }
+
+
public void run() {
Logger.info(this, "=== Starting ===");
@@ -49,11 +83,16 @@
int nmb = 0;
while(set.next()) {
+ String key = set.getString("publicKey");
+
+ if (FreenetURIHelper.isObsolete(key))
+ continue;
+
/* will register itself in the
graphPanel */
new Node(nmb,
set.getInt("id") /* index id
*/,
set.getString("displayName"),
- set.getString("publicKey"),
+ key,
graphPanel);
nmb++;
}
@@ -87,6 +126,9 @@
while(set.next()) {
String lnk =
set.getString("publicKey");
+ if
(FreenetURIHelper.isObsolete(lnk))
+ continue;
+
Node target =
graphPanel.getNode(lnk);
if (target == null) {
@@ -129,7 +171,7 @@
if (!node.isPositionSet()) {
node.setPosition(x, 0.0);
node.setInitialNeightboorPositions();
- x += (node.getLinkCount()+1);
+ x += ((Node.FACTOR_INITIAL_DISTANCE *
node.getLinkCount())+1);
}
}
@@ -138,7 +180,34 @@
plugin.setProgress(4);
Logger.info(this, "4) Optimizing placement ...");
- for (int i = 0 ; i < 100 ; i++) {
+ Refresher refresher = new Refresher();
+ Thread refresherTh = null;
+
+ int lastStep = 4;
+
+ for (int i = 0 ; i < Node.NMB_STEPS && !stop ; i++) {
+ int currentStep = (6 * i) / Node.NMB_STEPS;
+
+ if (currentStep != lastStep) {
+ plugin.setProgress(currentStep+4);
+ lastStep = currentStep;
+ }
+
+ if (i == 0)
+ graphPanel.guessZoom();
+
+ if (!faster)
+ refresher.run(false);
+ else {
+ if (refresherTh == null) {
+ refresherTh = new Thread(refresher);
+ refresherTh.start();
+ }
+ }
+
+ if (i%100 == 0)
+ Logger.info(this, "- Step
"+Integer.toString(i)+"/"+Node.NMB_STEPS);
+
for (Iterator it = nodes.iterator();
it.hasNext();) {
Node node = (Node)it.next();
@@ -171,6 +240,30 @@
plugin.setProgress(10);
Logger.info(this, "== Pouf, done ==");
+
+ for (Iterator it = nodes.iterator();
+ it.hasNext();) {
+ Node node = (Node)it.next();
+ Logger.info(this, node.toString());
+ }
+
+ finish = true;
} /* /run */
+
+ public void setFasterFlag(boolean faster) {
+ this.faster = faster;
+ }
+
+ public boolean fasterFlag() {
+ return faster;
+ }
+
+ public void stop() {
+ stop = true;
+ }
+
+ public boolean isFinished() {
+ return finish;
+ }
}
Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphPanel.java
2007-08-25 16:15:52 UTC (rev 14878)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/GraphPanel.java
2007-08-25 18:54:59 UTC (rev 14879)
@@ -79,7 +79,7 @@
private double maxY = 0;
- public void guessZoom() {
+ public void recomputeMinMax() {
minX = 0;
maxX = 0;
minY = 0;
@@ -94,7 +94,11 @@
if (node.getY() < minY) minY = node.getY();
if (node.getY() > maxY) maxY = node.getY();
}
+ }
+ public void guessZoom() {
+ recomputeMinMax();
+
Dimension size = plugin.getScrollPane().getSize();
double zoomX = (size.getWidth()-(2*BORDER)) / (maxX - minX);
@@ -138,6 +142,10 @@
int zeroX = (-1 * (int)(minX * zoom)) + BORDER;
int zeroY = (-1 * (int)(minY * zoom)) + BORDER;
+ g.setColor(java.awt.Color.GRAY);
+ g.drawLine(zeroX, 0, zeroX, (int)d.getHeight());
+ g.drawLine(0, zeroY, (int)d.getWidth(), zeroY);
+
for (Iterator it = nodeList.iterator();
it.hasNext();) {
((Node)it.next()).paintTaNodeFaceDeNoeud(g, zoom,
zeroX, zeroY);
Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java 2007-08-25
16:15:52 UTC (rev 14878)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java 2007-08-25
18:54:59 UTC (rev 14879)
@@ -119,14 +119,48 @@
private double velocityX = 0.0;
private double velocityY = 0.0;
- public final static double TIMESTEP = 0.1;
+ public final static double TIMESTEP = 0.001;
+ public final static int NMB_STEPS = 50000;
+ public final static double FACTOR_ATTRACTION = 1;
+ public final static double FACTOR_REPULSION = 1;
+ public final static double REPULSE_LIMIT = 10000;
+ public final static double FACTOR_DECELERATION = 1.1;
+ public final static double FACTOR_INITIAL_DISTANCE = 2.0;
+ /**
+ * attracted by its peers/neightbours
+ */
private double[] attraction(Node node) {
- return new double[] {0, 0};
+ double attrX = 0.0;
+ double attrY = 0.0;
+
+ attrX = (node.getX() - x)*FACTOR_ATTRACTION;
+ attrY = (node.getY() - y)*FACTOR_ATTRACTION;
+
+ return new double[] {attrX, attrY};
}
+ /**
+ * repulsed by all the node != peers / neightbours
+ */
private double[] repulsion(Node node) {
- return new double[] {0, 0};
+ double repX = 0.0;
+ double repY = 0.0;
+
+ if (x != node.getX())
+ repX = (1/(x-node.getX())*FACTOR_REPULSION);
+
+ if (y != node.getY())
+ repY = (1/(y-node.getY())*FACTOR_REPULSION);
+
+
+ if (repX > REPULSE_LIMIT) repX = REPULSE_LIMIT;
+ if (repY > REPULSE_LIMIT) repY = REPULSE_LIMIT;
+ if (repX < -REPULSE_LIMIT) repX = -REPULSE_LIMIT;
+ if (repY < -REPULSE_LIMIT) repY = -REPULSE_LIMIT;
+
+
+ return new double[] {repX, repY};
}
/**
@@ -141,10 +175,14 @@
it.hasNext();) {
Node node = (Node)it.next();
- if (node == this
+ /*
+ if (node == this
|| linkTo.indexOf(node) >= 0
|| linkedFrom.indexOf(node) >= 0)
continue;
+ */
+ if (node == this)
+ continue;
double[] repuls = repulsion(node);
netForceX += repuls[0];
@@ -177,6 +215,9 @@
netForceY += attr[1];
}
+ velocityX = velocityX/FACTOR_DECELERATION;
+ velocityY = velocityY/FACTOR_DECELERATION;
+
velocityX += netForceX;
velocityY += netForceY;
}
@@ -221,8 +262,8 @@
Node node = (Node)it.next();
if (!node.isPositionSet()) {
- double diffX = Math.cos(current) * (unplaced+1);
- double diffY = Math.sin(current) * (unplaced+1);
+ double diffX = Math.cos(current) *
((FACTOR_INITIAL_DISTANCE*unplaced)+1);
+ double diffY = Math.sin(current) *
((FACTOR_INITIAL_DISTANCE*unplaced)+1);
node.setPosition(x + diffX,
y + diffY);
@@ -296,6 +337,8 @@
if (selected)
g.setColor(Color.RED);
+ else if (getLinkCount() == 0)
+ g.setColor(Color.ORANGE);
else
g.setColor(Color.GREEN);
@@ -313,4 +356,8 @@
realY + zeroY - 10);
}
}
+
+ public String toString() {
+ return Double.toString(x) + " - " + Double.toString(y) + " ; "+
indexName;
+ }
}