/** @see prefuse.render.Renderer#render(java.awt.Graphics2D, prefuse.visual.VisualItem) */
    @Override
    public void render(Graphics2D g, VisualItem item) {
      Shape s = getShape(item);
      GraphicsLib.paint(g, item, m_line, getStroke(item), getRenderType(item));

      // check if we have a text label, if so, render it
      String str;
      if (item.canGetString(VisualItem.LABEL)) {
        str = (String) item.getString(VisualItem.LABEL);
        if (str != null && !str.equals("")) {
          float x = (float) m_box.getMinX();
          float y = (float) m_box.getMinY() + m_ascent;

          // draw label background
          GraphicsLib.paint(g, item, s, null, RENDER_TYPE_FILL);

          AffineTransform origTransform = g.getTransform();
          AffineTransform transform = this.getTransform(item);
          if (transform != null) {
            g.setTransform(transform);
          }

          g.setFont(item.getFont());
          g.setColor(ColorLib.getColor(item.getTextColor()));

          if (!(str.length() > 5
              && str.substring(str.length() - 5, str.length()).equals("_last"))) {

            g.setColor(Color.WHITE);
            // TODO properly hunt down source of null str! for now, triage
            if (str != null) {
              // bump y down by appropriate amount
              FontMetrics fm = g.getFontMetrics(item.getFont());
              int strHeight = fm.getAscent();
              //                        g.drawString(str, x, y);
              g.drawString(str, x, y + strHeight);
            }

            if (transform != null) {
              g.setTransform(origTransform);
            }
          }
        }
      }
    }
Example #2
0
 private void adjustEndingPoint(Point2D start, Point2D end, VisualItem source, VisualItem target) {
   Rectangle2D sourceBounds = source.getBounds();
   Rectangle2D targetBounds = target.getBounds();
   if (source.getShape() == Constants.SHAPE_ELLIPSE) {
     m_edgeTrans.setToTranslation(start.getX(), start.getY());
     m_edgeTrans.rotate(
         -HALF_PI + Math.atan2(start.getY() - end.getY(), start.getX() - end.getX()));
     start.setLocation(0, -sourceBounds.getWidth() / 2.0D);
     m_edgeTrans.transform(start, start);
   } else if (GraphicsLib.intersectLineRectangle(start, end, sourceBounds, m_isctPoints) > 0) {
     start.setLocation(m_isctPoints[0]);
   }
   if (target.getShape() == Constants.SHAPE_ELLIPSE) {
     m_edgeTrans.setToTranslation(end.getX(), end.getY());
     m_edgeTrans.rotate(
         -HALF_PI + Math.atan2(end.getY() - start.getY(), end.getX() - start.getX()));
     end.setLocation(0, -targetBounds.getWidth() / 2.0D);
     m_edgeTrans.transform(end, end);
   } else if (GraphicsLib.intersectLineRectangle(start, end, targetBounds, m_isctPoints) > 0) {
     end.setLocation(m_isctPoints[0]);
   }
 }
Example #3
0
  /**
   * @see edu.berkeley.guir.prefuse.action.Action#run(edu.berkeley.guir.prefuse.ItemRegistry,
   *     double)
   */
  public void run(double frac) {

    AggregateTable aggr = (AggregateTable) m_vis.getGroup(m_group);
    // do we have any  to process?
    int num = aggr.getTupleCount();
    if (num == 0) return;

    // update buffers
    int maxsz = 0;
    for (Iterator aggrs = aggr.tuples(); aggrs.hasNext(); )
      maxsz = Math.max(maxsz, 4 * 2 * ((AggregateItem) aggrs.next()).getAggregateSize());
    if (m_pts == null || maxsz > m_pts.length) {
      m_pts = new double[maxsz];
    }

    // compute and assign convex hull for each aggregate
    Iterator aggrs = m_vis.visibleItems(m_group);
    while (aggrs.hasNext()) {
      AggregateItem aitem = (AggregateItem) aggrs.next();

      int idx = 0;
      if (aitem.getAggregateSize() == 0) continue;
      VisualItem item = null;
      Iterator iter = aitem.items();
      while (iter.hasNext()) {
        item = (VisualItem) iter.next();
        if (item.isVisible()) {
          addPoint(m_pts, idx, item, m_margin);
          idx += 2 * 4;
        }
      }
      // if no aggregates are visible, do nothing
      if (idx == 0) continue;

      // compute convex hull
      double[] nhull = GraphicsLib.convexHull(m_pts, idx);

      // prepare viz attribute array
      float[] fhull = (float[]) aitem.get(VisualItem.POLYGON);
      if (fhull == null || fhull.length < nhull.length) fhull = new float[nhull.length];
      else if (fhull.length > nhull.length) fhull[nhull.length] = Float.NaN;

      // copy hull values
      for (int j = 0; j < nhull.length; j++) fhull[j] = (float) nhull[j];
      aitem.set(VisualItem.POLYGON, fhull);
      aitem.setValidated(false); // force invalidation
    }
  }
 /** @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */
 @Override
 public void setBounds(VisualItem item) {
   if (!m_manageBounds) {
     return;
   }
   Shape shape = getShape(item);
   if (shape == null) {
     item.setBounds(item.getX(), item.getY(), 0, 0);
   } else if (shape == m_line) {
     GraphicsLib.setBounds(item, shape, getStroke(item));
   } else {
     m_box.add(m_line.getX1(), m_line.getY1());
     m_box.add(m_line.getX2(), m_line.getY2());
     item.setBounds(m_box.getMinX(), m_box.getMinY(), m_box.getWidth(), m_box.getHeight());
   }
 }
