Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force layout fixes #579

Merged
merged 8 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class ForceLayout<V, E> {
/** Deterministic randomness */
private final Random random = new Random(3L);

private static final int DEFAULT_MAX_STEPS = 1000;
private static final int DEFAULT_MAX_STEPS = 400;
private static final double DEFAULT_MIN_ENERGY_THRESHOLD = 0.001;
private static final double DEFAULT_DELTA_TIME = 1;
private static final double DEFAULT_DELTA_TIME = 0.1;
private static final double DEFAULT_REPULSION = 800.0;
private static final double DEFAULT_FRICTION = 500;
private static final double DEFAULT_MAX_SPEED = 100;
Expand Down Expand Up @@ -146,14 +146,12 @@ public ForceLayout<V, E> setFixedNodes(Set<V> fixedNodes) {
}

private void initializePoints() {
int nbUnknownPositions = graph.vertexSet().size() - initialPoints.size();

// instead of generating initial points in the [0,1] interval apply a scale depending on the number of unknown positions
double scale = Math.sqrt(nbUnknownPositions) * 5;
for (V vertex : graph.vertexSet()) {
Point p;
if (initialPoints.containsKey(vertex)) {
p = initialPoints.get(vertex);
} else {
p = new Point(random.nextDouble(), random.nextDouble());
}
points.put(vertex, p);
points.put(vertex, initialPoints.getOrDefault(vertex, new Point(scale * random.nextDouble(), scale * random.nextDouble())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void setEdgeVisibility(Node node, BranchEdge branchEdge, BranchEdge.Side
}

private void computeSize(Graph graph) {
double[] dims = new double[4];
double[] dims = new double[] {Double.MAX_VALUE, -Double.MAX_VALUE, Double.MAX_VALUE, -Double.MAX_VALUE};
Stream.concat(graph.getTextNodesStream(), graph.getNodesStream()).forEach(node -> {
dims[0] = Math.min(dims[0], node.getX());
dims[1] = Math.max(dims[1], node.getX());
Expand Down
60 changes: 30 additions & 30 deletions network-area-diagram/src/test/resources/3wt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 30 additions & 30 deletions network-area-diagram/src/test/resources/3wt_disconnected.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading