From 5b69bfb87dab02bcb00e883692dd4bebb68857ba Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Date: Sat, 13 May 2017 14:27:48 +0200 Subject: [PATCH] Fix #1709 Make sure all layouts + timeline work fine with dynamic weights --- .../plugin/forceAtlas/ForceAtlasLayout.java | 20 +++++++++++++++---- .../plugin/forceAtlas2/ForceAtlas2.java | 18 ++++++++++++++--- .../layout/plugin/openord/OpenOrdLayout.java | 7 ++++++- modules/LayoutPlugin/src/main/nbm/manifest.mf | 2 +- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas/ForceAtlasLayout.java b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas/ForceAtlasLayout.java index 668c19990..27588f144 100644 --- a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas/ForceAtlasLayout.java +++ b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas/ForceAtlasLayout.java @@ -54,6 +54,7 @@ import org.openide.util.NbBundle; import java.util.ArrayList; import java.util.List; +import org.gephi.graph.api.Interval; import org.openide.util.Exceptions; /** @@ -102,10 +103,21 @@ public class ForceAtlasLayout extends AbstractLayout implements Layout { public void initAlgo() { } + private double getEdgeWeight(Edge edge, boolean isDynamicWeight, Interval interval) { + if (isDynamicWeight) { + return edge.getWeight(interval); + } else { + return edge.getWeight(); + } + } + @Override public void goAlgo() { this.graph = graphModel.getGraphVisible(); graph.readLock(); + boolean isDynamicWeight = graphModel.getEdgeTable().getColumn("weight").isDynamic(); + Interval interval = graph.getView().getTimeInterval(); + try { Node[] nodes = graph.getNodes().toArray(); Edge[] edges = graph.getEdges().toArray(); @@ -148,7 +160,7 @@ public class ForceAtlasLayout extends AbstractLayout implements Layout { Node nf = e.getSource(); Node nt = e.getTarget(); double bonus = (nf.isFixed() || nt.isFixed()) ? (100) : (1); - bonus *= e.getWeight(); + bonus *= getEdgeWeight(e, isDynamicWeight, interval); ForceVectorUtils.fcBiAttractor_noCollide(nf, nt, bonus * getAttractionStrength() / (1 + graph.getDegree(nf))); } } else { @@ -156,7 +168,7 @@ public class ForceAtlasLayout extends AbstractLayout implements Layout { Node nf = e.getSource(); Node nt = e.getTarget(); double bonus = (nf.isFixed() || nt.isFixed()) ? (100) : (1); - bonus *= e.getWeight(); + bonus *= getEdgeWeight(e, isDynamicWeight, interval); ForceVectorUtils.fcBiAttractor_noCollide(nf, nt, bonus * getAttractionStrength()); } } @@ -166,7 +178,7 @@ public class ForceAtlasLayout extends AbstractLayout implements Layout { Node nf = e.getSource(); Node nt = e.getTarget(); double bonus = (nf.isFixed() || nt.isFixed()) ? (100) : (1); - bonus *= e.getWeight(); + bonus *= getEdgeWeight(e, isDynamicWeight, interval); ForceVectorUtils.fcBiAttractor(nf, nt, bonus * getAttractionStrength() / (1 + graph.getDegree(nf))); } } else { @@ -174,7 +186,7 @@ public class ForceAtlasLayout extends AbstractLayout implements Layout { Node nf = e.getSource(); Node nt = e.getTarget(); double bonus = (nf.isFixed() || nt.isFixed()) ? (100) : (1); - bonus *= e.getWeight(); + bonus *= getEdgeWeight(e, isDynamicWeight, interval); ForceVectorUtils.fcBiAttractor(nf, nt, bonus * getAttractionStrength()); } } diff --git a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas2/ForceAtlas2.java b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas2/ForceAtlas2.java index 12690c58b..62466729a 100644 --- a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas2/ForceAtlas2.java +++ b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/forceAtlas2/ForceAtlas2.java @@ -57,6 +57,7 @@ import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import org.gephi.graph.api.Interval; import org.openide.util.Exceptions; /** @@ -123,6 +124,15 @@ public class ForceAtlas2 implements Layout { graph.readUnlockAll(); } } + + private double getEdgeWeight(Edge edge, boolean isDynamicWeight, Interval interval) { + if (isDynamicWeight) { + return edge.getWeight(interval); + } else { + return edge.getWeight(); + } + } + @Override public void goAlgo() { @@ -131,8 +141,10 @@ public class ForceAtlas2 implements Layout { return; } graph = graphModel.getGraphVisible(); - graph.readLock(); + boolean isDynamicWeight = graphModel.getEdgeTable().getColumn("weight").isDynamic(); + Interval interval = graph.getView().getTimeInterval(); + try { Node[] nodes = graph.getNodes().toArray(); Edge[] edges = graph.getEdges().toArray(); @@ -196,11 +208,11 @@ public class ForceAtlas2 implements Layout { } } else if (getEdgeWeightInfluence() == 1) { for (Edge e : edges) { - Attraction.apply(e.getSource(), e.getTarget(), e.getWeight()); + Attraction.apply(e.getSource(), e.getTarget(), getEdgeWeight(e, isDynamicWeight, interval)); } } else { for (Edge e : edges) { - Attraction.apply(e.getSource(), e.getTarget(), Math.pow(e.getWeight(), getEdgeWeightInfluence())); + Attraction.apply(e.getSource(), e.getTarget(), Math.pow(getEdgeWeight(e, isDynamicWeight, interval), getEdgeWeightInfluence())); } } diff --git a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/openord/OpenOrdLayout.java b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/openord/OpenOrdLayout.java index 14fd67250..4dc41f868 100644 --- a/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/openord/OpenOrdLayout.java +++ b/modules/LayoutPlugin/src/main/java/org/gephi/layout/plugin/openord/OpenOrdLayout.java @@ -52,6 +52,8 @@ import java.util.concurrent.CyclicBarrier; import org.gephi.graph.api.Edge; import org.gephi.graph.api.Graph; import org.gephi.graph.api.GraphModel; +import org.gephi.graph.api.GraphView; +import org.gephi.graph.api.Interval; import org.gephi.layout.spi.Layout; import org.gephi.layout.spi.LayoutBuilder; import org.gephi.layout.spi.LayoutProperty; @@ -113,6 +115,9 @@ public class OpenOrdLayout implements Layout, LongTask { //Get graph graph = graphModel.getUndirectedGraphVisible(); graph.readLock(); + boolean isDynamicWeight = graphModel.getEdgeTable().getColumn("weight").isDynamic(); + Interval interval = graph.getView().getTimeInterval(); + try { int numNodes = graph.getNodeCount(); @@ -145,7 +150,7 @@ public class OpenOrdLayout implements Layout, LongTask { int source = idMap.get(e.getSource().getStoreId()); int target = idMap.get(e.getTarget().getStoreId()); if (source != target) { //No self-loop - float weight = (float) e.getWeight(); + float weight = (float) (isDynamicWeight ? e.getWeight(interval) : e.getWeight()); if (neighbors[source] == null) { neighbors[source] = new TIntFloatHashMap(hashingStrategy); } diff --git a/modules/LayoutPlugin/src/main/nbm/manifest.mf b/modules/LayoutPlugin/src/main/nbm/manifest.mf index 4151d1211..bcfbe9181 100644 --- a/modules/LayoutPlugin/src/main/nbm/manifest.mf +++ b/modules/LayoutPlugin/src/main/nbm/manifest.mf @@ -1,6 +1,6 @@ Manifest-Version: 1.0 AutoUpdate-Essential-Module: true OpenIDE-Module-Localizing-Bundle: org/gephi/layout/plugin/Bundle.properties -OpenIDE-Module-Specification-Version: 0.9.1.1 +OpenIDE-Module-Specification-Version: 0.9.1.2 OpenIDE-Module-Display-Category: Plugin OpenIDE-Module-Name: Layout Plugin \ No newline at end of file -- GitLab