Search in sources :

Example 1 with Scale3D

use of org.cytoscape.math.xform.Scale3D in project cytoscape-impl by cytoscape.

the class ScaleLayouter method scaleGraph.

/**
 * A scaleFactor of 1.0 does not move anything.
 *
 * @exception IllegalArgumentException if
 *   scaleFactor < 0.001 or if scaleFactor > 1000.0.
 */
public void scaleGraph(double scaleFactor, final Direction direction) {
    if ((scaleFactor < 0.001d) || (scaleFactor > 1000.0d))
        throw new IllegalArgumentException("scaleFactor is outside allowable range [0.001, 1000.0]");
    if (m_translationToOrig == null)
        return;
    double xFactor = scaleFactor, yFactor = scaleFactor;
    switch(direction) {
        case X_AXIS_ONLY:
            yFactor = 1.0;
            break;
        case Y_AXIS_ONLY:
            xFactor = 1.0;
            break;
        case BOTH_AXES:
            /* Intentionally empty. */
            break;
    }
    final AffineTransform3D xform = m_translationToOrig.concatenatePost((new Scale3D(xFactor, yFactor, 1.0d)).concatenatePost(m_translationFromOrig));
    for (CyNode node : m_graph.nodes()) {
        if (!m_graph.isMovableNode(node))
            continue;
        m_pointBuff[0] = m_graph.getNodePosition(node, true);
        m_pointBuff[1] = m_graph.getNodePosition(node, false);
        m_pointBuff[2] = 0.0d;
        xform.transformArr(m_pointBuff);
        m_graph.setNodePosition(node, m_pointBuff[0], m_pointBuff[1]);
    }
    for (CyEdge edge : m_graph.edges()) {
        if (!(m_graph.isMovableNode(edge.getSource())) && m_graph.isMovableNode(edge.getTarget()))
            continue;
    /* TODO support anchors
			final int numAnchors = m_graph.getNumAnchors(edge);

			for (int j = 0; j < numAnchors; j++) {
				m_pointBuff[0] = m_graph.getAnchorPosition(edge, j, true);
				m_pointBuff[1] = m_graph.getAnchorPosition(edge, j, false);
				m_pointBuff[2] = 0.0d;
				xform.transformArr(m_pointBuff);
				m_graph.setAnchorPosition(edge, j, m_pointBuff[0], m_pointBuff[1]);
			}
			*/
    }
}
Also used : Scale3D(org.cytoscape.math.xform.Scale3D) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) AffineTransform3D(org.cytoscape.math.xform.AffineTransform3D)

Aggregations

AffineTransform3D (org.cytoscape.math.xform.AffineTransform3D)1 Scale3D (org.cytoscape.math.xform.Scale3D)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1