Skip to content

Commit 2de5640

Browse files
committed
Improved MarkerView, fix issues.
1 parent e5578bf commit 2de5640

11 files changed

Lines changed: 82 additions & 49 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
7171

7272
// define an offset to change the original position of the marker
7373
// (optional)
74-
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
74+
// mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
7575

7676
// set the marker to the chart
7777
mChart.setMarkerView(mv);

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ protected void onCreate(Bundle savedInstanceState) {
9292
// to use for it
9393
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
9494

95-
// define an offset to change the original position of the marker
96-
// (optional)
97-
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
98-
9995
// set the marker to the chart
10096
mChart.setMarkerView(mv);
10197

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ protected void onCreate(Bundle savedInstanceState) {
109109
// to use for it
110110
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
111111

112-
// define an offset to change the original position of the marker
113-
// (optional)
114-
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
115-
116112
// set the marker to the chart
117113
mChart.setMarkerView(mv);
118114

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {
5757

5858
mChart = (LineChart) findViewById(R.id.chart1);
5959
mChart.setOnChartValueSelectedListener(this);
60+
mChart.setValueTextColor(Color.WHITE);
6061

6162
mChart.setUnit(" $");
6263
mChart.setDrawUnitsInChart(true);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import com.github.mikephil.charting.utils.MarkerView;
1010
import com.github.mikephil.charting.utils.Utils;
1111

12+
/**
13+
* Custom implementation of the MarkerView.
14+
*
15+
* @author Philipp Jahoda
16+
*/
1217
public class MyMarkerView extends MarkerView {
1318

1419
private TextView tvContent;
@@ -34,4 +39,16 @@ public void refreshContent(Entry e, int dataSetIndex) {
3439
tvContent.setText("" + Utils.formatNumber(e.getVal(), 0, true));
3540
}
3641
}
42+
43+
@Override
44+
public int getXOffset() {
45+
// this will center the marker-view horizontally
46+
return -(getWidth() / 2);
47+
}
48+
49+
@Override
50+
public int getYOffset() {
51+
// this will cause the marker-view to be above the selected value
52+
return -getHeight();
53+
}
3754
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ protected void onCreate(Bundle savedInstanceState) {
5353
// to use for it
5454
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
5555

56-
// define an offset to change the original position of the marker
57-
// (optional)
58-
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
59-
6056
// set the marker to the chart
6157
mChart.setMarkerView(mv);
6258

MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/BarChartFrag.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
3131
mChart.setDescription("");
3232

3333
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
34-
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
3534

3635
mChart.setMarkerView(mv);
3736

MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/ScatterChartFrag.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
3535
labels.setTypeface(tf);
3636

3737
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
38-
mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());
3938

4039
mChart.setMarkerView(mv);
4140

MPChartLib/src/com/github/mikephil/charting/charts/Chart.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
145145
protected Paint mLimitLinePaint;
146146

147147
/** description text that appears in the bottom right corner of the chart */
148-
protected String mDescription = "Description.";
148+
protected String mDescription = "Description";
149149

150150
/** flag that indicates if the chart has been fed with data yet */
151151
protected boolean mDataNotSet = true;
@@ -1048,11 +1048,24 @@ protected void drawMarkers() {
10481048
// callbacks to update the content
10491049
mMarkerView.refreshContent(e, dataSetIndex);
10501050

1051+
// mMarkerView.measure(MeasureSpec.makeMeasureSpec(0,
1052+
// MeasureSpec.UNSPECIFIED),
1053+
// MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
1054+
// mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
1055+
// mMarkerView.getMeasuredHeight());
1056+
// mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
1057+
10511058
mMarkerView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
10521059
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
10531060
mMarkerView.layout(0, 0, mMarkerView.getMeasuredWidth(),
10541061
mMarkerView.getMeasuredHeight());
1055-
mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
1062+
1063+
if (pos[1] - mMarkerView.getHeight() <= 0) {
1064+
float y = mMarkerView.getHeight() - pos[1];
1065+
mMarkerView.draw(mDrawCanvas, pos[0], pos[1] + y);
1066+
} else {
1067+
mMarkerView.draw(mDrawCanvas, pos[0], pos[1]);
1068+
}
10561069
}
10571070
}
10581071
}
@@ -1477,6 +1490,8 @@ public void setLogEnabled(boolean enabled) {
14771490
* @param desc
14781491
*/
14791492
public void setDescription(String desc) {
1493+
if (desc == null)
1494+
desc = "";
14801495
this.mDescription = desc;
14811496
}
14821497

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public void setHoleColor(int color) {
563563
* Set the hole in the center of the PieChart transparent. Thank you, code
564564
* provided by:
565565
*
566-
* @link https://github.com/wogg
566+
* @link https://github.com/tbarthel-fr
567567
* @param enable
568568
*/
569569
public void setHoleColorTransparent(boolean enable) {

0 commit comments

Comments
 (0)