Package com.jgraph.layout.hierarchical.model

Examples of com.jgraph.layout.hierarchical.model.JGraphHierarchyRank


        // there
        // are less heavily angled edges and so the current positioning
        // is used
        if (currentXDelta < bestXDelta) {
          for (int j = 0; j < model.ranks.size(); j++) {
            JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
                .get(new Integer(j));
            Iterator iter = rank.iterator();
            while (iter.hasNext()) {
              JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
                  .next();
              cell.setX(j, cell.getGeneralPurposeVariable(j));
            }
          }
          bestXDelta = currentXDelta;
        } else {
          // Restore the best positions
          for (int j = 0; j < model.ranks.size(); j++) {
            JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
                .get(new Integer(j));
            Iterator iter = rank.iterator();
            while (iter.hasNext()) {
              JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
                  .next();
              cell.setGeneralPurposeVariable(j, (int) cell
                  .getX(j));
View Full Code Here


    LinkedList nodeList = new LinkedList();
    // Need to be able to map from cell to cellWrapper
    Map map = new Hashtable();
    Object[][] rank = new Object[model.maxRank + 1][];
    for (int i = 0; i <= model.maxRank; i++) {
      JGraphHierarchyRank rankSet = (JGraphHierarchyRank) model.ranks
          .get(new Integer(i));
      rank[i] = rankSet.toArray();
      for (int j = 0; j < rank[i].length; j++) {
        // Use the weight to store the rank and visited to store whether
        // or not the cell is in the list
        JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) rank[i][j];
        WeightedCellSorter cellWrapper = new WeightedCellSorter(cell, i);
View Full Code Here

   *            the layer number whose connected cels are to be laid out
   *            relative to
   */
  protected void rankMedianPosition(int rankValue,
      JGraphHierarchyModel model, int nextRankValue) {
    JGraphHierarchyRank rankSet = (JGraphHierarchyRank) model.ranks
        .get(new Integer(rankValue));
    Object[] rank = rankSet.toArray();
    // Form an array of the order in which the cell are to be processed
    // , the order is given by the weighted sum of the in or out edges,
    // depending on whether we're travelling up or down the hierarchy.
    WeightedCellSorter[] weightedValues = new WeightedCellSorter[rank.length];
    Map cellMap = new Hashtable(rank.length);
View Full Code Here

   * @param model
   *            an internal model of the hierarchical layout
   */
  protected void rankCoordinates(int rankValue, JGraphFacade facade,
      JGraphHierarchyModel model) {
    JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
        .get(new Integer(rankValue));
    // Pad out the initial cell spacing to give a better chance of a cell
    // not being restricted in one direction.
    double extraCellSpacing = (widestRankValue - rankWidths[rankValue]) / (rank.size() + 1);
    double localIntraCellSpacing = intraCellSpacing + extraCellSpacing;
    // Check this doesn't make the rank too wide, if it does, reduce it
    if (extraCellSpacing * (rank.size() + 1) + rankWidths[rankValue] > widestRankValue) {
      localIntraCellSpacing = intraCellSpacing;
    }
    double maxY = 0.0;
    double localX = initialX + extraCellSpacing;
    Iterator iter = rank.iterator();
    // Store whether or not any of the cells' bounds were unavailable so
    // to only issue the warning once for all cells
    boolean boundsWarning = false;
    while (iter.hasNext()) {
      JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
View Full Code Here

    for (int rankValue = model.maxRank; rankValue >= 0; rankValue--) {
      // Keep track of the widest cell on this rank
      double maxCellHeight = 0.0;

      JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
          .get(new Integer(rankValue));
      double localX = initialX;
      Iterator iter = rank.iterator();
      // Store whether or not any of the cells' bounds were unavailable so
      // to only issue the warning once for all cells
      boolean boundsWarning = false;
      while (iter.hasNext()) {
        JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
            .next();
        if (cell.isVertex()) {
          JGraphHierarchyNode node = (JGraphHierarchyNode) cell;
          Rectangle2D bounds = facade.getBounds(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()) {
          JGraphHierarchyEdge edge = (JGraphHierarchyEdge) 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()) {
        JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
            .next();
        cell.setY(rankValue, y);
      }
View Full Code Here

    // Run through the ranks twice, once for vertices, then for edges
    // The reason for this is if the vertices need to offset again from
    // the last context
    for (int cellType = 0; cellType < 2; cellType++) {
      for (int i = 0; i < model.ranks.size(); i++) {
        JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
            .get(new Integer(i));
        Iterator iter = rank.iterator();
        while (iter.hasNext()) {
          JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
              .next();
          if (cellType == 0 && cell.isVertex()) {
            JGraphHierarchyNode node = (JGraphHierarchyNode) cell;
View Full Code Here

      return null;
    }
    // Stores initial ordering as being the best one found so far
    nestedBestRanks = new Object[model.ranks.size()][];
    for (int i = 0; i < nestedBestRanks.length; i++) {
      JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
          .get(new Integer(i));
      nestedBestRanks[i] = rank.toArray();
    }

    progress.reset(maxIterations);
    iterationsWithoutImprovement = 0;

    currentBestCrossings = calculateCrossings(model);

    for (int i = 0; i < maxIterations && !progress.isStopped()
        && iterationsWithoutImprovement < maxNoImprovementIterations; i++) {
      progress.setProgress(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++) {
          JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
              .get(new Integer(j));
          Iterator iter = rank.iterator();
          for (int k = 0; k < rank.size(); k++) {
            JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) 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++) {
          JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
              .get(new Integer(j));
          Iterator iter = rank.iterator();
          for (int k = 0; k < rank.size(); k++) {
            JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
                .next();
            cell.setGeneralPurposeVariable(j, k);
          }
        }
      }
      if (currentBestCrossings == 0) {
        // Do nothing further
        break;
      }
    }

    // Store the best rankings but in the model
    Map ranks = new LinkedHashMap(model.maxRank + 1);
    final Collection[] rankList = new JGraphHierarchyRank[model.maxRank + 1];
    for (int i = 0; i < model.maxRank + 1; i++) {
      rankList[i] = new JGraphHierarchyRank();
      ranks.put(new Integer(i), rankList[i]);
    }

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

   *            the internal hierarchy model of the graph
   * @return the number of edges crossings with the rank beneath
   */
  protected int calculateRankCrossing(int i, JGraphHierarchyModel model) {
    int totalCrossings = 0;
    JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
        .get(new Integer(i));
    JGraphHierarchyRank previousRank = (JGraphHierarchyRank) 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 iter = rank.iterator();
    while (iter.hasNext()) {
      JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
View Full Code Here

        nudge = true;
      }

      improved = false;
      for (int i = 0; i < model.ranks.size(); i++) {
        JGraphHierarchyRank rank = (JGraphHierarchyRank) model.ranks
            .get(new Integer(i));
        JGraphAbstractHierarchyCell[] orderedCells = new JGraphAbstractHierarchyCell[rank
            .size()];
        Iterator iter = rank.iterator();
        for (int j = 0; j < orderedCells.length; j++) {
          JGraphAbstractHierarchyCell cell = (JGraphAbstractHierarchyCell) iter
              .next();
          orderedCells[cell.getGeneralPurposeVariable(i)] = cell;
        }
        List leftCellAboveConnections = null;
        List leftCellBelowConnections = null;
        List rightCellAboveConnections = null;
        List rightCellBelowConnections = null;
        int[] leftAbovePositions = null;
        int[] leftBelowPositions = null;
        int[] rightAbovePositions = null;
        int[] rightBelowPositions = null;
        JGraphAbstractHierarchyCell leftCell = null;
        JGraphAbstractHierarchyCell 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
          // can save processing using the previous values for the
View Full Code Here

TOP

Related Classes of com.jgraph.layout.hierarchical.model.JGraphHierarchyRank

Copyright © 2018 www.massapicom. 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.