Skip to content

Commit 99f53d7

Browse files
devnullorthrowhannesa2
authored andcommitted
Modified and expanded, made more flexible marker interaction interface
1 parent e99aea2 commit 99f53d7

2 files changed

Lines changed: 38 additions & 23 deletions

File tree

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
import java.io.IOException;
5353
import java.io.OutputStream;
5454
import java.util.ArrayList;
55+
import java.util.Collections;
56+
import java.util.List;
5557

5658
import androidx.annotation.NonNull;
5759

@@ -543,12 +545,17 @@ public void highlightValues(Highlight[] highs) {
543545
invalidate();
544546
}
545547

546-
/**
547-
* Highlights any y-value at the given x-value in the given DataSet.
548-
* Provide -1 as the dataSetIndex to undo all highlighting.
549-
* This method will call the listener.
550-
*
551-
* @param x The x-value to highlight
548+
public void highlightValues(List<Highlight> highs, List<IMarker> markers) {
549+
if (highs.size() != markers.size()) throw new IllegalArgumentException("Markers and highs must be mutually corresponding. High size = " + highs.size() + " Markers size = " + markers.size());
550+
setMarkers(markers);
551+
highlightValues(highs.toArray(new Highlight[0]));
552+
}
553+
554+
/**
555+
* Highlights any y-value at the given x-value in the given DataSet.
556+
* Provide -1 as the dataSetIndex to undo all highlighting.
557+
* This method will call the listener.
558+
** @param x The x-value to highlight
552559
* @param dataSetIndex The dataset index to search in
553560
* @param dataIndex The data index to search in (only used in CombinedChartView currently)
554561
*/
@@ -747,15 +754,15 @@ public ChartTouchListener getOnTouchListener() {
747754
/**
748755
* the view that represents the marker
749756
*/
750-
protected IMarker mMarker;
757+
protected List<IMarker> mMarkers;
751758

752759
/**
753760
* draws all MarkerViews on the highlighted positions
754761
*/
755762
protected void drawMarkers(Canvas canvas) {
756763

757764
// if there is no marker view or drawing marker is disabled
758-
if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) {
765+
if (mMarkers == null || !isDrawMarkersEnabled() || !valuesToHighlight()) {
759766
return;
760767
}
761768

@@ -789,10 +796,12 @@ protected void drawMarkers(Canvas canvas) {
789796
}
790797

791798
// callbacks to update the content
792-
mMarker.refreshContent(e, highlight);
799+
int markerIndex = i % mMarkers.size();
800+
IMarker markerItem = mMarkers.get(markerIndex);
801+
markerItem.refreshContent(e, highlight);
793802

794803
// draw the marker
795-
mMarker.draw(canvas, pos[0], pos[1]);
804+
markerItem.draw(canvas, pos[0], pos[1]);
796805
}
797806
}
798807

@@ -1136,18 +1145,22 @@ public void setTouchEnabled(boolean enabled) {
11361145
this.mTouchEnabled = enabled;
11371146
}
11381147

1139-
/**
1140-
* sets the marker that is displayed when a value is clicked on the chart
1141-
*/
1142-
public void setMarker(IMarker marker) {
1143-
mMarker = marker;
1144-
}
1148+
public void setMarkers(List<IMarker> marker) {
1149+
mMarkers = marker;
1150+
}
11451151

1146-
/**
1152+
/**
1153+
* sets the marker that is displayed when a value is clicked on the chart
1154+
*/
1155+
public void setMarker(IMarker marker) {
1156+
setMarkers(Collections.unmodifiableList(Collections.singletonList(marker)));
1157+
}
1158+
/**
11471159
* returns the marker that is set as a marker view for the chart
1160+
11481161
*/
1149-
public IMarker getMarker() {
1150-
return mMarker;
1162+
public List<IMarker> getMarker() {
1163+
return mMarkers;
11511164
}
11521165

11531166
@Deprecated
@@ -1156,7 +1169,7 @@ public void setMarkerView(IMarker v) {
11561169
}
11571170

11581171
@Deprecated
1159-
public IMarker getMarkerView() {
1172+
public List<IMarker> getMarkerView() {
11601173
return getMarker();
11611174
}
11621175

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.util.AttributeSet;
77
import android.util.Log;
88

9+
import com.github.mikephil.charting.components.IMarker;
910
import com.github.mikephil.charting.data.BarData;
1011
import com.github.mikephil.charting.data.BubbleData;
1112
import com.github.mikephil.charting.data.CandleData;
@@ -231,7 +232,7 @@ public void setDrawOrder(DrawOrder[] order) {
231232
protected void drawMarkers(Canvas canvas) {
232233

233234
// if there is no marker view or drawing marker is disabled
234-
if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) {
235+
if (mMarkers == null || !isDrawMarkersEnabled() || !valuesToHighlight()) {
235236
return;
236237
}
237238

@@ -259,10 +260,11 @@ protected void drawMarkers(Canvas canvas) {
259260
}
260261

261262
// callbacks to update the content
262-
mMarker.refreshContent(e, highlight);
263+
IMarker markerItem = mMarkers.get(i % mMarkers.size());
264+
markerItem.refreshContent(e, highlight);
263265

264266
// draw the marker
265-
mMarker.draw(canvas, pos[0], pos[1]);
267+
markerItem.draw(canvas, pos[0], pos[1]);
266268
}
267269
}
268270

0 commit comments

Comments
 (0)