Esempio n. 1
0
  /**
   * Adds an Entry to the DataSet at the specified index. Entries are added to the end of the list.
   *
   * @param e
   * @param dataSetIndex
   */
  public void addEntry(Entry e, int dataSetIndex) {

    if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) {

      IDataSet set = mDataSets.get(dataSetIndex);
      // add the entry to the dataset
      if (!set.addEntry(e)) return;

      float val = e.getVal();

      if (mYValCount == 0) {
        mYMin = val;
        mYMax = val;

        if (set.getAxisDependency() == AxisDependency.LEFT) {

          mLeftAxisMax = e.getVal();
          mLeftAxisMin = e.getVal();
        } else {
          mRightAxisMax = e.getVal();
          mRightAxisMin = e.getVal();
        }
      } else {

        if (mYMax < val) mYMax = val;
        if (mYMin > val) mYMin = val;

        if (set.getAxisDependency() == AxisDependency.LEFT) {

          if (mLeftAxisMax < e.getVal()) mLeftAxisMax = e.getVal();
          if (mLeftAxisMin > e.getVal()) mLeftAxisMin = e.getVal();
        } else {
          if (mRightAxisMax < e.getVal()) mRightAxisMax = e.getVal();
          if (mRightAxisMin > e.getVal()) mRightAxisMin = e.getVal();
        }
      }

      mYValCount += 1;

      handleEmptyAxis(getFirstLeft(), getFirstRight());

    } else {
      Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low.");
    }
  }
Esempio n. 2
0
  /** calc minimum and maximum y value over all datasets */
  public void calcMinMax(int start, int end) {

    if (mDataSets == null || mDataSets.size() < 1) {

      mYMax = 0f;
      mYMin = 0f;
    } else {

      mYMin = Float.MAX_VALUE;
      mYMax = -Float.MAX_VALUE;

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

        IDataSet set = mDataSets.get(i);
        set.calcMinMax(start, end);

        if (set.getYMin() < mYMin) mYMin = set.getYMin();

        if (set.getYMax() > mYMax) mYMax = set.getYMax();
      }

      if (mYMin == Float.MAX_VALUE) {
        mYMin = 0.f;
        mYMax = 0.f;
      }

      // left axis
      T firstLeft = getFirstLeft();

      if (firstLeft != null) {

        mLeftAxisMax = firstLeft.getYMax();
        mLeftAxisMin = firstLeft.getYMin();

        for (IDataSet dataSet : mDataSets) {
          if (dataSet.getAxisDependency() == AxisDependency.LEFT) {
            if (dataSet.getYMin() < mLeftAxisMin) mLeftAxisMin = dataSet.getYMin();

            if (dataSet.getYMax() > mLeftAxisMax) mLeftAxisMax = dataSet.getYMax();
          }
        }
      }

      // right axis
      T firstRight = getFirstRight();

      if (firstRight != null) {

        mRightAxisMax = firstRight.getYMax();
        mRightAxisMin = firstRight.getYMin();

        for (IDataSet dataSet : mDataSets) {
          if (dataSet.getAxisDependency() == AxisDependency.RIGHT) {
            if (dataSet.getYMin() < mRightAxisMin) mRightAxisMin = dataSet.getYMin();

            if (dataSet.getYMax() > mRightAxisMax) mRightAxisMax = dataSet.getYMax();
          }
        }
      }

      // in case there is only one axis, adjust the second axis
      handleEmptyAxis(firstLeft, firstRight);
    }
  }