Skip to content

Commit 5cbc6b7

Browse files
committed
Allow disabling tap-highlight while still being able to highlight programatically or via drag.
1 parent 18e3b07 commit 5cbc6b7

5 files changed

Lines changed: 26 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ public void onChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesture
370370
public void onChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture) {
371371
Log.i("Gesture", "END, lastGesture: " + lastPerformedGesture);
372372

373+
// un-highlight values after the gesture is finished and no single-tap
373374
if(lastPerformedGesture != ChartTouchListener.ChartGesture.SINGLE_TAP)
374-
mChart.highlightValues(null);
375+
mChart.highlightValues(null); // or highlightTouch(null) for callback to onNothingSelected(...)
375376
}
376377

377378
@Override

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected void onCreate(Bundle savedInstanceState) {
8585
mChart.setRotationAngle(0);
8686
// enable rotation of the chart by touch
8787
mChart.setRotationEnabled(true);
88+
mChart.setHighLightPerTapEnabled(false);
8889

8990
// mChart.setUnit(" €");
9091
// mChart.setDrawUnitsInChart(true);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public abstract class Chart<T extends ChartData<? extends DataSet<? extends Entr
7676
*/
7777
protected T mData = null;
7878

79+
/**
80+
* Flag that indicates if highlighting per tap (touch) is enabled
81+
*/
82+
protected boolean mHighLightPerTapEnabled = true;
83+
7984
/**
8085
* If set to true, chart continues to scroll after touch up
8186
*/
@@ -495,6 +500,14 @@ public Highlight[] getHighlighted() {
495500
return mIndicesToHighlight;
496501
}
497502

503+
public boolean isHighLightPerTapEnabled() {
504+
return mHighLightPerTapEnabled;
505+
}
506+
507+
public void setHighLightPerTapEnabled(boolean enabled) {
508+
mHighLightPerTapEnabled = enabled;
509+
}
510+
498511
/**
499512
* Returns true if there are values to highlight, false if there are no
500513
* values to highlight. Checks if the highlight array is null, has a length

MPChartLib/src/com/github/mikephil/charting/listener/BarLineChartTouchListener.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,6 @@ public void onLongPress(MotionEvent e) {
542542
@Override
543543
public boolean onSingleTapUp(MotionEvent e) {
544544

545-
performHighlight(e);
546-
547545
mLastGesture = ChartGesture.SINGLE_TAP;
548546

549547
OnChartGestureListener l = mChart.getOnChartGestureListener();
@@ -552,6 +550,12 @@ public boolean onSingleTapUp(MotionEvent e) {
552550
l.onChartSingleTapped(e);
553551
}
554552

553+
if(!mChart.isHighLightPerTapEnabled()) {
554+
return false;
555+
}
556+
557+
performHighlight(e);
558+
555559
return super.onSingleTapUp(e);
556560
}
557561

MPChartLib/src/com/github/mikephil/charting/listener/PieRadarChartTouchListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public boolean onSingleTapUp(MotionEvent e) {
147147
l.onChartSingleTapped(e);
148148
}
149149

150+
if(!mChart.isHighLightPerTapEnabled()) {
151+
return false;
152+
}
153+
150154
float distance = mChart.distanceToCenter(e.getX(), e.getY());
151155

152156
// check if a slice was touched

0 commit comments

Comments
 (0)