Improvements to scatter value rendering

This commit is contained in:
Philipp Jahoda 2016-06-19 21:53:31 +02:00
parent adfc9a5c77
commit c18a2e270c
3 changed files with 21 additions and 10 deletions

View file

@ -59,6 +59,10 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
List<Highlight> closestValues = getHighlightsAtXPos(xVal, x, y);
if(closestValues.isEmpty()) {
return null;
}
float leftAxisMinDist = getMinimumDistance(closestValues, y, YAxis.AxisDependency.LEFT);
float rightAxisMinDist = getMinimumDistance(closestValues, y, YAxis.AxisDependency.RIGHT);
@ -128,7 +132,10 @@ public class ChartHighlighter<T extends BarLineScatterCandleBubbleDataProvider>
if (!dataSet.isHighlightEnabled())
continue;
vals.add(buildHighlight(dataSet, i, xVal, DataSet.Rounding.CLOSEST));
Highlight high = buildHighlight(dataSet, i, xVal, DataSet.Rounding.CLOSEST);
if(high != null)
vals.add(high);
//vals.add(buildHighlight(dataSet, i, xVal, DataSet.Rounding.DOWN));
}

View file

@ -319,13 +319,15 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
// apply the text-styling defined by the DataSet
applyValueTextStyle(dataSet);
XBounds bounds = getXBounds(mChart, dataSet);
float[] positions = mChart.getTransformer(dataSet.getAxisDependency())
.generateTransformedValuesScatter(dataSet,
mAnimator.getPhaseY());
mAnimator.getPhaseX(), mAnimator.getPhaseY(), bounds.min, bounds.max);
float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize());
for (int j = 0; j < positions.length * mAnimator.getPhaseX(); j += 2) {
for (int j = 0; j < positions.length; j += 2) {
if (!mViewPortHandler.isInBoundsRight(positions[j]))
break;
@ -335,10 +337,10 @@ public class ScatterChartRenderer extends LineScatterCandleRadarRenderer {
|| !mViewPortHandler.isInBoundsY(positions[j + 1])))
continue;
Entry entry = dataSet.getEntryForIndex(j / 2);
Entry entry = dataSet.getEntryForIndex(j / 2 + bounds.min);
drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, i, positions[j],
positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2));
positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + bounds.min));
}
}
}

View file

@ -102,14 +102,16 @@ public class Transformer {
* @param data
* @return
*/
public float[] generateTransformedValuesScatter(IScatterDataSet data,
float phaseY) {
public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX,
float phaseY, int from, int to) {
float[] valuePoints = new float[data.getEntryCount() * 2];
final int count = (int) ((to - from) * phaseX + 1) * 2;
for (int j = 0; j < valuePoints.length; j += 2) {
float[] valuePoints = new float[count];
Entry e = data.getEntryForIndex(j / 2);
for (int j = 0; j < count; j += 2) {
Entry e = data.getEntryForIndex(j / 2 + from);
if (e != null) {
valuePoints[j] = e.getX();