Example #5
0
 /** @see prefuse.render.Renderer#setBounds(prefuse.visual.VisualItem) */
 @Override
 public void setBounds(VisualItem item) {
   if (!m_manageBounds) {
     return;
   }
   Shape shape = getShape(item);
   if (shape == null) {
     item.setBounds(item.getX(), item.getY(), 0, 0);
     return;
   }
   //        GraphicsLib.setBounds(item, shape, getStroke(item));
   //        if (m_curArrow != null) {
   //            Rectangle2D bbox = (Rectangle2D) item.get(VisualItem.BOUNDS);
   //            Rectangle2D.union(bbox, m_curArrow.getBounds2D(), bbox);
   //        }
   GraphicsLib.getBounds(m_tmpBounds, shape, getStroke(item));
   if (m_curArrow != null) {
     Rectangle2D.union(m_tmpBounds, m_curArrow.getBounds2D(), m_tmpBounds);
   }
   item.setBounds(
       m_tmpBounds.getX(), m_tmpBounds.getY(), m_tmpBounds.getWidth(), m_tmpBounds.getHeight());
 }
Example #6
0
  /** @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem) */
  @Override
  protected Shape getRawShape(VisualItem item) {
    EdgeItem e = (EdgeItem) item;
    VisualItem source = e.getSourceItem();
    VisualItem target = e.getTargetItem();

    int type = m_edgeType;
    int edgeIndex = -1;

    getAlignedPoint(m_tmpPoints[0], source.getBounds(), m_xAlign1, m_yAlign1);
    getAlignedPoint(m_tmpPoints[1], target.getBounds(), m_xAlign2, m_yAlign2);
    m_curWidth = (float) (m_width * getLineWidth(item));

    boolean curveCtrlPtsReady = false;
    Polygon arrowHead;
    // create the arrow head, if needed
    if (isDirected(e)
        && m_edgeArrow != Constants.EDGE_ARROW_NONE
        && (arrowHead = getArrowHead(e)) != null) {
      // get starting and ending edge endpoints
      boolean forward = (m_edgeArrow == Constants.EDGE_ARROW_FORWARD);
      Point2D start = null, end = null;
      start = m_tmpPoints[forward ? 0 : 1];
      end = m_tmpPoints[forward ? 1 : 0];
      // compute the intersection with the source/target bounding box
      VisualItem src = getSourceItem(e, forward);
      VisualItem dest = getTargetItem(e, forward);

      if (edgeBounded && !e.isAggregating()) {
        adjustEndingPoint(start, end, src, dest);
      } else if (GraphicsLib.intersectLineRectangle(start, end, dest.getBounds(), m_isctPoints)
          > 0) {
        end.setLocation(m_isctPoints[0]);
      }

      // create the arrow head shape
      AffineTransform arrowTrans;
      if (multipleEdge) {
        edgeIndex = adjustEndingPointByMultipleEdge(e, start, end);
        if (lineForSingleEdge && edgeIndex < 0) {
          type = Constants.EDGE_TYPE_LINE;
          arrowTrans = getArrowTrans(start, end, m_curWidth);
        } else {
          getCurveControlPoints(
              edgeIndex, m_ctrlPoints, start.getX(), start.getY(), end.getX(), end.getY());
          curveCtrlPtsReady = true;
          arrowTrans = getArrowTrans(m_ctrlPoints[0], end, m_curWidth);
        }
      } else {
        arrowTrans = getArrowTrans(start, end, m_curWidth);
      }
      m_curArrow = m_tmpArrow.set(arrowHead, arrowTrans);

      // update the endpoints for the edge shape
      // need to bias this by arrow head size
      adjustLineEndByArrowHead(e, end);
      arrowTrans.transform(end, end);
    } else {
      m_curArrow = null;
      if (edgeBounded && !e.isAggregating()) {
        adjustEndingPoint(m_tmpPoints[0], m_tmpPoints[1], source, target);
      }
      if (multipleEdge) {
        edgeIndex = adjustEndingPointByMultipleEdge(e, m_tmpPoints[0], m_tmpPoints[1]);
        if (lineForSingleEdge && edgeIndex < 0) {
          type = Constants.EDGE_TYPE_LINE;
        } else {
          getCurveControlPoints(
              edgeIndex,
              m_ctrlPoints,
              m_tmpPoints[0].getX(),
              m_tmpPoints[0].getY(),
              m_tmpPoints[1].getX(),
              m_tmpPoints[1].getY());
          curveCtrlPtsReady = true;
        }
      }
    }

    // create the edge shape
    Shape shape = null;
    double sx = m_tmpPoints[0].getX();
    double sy = m_tmpPoints[0].getY();
    double ex = m_tmpPoints[1].getX();
    double ey = m_tmpPoints[1].getY();
    switch (type) {
      case Constants.EDGE_TYPE_LINE:
        m_line.setLine(sx, sy, ex, ey);
        shape = m_line;
        break;
      case Constants.EDGE_TYPE_CURVE:
        if (!curveCtrlPtsReady) {
          getCurveControlPoints(e, m_ctrlPoints, sx, sy, ex, ey);
        }
        m_quad.setCurve(sx, sy, m_ctrlPoints[0].getX(), m_ctrlPoints[0].getY(), ex, ey);
        shape = m_quad;
        break;
      default:
        throw new IllegalStateException("Unknown edge type");
    }

    // return the edge shape
    return shape;
  }
 public void run(double frac) {
   Rectangle2D bounds = m_vis.getBounds(m_group);
   GraphicsLib.expand(bounds, m_margin + (int) (1 / m_display_self.getScale()));
   DisplayLib.fitViewToBounds(m_display_self, bounds, m_duration);
 }