Пример #1
0
  /**
   * Get labels position having into account the horizontal padding of text size.
   *
   * @param nLabels - number of labels to display
   */
  private ArrayList<Float> calcLabelsPos(int nLabels) {
    final ArrayList<Float> result = new ArrayList<Float>();

    if (nLabels == 1)
      result.add(
          mChartView.getInnerChartLeft()
              + (getInnerChartRight() - mChartView.getInnerChartLeft()) / 2);
    else {
      final float screenStep =
          (getInnerChartRight()
                  - mChartView.getInnerChartLeft()
                  - mChartView.style.axisThickness / 2
                  // if 0 first label will be right at the beginning of the
                  // axis
                  - borderSpacing * 2
                  - mandatoryBorderSpacing * 2)
              / (nLabels - 1);

      float pos = mChartView.getInnerChartLeft() + borderSpacing + mandatoryBorderSpacing;
      while (pos <= mChartView.chartRight - borderSpacing - mandatoryBorderSpacing) {
        result.add(pos);
        pos += screenStep;
      }
    }

    return result;
  }
Пример #2
0
  public XController(ChartView chartView) {
    mChartView = chartView;

    // Initialize variables and set defaults
    mDistLabelToAxis = (int) (mChartView.getResources().getDimension(R.dimen.axis_dist_from_label));
    mandatoryBorderSpacing = 0;
    hasAxis = true;
    labelsPos = new ArrayList<Float>();
    labelsPositioning = LabelPosition.OUTSIDE;
    borderSpacing = mChartView.getResources().getDimension(R.dimen.axis_border_spacing);
  }
Пример #3
0
  protected void init() {
    // Set the vertical display coordinate
    mLabelVerCoord = mChartView.chartBottom;
    if (labelsPositioning == LabelPosition.INSIDE) mLabelVerCoord -= mDistLabelToAxis;

    // In case of mandatory border spacing (ex. BarChart)
    if (mandatoryBorderSpacing == 1)
      mandatoryBorderSpacing =
          (getInnerChartRight() - mChartView.getInnerChartLeft() - borderSpacing * 2)
              / mChartView.data.get(0).size()
              / 2;

    labelsPos = calcLabelsPos(mChartView.data.get(0).size());
  }
Пример #4
0
  /**
   * Method called from onDraw method to draw XController data
   *
   * @param canvas - Canvas to use while drawing the data.
   */
  protected void draw(Canvas canvas) {
    // Draw axis
    if (hasAxis)
      canvas.drawLine(
          mChartView.getInnerChartLeft(),
          getAxisVerticalPosition(),
          getInnerChartRight(),
          getAxisVerticalPosition(),
          mChartView.style.chartPaint);

    // Draw labels
    if (labelsPositioning != LabelPosition.NONE) {

      mChartView.style.labelPaint.setTextAlign(Align.CENTER);
      for (int i = 0; i < mChartView.data.get(0).size(); i++) {
        canvas.drawText(
            mChartView.data.get(0).getLabel(i),
            labelsPos.get(i),
            mLabelVerCoord,
            mChartView.style.labelPaint);
      }
    }
  }