Skip to content

Commit

Permalink
Cleaned Zest Algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
azoitl committed Nov 4, 2023
1 parent f5ae4fa commit 713451a
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 530 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ public void applyLayout(LayoutEntity[] entitiesToLayout, LayoutRelationship[] re

public void removeRelationship(LayoutRelationship relationship);

public void removeRelationships(List relationships);
public void removeRelationships(List<? extends LayoutRelationship> relationships);

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.lang.reflect.Field;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.SWT;

Expand Down Expand Up @@ -58,7 +59,7 @@ public DirectedGraphLayoutAlgorithm(int styles) {
@Override
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider,
double boundsX, double boundsY, double boundsWidth, double boundsHeight) {
HashMap mapping = new HashMap(entitiesToLayout.length);
Map<InternalNode, Node> mapping = new HashMap<>(entitiesToLayout.length);
DirectedGraph graph = new DirectedGraph();
for (InternalNode internalNode : entitiesToLayout) {
Node node = new Node(internalNode);
Expand All @@ -67,8 +68,8 @@ protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRela
graph.nodes.add(node);
}
for (InternalRelationship relationship : relationshipsToConsider) {
Node source = (Node) mapping.get(relationship.getSource());
Node dest = (Node) mapping.get(relationship.getDestination());
Node source = mapping.get(relationship.getSource());
Node dest = mapping.get(relationship.getDestination());
Edge edge = new Edge(relationship, source, dest);
graph.edges.add(edge);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*******************************************************************************
* Copyright 2006, CHISEL Group, University of Victoria, Victoria, BC, Canada.
* Copyright 2006, 2023 CHISEL Group, University of Victoria, Victoria, BC,
* Canada, Johannes Kepler University Linz
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: The Chisel Group, University of Victoria
* Contributors: The Chisel Group, University of Victoria, Alois Zoitl
*******************************************************************************/
package org.eclipse.zest.layouts.algorithms;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.eclipse.zest.layouts.LayoutEntity;
Expand All @@ -38,35 +38,27 @@ public HorizontalShift(int styles) {
protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider,
double boundsX, double boundsY, double boundsWidth, double boundsHeight) {

ArrayList row = new ArrayList();
List<List<InternalNode>> row = new ArrayList<>();
for (InternalNode element : entitiesToLayout) {
addToRowList(element, row);
}

int heightSoFar = 0;

Collections.sort(row, (arg0, arg1) -> {
// TODO Auto-generated method stub
List a0 = (List) arg0;
List a1 = (List) arg1;
LayoutEntity node0 = ((InternalNode) a0.get(0)).getLayoutEntity();
LayoutEntity node1 = ((InternalNode) a1.get(0)).getLayoutEntity();
LayoutEntity node0 = arg0.get(0).getLayoutEntity();
LayoutEntity node1 = arg1.get(0).getLayoutEntity();
return (int) (node0.getYInLayout() - (node1.getYInLayout()));
});

Iterator iterator = row.iterator();
while (iterator.hasNext()) {
List currentRow = (List) iterator.next();
Collections.sort(currentRow, (arg0, arg1) -> (int) (((InternalNode) arg1).getLayoutEntity().getYInLayout()
- ((InternalNode) arg0).getLayoutEntity().getYInLayout()));
Iterator iterator2 = currentRow.iterator();
for (List<InternalNode> currentRow : row) {
Collections.sort(currentRow, (arg0,
arg1) -> (int) (arg1.getLayoutEntity().getYInLayout() - arg0.getLayoutEntity().getYInLayout()));
int i = 0;
int width = (int) ((boundsWidth / 2) - currentRow.size() * 75);

heightSoFar += ((InternalNode) currentRow.get(0)).getLayoutEntity().getHeightInLayout() + VSPACING * 8;
while (iterator2.hasNext()) {
InternalNode currentNode = (InternalNode) iterator2.next();

heightSoFar += currentRow.get(0).getLayoutEntity().getHeightInLayout() + VSPACING * 8;
for (InternalNode currentNode : currentRow) {
i++;
double location = width + 10 * i;
currentNode.setLocation(location, heightSoFar);
Expand All @@ -75,12 +67,11 @@ protected void applyLayoutInternal(InternalNode[] entitiesToLayout, InternalRela
}
}

private void addToRowList(InternalNode node, ArrayList list) {
private static void addToRowList(InternalNode node, List<List<InternalNode>> list) {
double layoutY = node.getLayoutEntity().getYInLayout();

for (Object element : list) {
List currentRow = (List) element;
InternalNode currentRowNode = (InternalNode) currentRow.get(0);
for (List<InternalNode> currentRow : list) {
InternalNode currentRowNode = currentRow.get(0);
double currentRowY = currentRowNode.getLayoutEntity().getYInLayout();
// double currentRowHeight =
// currentRowNode.getLayoutEntity().getHeightInLayout();
Expand All @@ -90,7 +81,7 @@ private void addToRowList(InternalNode node, ArrayList list) {
return;
}
}
List newRow = new ArrayList();
List<InternalNode> newRow = new ArrayList<>();
newRow.add(node);
list.add(newRow);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/*******************************************************************************
* Copyright 2005 CHISEL Group, University of Victoria, Victoria, BC,
* Canada.
* Copyright 2005, 2023 CHISEL Group, University of Victoria, Victoria, BC,
* Canada, Johannes Kepler University Linz
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors: The Chisel Group, University of Victoria
* Contributors: The Chisel Group, University of Victoria, Alois Zoitl
*******************************************************************************/
package org.eclipse.zest.layouts.algorithms;

import java.util.Iterator;
import java.util.List;

import org.eclipse.zest.layouts.LayoutStyles;
Expand All @@ -32,7 +31,7 @@ public class RadialLayoutAlgorithm extends TreeLayoutAlgorithm {
private static final double MAX_DEGREES = Math.PI * 2;
private double startDegree;
private double endDegree;
private TreeLayoutAlgorithm treeLayout;
private final TreeLayoutAlgorithm treeLayout;
private List roots;

/**
Expand All @@ -53,19 +52,23 @@ public RadialLayoutAlgorithm(int styles) {

@Override
public void setLayoutArea(double x, double y, double width, double height) {
throw new RuntimeException("Operation not implemented");
throw new RuntimeException("Operation not implemented"); //$NON-NLS-1$
}

@Override
protected boolean isValidConfiguration(boolean asynchronous, boolean continueous) {
if (asynchronous && continueous)
if (asynchronous && continueous) {
return false;
else if (asynchronous && !continueous)
}
if (asynchronous && !continueous) {
return true;
else if (!asynchronous && continueous)
}
if (!asynchronous && continueous) {
return false;
else if (!asynchronous && !continueous)
}
if (!asynchronous && !continueous) {
return true;
}

return false;
}
Expand All @@ -75,7 +78,6 @@ else if (!asynchronous && !continueous)
@Override
protected void preLayoutAlgorithm(InternalNode[] entitiesToLayout, InternalRelationship[] relationshipsToConsider,
double x, double y, double width, double height) {
// TODO Auto-generated method stub
layoutBounds = new DisplayIndependentRectangle(x, y, width, height);
super.preLayoutAlgorithm(entitiesToLayout, relationshipsToConsider, x, y, width, height);
}
Expand Down Expand Up @@ -106,13 +108,11 @@ public void setRangeToLayout(double startDegree, double endDegree) {
* each entity in terms of its percentage in the tree layout. Then apply that
* percentage to the radius and distance from the center.
*/
protected void computeRadialPositions(InternalNode[] entities, DisplayIndependentRectangle bounds2) { // TODO TODO
// TODO
protected void computeRadialPositions(InternalNode[] entities, DisplayIndependentRectangle bounds2) {
DisplayIndependentRectangle bounds = new DisplayIndependentRectangle(getLayoutBounds(entities, true));
bounds.height = bounds2.height;
bounds.y = bounds2.y;
for (int i = 0; i < entities.length; i++) {
InternalNode entity = entities[i];
for (InternalNode entity : entities) {
double percentTheta = (entity.getInternalX() - bounds.x) / bounds.width;
double distance = (entity.getInternalY() - bounds.y) / bounds.height;
double theta = startDegree + Math.abs(endDegree - startDegree) * percentTheta;
Expand Down Expand Up @@ -141,18 +141,17 @@ protected DisplayIndependentRectangle getLayoutBounds(InternalNode[] entitiesToL
Math.abs(centerPoint.x - layoutBounds.x));
double maxDistanceY = Math.max(Math.abs(layoutBounds.y + layoutBounds.height - centerPoint.y),
Math.abs(centerPoint.y - layoutBounds.y));
layoutBounds = new DisplayIndependentRectangle(centerPoint.x - maxDistanceX, centerPoint.y - maxDistanceY,
return new DisplayIndependentRectangle(centerPoint.x - maxDistanceX, centerPoint.y - maxDistanceY,
maxDistanceX * 2, maxDistanceY * 2);
return layoutBounds;
}

/**
* Find the center point between the roots
*/
private DisplayIndependentPoint determineCenterPoint(List roots) {
double totalX = 0, totalY = 0;
for (Iterator iterator = roots.iterator(); iterator.hasNext();) {
InternalNode entity = (InternalNode) iterator.next();
private static DisplayIndependentPoint determineCenterPoint(List<InternalNode> roots) {
double totalX = 0;
double totalY = 0;
for (InternalNode entity : roots) {
totalX += entity.getInternalX();
totalY += entity.getInternalY();
}
Expand Down
Loading

0 comments on commit 713451a

Please sign in to comment.