if (!shouldDrawValues(dataSet) || dataSet.getEntryCount() < 1) continue; float[] positions = mChart.getTransformer(dataSet.getAxisDependency()) .generateTransformedValuesScatter(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max); float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize()); ValueFormatter formatter = dataSet.getValueFormatter(); MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset()); iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x); iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y); continue; Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); if (dataSet.isDrawValuesEnabled()) { drawValue(c, formatter.getPointLabel(entry), positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min)); if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) { if (dataSet.getEntryCount() < 1) return; Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); IShapeRenderer renderer = dataSet.getShapeRenderer(); if (renderer == null) { Log.i("MISSING", "There's no IShapeRenderer specified for ScatterDataSet"); Math.ceil((float)dataSet.getEntryCount() * mAnimator.getPhaseX()), (float)dataSet.getEntryCount())); Entry e = dataSet.getEntryForIndex(i); continue; mRenderPaint.setColor(dataSet.getColor(i / 2)); renderer.renderShape( c, dataSet, mViewPortHandler,
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { ScatterData scatterData = mChart.getScatterData(); for (Highlight high : indices) { IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; final Entry e = set.getEntryForXValue(high.getX(), high.getY()); if (!isInBoundsX(e, set)) continue; MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator .getPhaseY()); high.setDraw((float) pix.x, (float) pix.y); // draw the lines drawHighlightLines(c, (float) pix.x, (float) pix.y, set); } } }
float posX, float posY, Paint renderPaint) { final float shapeSize = dataSet.getScatterShapeSize(); final float shapeHalf = shapeSize / 2f; final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); final float shapeHoleSize = shapeHoleSizeHalf * 2.f; final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f; final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
/** * Returns the maximum shape-size across all DataSets. * * @return */ public float getGreatestShapeSize() { float max = 0f; for (IScatterDataSet set : mDataSets) { float size = set.getScatterShapeSize(); if (size > max) max = size; } return max; } }
assertEquals(50f, data.getYMax(), 0.01f); assertEquals(3, data.getMaxEntryCountSet().getEntryCount()); assertEquals(4, data.getMaxEntryCountSet().getEntryCount());
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the SCATTERCHART. * * @param data * @return */ public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesScatter.length != count) { valuePointsForGenerateTransformedValuesScatter = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesScatter; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getY() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
float posX, float posY, Paint renderPaint) { final float shapeSize = dataSet.getScatterShapeSize(); final float shapeHalf = shapeSize / 2f; final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); final float shapeHoleSize = shapeHoleSizeHalf * 2.f; final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f; final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
@Override public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, float posX, float posY, Paint renderPaint) { final float shapeHalf = dataSet.getScatterShapeSize() / 2f; c.drawLine( posX - shapeHalf, posY - shapeHalf, posX + shapeHalf, posY + shapeHalf, renderPaint); } }
assertEquals(50f, data.getYMax(), 0.01f); assertEquals(3, data.getMaxEntryCountSet().getEntryCount()); assertEquals(4, data.getMaxEntryCountSet().getEntryCount());
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the SCATTERCHART. * * @param data * @return */ public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesScatter.length != count) { valuePointsForGenerateTransformedValuesScatter = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesScatter; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getY() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
float[] positions = mChart.getTransformer(dataSet.getAxisDependency()) .generateTransformedValuesScatter(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max); float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize()); MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset()); iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x); iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y); continue; Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); if (dataSet.isDrawValuesEnabled()) { drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min)); if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
float posX, float posY, Paint renderPaint) { final float shapeSize = dataSet.getScatterShapeSize(); final float shapeHalf = shapeSize / 2f; final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); final float shapeHoleSize = shapeHoleSizeHalf * 2.f; final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; final int shapeHoleColor = dataSet.getScatterShapeHoleColor();
protected void drawDataSet(Canvas c, IScatterDataSet dataSet) { ViewPortHandler viewPortHandler = mViewPortHandler; Transformer trans = mChart.getTransformer(dataSet.getAxisDependency()); float phaseY = mAnimator.getPhaseY(); IShapeRenderer renderer = dataSet.getShapeRenderer(); if (renderer == null) { Log.i("MISSING", "There's no IShapeRenderer specified for ScatterDataSet"); return; } int max = (int)(Math.min( Math.ceil((float)dataSet.getEntryCount() * mAnimator.getPhaseX()), (float)dataSet.getEntryCount())); for (int i = 0; i < max; i++) { Entry e = dataSet.getEntryForIndex(i); mPixelBuffer[0] = e.getX(); mPixelBuffer[1] = e.getY() * phaseY; trans.pointValuesToPixel(mPixelBuffer); if (!viewPortHandler.isInBoundsRight(mPixelBuffer[0])) break; if (!viewPortHandler.isInBoundsLeft(mPixelBuffer[0]) || !viewPortHandler.isInBoundsY(mPixelBuffer[1])) continue; mRenderPaint.setColor(dataSet.getColor(i / 2)); renderer.renderShape( c, dataSet, mViewPortHandler, mPixelBuffer[0], mPixelBuffer[1], mRenderPaint); } }
@Override public void renderShape(Canvas c, IScatterDataSet dataSet, ViewPortHandler viewPortHandler, float posX, float posY, Paint renderPaint) { final float shapeHalf = dataSet.getScatterShapeSize() / 2f; renderPaint.setStyle(Paint.Style.STROKE); renderPaint.setStrokeWidth(Utils.convertDpToPixel(1f)); c.drawLine( posX - shapeHalf, posY - shapeHalf, posX + shapeHalf, posY + shapeHalf, renderPaint); c.drawLine( posX + shapeHalf, posY - shapeHalf, posX - shapeHalf, posY + shapeHalf, renderPaint); }
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { ScatterData scatterData = mChart.getScatterData(); for (Highlight high : indices) { IScatterDataSet set = scatterData.getDataSetByIndex(high.getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; final Entry e = set.getEntryForXValue(high.getX(), high.getY()); if (!isInBoundsX(e, set)) continue; MPPointD pix = mChart.getTransformer(set.getAxisDependency()).getPixelForValues(e.getX(), e.getY() * mAnimator .getPhaseY()); high.setDraw((float) pix.x, (float) pix.y); // draw the lines drawHighlightLines(c, (float) pix.x, (float) pix.y, set); } } }
assertEquals(50f, data.getYMax(), 0.01f); assertEquals(3, data.getMaxEntryCountSet().getEntryCount()); assertEquals(4, data.getMaxEntryCountSet().getEntryCount());
/** * Transforms an List of Entry into a float array containing the x and * y values transformed with all matrices for the SCATTERCHART. * * @param data * @return */ public float[] generateTransformedValuesScatter(IScatterDataSet data, float phaseX, float phaseY, int from, int to) { final int count = (int) ((to - from) * phaseX + 1) * 2; if (valuePointsForGenerateTransformedValuesScatter.length != count) { valuePointsForGenerateTransformedValuesScatter = new float[count]; } float[] valuePoints = valuePointsForGenerateTransformedValuesScatter; for (int j = 0; j < count; j += 2) { Entry e = data.getEntryForIndex(j / 2 + from); if (e != null) { valuePoints[j] = e.getX(); valuePoints[j + 1] = e.getY() * phaseY; } else { valuePoints[j] = 0; valuePoints[j + 1] = 0; } } getValueToPixelMatrix().mapPoints(valuePoints); return valuePoints; }
float[] positions = mChart.getTransformer(dataSet.getAxisDependency()) .generateTransformedValuesScatter(dataSet, mAnimator.getPhaseX(), mAnimator.getPhaseY(), mXBounds.min, mXBounds.max); float shapeSize = Utils.convertDpToPixel(dataSet.getScatterShapeSize()); MPPointF iconsOffset = MPPointF.getInstance(dataSet.getIconsOffset()); iconsOffset.x = Utils.convertDpToPixel(iconsOffset.x); iconsOffset.y = Utils.convertDpToPixel(iconsOffset.y); continue; Entry entry = dataSet.getEntryForIndex(j / 2 + mXBounds.min); if (dataSet.isDrawValuesEnabled()) { drawValue(c, dataSet.getValueFormatter(), entry.getY(), entry, positions[j], positions[j + 1] - shapeSize, dataSet.getValueTextColor(j / 2 + mXBounds.min)); if (entry.getIcon() != null && dataSet.isDrawIconsEnabled()) {
float posX, float posY, Paint renderPaint) { final float shapeSize = dataSet.getScatterShapeSize(); final float shapeHalf = shapeSize / 2f; final float shapeHoleSizeHalf = Utils.convertDpToPixel(dataSet.getScatterShapeHoleRadius()); final float shapeHoleSize = shapeHoleSizeHalf * 2.f; final float shapeStrokeSize = (shapeSize - shapeHoleSize) / 2.f; final float shapeStrokeSizeHalf = shapeStrokeSize / 2.f; final int shapeHoleColor = dataSet.getScatterShapeHoleColor();