Exemple #1
0
  /**
   * Draws the LimitLines associated with this axis to the screen.
   *
   * @param c
   */
  @Override
  public void renderLimitLines(Canvas c) {

    List<LimitLine> limitLines = mXAxis.getLimitLines();

    if (limitLines == null || limitLines.size() <= 0) return;

    float[] pts = new float[4];
    Path limitLinePath = new Path();

    for (int i = 0; i < limitLines.size(); i++) {

      LimitLine l = limitLines.get(i);

      pts[0] = l.getLimit();
      pts[2] = l.getLimit();

      mTrans.pointValuesToPixel(pts);

      pts[1] = mViewPortHandler.contentTop();
      pts[3] = mViewPortHandler.contentBottom();

      limitLinePath.moveTo(pts[0], pts[1]);
      limitLinePath.lineTo(pts[2], pts[3]);

      mLimitLinePaint.setStyle(Paint.Style.STROKE);
      mLimitLinePaint.setColor(l.getLineColor());
      mLimitLinePaint.setStrokeWidth(l.getLineWidth());
      mLimitLinePaint.setPathEffect(l.getDashPathEffect());

      c.drawPath(limitLinePath, mLimitLinePaint);
      limitLinePath.reset();

      String label = l.getLabel();

      // if drawing the limit-value label is enabled
      if (label != null && !label.equals("")) {

        float xOffset = l.getLineWidth();
        float add = Utils.convertDpToPixel(4f);

        mLimitLinePaint.setStyle(l.getTextStyle());
        mLimitLinePaint.setPathEffect(null);
        mLimitLinePaint.setColor(l.getTextColor());
        mLimitLinePaint.setStrokeWidth(0.5f);
        mLimitLinePaint.setTextSize(l.getTextSize());

        float yOffset = Utils.calcTextHeight(mLimitLinePaint, label) + add / 2f;

        if (l.getLabelPosition() == LimitLine.LimitLabelPosition.POS_RIGHT) {
          c.drawText(
              label, pts[0] + xOffset, mViewPortHandler.contentBottom() - add, mLimitLinePaint);
        } else {
          c.drawText(
              label, pts[0] + xOffset, mViewPortHandler.contentTop() + yOffset, mLimitLinePaint);
        }
      }
    }
  }
Exemple #2
0
  @Override
  protected void onDraw(Canvas canvas) {
    // super.onDraw(canvas);

    if (mData == null) {

      boolean hasText = !TextUtils.isEmpty(mNoDataText);
      boolean hasDescription = !TextUtils.isEmpty(mNoDataTextDescription);
      float line1height = hasText ? Utils.calcTextHeight(mInfoPaint, mNoDataText) : 0.f;
      float line2height =
          hasDescription ? Utils.calcTextHeight(mInfoPaint, mNoDataTextDescription) : 0.f;
      float lineSpacing =
          (hasText && hasDescription) ? (mInfoPaint.getFontSpacing() - line1height) : 0.f;

      // if no data, inform the user

      float y = (getHeight() - (line1height + lineSpacing + line2height)) / 2.f + line1height;

      if (hasText) {
        canvas.drawText(mNoDataText, getWidth() / 2, y, mInfoPaint);

        if (hasDescription) {
          y = y + line1height + lineSpacing;
        }
      }

      if (hasDescription) {
        canvas.drawText(mNoDataTextDescription, getWidth() / 2, y, mInfoPaint);
      }
      return;
    }

    if (!mOffsetsCalculated) {

      calculateOffsets();
      mOffsetsCalculated = true;
    }
  }
Exemple #3
0
  /**
   * returns the maximum height in pixels across all legend labels
   *
   * @param p the paint object used for rendering the text
   * @return
   */
  public float getMaximumEntryHeight(Paint p) {

    float max = 0f;

    for (int i = 0; i < mLabels.length; i++) {

      if (mLabels[i] != null) {

        float length = (float) Utils.calcTextHeight(p, mLabels[i]);

        if (length > max) max = length;
      }
    }

    return max;
  }
