@@ -24,28 +24,29 @@ public abstract class ChartData<T extends IDataSet<? extends Entry>> {
2424 /**
2525 * maximum y-value in the value array across all axes
2626 */
27- protected float mYMax = 0.0f ;
27+ protected float mYMax = - Float . MAX_VALUE ;
2828
2929 /**
3030 * the minimum y-value in the value array across all axes
3131 */
32- protected float mYMin = 0.0f ;
32+ protected float mYMin = Float . MAX_VALUE ;
3333
3434 /**
3535 * maximum x-value in the value array
3636 */
37- protected float mXMax = 0f ;
37+ protected float mXMax = - Float . MAX_VALUE ;
3838
3939 /**
4040 * minimum x-value in the value array
4141 */
42- protected float mXMin = 0f ;
42+ protected float mXMin = Float . MAX_VALUE ;
4343
44- protected float mLeftAxisMax = Float .MIN_VALUE ;
44+
45+ protected float mLeftAxisMax = -Float .MAX_VALUE ;
4546
4647 protected float mLeftAxisMin = Float .MAX_VALUE ;
4748
48- protected float mRightAxisMax = Float .MIN_VALUE ;
49+ protected float mRightAxisMax = - Float .MAX_VALUE ;
4950
5051 protected float mRightAxisMin = Float .MAX_VALUE ;
5152
@@ -125,68 +126,57 @@ public void notifyDataChanged() {
125126 */
126127 public void calcMinMax () {
127128
128- if (mDataSets == null || mDataSets .size () < 1 ) {
129-
130- mYMax = 0f ;
131- mYMin = 0f ;
132-
133- mXMax = 0f ;
134- mXMin = 0f ;
135-
136- } else {
137-
138- mYMin = Float .MAX_VALUE ;
139- mYMax = -Float .MAX_VALUE ;
140-
141- mXMin = Float .MAX_VALUE ;
142- mXMax = -Float .MAX_VALUE ;
129+ if (mDataSets == null )
130+ return ;
143131
144- for (int i = 0 ; i < mDataSets .size (); i ++) {
132+ mYMax = -Float .MAX_VALUE ;
133+ mYMin = Float .MAX_VALUE ;
134+ mXMax = -Float .MAX_VALUE ;
135+ mXMin = Float .MAX_VALUE ;
145136
146- T set = mDataSets . get ( i );
147- calcMinMax (set );
148- }
137+ for ( T set : mDataSets ) {
138+ calcMinMax (set );
139+ }
149140
150- if ( mYMin == Float .MAX_VALUE ) {
151- mYMin = 0.f ;
152- mYMax = 0.f ;
153- }
141+ mLeftAxisMax = - Float .MAX_VALUE ;
142+ mLeftAxisMin = Float . MAX_VALUE ;
143+ mRightAxisMax = - Float . MAX_VALUE ;
144+ mRightAxisMin = Float . MAX_VALUE ;
154145
155- // left axis
156- T firstLeft = getFirstLeft ();
146+ // left axis
147+ T firstLeft = getFirstLeft ();
157148
158- if (firstLeft != null ) {
149+ if (firstLeft != null ) {
159150
160- mLeftAxisMax = firstLeft .getYMax ();
161- mLeftAxisMin = firstLeft .getYMin ();
151+ mLeftAxisMax = firstLeft .getYMax ();
152+ mLeftAxisMin = firstLeft .getYMin ();
162153
163- for (IDataSet dataSet : mDataSets ) {
164- if (dataSet .getAxisDependency () == AxisDependency .LEFT ) {
165- if (dataSet .getYMin () < mLeftAxisMin )
166- mLeftAxisMin = dataSet .getYMin ();
154+ for (IDataSet dataSet : mDataSets ) {
155+ if (dataSet .getAxisDependency () == AxisDependency .LEFT ) {
156+ if (dataSet .getYMin () < mLeftAxisMin )
157+ mLeftAxisMin = dataSet .getYMin ();
167158
168- if (dataSet .getYMax () > mLeftAxisMax )
169- mLeftAxisMax = dataSet .getYMax ();
170- }
159+ if (dataSet .getYMax () > mLeftAxisMax )
160+ mLeftAxisMax = dataSet .getYMax ();
171161 }
172162 }
163+ }
173164
174- // right axis
175- T firstRight = getFirstRight ();
165+ // right axis
166+ T firstRight = getFirstRight ();
176167
177- if (firstRight != null ) {
168+ if (firstRight != null ) {
178169
179- mRightAxisMax = firstRight .getYMax ();
180- mRightAxisMin = firstRight .getYMin ();
170+ mRightAxisMax = firstRight .getYMax ();
171+ mRightAxisMin = firstRight .getYMin ();
181172
182- for (IDataSet dataSet : mDataSets ) {
183- if (dataSet .getAxisDependency () == AxisDependency .RIGHT ) {
184- if (dataSet .getYMin () < mRightAxisMin )
185- mRightAxisMin = dataSet .getYMin ();
173+ for (IDataSet dataSet : mDataSets ) {
174+ if (dataSet .getAxisDependency () == AxisDependency .RIGHT ) {
175+ if (dataSet .getYMin () < mRightAxisMin )
176+ mRightAxisMin = dataSet .getYMin ();
186177
187- if (dataSet .getYMax () > mRightAxisMax )
188- mRightAxisMax = dataSet .getYMax ();
189- }
178+ if (dataSet .getYMax () > mRightAxisMax )
179+ mRightAxisMax = dataSet .getYMax ();
190180 }
191181 }
192182 }
@@ -275,12 +265,12 @@ public float getYMax() {
275265 public float getYMax (AxisDependency axis ) {
276266 if (axis == AxisDependency .LEFT ) {
277267
278- if (mLeftAxisMax == Float .MIN_VALUE ) {
268+ if (mLeftAxisMax == - Float .MAX_VALUE ) {
279269 return mRightAxisMax ;
280270 } else
281271 return mLeftAxisMax ;
282272 } else {
283- if (mRightAxisMax == Float .MIN_VALUE ) {
273+ if (mRightAxisMax == - Float .MAX_VALUE ) {
284274 return mLeftAxisMax ;
285275 } else
286276 return mRightAxisMax ;
@@ -325,6 +315,11 @@ public int getYValCount() {
325315 return mValueCount ;
326316 }
327317
318+ /**
319+ * Returns all DataSet objects this ChartData object holds.
320+ *
321+ * @return
322+ */
328323 public List <T > getDataSets () {
329324 return mDataSets ;
330325 }
@@ -578,23 +573,23 @@ public boolean removeEntry(Entry e, int dataSetIndex) {
578573 }
579574
580575 /**
581- * Removes the Entry object at the given xIndex from the DataSet at the
576+ * Removes the Entry object closest to the given DataSet at the
582577 * specified index. Returns true if an Entry was removed, false if no Entry
583578 * was found that meets the specified requirements.
584579 *
585- * @param xIndex
580+ * @param xPos
586581 * @param dataSetIndex
587582 * @return
588583 */
589- public boolean removeEntry (int xIndex , int dataSetIndex ) {
584+ public boolean removeEntry (float xPos , int dataSetIndex ) {
590585
591586 if (dataSetIndex >= mDataSets .size ())
592587 return false ;
593588
594589 IDataSet dataSet = mDataSets .get (dataSetIndex );
595- Entry e = dataSet .getEntryForXPos (xIndex );
590+ Entry e = dataSet .getEntryForXPos (xPos );
596591
597- if (e == null || e . getX () != xIndex )
592+ if (e == null )
598593 return false ;
599594
600595 return removeEntry (e , dataSetIndex );
@@ -658,13 +653,14 @@ public int[] getColors() {
658653 return colors ;
659654 }
660655
656+ /**
657+ * Returns the index of the provided DataSet in the DataSet array of this data object, or -1 if it does not exist.
658+ *
659+ * @param dataSet
660+ * @return
661+ */
661662 public int getIndexOfDataSet (T dataSet ) {
662- for (int i = 0 ; i < mDataSets .size (); i ++) {
663- if (mDataSets .get (i ) == dataSet )
664- return i ;
665- }
666-
667- return -1 ;
663+ return mDataSets .indexOf (dataSet );
668664 }
669665
670666 /**
@@ -678,7 +674,6 @@ public T getFirstLeft() {
678674 if (dataSet .getAxisDependency () == AxisDependency .LEFT )
679675 return dataSet ;
680676 }
681-
682677 return null ;
683678 }
684679
@@ -693,7 +688,6 @@ public T getFirstRight() {
693688 if (dataSet .getAxisDependency () == AxisDependency .RIGHT )
694689 return dataSet ;
695690 }
696-
697691 return null ;
698692 }
699693
@@ -840,12 +834,15 @@ public int getEntryCount() {
840834 }
841835
842836 /**
843- * Returns the DataSet object with the maximum number of entries.
837+ * Returns the DataSet object with the maximum number of entries or null if there are no DataSets .
844838 *
845839 * @return
846840 */
847841 public T getMaxEntryCountSet () {
848842
843+ if (mDataSets == null || mDataSets .isEmpty ())
844+ return null ;
845+
849846 T max = mDataSets .get (0 );
850847
851848 for (T set : mDataSets ) {
0 commit comments