Skip to content

Commit 5ff8f96

Browse files
committed
More fixes related to MarkerView drawing
1 parent 8a37bbd commit 5ff8f96

14 files changed

Lines changed: 102 additions & 31 deletions

File tree

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) {
6868
mChart.setMaxVisibleValueCount(200);
6969
mChart.setPinchZoom(true);
7070

71-
mSeekBarX.setProgress(1);
71+
mSeekBarX.setProgress(10);
7272
mSeekBarY.setProgress(50);
7373

7474
Legend l = mChart.getLegend();

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivitry.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import com.github.mikephil.charting.components.MarkerView;
1818
import com.github.mikephil.charting.components.XAxis;
1919
import com.github.mikephil.charting.components.YAxis;
20-
import com.github.mikephil.charting.data.Entry;
2120
import com.github.mikephil.charting.data.RadarData;
2221
import com.github.mikephil.charting.data.RadarDataSet;
22+
import com.github.mikephil.charting.data.RadarEntry;
2323
import com.github.mikephil.charting.formatter.AxisValueFormatter;
2424
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
2525
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
@@ -210,20 +210,20 @@ public void setData() {
210210
float min = 20;
211211
int cnt = 5;
212212

213-
ArrayList<Entry> yVals1 = new ArrayList<Entry>();
214-
ArrayList<Entry> yVals2 = new ArrayList<Entry>();
213+
ArrayList<RadarEntry> yVals1 = new ArrayList<RadarEntry>();
214+
ArrayList<RadarEntry> yVals2 = new ArrayList<RadarEntry>();
215215

216216
// IMPORTANT: In a PieChart, no values (Entry) should have the same
217217
// xIndex (even if from different DataSets), since no values can be
218218
// drawn above each other.
219219
for (int i = 0; i < cnt; i++) {
220220
float val = (float) (Math.random() * mult) + min;
221-
yVals1.add(new Entry(i, val));
221+
yVals1.add(new RadarEntry(val));
222222
}
223223

224224
for (int i = 0; i < cnt; i++) {
225225
float val = (float) (Math.random() * mult) + min;
226-
yVals2.add(new Entry(i, val));
226+
yVals2.add(new RadarEntry(val));
227227
}
228228

229229
RadarDataSet set1 = new RadarDataSet(yVals1, "Last Week");

‎MPChartLib/src/main/java/com/github/mikephil/charting/charts/PieChart.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected float[] getMarkerPosition(Highlight highlight) {
183183

184184
float rotationAngle = getRotationAngle();
185185

186-
int entryIndex = getData().getDataSet().getEntryIndex(highlight.getX(), DataSet.Rounding.CLOSEST);
186+
int entryIndex = (int) highlight.getX();
187187

188188
// offset needed to center the drawn text in the slice
189189
float offset = mDrawAngles[entryIndex] / 2;

‎MPChartLib/src/main/java/com/github/mikephil/charting/charts/RadarChart.java‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,21 @@ public int getIndexForAngle(float angle) {
201201

202202
float sliceangle = getSliceAngle();
203203

204-
for (int i = 0; i < mData.getMaxEntryCountSet().getEntryCount(); i++) {
205-
if (sliceangle * (i + 1) - sliceangle / 2f > a)
206-
return i;
204+
int max = mData.getMaxEntryCountSet().getEntryCount();
205+
206+
int index = 0;
207+
208+
for (int i = 0; i < max; i++) {
209+
210+
float referenceAngle = sliceangle * (i + 1) - sliceangle / 2f;
211+
212+
if (referenceAngle > a) {
213+
index = i;
214+
break;
215+
}
207216
}
208217

209-
return 0;
218+
return index;
210219
}
211220

212221
/**

‎MPChartLib/src/main/java/com/github/mikephil/charting/data/PieEntry.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public void setLabel(String label) {
4545
this.label = label;
4646
}
4747

48+
@Deprecated
49+
@Override
50+
public void setX(float x) {
51+
super.setX(x);
52+
}
53+
54+
@Deprecated
55+
@Override
56+
public float getX() {
57+
return super.getX();
58+
}
59+
4860
public PieEntry copy() {
4961
PieEntry e = new PieEntry(getY(), label, getData());
5062
return e;

‎MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarData.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
package com.github.mikephil.charting.data;
33

4+
import com.github.mikephil.charting.highlight.Highlight;
45
import com.github.mikephil.charting.interfaces.datasets.IRadarDataSet;
56

67
import java.util.ArrayList;
@@ -49,4 +50,9 @@ public void setLabels(String... labels) {
4950
public List<String> getLabels() {
5051
return mLabels;
5152
}
53+
54+
@Override
55+
public Entry getEntryForHighlight(Highlight highlight) {
56+
return getDataSetByIndex(highlight.getDataSetIndex()).getEntryForIndex((int) highlight.getX());
57+
}
5258
}

‎MPChartLib/src/main/java/com/github/mikephil/charting/data/RadarDataSet.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.ArrayList;
1010
import java.util.List;
1111

12-
public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataSet {
12+
public class RadarDataSet extends LineRadarDataSet<RadarEntry> implements IRadarDataSet {
1313

1414
/// flag indicating whether highlight circle should be drawn or not
1515
protected boolean mDrawHighlightCircleEnabled = false;
@@ -25,7 +25,7 @@ public class RadarDataSet extends LineRadarDataSet<Entry> implements IRadarDataS
2525
protected float mHighlightCircleOuterRadius = 4.0f;
2626
protected float mHighlightCircleStrokeWidth = 2.0f;
2727

28-
public RadarDataSet(List<Entry> yVals, String label) {
28+
public RadarDataSet(List<RadarEntry> yVals, String label) {
2929
super(yVals, label);
3030
}
3131

@@ -114,9 +114,9 @@ public void setHighlightCircleStrokeWidth(float strokeWidth)
114114
}
115115

116116
@Override
117-
public DataSet<Entry> copy() {
117+
public DataSet<RadarEntry> copy() {
118118

119-
List<Entry> yVals = new ArrayList<Entry>();
119+
List<RadarEntry> yVals = new ArrayList<RadarEntry>();
120120

121121
for (int i = 0; i < mValues.size(); i++) {
122122
yVals.add(mValues.get(i).copy());
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.github.mikephil.charting.data;
2+
3+
import android.annotation.SuppressLint;
4+
5+
/**
6+
* Created by philipp on 13/06/16.
7+
*/
8+
@SuppressLint("ParcelCreator")
9+
public class RadarEntry extends Entry {
10+
11+
public RadarEntry(float value) {
12+
super(0f, value);
13+
}
14+
15+
public RadarEntry(float value, Object data) {
16+
super(0f, value, data);
17+
}
18+
19+
/**
20+
* This is the same as getY(). Returns the value of the RadarEntry.
21+
*
22+
* @return
23+
*/
24+
public float getValue() {
25+
return getY();
26+
}
27+
28+
public RadarEntry copy() {
29+
RadarEntry e = new RadarEntry(getY(), getData());
30+
return e;
31+
}
32+
33+
@Deprecated
34+
@Override
35+
public void setX(float x) {
36+
super.setX(x);
37+
}
38+
39+
@Deprecated
40+
@Override
41+
public float getX() {
42+
return super.getX();
43+
}
44+
}

‎MPChartLib/src/main/java/com/github/mikephil/charting/data/realm/base/RealmLineRadarDataSet.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Created by Philipp Jahoda on 08/11/15.
1616
*/
17-
public abstract class RealmLineRadarDataSet<T extends RealmObject> extends RealmLineScatterCandleRadarDataSet<T, Entry> implements ILineRadarDataSet<Entry> {
17+
public abstract class RealmLineRadarDataSet<T extends RealmObject, S extends Entry> extends RealmLineScatterCandleRadarDataSet<T, S> implements ILineRadarDataSet<S> {
1818

1919
/** the color that is used for filling the line surface */
2020
private int mFillColor = Color.rgb(140, 234, 255);

‎MPChartLib/src/main/java/com/github/mikephil/charting/data/realm/implementation/RealmLineDataSet.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Color;
55
import android.graphics.DashPathEffect;
66

7+
import com.github.mikephil.charting.data.Entry;
78
import com.github.mikephil.charting.data.LineDataSet;
89
import com.github.mikephil.charting.data.realm.base.RealmLineRadarDataSet;
910
import com.github.mikephil.charting.formatter.DefaultFillFormatter;
@@ -21,7 +22,7 @@
2122
/**
2223
* Created by Philipp Jahoda on 21/10/15.
2324
*/
24-
public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T> implements ILineDataSet {
25+
public class RealmLineDataSet<T extends RealmObject> extends RealmLineRadarDataSet<T, Entry> implements ILineDataSet {
2526

2627
/** Drawing mode for this line dataset **/
2728
private LineDataSet.Mode mMode = LineDataSet.Mode.LINEAR;

0 commit comments

Comments
 (0)