diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java index b104935d30..1920284927 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/Chart.java @@ -13,7 +13,6 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.os.Build; import android.os.Environment; import android.provider.MediaStore.Images; import androidx.annotation.RequiresApi; @@ -25,7 +24,6 @@ import android.view.ViewParent; import com.github.mikephil.charting.animation.ChartAnimator; -import com.github.mikephil.charting.animation.Easing; import com.github.mikephil.charting.animation.Easing.EasingFunction; import com.github.mikephil.charting.components.Description; import com.github.mikephil.charting.components.IMarker; @@ -54,6 +52,8 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * Baseclass of all Chart-Views. @@ -563,6 +563,12 @@ public void highlightValues(Highlight[] highs) { invalidate(); } + public void highlightValues(List highs, List markers) { + if (highs.size() != markers.size()) throw new IllegalArgumentException("Markers and highs must be mutually corresponding. High size = " + highs.size() + " Markers size = " + markers.size()); + setMarkers(markers); + highlightValues(highs.toArray(new Highlight[0])); + } + /** * Highlights any y-value at the given x-value in the given DataSet. * Provide -1 as the dataSetIndex to undo all highlighting. @@ -772,7 +778,7 @@ public ChartTouchListener getOnTouchListener() { /** * the view that represents the marker */ - protected IMarker mMarker; + protected List mMarkers; /** * draws all MarkerViews on the highlighted positions @@ -780,7 +786,7 @@ public ChartTouchListener getOnTouchListener() { protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled - if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) + if (mMarkers == null || !isDrawMarkersEnabled() || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHighlight.length; i++) { @@ -803,10 +809,12 @@ protected void drawMarkers(Canvas canvas) { continue; // callbacks to update the content - mMarker.refreshContent(e, highlight); + int markerIndex = i % mMarkers.size(); + IMarker markerItem = mMarkers.get(markerIndex); + markerItem.refreshContent(e, highlight); // draw the marker - mMarker.draw(canvas, pos[0], pos[1]); + markerItem.draw(canvas, pos[0], pos[1]); } } @@ -1246,22 +1254,25 @@ public void setTouchEnabled(boolean enabled) { this.mTouchEnabled = enabled; } + public void setMarkers(List marker) { + mMarkers = marker; + } + /** * sets the marker that is displayed when a value is clicked on the chart * * @param marker */ public void setMarker(IMarker marker) { - mMarker = marker; + setMarkers(Collections.unmodifiableList(Collections.singletonList(marker))); } - /** * returns the marker that is set as a marker view for the chart * * @return */ - public IMarker getMarker() { - return mMarker; + public List getMarker() { + return mMarkers; } @Deprecated @@ -1270,7 +1281,7 @@ public void setMarkerView(IMarker v) { } @Deprecated - public IMarker getMarkerView() { + public List getMarkerView() { return getMarker(); } diff --git a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/CombinedChart.java b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/CombinedChart.java index cd01f0ef73..25cfe1afe7 100644 --- a/MPChartLib/src/main/java/com/github/mikephil/charting/charts/CombinedChart.java +++ b/MPChartLib/src/main/java/com/github/mikephil/charting/charts/CombinedChart.java @@ -6,6 +6,7 @@ import android.util.AttributeSet; import android.util.Log; +import com.github.mikephil.charting.components.IMarker; import com.github.mikephil.charting.data.BarData; import com.github.mikephil.charting.data.BubbleData; import com.github.mikephil.charting.data.CandleData; @@ -236,7 +237,7 @@ public void setDrawOrder(DrawOrder[] order) { protected void drawMarkers(Canvas canvas) { // if there is no marker view or drawing marker is disabled - if (mMarker == null || !isDrawMarkersEnabled() || !valuesToHighlight()) + if (mMarkers == null || !isDrawMarkersEnabled() || !valuesToHighlight()) return; for (int i = 0; i < mIndicesToHighlight.length; i++) { @@ -262,10 +263,11 @@ protected void drawMarkers(Canvas canvas) { continue; // callbacks to update the content - mMarker.refreshContent(e, highlight); + IMarker markerItem = mMarkers.get(i % mMarkers.size()); + markerItem.refreshContent(e, highlight); // draw the marker - mMarker.draw(canvas, pos[0], pos[1]); + markerItem.draw(canvas, pos[0], pos[1]); } }