Esempio n. 1
0
  /**
   * ************************************************************** put text in axis coordinates
   * **************************************************************
   */
  public int text(float[] x, float[] y, String[] texts, int color, HALIGN ha, VALIGN va) {
    Seria s = new Seria(x, y);
    s.mWidth = 0; // we don't want stroke here
    if (texts.length != s.sz()) {
      throw new InvalidParameterException("x and y must be with the same length");
    }
    s.mColor = color;
    s.texts = texts;
    s.hAlign = ha;
    s.vAlign = va;

    mData.add(s);
    onDataChanged();
    return mData.size() - 1;
  }
Esempio n. 2
0
  /**
   * ************************************************************** add image seria
   * **************************************************************
   */
  public int bitmapScatter(float[] x, float[] y, Bitmap[] bm, String label, HALIGN ha, VALIGN va) {
    Seria s = new Seria(x, y);
    s.mLabel = label;
    s.mWidth = 0; // we don't want stroke here
    if (bm.length != s.sz()) {
      throw new InvalidParameterException("x and y must be with the same length");
    }
    s.bms = bm;
    s.hAlign = ha;
    s.vAlign = va;

    mData.add(s);
    onDataChanged();
    return mData.size() - 1;
  }
Esempio n. 3
0
  private void stroke(Seria s, Canvas canvas) {
    mPlotPaint.setStyle(Paint.Style.STROKE);
    // draw line
    if (s.mWidth > 0) {
      // create the path
      mPath.reset();
      mPath.moveTo(calcX(s.x[0]), calcY(s.y[0]));
      for (int i = 1; i < s.sz(); i++) {
        mPath.lineTo(calcX(s.x[i]), calcY(s.y[i]));
      }
      // draw the path
      mPlotPaint.setColor(s.mColor);
      mPlotPaint.setStrokeWidth(s.mWidth);
      mPlotPaint.setPathEffect(s.mEffect);
      canvas.drawPath(mPath, mPlotPaint);
    }

    // draw images seria
    if (s.bms != null) {
      for (int i = 0; i < s.sz(); i++) {
        Bitmap bm;
        if (s.bms.length > 1) {
          bm = s.bms[i];
        } else {
          bm = s.bms[0];
        }
        float left = calcX(s.x[i]);
        float top = calcY(s.y[i]);
        if (s.hAlign == HALIGN.CENTER) {
          left -= bm.getWidth() / 2;
        } else if (s.hAlign == HALIGN.RIGHT) {
          left -= bm.getWidth();
        }
        if (s.vAlign == VALIGN.CENTER) {
          top -= bm.getHeight() / 2;
        } else if (s.vAlign == VALIGN.BOTTOM) {
          top -= bm.getHeight();
        }
        canvas.drawBitmap(s.bms[i], left, top, mPlotPaint);
      }
    }
    if (s.texts != null) {
      Align align = Align.CENTER;
      switch (s.hAlign) {
        case LEFT:
          align = Align.RIGHT;
        case RIGHT:
          align = Align.LEFT;
      }

      mPlotPaint.setTextAlign(align);
      mPlotPaint.setStrokeWidth(0);
      mPlotPaint.setColor(s.mColor);
      for (int i = 0; i < s.sz(); i++) {
        float x = calcX(s.x[i]);
        float y = calcY(s.y[i]);
        switch (s.vAlign) {
          case TOP:
            y -= mPlotPaint.getTextSize();
          case CENTER:
            y -= 0.5 * mPlotPaint.getTextSize();
        }
        if (s.deg != 0) {
          canvas.save();
          canvas.rotate(s.deg, x, y);
        }
        canvas.drawText(s.texts[i], x, y, mPlotPaint);
        if (s.deg != 0) {
          canvas.restore();
        }
      }
    }
  }