예제 #1
0
  /**
   * Calculates the required maximum y-value in order to be able to provide the desired number of
   * label entries and rounded label values.
   */
  private void prepareYLabels() {

    int labelCount = mYLabels.getLabelCount();
    double range = mCurrentData.getYMax() - mYChartMin;

    double rawInterval = range / labelCount;
    double interval = Utils.roundToNextSignificant(rawInterval);
    double intervalMagnitude = Math.pow(10, (int) Math.log10(interval));
    int intervalSigDigit = (int) (interval / intervalMagnitude);
    if (intervalSigDigit > 5) {
      // Use one order of magnitude higher, to avoid intervals like 0.9 or
      // 90
      interval = Math.floor(10 * intervalMagnitude);
    }

    double first = Math.ceil(mYChartMin / interval) * interval;
    double last = Utils.nextUp(Math.floor(mCurrentData.getYMax() / interval) * interval);

    double f;
    int n = 0;
    for (f = first; f <= last; f += interval) {
      ++n;
    }

    mYLabels.mEntryCount = n;

    mYChartMax = (float) interval * n;

    // calc delta
    mDeltaY = Math.abs(mYChartMax - mYChartMin);
  }
예제 #2
0
  /** Draws the y-labels of the RadarChart. */
  private void drawYLabels() {

    if (!mDrawYLabels) return;

    mYLabelPaint.setTypeface(mYLabels.getTypeface());
    mYLabelPaint.setTextSize(mYLabels.getTextSize());
    mYLabelPaint.setColor(mYLabels.getTextColor());

    PointF c = getCenterOffsets();
    float factor = getFactor();

    int labelCount = mYLabels.mEntryCount;

    for (int j = 0; j < labelCount; j++) {

      if (j == labelCount - 1 && mYLabels.isDrawTopYLabelEntryEnabled() == false) break;

      float r = ((mYChartMax / labelCount) * j) * factor;

      PointF p = getPosition(c, r, mRotationAngle);

      float val = r / factor;

      String label =
          Utils.formatNumber(val, mYLabels.mDecimals, mYLabels.isSeparateThousandsEnabled());

      if (mYLabels.isDrawUnitsInYLabelEnabled())
        mDrawCanvas.drawText(label + mUnit, p.x + 10, p.y - 5, mYLabelPaint);
      else {
        mDrawCanvas.drawText(label, p.x + 10, p.y - 5, mYLabelPaint);
      }
    }
  }