Reinvented Markers - interface based, enhanced default behaviour · Android-View/MPAndroidChart@51f0e53 · GitHub
Skip to content

Commit 51f0e53

Browse files
committed
Reinvented Markers - interface based, enhanced default behaviour
Two default implementations exist now: MarkerView, MarkerImage The default behaviour constraints the marker to the view's bounds.
1 parent f63002e commit 51f0e53

36 files changed

Lines changed: 384 additions & 1479 deletions

MPChartExample/AndroidManifest.xml

Lines changed: 0 additions & 10 deletions

MPChartExample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apply plugin: 'com.android.application'
2-
apply plugin: 'realm-android'
2+
//apply plugin: 'realm-android'
33

44
android {
55
compileSdkVersion 23

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ protected void onCreate(Bundle savedInstanceState) {
119119
// l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
120120
// "def", "ghj", "ikl", "mno" });
121121

122-
mChart.setMarkerView(new XYMarkerView(this, xAxisFormatter));
122+
XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
123+
mv.setChartView(mChart); // For bounds control
124+
mChart.setMarker(mv); // Set the marker to the chart
123125

124126
setData(12, 50);
125127

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ protected void onCreate(Bundle savedInstanceState) {
7070
// create a custom MarkerView (extend MarkerView) and specify the layout
7171
// to use for it
7272
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
73-
74-
// set the marker to the chart
75-
mChart.setMarkerView(mv);
73+
mv.setChartView(mChart); // For bounds control
74+
mChart.setMarker(mv); // Set the marker to the chart
7675

7776
mSeekBarX.setProgress(10);
7877
mSeekBarY.setProgress(100);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ private void removeLastEntry() {
8787

8888
if (set != null) {
8989

90-
Entry e = set.getEntryForXPos(set.getEntryCount() - 1);
90+
Entry e = set.getEntryForXValue(set.getEntryCount() - 1);
9191

9292
data.removeEntry(e, 0);
9393
// or remove by index
94-
// mData.removeEntryByXPos(xIndex, dataSetIndex);
94+
// mData.removeEntryByXValue(xIndex, dataSetIndex);
9595
data.notifyDataChanged();
9696
mChart.notifyDataSetChanged();
9797
mChart.invalidate();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ protected void onCreate(Bundle savedInstanceState) {
7979
// create a custom MarkerView (extend MarkerView) and specify the layout
8080
// to use for it
8181
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
82-
83-
// set the marker to the chart
84-
mChart.setMarkerView(mv);
82+
mv.setChartView(mChart); // For bounds control
83+
mChart.setMarker(mv); // Set the marker to the chart
8584

8685
XAxis xl = mChart.getXAxis();
8786
xl.setAvoidFirstLastClipping(true);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ protected void onCreate(Bundle savedInstanceState) {
9292
// create a custom MarkerView (extend MarkerView) and specify the layout
9393
// to use for it
9494
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
95-
96-
// set the marker to the chart
97-
mChart.setMarkerView(mv);
95+
mv.setChartView(mChart); // For bounds control
96+
mChart.setMarker(mv); // Set the marker to the chart
9897

9998
// x-axis limit line
10099
LimitLine llXAxis = new LimitLine(10f, "Index 10");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.github.mikephil.charting.components.AxisBase;
1515
import com.github.mikephil.charting.components.Legend;
1616
import com.github.mikephil.charting.components.Legend.LegendPosition;
17+
import com.github.mikephil.charting.components.MarkerImage;
1718
import com.github.mikephil.charting.components.MarkerView;
1819
import com.github.mikephil.charting.components.XAxis;
1920
import com.github.mikephil.charting.components.YAxis;
@@ -58,9 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {
5859
// create a custom MarkerView (extend MarkerView) and specify the layout
5960
// to use for it
6061
MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
61-
62-
// set the marker to the chart
63-
mChart.setMarkerView(mv);
62+
mv.setChartView(mChart); // For bounds control
63+
mChart.setMarker(mv); // Set the marker to the chart
6464

6565
setData();
6666

MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/MyMarkerView.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.github.mikephil.charting.data.CandleEntry;
99
import com.github.mikephil.charting.data.Entry;
1010
import com.github.mikephil.charting.highlight.Highlight;
11+
import com.github.mikephil.charting.utils.MPPointF;
1112
import com.github.mikephil.charting.utils.Utils;
1213
import com.xxmassdeveloper.mpchartexample.R;
1314

@@ -40,17 +41,12 @@ public void refreshContent(Entry e, Highlight highlight) {
4041

4142
tvContent.setText("" + Utils.formatNumber(e.getY(), 0, true));
4243
}
43-
}
4444

45-
@Override
46-
public int getXOffset(float xpos) {
47-
// this will center the marker-view horizontally
48-
return -(getWidth() / 2);
45+
super.refreshContent(e, highlight);
4946
}
5047

5148
@Override
52-
public int getYOffset(float ypos) {
53-
// this will cause the marker-view to be above the selected value
54-
return -getHeight();
49+
public MPPointF getOffset() {
50+
return new MPPointF(-(getWidth() / 2), -getHeight());
5551
}
5652
}

MPChartExample/src/com/xxmassdeveloper/mpchartexample/custom/RadarMarkerView.java

Lines changed: 4 additions & 8 deletions

0 commit comments

Comments
 (0)