Modified and expanded, made more flexible marker interaction interface
This commit is contained in:
parent
eae977306e
commit
f3a2ec21c9
2 changed files with 27 additions and 14 deletions
|
@ -13,7 +13,6 @@ import android.graphics.Paint.Align;
|
|||
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.ViewGroup;
|
|||
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.FileOutputStream;
|
|||
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 abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
invalidate();
|
||||
}
|
||||
|
||||
public void highlightValues(List<Highlight> highs, List<IMarker> 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 abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
/**
|
||||
* the view that represents the marker
|
||||
*/
|
||||
protected IMarker mMarker;
|
||||
protected List<IMarker> mMarkers;
|
||||
|
||||
/**
|
||||
* draws all MarkerViews on the highlighted positions
|
||||
|
@ -780,7 +786,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
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 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
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 abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
this.mTouchEnabled = enabled;
|
||||
}
|
||||
|
||||
public void setMarkers(List<IMarker> 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<IMarker> getMarker() {
|
||||
return mMarkers;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
@ -1270,7 +1281,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
|
|||
}
|
||||
|
||||
@Deprecated
|
||||
public IMarker getMarkerView() {
|
||||
public List<IMarker> getMarkerView() {
|
||||
return getMarker();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.Canvas;
|
|||
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 class CombinedChart extends BarLineChartBase<CombinedData> implements Com
|
|||
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 @@ public class CombinedChart extends BarLineChartBase<CombinedData> implements Com
|
|||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue