コード例 #1
0
ファイル: PhotoGraphAxis.java プロジェクト: BodyTrack/Grapher
  /**
   * Draws a single tick at the specified location.
   *
   * <p>Draws a tick of width {@code width * TICK_WIDTH_FACTOR} with its left edge at the specified
   * X-value, and at Y-value determined by {@code projectY(value)}. If <tt>value</tt> is out of
   * range, though (the range is determined by {@linkplain GraphAxis#getMin()} and {@linkplain
   * GraphAxis#getMax()}), this method draws nothing.
   *
   * <p>Note that this method does not call {@code canvas.beginPath()} or {@code canvas.stroke()}.
   * It is up to a calling method to call {@code canvas.beginPath()} before calling this method, and
   * to call {@code canvas.stroke()} after calling this method.
   *
   * @param canvas a {@link Canvas} on which the tick will be drawn
   * @param value the location in which to draw the tick, specified not in pixels but in terms of
   *     the (INITIAL_MIN_VALUE, INITIAL_MAX_VALUE) value scale this class keeps in place
   * @param x the X-coordinate for the left edge of the tick
   * @param width the width of this axis, <em>NOT</em> the width of the tick
   */
  private void drawTick(
      final Canvas canvas, final double value, final double x, final double width) {
    // Don't draw anything that is out of bounds
    if (getMin() > value || getMax() < value) {
      return;
    }

    final double y = projectY(value);

    final double tickWidth = TICK_WIDTH_FACTOR * width;
    final double xRight = x + tickWidth;

    canvas.getRenderer().drawLineSegment(x, y, xRight, y);
  }
コード例 #2
0
ファイル: PhotoGraphAxis.java プロジェクト: BodyTrack/Grapher
  /** Draws this axis. */
  @Override
  public void paint(final int newPaintEventId) {
    // guard against redundant paints
    if (previousPaintEventId != newPaintEventId) {
      previousPaintEventId = newPaintEventId;

      final Canvas canvas = getDrawingCanvas();
      if (canvas == null) {
        return;
      }

      canvas.getSurface().clear();

      // Pick the color to use, based on highlighting status
      if (isHighlighted()) {
        canvas.setStrokeStyle(HIGHLIGHTED_COLOR);
      } else {
        canvas.setStrokeStyle(NORMAL_COLOR);
      }

      final double x = project2D(INITIAL_MIN).getX();
      final double width = getWidth();

      // Now figure out where the line should go, drawing ticks
      // as we go along
      double topValue = PHOTO_CENTER_LOCATION + PHOTO_HEIGHT / 2.0;
      double bottomValue = PHOTO_CENTER_LOCATION - PHOTO_HEIGHT / 2.0;

      // Don't draw anything at all if the line is out of bounds
      if (bottomValue > getMax() || topValue < getMin()) {
        return;
      }

      // Allow ourselves to begin drawing
      canvas.beginPath();

      if (topValue > getMax()) {
        topValue = getMax();
      } else {
        drawTick(canvas, topValue, x, width);
      }

      if (bottomValue < getMin()) {
        bottomValue = getMin();
      } else {
        drawTick(canvas, bottomValue, x, width);
      }

      // Get the values in pixels for where the line should go
      final double topY = projectY(topValue);
      final double bottomY = projectY(bottomValue);

      // Now draw the vertical line
      canvas.getRenderer().drawLineSegment(x, topY, x, bottomY);

      // Actually render all our ticks and lines on the canvas
      canvas.stroke();

      // Clean up after ourselves
      canvas.setStrokeStyle(Canvas.DEFAULT_COLOR);
    }
  }