use of csapps.layout.algorithms.hierarchicalLayout.Graph in project cytoscape-impl by cytoscape.
the class CircularLayoutAlgorithmTask method layoutPartition.
@Override
public void layoutPartition(LayoutPartition partition) {
if (cancelled)
return;
final int numNodes = partition.nodeCount();
if (numNodes == 1) {
// We were asked to do a circular layout of a single node -- done!
return;
}
nodeViews = new HashMap<Integer, View<CyNode>>(numNodes);
Map<CyNode, Integer> nodeIdexMap = new HashMap<CyNode, Integer>();
int nodeIndex = 0;
Iterator<LayoutNode> nodeIter = partition.getNodeList().iterator();
while (nodeIter.hasNext() && !cancelled) {
// final View<CyNode> nv = nodeIter.next().getNodeView();
LayoutNode ln = nodeIter.next();
if (ln.isLocked())
continue;
final View<CyNode> nv = ln.getNodeView();
nodeViews.put(nodeIndex, nv);
nodeIdexMap.put(nv.getModel(), nodeIndex);
nodeIndex++;
}
if (cancelled)
return;
/* create edge list from edges between selected nodes */
final List<Edge> edges = new LinkedList<Edge>();
final Iterator<LayoutEdge> edgeIter = partition.edgeIterator();
while (edgeIter.hasNext() && !cancelled) {
final LayoutEdge ev = edgeIter.next();
final Integer edgeFrom = nodeIdexMap.get(ev.getEdge().getSource());
final Integer edgeTo = nodeIdexMap.get(ev.getEdge().getTarget());
if ((edgeFrom == null) || (edgeTo == null))
continue;
edges.add(new Edge(edgeFrom, edgeTo));
edges.add(new Edge(edgeTo, edgeFrom));
}
nodeIdexMap.clear();
nodeIdexMap = null;
if (cancelled)
return;
/* find horizontal and vertical coordinates of each node */
final Edge[] edge = new Edge[edges.size()];
edges.toArray(edge);
final Graph graph = new Graph(numNodes, edge);
if (cancelled)
return;
// all false
posSet = new boolean[nodeViews.size()];
// all false
depthPosSet = new boolean[nodeViews.size()];
bc = graph.biconnectedComponents();
int maxSize = -1;
int maxIndex = -1;
for (int i = 0; i < bc.length; i++) if (bc[i].length > maxSize) {
maxSize = bc[i].length;
maxIndex = i;
}
if (maxIndex == -1)
return;
if (cancelled)
return;
drawnBiComps = new boolean[bc.length];
node2BiComp = new HashMap<Integer, Integer>();
for (int i = 0; i < bc.length; i++) if (bc[i].length > 3) {
for (int j = 0; j < bc[i].length; j++) {
node2BiComp.put(bc[i][j], i);
}
}
final double radius = (48 * maxSize) / (2 * Math.PI);
final double deltaAngle = (2 * Math.PI) / maxSize;
double angle = 0;
int startX = (int) radius;
int startY = (int) radius;
edgesFrom = graph.GetEdgesFrom();
// sorting nodes on inner circle
bc[maxIndex] = SortInnerCircle(bc[maxIndex]);
// setting nodes on inner circle
for (int i = 0; i < bc[maxIndex].length; i++) {
setOffset(nodeViews.get(bc[maxIndex][i]), startX + (Math.cos(angle) * radius), startY - (Math.sin(angle) * radius));
posSet[bc[maxIndex][i]] = true;
angle += deltaAngle;
}
drawnBiComps[maxIndex] = true;
nodeHeights = new HashMap<Integer, Integer>();
SetOuterCircle(maxIndex, radius, startX, startY, -1);
if (cancelled)
return;
nodeIter = partition.nodeIterator();
while (nodeIter.hasNext() && !cancelled) {
final LayoutNode ln = nodeIter.next();
final View<CyNode> nv = ln.getNodeView();
ln.setX(nv.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION));
ln.setY(nv.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION));
partition.moveNodeToLocation(ln);
}
}
Aggregations