Skip to content

Commit

Permalink
Fix #603 Nodes position to NaN on applied layout
Browse files Browse the repository at this point in the history
  • Loading branch information
eduramiba committed Aug 16, 2017
1 parent 0298a64 commit be1a3a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ Development and Distribution License("CDDL") (collectively, the
*/
package org.gephi.layout.plugin;

import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.NodeIterable;
import org.gephi.layout.spi.Layout;
import org.gephi.layout.spi.LayoutBuilder;

Expand Down Expand Up @@ -82,4 +85,27 @@ public void setConverged(boolean converged) {
public boolean isConverged() {
return converged;
}

/**
* See https://github.com/gephi/gephi/issues/603 Nodes position to NaN on applied layout
*
* @param graphModel
*/
public static void ensureSafeLayoutNodePositions(GraphModel graphModel) {
Graph graph = graphModel.getGraph();
NodeIterable nodesIterable = graph.getNodes();
for (Node node : nodesIterable) {
if (node.x() != 0 || node.y() != 0) {
nodesIterable.doBreak();
return;
}
}

//All at 0.0, init some random positions
nodesIterable = graph.getNodes();
for (Node node : nodesIterable) {
node.setX((float) ((0.01 + Math.random()) * 1000) - 500);
node.setY((float) ((0.01 + Math.random()) * 1000) - 500);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void resetPropertiesValues() {

@Override
public void initAlgo() {
ensureSafeLayoutNodePositions(graphModel);
}

private double getEdgeWeight(Edge edge, boolean isDynamicWeight, Interval interval) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Development and Distribution License("CDDL") (collectively, the
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.gephi.graph.api.Interval;
import org.gephi.layout.plugin.AbstractLayout;
import org.openide.util.Exceptions;

/**
Expand Down Expand Up @@ -95,6 +96,8 @@ public ForceAtlas2(ForceAtlas2Builder layoutBuilder) {

@Override
public void initAlgo() {
AbstractLayout.ensureSafeLayoutNodePositions(graphModel);

speed = 1.;
speedEfficiency = 1.;

Expand Down

0 comments on commit be1a3a1

Please sign in to comment.