Skip to content

Commit 94a67cc

Browse files
committed
Fixes & improvements related to circle cache
1 parent 6d21817 commit 94a67cc

4 files changed

Lines changed: 186 additions & 150 deletions

File tree

MPChartExample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ repositories {
5656
dependencies {
5757
//compile fileTree(dir: 'libs', include: ['*.jar'])
5858
//compile project(':MPChartLib-Realm') // clone "https://github.com/PhilJay/MPAndroidChart-Realm" to get this or uncomment the gradle dependency below:
59-
compile 'com.github.PhilJay:MPAndroidChart-Realm:v1.0.0@aar'
59+
compile 'com.github.PhilJay:MPAndroidChart-Realm:v1.0.2@aar'
6060

6161
compile project(':MPChartLib')
6262
compile 'com.android.support:appcompat-v7:23.1.1'

MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
193193
LineDataSet set = (LineDataSet) iSet;
194194
set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER
195195
? LineDataSet.Mode.LINEAR
196-
: LineDataSet.Mode.CUBIC_BEZIER);
196+
: LineDataSet.Mode.CUBIC_BEZIER);
197197
}
198198
mChart.invalidate();
199199
break;
@@ -207,7 +207,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
207207
LineDataSet set = (LineDataSet) iSet;
208208
set.setMode(set.getMode() == LineDataSet.Mode.STEPPED
209209
? LineDataSet.Mode.LINEAR
210-
: LineDataSet.Mode.STEPPED);
210+
: LineDataSet.Mode.STEPPED);
211211
}
212212
mChart.invalidate();
213213
break;
@@ -221,7 +221,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
221221
LineDataSet set = (LineDataSet) iSet;
222222
set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER
223223
? LineDataSet.Mode.LINEAR
224-
: LineDataSet.Mode.HORIZONTAL_BEZIER);
224+
: LineDataSet.Mode.HORIZONTAL_BEZIER);
225225
}
226226
mChart.invalidate();
227227
break;
@@ -306,8 +306,8 @@ private void setData(int count, float range) {
306306

307307
if (mChart.getData() != null &&
308308
mChart.getData().getDataSetCount() > 0) {
309-
set1 = (LineDataSet)mChart.getData().getDataSetByIndex(0);
310-
set2 = (LineDataSet)mChart.getData().getDataSetByIndex(1);
309+
set1 = (LineDataSet) mChart.getData().getDataSetByIndex(0);
310+
set2 = (LineDataSet) mChart.getData().getDataSetByIndex(1);
311311
set1.setValues(yVals1);
312312
set2.setValues(yVals2);
313313
mChart.getData().notifyDataChanged();
@@ -361,9 +361,12 @@ private void setData(int count, float range) {
361361
public void onValueSelected(Entry e, Highlight h) {
362362
Log.i("Entry selected", e.toString());
363363

364-
mChart.centerViewToAnimated(e.getX(), e.getY(), mChart.getData().getDataSetByIndex(h.getDataSetIndex()).getAxisDependency(), 500);
365-
//mChart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex).getAxisDependency(), 1000);
366-
//mChart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex).getAxisDependency(), 1000);
364+
mChart.centerViewToAnimated(e.getX(), e.getY(), mChart.getData().getDataSetByIndex(h.getDataSetIndex())
365+
.getAxisDependency(), 500);
366+
//mChart.zoomAndCenterAnimated(2.5f, 2.5f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex)
367+
// .getAxisDependency(), 1000);
368+
//mChart.zoomAndCenterAnimated(1.8f, 1.8f, e.getX(), e.getY(), mChart.getData().getDataSetByIndex(dataSetIndex)
369+
// .getAxisDependency(), 1000);
367370
}
368371

369372
@Override

MPChartLib/src/main/java/com/github/mikephil/charting/data/LineDataSet.java

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,60 @@
55
import android.graphics.Color;
66
import android.graphics.DashPathEffect;
77

8-
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
9-
import com.github.mikephil.charting.utils.ColorTemplate;
108
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
119
import com.github.mikephil.charting.formatter.FillFormatter;
10+
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
11+
import com.github.mikephil.charting.utils.ColorTemplate;
1212
import com.github.mikephil.charting.utils.Utils;
1313

1414
import java.util.ArrayList;
1515
import java.util.List;
1616

1717
public class LineDataSet extends LineRadarDataSet<Entry> implements ILineDataSet {
1818

19-
/** Drawing mode for this line dataset **/
19+
/**
20+
* Drawing mode for this line dataset
21+
**/
2022
private LineDataSet.Mode mMode = Mode.LINEAR;
2123

22-
/** List representing all colors that are used for the circles */
24+
/**
25+
* List representing all colors that are used for the circles
26+
*/
2327
private List<Integer> mCircleColors = null;
2428

25-
/** the color of the inner circles */
29+
/**
30+
* the color of the inner circles
31+
*/
2632
private int mCircleColorHole = Color.WHITE;
2733

28-
/** the radius of the circle-shaped value indicators */
34+
/**
35+
* the radius of the circle-shaped value indicators
36+
*/
2937
private float mCircleRadius = 8f;
3038

31-
/** the hole radius of the circle-shaped value indicators */
39+
/**
40+
* the hole radius of the circle-shaped value indicators
41+
*/
3242
private float mCircleHoleRadius = 4f;
3343

34-
/** sets the intensity of the cubic lines */
44+
/**
45+
* sets the intensity of the cubic lines
46+
*/
3547
private float mCubicIntensity = 0.2f;
3648

37-
/** the path effect of this DataSet that makes dashed lines possible */
49+
/**
50+
* the path effect of this DataSet that makes dashed lines possible
51+
*/
3852
private DashPathEffect mDashPathEffect = null;
3953

40-
/** formatter for customizing the position of the fill-line */
54+
/**
55+
* formatter for customizing the position of the fill-line
56+
*/
4157
private FillFormatter mFillFormatter = new DefaultFillFormatter();
4258

43-
/** if true, drawing circles is enabled */
59+
/**
60+
* if true, drawing circles is enabled
61+
*/
4462
private boolean mDrawCircles = true;
4563

4664
private boolean mDrawCircleHole = true;
@@ -52,11 +70,11 @@ public LineDataSet(List<Entry> yVals, String label) {
5270
// mCircleRadius = Utils.convertDpToPixel(4f);
5371
// mLineWidth = Utils.convertDpToPixel(1f);
5472

55-
if(mCircleColors == null) {
73+
if (mCircleColors == null) {
5674
mCircleColors = new ArrayList<Integer>();
5775
}
5876
mCircleColors.clear();
59-
77+
6078
// default colors
6179
// mColors.add(Color.rgb(192, 255, 140));
6280
// mColors.add(Color.rgb(255, 247, 140));
@@ -108,7 +126,7 @@ public void setMode(LineDataSet.Mode mode) {
108126
/**
109127
* Sets the intensity for cubic lines (if enabled). Max = 1f = very cubic,
110128
* Min = 0.05f = low cubic effect, Default: 0.2f
111-
*
129+
*
112130
* @param intensity
113131
*/
114132
public void setCubicIntensity(float intensity) {
@@ -160,7 +178,7 @@ public float getCircleHoleRadius() {
160178
/**
161179
* sets the size (radius) of the circle shpaed value indicators,
162180
* default size = 4f
163-
*
181+
* <p/>
164182
* This method is deprecated because of unclarity. Use setCircleRadius instead.
165183
*
166184
* @param size
@@ -171,9 +189,7 @@ public void setCircleSize(float size) {
171189
}
172190

173191
/**
174-
*
175192
* This function is deprecated because of unclarity. Use getCircleRadius instead.
176-
*
177193
*/
178194
@Deprecated
179195
public float getCircleSize() {
@@ -184,13 +200,13 @@ public float getCircleSize() {
184200
* Enables the line to be drawn in dashed mode, e.g. like this
185201
* "- - - - - -". THIS ONLY WORKS IF HARDWARE-ACCELERATION IS TURNED OFF.
186202
* Keep in mind that hardware acceleration boosts performance.
187-
*
188-
* @param lineLength the length of the line pieces
203+
*
204+
* @param lineLength the length of the line pieces
189205
* @param spaceLength the length of space in between the pieces
190-
* @param phase offset, in degrees (normally, use 0)
206+
* @param phase offset, in degrees (normally, use 0)
191207
*/
192208
public void enableDashedLine(float lineLength, float spaceLength, float phase) {
193-
mDashPathEffect = new DashPathEffect(new float[] {
209+
mDashPathEffect = new DashPathEffect(new float[]{
194210
lineLength, spaceLength
195211
}, phase);
196212
}
@@ -215,7 +231,7 @@ public DashPathEffect getDashPathEffect() {
215231
/**
216232
* set this to true to enable the drawing of circle indicators for this
217233
* DataSet, default true
218-
*
234+
*
219235
* @param enabled
220236
*/
221237
public void setDrawCircles(boolean enabled) {
@@ -243,7 +259,7 @@ public boolean isDrawSteppedEnabled() {
243259

244260
/**
245261
* returns all colors specified for the circles
246-
*
262+
*
247263
* @return
248264
*/
249265
public List<Integer> getCircleColors() {
@@ -252,11 +268,11 @@ public List<Integer> getCircleColors() {
252268

253269
@Override
254270
public int getCircleColor(int index) {
255-
return mCircleColors.get(index % mCircleColors.size());
271+
return mCircleColors.get(index);
256272
}
257273

258274
@Override
259-
public int getCircleColorCount(){
275+
public int getCircleColorCount() {
260276
return mCircleColors.size();
261277
}
262278

@@ -266,7 +282,7 @@ public int getCircleColorCount(){
266282
* is higher than the size of the colors array. Make sure that the colors
267283
* are already prepared (by calling getResources().getColor(...)) before
268284
* adding them to the DataSet.
269-
*
285+
*
270286
* @param colors
271287
*/
272288
public void setCircleColors(List<Integer> colors) {
@@ -279,7 +295,7 @@ public void setCircleColors(List<Integer> colors) {
279295
* is higher than the size of the colors array. Make sure that the colors
280296
* are already prepared (by calling getResources().getColor(...)) before
281297
* adding them to the DataSet.
282-
*
298+
*
283299
* @param colors
284300
*/
285301
public void setCircleColors(int[] colors) {
@@ -293,13 +309,13 @@ public void setCircleColors(int[] colors) {
293309
* "new String[] { R.color.red, R.color.green, ... }" to provide colors for
294310
* this method. Internally, the colors are resolved using
295311
* getResources().getColor(...)
296-
*
312+
*
297313
* @param colors
298314
*/
299315
public void setCircleColors(int[] colors, Context c) {
300316

301317
List<Integer> clrs = mCircleColors;
302-
if(clrs == null){
318+
if (clrs == null) {
303319
clrs = new ArrayList<>();
304320
}
305321
clrs.clear();
@@ -314,7 +330,7 @@ public void setCircleColors(int[] colors, Context c) {
314330
/**
315331
* Sets the one and ONLY color that should be used for this DataSet.
316332
* Internally, this recreates the colors array and adds the specified color.
317-
*
333+
*
318334
* @param color
319335
*/
320336
public void setCircleColor(int color) {
@@ -326,15 +342,15 @@ public void setCircleColor(int color) {
326342
* resets the circle-colors array and creates a new one
327343
*/
328344
public void resetCircleColors() {
329-
if(mCircleColors == null) {
345+
if (mCircleColors == null) {
330346
mCircleColors = new ArrayList<Integer>();
331347
}
332348
mCircleColors.clear();
333349
}
334350

335351
/**
336352
* Sets the color of the inner circle of the line-circles.
337-
*
353+
*
338354
* @param color
339355
*/
340356
public void setCircleColorHole(int color) {
@@ -348,7 +364,7 @@ public int getCircleHoleColor() {
348364

349365
/**
350366
* Set this to true to allow drawing a hole in each data circle.
351-
*
367+
*
352368
* @param enabled
353369
*/
354370
public void setDrawCircleHole(boolean enabled) {

0 commit comments

Comments
 (0)