Exemple #4
0
  public void computeAxis(float xValAverageLength, List<String> xValues) {

    mAxisLabelPaint.setTypeface(mXAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mXAxis.getTextSize());

    StringBuffer a = new StringBuffer();

    int max = (int) Math.round(xValAverageLength + mXAxis.getSpaceBetweenLabels());

    for (int i = 0; i < max; i++) {
      a.append("h");
    }

    mXAxis.mLabelWidth = Utils.calcTextWidth(mAxisLabelPaint, a.toString());
    mXAxis.mLabelHeight = Utils.calcTextHeight(mAxisLabelPaint, "Q");
    mXAxis.setValues(xValues);
  }
  @Override
  public void drawValues(Canvas c) {

    PointF center = mChart.getCenterCircleBox();

    // get whole the radius
    float r = mChart.getRadius();
    float rotationAngle = mChart.getRotationAngle();
    float[] drawAngles = mChart.getDrawAngles();
    float[] absoluteAngles = mChart.getAbsoluteAngles();

    float phaseX = mAnimator.getPhaseX();
    float phaseY = mAnimator.getPhaseY();

    float off = r / 10f * 3.6f;

    if (mChart.isDrawHoleEnabled()) {
      off = (r - (r / 100f * mChart.getHoleRadius())) / 2f;
    }

    r -= off; // offset to keep things inside the chart

    PieData data = mChart.getData();
    List<IPieDataSet> dataSets = data.getDataSets();

    float yValueSum = data.getYValueSum();

    boolean drawXVals = mChart.isDrawSliceTextEnabled();

    float angle;
    int xIndex = 0;

    for (int i = 0; i < dataSets.size(); i++) {

      IPieDataSet dataSet = dataSets.get(i);

      if (!dataSet.isDrawValuesEnabled() && !drawXVals) continue;

      // apply the text-styling defined by the DataSet
      applyValueTextStyle(dataSet);

      float lineHeight = Utils.calcTextHeight(mValuePaint, "Q") + Utils.convertDpToPixel(4f);

      int entryCount = dataSet.getEntryCount();

      for (int j = 0, maxEntry = Math.min((int) Math.ceil(entryCount * phaseX), entryCount);
          j < maxEntry;
          j++) {

        Entry entry = dataSet.getEntryForIndex(j);

        if (xIndex == 0) angle = 0.f;
        else angle = absoluteAngles[xIndex - 1] * phaseX;

        final float sliceAngle = drawAngles[xIndex];
        final float sliceSpace = dataSet.getSliceSpace();

        // offset needed to center the drawn text in the slice
        final float offset = (sliceAngle - sliceSpace / 2.f) / 2.f;

        angle = angle + offset;

        // calculate the text position
        float x = (float) (r * Math.cos(Math.toRadians(rotationAngle + angle)) + center.x);
        float y = (float) (r * Math.sin(Math.toRadians(rotationAngle + angle)) + center.y);

        float value =
            mChart.isUsePercentValuesEnabled() ? entry.getVal() / yValueSum * 100f : entry.getVal();

        ValueFormatter formatter = dataSet.getValueFormatter();

        boolean drawYVals = dataSet.isDrawValuesEnabled();

        // draw everything, depending on settings
        if (drawXVals && drawYVals) {

          drawValue(c, formatter, value, entry, 0, x, y);

          if (j < data.getXValCount())
            c.drawText(data.getXVals().get(j), x, y + lineHeight, mValuePaint);

        } else if (drawXVals) {
          if (j < data.getXValCount())
            c.drawText(data.getXVals().get(j), x, y + lineHeight / 2f, mValuePaint);
        } else if (drawYVals) {

          drawValue(c, formatter, value, entry, 0, x, y + lineHeight / 2f);
        }

        xIndex++;
      }
    }
  }
  @Override
  public void drawValues(Canvas c) {

    BubbleData bubbleData = mChart.getBubbleData();

    if (bubbleData == null) return;

    // if values are drawn
    if (bubbleData.getYValCount()
        < (int) (Math.ceil((float) (mChart.getMaxVisibleCount()) * mViewPortHandler.getScaleX()))) {

      final List<IBubbleDataSet> dataSets = bubbleData.getDataSets();

      float lineHeight = Utils.calcTextHeight(mValuePaint, "1");

      for (int i = 0; i < dataSets.size(); i++) {

        IBubbleDataSet dataSet = dataSets.get(i);

        if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0) continue;

        // apply the text-styling defined by the DataSet
        applyValueTextStyle(dataSet);

        final float phaseX = mAnimator.getPhaseX();
        final float phaseY = mAnimator.getPhaseY();

        BubbleEntry entryFrom = dataSet.getEntryForXIndex(mMinX);
        BubbleEntry entryTo = dataSet.getEntryForXIndex(mMaxX);

        int minx = dataSet.getEntryIndex(entryFrom);
        int maxx = Math.min(dataSet.getEntryIndex(entryTo) + 1, dataSet.getEntryCount());

        final float[] positions =
            mChart
                .getTransformer(dataSet.getAxisDependency())
                .generateTransformedValuesBubble(dataSet, phaseX, phaseY, minx, maxx);

        for (int j = 0; j < positions.length; j += 2) {

          final float alpha = phaseX == 1 ? phaseY : phaseX;
          int valueTextColor = dataSet.getValueTextColor(j / 2);
          valueTextColor =
              Color.argb(
                  Math.round(255.f * alpha),
                  Color.red(valueTextColor),
                  Color.green(valueTextColor),
                  Color.blue(valueTextColor));

          float x = positions[j];
          float y = positions[j + 1];

          if (!mViewPortHandler.isInBoundsRight(x)) break;

          if ((!mViewPortHandler.isInBoundsLeft(x) || !mViewPortHandler.isInBoundsY(y))) continue;

          BubbleEntry entry = dataSet.getEntryForIndex(j / 2 + minx);

          drawValue(
              c,
              dataSet.getValueFormatter(),
              entry.getSize(),
              entry,
              i,
              x,
              y + (0.5f * lineHeight),
              valueTextColor);
        }
      }
    }
  }