曼哈顿布局算法

发布于 2024-08-01 23:47:07 字数 1542 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2024-08-08 23:47:07

使用 prefuse 创建 EdgeRenderer 子类:

/**
 * Responsible for drawing orthogonal edges between two nodes.
 */
public class OrthogonalEdgeRenderer
  extends EdgeRenderer {
  /**
   * Creates a new edge renderer with a given arrowType. The edgeType is
   * ignored -- the edges are drawn orthogonally, as per the responsibility
   * of this class. The arrowType is one of the Constants.EDGE_ARROW_* values.
   *
   * @param edgeType Ignored.
   * @param arrowType One of Constants.EDGE_ARROW_*.
   * @see prefuse.Constants
   */
  public OrthogonalEdgeRenderer( int edgeType, int arrowType ) {
    super( edgeType, arrowType );
  }

  /**
   * Creates a new instance with no arrow head.
   */
  public OrthogonalEdgeRenderer() {
    this( Constants.EDGE_TYPE_LINE, Constants.EDGE_ARROW_NONE );
  }

  /**
   * Creates an orthogonal shape (an edge) to draw between two nodes.
   *
   * @param vi The visual item with start and end points.
   * @return The shape to draw between the nodes for this edge.
   */
  protected Shape getRawShape( VisualItem vi ) {
    Path2D.Double result = new Path2D.Double();

    if( vi instanceof EdgeItem ) {
      EdgeItem ei = ( EdgeItem )vi;

      double sx = ei.getSourceItem().getX();
      double sy = ei.getSourceItem().getY();
      double tx = ei.getTargetItem().getX();
      double ty = ei.getTargetItem().getY();

      double midy = ( sy + ty ) / 2;

      if( midy != sy && midy != ty ) {
        result.moveTo( sx, sy );
        result.lineTo( sx, midy );
        result.lineTo( tx, midy );
        result.lineTo( tx, ty );
      }
    }

    return result;
  }
}

Use prefuse to create an EdgeRenderer subclass:

/**
 * Responsible for drawing orthogonal edges between two nodes.
 */
public class OrthogonalEdgeRenderer
  extends EdgeRenderer {
  /**
   * Creates a new edge renderer with a given arrowType. The edgeType is
   * ignored -- the edges are drawn orthogonally, as per the responsibility
   * of this class. The arrowType is one of the Constants.EDGE_ARROW_* values.
   *
   * @param edgeType Ignored.
   * @param arrowType One of Constants.EDGE_ARROW_*.
   * @see prefuse.Constants
   */
  public OrthogonalEdgeRenderer( int edgeType, int arrowType ) {
    super( edgeType, arrowType );
  }

  /**
   * Creates a new instance with no arrow head.
   */
  public OrthogonalEdgeRenderer() {
    this( Constants.EDGE_TYPE_LINE, Constants.EDGE_ARROW_NONE );
  }

  /**
   * Creates an orthogonal shape (an edge) to draw between two nodes.
   *
   * @param vi The visual item with start and end points.
   * @return The shape to draw between the nodes for this edge.
   */
  protected Shape getRawShape( VisualItem vi ) {
    Path2D.Double result = new Path2D.Double();

    if( vi instanceof EdgeItem ) {
      EdgeItem ei = ( EdgeItem )vi;

      double sx = ei.getSourceItem().getX();
      double sy = ei.getSourceItem().getY();
      double tx = ei.getTargetItem().getX();
      double ty = ei.getTargetItem().getY();

      double midy = ( sy + ty ) / 2;

      if( midy != sy && midy != ty ) {
        result.moveTo( sx, sy );
        result.lineTo( sx, midy );
        result.lineTo( tx, midy );
        result.lineTo( tx, ty );
      }
    }

    return result;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文