Skip to content

Commit 810c99c

Browse files
committed
Make highlightFullBarEnabled feature work again
1 parent 0fec2ef commit 810c99c

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

Diff for: MPChartLib/src/main/java/com/github/mikephil/charting/charts/BarChart.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@ public Highlight getHighlightByTouchPoint(float x, float y) {
9292
if (mData == null) {
9393
Log.e(LOG_TAG, "Can't select by touch. No data set.");
9494
return null;
95-
} else
96-
return getHighlighter().getHighlight(x, y);
95+
} else {
96+
Highlight h = getHighlighter().getHighlight(x, y);
97+
if (h == null || !isHighlightFullBarEnabled()) return h;
98+
99+
// For isHighlightFullBarEnabled, remove stackIndex
100+
return new Highlight(h.getX(), h.getY(),
101+
h.getXPx(), h.getYPx(),
102+
h.getDataSetIndex(), -1, h.getAxis());
103+
}
97104
}
98105

99106
/**

Diff for: MPChartLib/src/main/java/com/github/mikephil/charting/charts/CombinedChart.java

+28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import android.content.Context;
55
import android.util.AttributeSet;
6+
import android.util.Log;
67

78
import com.github.mikephil.charting.data.BarData;
89
import com.github.mikephil.charting.data.BubbleData;
@@ -11,6 +12,7 @@
1112
import com.github.mikephil.charting.data.LineData;
1213
import com.github.mikephil.charting.data.ScatterData;
1314
import com.github.mikephil.charting.highlight.CombinedHighlighter;
15+
import com.github.mikephil.charting.highlight.Highlight;
1416
import com.github.mikephil.charting.interfaces.dataprovider.CombinedDataProvider;
1517
import com.github.mikephil.charting.renderer.CombinedChartRenderer;
1618

@@ -92,6 +94,32 @@ public void setData(CombinedData data) {
9294
mRenderer.initBuffers();
9395
}
9496

97+
/**
98+
* Returns the Highlight object (contains x-index and DataSet index) of the selected value at the given touch
99+
* point
100+
* inside the CombinedChart.
101+
*
102+
* @param x
103+
* @param y
104+
* @return
105+
*/
106+
@Override
107+
public Highlight getHighlightByTouchPoint(float x, float y) {
108+
109+
if (mData == null) {
110+
Log.e(LOG_TAG, "Can't select by touch. No data set.");
111+
return null;
112+
} else {
113+
Highlight h = getHighlighter().getHighlight(x, y);
114+
if (h == null || !isHighlightFullBarEnabled()) return h;
115+
116+
// For isHighlightFullBarEnabled, remove stackIndex
117+
return new Highlight(h.getX(), h.getY(),
118+
h.getXPx(), h.getYPx(),
119+
h.getDataSetIndex(), -1, h.getAxis());
120+
}
121+
}
122+
95123
@Override
96124
public LineData getLineData() {
97125
if (mData == null)

Diff for: MPChartLib/src/main/java/com/github/mikephil/charting/highlight/Highlight.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Highlight(float x, int dataSetIndex, int stackIndex) {
7878
* @param y the y-value of the highlighted value
7979
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
8080
*/
81-
protected Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, YAxis.AxisDependency axis) {
81+
public Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, YAxis.AxisDependency axis) {
8282
this.mX = x;
8383
this.mY = y;
8484
this.mXPx = xPx;
@@ -96,7 +96,7 @@ protected Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, YA
9696
* @param stackIndex references which value of a stacked-bar entry has been
9797
* selected
9898
*/
99-
protected Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, int stackIndex, YAxis.AxisDependency axis) {
99+
public Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, int stackIndex, YAxis.AxisDependency axis) {
100100
this(x, y, xPx, yPx, dataSetIndex, axis);
101101
this.mStackIndex = stackIndex;
102102
}

0 commit comments

Comments
 (0)