Work on highlight

This commit is contained in:
Philipp Jahoda 2016-06-11 00:07:53 +02:00
parent c28b41b05e
commit f283de1698
6 changed files with 36 additions and 27 deletions

View file

@ -633,7 +633,7 @@ public abstract class Chart<T extends ChartData<? extends IDataSet<? extends Ent
} else {
if (this instanceof BarLineChartBase
&& ((BarLineChartBase) this).isHighlightFullBarEnabled())
high = new Highlight(high.getX(), Float.NaN, -1, -1, -1);
high = new Highlight(high.getX(), Float.NaN, -1, -1);
// set the indices to highlight
mIndicesToHighlight = new Highlight[]{

View file

@ -2,6 +2,7 @@ package com.github.mikephil.charting.highlight;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.utils.PointD;
@ -40,8 +41,7 @@ public class BarHighlighter extends ChartHighlighter<BarDataProvider> {
selectionDetail.xValue,
selectionDetail.yValue,
selectionDetail.dataIndex,
selectionDetail.dataSetIndex,
-1);
selectionDetail.dataSetIndex);
}
/**
@ -152,4 +152,9 @@ public class BarHighlighter extends ChartHighlighter<BarDataProvider> {
protected float getDistance(float x1, float y1, float x2, float y2) {
return Math.abs(x1 - x2);
}
@Override
protected BarLineScatterCandleBubbleData getData() {
return mChart.getBarData();
}
}

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarLineScatterCandleBubbleData;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
@ -69,8 +71,7 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
YAxis.AxisDependency axis = leftAxisMinDist < rightAxisMinDist ? YAxis.AxisDependency.LEFT : YAxis.AxisDependency.RIGHT;
SelectionDetail detail = getClosestSelectionDetailByPixel(closestValues, x, y, axis, mChart
.getMaxHighlightDistance());
SelectionDetail detail = getClosestSelectionDetailByPixel(closestValues, x, y, axis, mChart.getMaxHighlightDistance());
return detail;
}
@ -119,11 +120,14 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
List<SelectionDetail> vals = new ArrayList<SelectionDetail>();
if (mChart.getData() == null) return vals;
BarLineScatterCandleBubbleData data = getData();
for (int i = 0, dataSetCount = mChart.getData().getDataSetCount(); i < dataSetCount; i++) {
if (data == null)
return vals;
IDataSet dataSet = mChart.getData().getDataSetByIndex(i);
for (int i = 0, dataSetCount = data.getDataSetCount(); i < dataSetCount; i++) {
IDataSet dataSet = data.getDataSetByIndex(i);
// dont include datasets that cannot be highlighted
if (!dataSet.isHighlightEnabled())
@ -204,4 +208,8 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
protected float getDistance(float x1, float y1, float x2, float y2) {
return (float) Math.hypot(x1 - x2, y1 - y2);
}
protected BarLineScatterCandleBubbleData getData() {
return mChart.getData();
}
}

View file

@ -29,7 +29,11 @@ public class CombinedHighlighter extends ChartHighlighter<BarLineScatterCandleBu
Highlight h1 = super.getHighlight(x, y);
Highlight h2 = barHighlighter.getHighlight(x, y);
return h1;
return getClosest(x, y, h1, h2);
}
protected Highlight getClosest(float x, float y, Highlight... highs) {
return null;
}
@Override

View file

@ -14,6 +14,12 @@ public class Highlight {
/** the y-value of the highlighted value */
private float mY = Float.NaN;
/** the x-pixel of the highlight */
private float mXPx;
/** the y-pixel of the highlight */
private float mYPx;
/** the index of the data object - in case it refers to more than one */
private int mDataIndex;
@ -40,20 +46,6 @@ public class Highlight {
this.mDataIndex = dataIndex;
this.mDataSetIndex = dataSetIndex;
}
/**
* Constructor, only used for stacked-barchart.
*
* @param x the x-value of the highlighted value on the x-axis
* @param y the y-value of the highlighted value
* @param dataIndex the index of the Data the highlighted value belongs to
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
* @param stackIndex references which value of a stacked-bar entry has been
* selected
*/
public Highlight(float x, float y, int dataIndex, int dataSetIndex, int stackIndex) {
this(x, y, dataIndex, dataSetIndex);
mStackIndex = stackIndex;
}
/**
* Constructor, only used for stacked-barchart.
@ -67,7 +59,8 @@ public class Highlight {
* @param range the range the selected stack-value is in
*/
public Highlight(float x, float y, int dataIndex, int dataSetIndex, int stackIndex, Range range) {
this(x, y, dataIndex, dataSetIndex, stackIndex);
this(x, y, dataIndex, dataSetIndex);
this.mStackIndex = stackIndex;
this.mRange = range;
}
@ -78,7 +71,7 @@ public class Highlight {
* @param dataSetIndex the index of the DataSet the highlighted value belongs to
*/
public Highlight(float x, int dataSetIndex) {
this(x, Float.NaN, 0, dataSetIndex, -1);
this(x, Float.NaN, 0, dataSetIndex);
}
/**

View file

@ -46,8 +46,7 @@ public class HorizontalBarHighlighter extends BarHighlighter {
selectionDetail.xValue,
selectionDetail.yValue,
selectionDetail.dataIndex,
selectionDetail.dataSetIndex,
-1);
selectionDetail.dataSetIndex);
}
@Override