提交 5b69bfb8 编写于 作者: E Eduardo Ramos

Fix #1709 Make sure all layouts + timeline work fine with dynamic weights

上级 54d581a9
......@@ -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());
}
}
......
......@@ -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()));
}
}
......
......@@ -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);
}
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册