Added dataIndex param for highlightValue (combined charts)

https://github.com/danielgindi/Charts/pull/2852
This commit is contained in:
Daniel Cohen Gindi 2020-01-22 12:25:34 +02:00
parent bafb0fbbe4
commit ea816e8d6d
2 changed files with 67 additions and 9 deletions

View file

@ -563,6 +563,18 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
invalidate();
}
/**
* Highlights any y-value at the given x-value in the given DataSet.
* Provide -1 as the dataSetIndex to undo all highlighting.
* This method will call the listener.
* @param x The x-value to highlight
* @param dataSetIndex The dataset index to search in
* @param dataIndex The data index to search in (only used in CombinedChartView currently)
*/
public void highlightValue(float x, int dataSetIndex, int dataIndex) {
highlightValue(x, dataSetIndex, dataIndex, true);
}
/**
* Highlights any y-value at the given x-value in the given DataSet.
* Provide -1 as the dataSetIndex to undo all highlighting.
@ -571,7 +583,20 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
* @param dataSetIndex The dataset index to search in
*/
public void highlightValue(float x, int dataSetIndex) {
highlightValue(x, dataSetIndex, true);
highlightValue(x, dataSetIndex, -1, true);
}
/**
* Highlights the value at the given x-value and y-value in the given DataSet.
* Provide -1 as the dataSetIndex to undo all highlighting.
* This method will call the listener.
* @param x The x-value to highlight
* @param y The y-value to highlight. Supply `NaN` for "any"
* @param dataSetIndex The dataset index to search in
* @param dataIndex The data index to search in (only used in CombinedChartView currently)
*/
public void highlightValue(float x, float y, int dataSetIndex, int dataIndex) {
highlightValue(x, y, dataSetIndex, dataIndex, true);
}
/**
@ -583,7 +608,19 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
* @param dataSetIndex The dataset index to search in
*/
public void highlightValue(float x, float y, int dataSetIndex) {
highlightValue(x, y, dataSetIndex, true);
highlightValue(x, y, dataSetIndex, -1, true);
}
/**
* Highlights any y-value at the given x-value in the given DataSet.
* Provide -1 as the dataSetIndex to undo all highlighting.
* @param x The x-value to highlight
* @param dataSetIndex The dataset index to search in
* @param dataIndex The data index to search in (only used in CombinedChartView currently)
* @param callListener Should the listener be called for this change
*/
public void highlightValue(float x, int dataSetIndex, int dataIndex, boolean callListener) {
highlightValue(x, Float.NaN, dataSetIndex, dataIndex, callListener);
}
/**
@ -594,7 +631,25 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
* @param callListener Should the listener be called for this change
*/
public void highlightValue(float x, int dataSetIndex, boolean callListener) {
highlightValue(x, Float.NaN, dataSetIndex, callListener);
highlightValue(x, Float.NaN, dataSetIndex, -1, callListener);
}
/**
* Highlights any y-value at the given x-value in the given DataSet.
* Provide -1 as the dataSetIndex to undo all highlighting.
* @param x The x-value to highlight
* @param y The y-value to highlight. Supply `NaN` for "any"
* @param dataSetIndex The dataset index to search in
* @param dataIndex The data index to search in (only used in CombinedChartView currently)
* @param callListener Should the listener be called for this change
*/
public void highlightValue(float x, float y, int dataSetIndex, int dataIndex, boolean callListener) {
if (dataSetIndex < 0 || dataSetIndex >= mData.getDataSetCount()) {
highlightValue(null, callListener);
} else {
highlightValue(new Highlight(x, y, dataSetIndex, dataIndex), callListener);
}
}
/**
@ -606,12 +661,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
* @param callListener Should the listener be called for this change
*/
public void highlightValue(float x, float y, int dataSetIndex, boolean callListener) {
if (dataSetIndex < 0 || dataSetIndex >= mData.getDataSetCount()) {
highlightValue(null, callListener);
} else {
highlightValue(new Highlight(x, y, dataSetIndex), callListener);
}
highlightValue(x, y, dataSetIndex, -1, callListener);
}
/**

View file

@ -60,10 +60,18 @@ public class Highlight {
*/
private float mDrawY;
public Highlight(float x, float y, int dataSetIndex, int dataIndex) {
this.mX = x;
this.mY = y;
this.mDataSetIndex = dataSetIndex;
this.mDataIndex = dataIndex;
}
public Highlight(float x, float y, int dataSetIndex) {
this.mX = x;
this.mY = y;
this.mDataSetIndex = dataSetIndex;
this.mDataIndex = -1;
}
public Highlight(float x, int dataSetIndex, int stackIndex) {