Examples of mxGraphHierarchyRank


Examples of com.mxgraph.layout.hierarchical.model.mxGraphHierarchyRank

   *            an internal model of the hierarchical layout
   */
  protected void rankCoordinates(int rankValue, mxGraph graph,
      mxGraphHierarchyModel model)
  {
    mxGraphHierarchyRank rank = model.ranks.get(new Integer(rankValue));
    double maxY = 0.0;
    double localX = initialX + (widestRankValue - rankWidths[rankValue])
        / 2;

    // Store whether or not any of the cells' bounds were unavailable so
View Full Code Here

Examples of com.mxgraph.layout.hierarchical.model.mxGraphHierarchyRank

    for (int rankValue = model.maxRank; rankValue >= 0; rankValue--)
    {
      // Keep track of the widest cell on this rank
      double maxCellHeight = 0.0;
      mxGraphHierarchyRank rank = model.ranks.get(new Integer(rankValue));
      double localX = initialX;

      // Store whether or not any of the cells' bounds were unavailable so
      // to only issue the warning once for all cells
      boolean boundsWarning = false;
      Iterator<mxGraphAbstractHierarchyCell> iter = rank.iterator();

      while (iter.hasNext())
      {
        mxGraphAbstractHierarchyCell cell = iter.next();

        if (cell.isVertex())
        {
          mxGraphHierarchyNode node = (mxGraphHierarchyNode) cell;
          mxRectangle bounds = layout.getVertexBounds(node.cell);

          if (bounds != null)
          {
            if (orientation == SwingConstants.NORTH
                || orientation == SwingConstants.SOUTH)
            {
              cell.width = bounds.getWidth();
              cell.height = bounds.getHeight();
            }
            else
            {
              cell.width = bounds.getHeight();
              cell.height = bounds.getWidth();
            }
          }
          else
          {
            boundsWarning = true;
          }

          maxCellHeight = Math.max(maxCellHeight, cell.height);
        }
        else if (cell.isEdge())
        {
          mxGraphHierarchyEdge edge = (mxGraphHierarchyEdge) cell;
          // The width is the number of additional parallel edges
          // time the parallel edge spacing
          int numEdges = 1;

          if (edge.edges != null)
          {
            numEdges = edge.edges.size();
          }
          else
          {
            logger.info("edge.edges is null");
          }

          cell.width = (numEdges - 1) * parallelEdgeSpacing;
        }

        // Set the initial x-value as being the best result so far
        localX += cell.width / 2.0;
        cell.setX(rankValue, localX);
        cell.setGeneralPurposeVariable(rankValue, (int) localX);
        localX += cell.width / 2.0;
        localX += intraCellSpacing;

        if (localX > widestRankValue)
        {
          widestRankValue = localX;
          widestRank = rankValue;
        }

        rankWidths[rankValue] = localX;
      }

      if (boundsWarning == true)
      {
        logger.info("At least one cell has no bounds");
      }

      rankY[rankValue] = y;
      double distanceToNextRank = maxCellHeight / 2.0
          + lastRankMaxCellHeight / 2.0 + interRankCellSpacing;
      lastRankMaxCellHeight = maxCellHeight;

      if (orientation == SwingConstants.NORTH
          || orientation == SwingConstants.WEST)
      {
        y += distanceToNextRank;
      }
      else
      {
        y -= distanceToNextRank;
      }

      iter = rank.iterator();

      while (iter.hasNext())
      {
        mxGraphAbstractHierarchyCell cell = iter.next();
        cell.setY(rankValue, y);
View Full Code Here

Examples of com.mxgraph.layout.hierarchical.model.mxGraphHierarchyRank

   * @return whether or not the virtual node can be moved to this position
   */
  protected boolean repositionValid(mxGraphHierarchyModel model,
      mxGraphAbstractHierarchyCell cell, int rank, double position)
  {
    mxGraphHierarchyRank rankSet = model.ranks.get(new Integer(rank));
    mxGraphAbstractHierarchyCell[] rankArray = rankSet
        .toArray(new mxGraphAbstractHierarchyCell[rankSet.size()]);
    int rankIndex = -1;

    for (int i = 0; i < rankArray.length; i++)
    {
      if (cell == rankArray[i])
View Full Code Here

Examples of com.mxgraph.layout.hierarchical.model.mxGraphHierarchyRank

    // Stores initial ordering as being the best one found so far
    nestedBestRanks = new mxGraphAbstractHierarchyCell[model.ranks.size()][];

    for (int i = 0; i < nestedBestRanks.length; i++)
    {
      mxGraphHierarchyRank rank = model.ranks.get(new Integer(i));
      nestedBestRanks[i] = new mxGraphAbstractHierarchyCell[rank.size()];
      rank.toArray(nestedBestRanks[i]);
    }

    iterationsWithoutImprovement = 0;
    currentBestCrossings = calculateCrossings(model);

    for (int i = 0; i < maxIterations
        && iterationsWithoutImprovement < maxNoImprovementIterations; i++)
    {
      weightedMedian(i, model);
      transpose(i, model);
      int candidateCrossings = calculateCrossings(model);

      if (candidateCrossings < currentBestCrossings)
      {
        currentBestCrossings = candidateCrossings;
        iterationsWithoutImprovement = 0;

        // Store the current rankings as the best ones
        for (int j = 0; j < nestedBestRanks.length; j++)
        {
          mxGraphHierarchyRank rank = model.ranks.get(new Integer(j));
          Iterator<mxGraphAbstractHierarchyCell> iter = rank
              .iterator();

          for (int k = 0; k < rank.size(); k++)
          {
            mxGraphAbstractHierarchyCell cell = iter
                .next();
            nestedBestRanks[j][cell.getGeneralPurposeVariable(j)] = cell;
          }
        }
      }
      else
      {
        // Increase count of iterations where we haven't improved the
        // layout
        iterationsWithoutImprovement++;

        // Restore the best values to the cells
        for (int j = 0; j < nestedBestRanks.length; j++)
        {
          mxGraphHierarchyRank rank = model.ranks.get(new Integer(j));
          Iterator<mxGraphAbstractHierarchyCell> iter = rank
              .iterator();

          for (int k = 0; k < rank.size(); k++)
          {
            mxGraphAbstractHierarchyCell cell = iter
                .next();
            cell.setGeneralPurposeVariable(j, k);
          }
        }
      }

      if (currentBestCrossings == 0)
      {
        // Do nothing further
        break;
      }
    }

    // Store the best rankings but in the model
    Map<Integer, mxGraphHierarchyRank> ranks = new LinkedHashMap<Integer, mxGraphHierarchyRank>(
        model.maxRank + 1);
    mxGraphHierarchyRank[] rankList = new mxGraphHierarchyRank[model.maxRank + 1];

    for (int i = 0; i < model.maxRank + 1; i++)
    {
      rankList[i] = new mxGraphHierarchyRank();
      ranks.put(new Integer(i), rankList[i]);
    }

    for (int i = 0; i < nestedBestRanks.length; i++)
    {
View Full Code Here

Examples of com.mxgraph.layout.hierarchical.model.mxGraphHierarchyRank

   * @return the number of edges crossings with the rank beneath
   */
  protected int calculateRankCrossing(int i, mxGraphHierarchyModel model)
  {
    int totalCrossings = 0;
    mxGraphHierarchyRank rank = model.ranks.get(new Integer(i));
    mxGraphHierarchyRank previousRank = model.ranks.get(new Integer(i - 1));

    // Create an array of connections between these two levels
    int currentRankSize = rank.size();
    int previousRankSize = previousRank.size();
    int[][] connections = new int[currentRankSize][previousRankSize];

    // Iterate over the top rank and fill in the connection information
    Iterator<mxGraphAbstractHierarchyCell> iter = rank.iterator();

View Full Code Here

Examples of com.mxgraph.layout.hierarchical.model.mxGraphHierarchyRank

      boolean nudge = mainLoopIteration % 2 == 1 && count % 2 == 1;
      improved = false;

      for (int i = 0; i < model.ranks.size(); i++)
      {
        mxGraphHierarchyRank rank = model.ranks.get(new Integer(i));
        mxGraphAbstractHierarchyCell[] orderedCells = new mxGraphAbstractHierarchyCell[rank
            .size()];
        Iterator<mxGraphAbstractHierarchyCell> iter = rank.iterator();

        for (int j = 0; j < orderedCells.length; j++)
        {
          mxGraphAbstractHierarchyCell cell = iter
              .next();
          orderedCells[cell.getGeneralPurposeVariable(i)] = cell;
        }

        List<mxGraphAbstractHierarchyCell> leftCellAboveConnections = null;
        List<mxGraphAbstractHierarchyCell> leftCellBelowConnections = null;
        List<mxGraphAbstractHierarchyCell> rightCellAboveConnections = null;
        List<mxGraphAbstractHierarchyCell> rightCellBelowConnections = null;

        int[] leftAbovePositions = null;
        int[] leftBelowPositions = null;
        int[] rightAbovePositions = null;
        int[] rightBelowPositions = null;

        mxGraphAbstractHierarchyCell leftCell = null;
        mxGraphAbstractHierarchyCell rightCell = null;

        for (int j = 0; j < (rank.size() - 1); j++)
        {
          // For each intra-rank adjacent pair of cells
          // see if swapping them around would reduce the
          // number of edges crossing they cause in total
          // On every cell pair except the first on each rank, we
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.