protected ScatterData generateScatterData(int dataSets, float range, int count) { ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>(); ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes(); for(int i = 0; i < dataSets; i++) { ArrayList<Entry> entries = new ArrayList<Entry>(); for(int j = 0; j < count; j++) { entries.add(new Entry(j, (float) (Math.random() * range) + range / 4)); } ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i)); ds.setScatterShapeSize(12f); ds.setScatterShape(shapes[i % shapes.length]); ds.setColors(ColorTemplate.COLORFUL_COLORS); ds.setScatterShapeSize(9f); sets.add(ds); } ScatterData d = new ScatterData(sets); d.setValueTypeface(tf); return d; }
protected ScatterData generateScatterData() { ScatterData d = new ScatterData(); ArrayList<Entry> entries = new ArrayList<Entry>(); for (float index = 0; index < itemcount; index += 0.5f) entries.add(new Entry(index + 0.25f, getRandom(10, 55))); ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet"); set.setColors(ColorTemplate.MATERIAL_COLORS); set.setScatterShapeSize(7.5f); set.setDrawValues(false); set.setValueTextSize(10f); d.addDataSet(set); return d; }
protected ScatterData generateScatterData(int dataSets, float range, int count) { ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>(); ScatterShape[] shapes = ScatterChart.getAllPossibleShapes(); for(int i = 0; i < dataSets; i++) { ArrayList<Entry> entries = new ArrayList<Entry>(); for(int j = 0; j < count; j++) { entries.add(new Entry((float) (Math.random() * range) + range / 4, j)); } ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i)); ds.setScatterShapeSize(12f); ds.setScatterShape(shapes[i % shapes.length]); ds.setColors(ColorTemplate.COLORFUL_COLORS); ds.setScatterShapeSize(9f); sets.add(ds); } ScatterData d = new ScatterData(ChartData.generateXVals(0, count), sets); d.setValueTypeface(tf); return d; }
protected ScatterData generateScatterData() { ScatterData d = new ScatterData(); ArrayList<Entry> entries = new ArrayList<Entry>(); for (int index = 0; index < itemcount; index++) entries.add(new Entry(getRandom(20, 15), index)); ScatterDataSet set = new ScatterDataSet(entries, "Scatter DataSet"); set.setColor(Color.GREEN); set.setScatterShapeSize(7.5f); set.setDrawValues(false); set.setValueTextSize(10f); d.addDataSet(set); return d; }
@Override void dataSetConfig(IDataSet<Entry> dataSet, ReadableMap config) { ScatterDataSet scatterDataSet = (ScatterDataSet) dataSet; ChartDataSetConfigUtils.commonConfig(scatterDataSet, config); ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(scatterDataSet, config); ChartDataSetConfigUtils.commonLineScatterCandleRadarConfig(scatterDataSet, config); // ScatterDataSet only config if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeSize")) { scatterDataSet.setScatterShapeSize((float) config.getDouble("scatterShapeSize")); } if (BridgeUtils.validate(config, ReadableType.String, "scatterShape")) { scatterDataSet.setScatterShape(ScatterShape.valueOf(config.getString("scatterShape").toUpperCase())); } if (BridgeUtils.validate(config, ReadableType.String, "scatterShapeHoleColor")) { scatterDataSet.setScatterShapeHoleColor(Color.parseColor(config.getString("scatterShapeHoleColor"))); } if (BridgeUtils.validate(config, ReadableType.Number, "scatterShapeHoleRadius")) { scatterDataSet.setScatterShapeHoleRadius((float) config.getDouble("scatterShapeHoleRadius")); } }
private void drawLatencyChart(List<Entry> phoneEntriesShifted, List<Entry> waltEntries) { final ScatterDataSet dataSetWalt = new ScatterDataSet(waltEntries, "WALT Events"); dataSetWalt.setColor(Color.BLUE); dataSetWalt.setScatterShape(ScatterChart.ScatterShape.CIRCLE); dataSetWalt.setScatterShapeSize(8f); final ScatterDataSet dataSetPhoneShifted = new ScatterDataSet(phoneEntriesShifted, "Phone Events Shifted"); dataSetPhoneShifted.setColor(Color.RED); dataSetPhoneShifted.setScatterShapeSize(10f); dataSetPhoneShifted.setScatterShape(ScatterChart.ScatterShape.X); final ScatterData scatterData = new ScatterData(dataSetWalt, dataSetPhoneShifted); final Description desc = new Description(); desc.setText(""); desc.setTextSize(12f); latencyChart.setDescription(desc); latencyChart.setData(scatterData); latencyChart.invalidate(); latencyChartLayout.setVisibility(View.VISIBLE); }
@Test public void testGetEntryForXValue() { List<Entry> entries = new ArrayList<Entry>(); entries.add(new Entry(10, 10)); entries.add(new Entry(15, 5)); entries.add(new Entry(21, 5)); ScatterDataSet set = new ScatterDataSet(entries, ""); Entry closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(15, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.DOWN); assertEquals(15, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXValue(15, Float.NaN, DataSet.Rounding.DOWN); assertEquals(15, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXValue(14, Float.NaN, DataSet.Rounding.DOWN); assertEquals(10, closest.getX(), 0.01f); assertEquals(10, closest.getY(), 0.01f); closest = set.getEntryForXValue(17, Float.NaN, DataSet.Rounding.UP); assertEquals(21, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXValue(21, Float.NaN, DataSet.Rounding.UP); assertEquals(21, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXValue(21, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(21, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); }
/** * Prepare ScatterData object * @param averageValue * @param seriesName * @return ScatterData */ private ScatterData generateScatterData(float averageValue, String seriesName){ ScatterData d = new ScatterData(); ArrayList<Entry> entries = new ArrayList<>(); entries.add(new Entry(1.5f, averageValue)); ScatterDataSet set = new ScatterDataSet(entries, seriesName); set.setColor(Color.parseColor("#FF4081")); set.setScatterShape(ScatterChart.ScatterShape.SQUARE); set.setScatterShapeSize(15f); set.setDrawValues(false); set.setValueTextSize(10f); d.addDataSet(set); return d; }
@Override public void initBuffers() { ScatterData scatterData = mChart.getScatterData(); mScatterBuffers = new ScatterBuffer[scatterData.getDataSetCount()]; for (int i = 0; i < mScatterBuffers.length; i++) { ScatterDataSet set = scatterData.getDataSetByIndex(i); mScatterBuffers[i] = new ScatterBuffer(set.getEntryCount() * 2); } }
@Override public void drawData(Canvas c) { ScatterData scatterData = mChart.getScatterData(); for (ScatterDataSet set : scatterData.getDataSets()) { if (set.isVisible()) drawDataSet(c, set); } }
private void drawLatencyGraph(double[] ft, double[] fy, double[] lt, double averageBestShift) { final ArrayList<Entry> touchEntries = new ArrayList<>(); final ArrayList<Entry> laserEntries = new ArrayList<>(); final double[] laserT = new double[lt.length]; for (int i = 0; i < ft.length; i++) { touchEntries.add(new Entry((float) ft[i], (float) fy[i])); } for (int i = 0; i < lt.length; i++) { laserT[i] = lt[i] + averageBestShift; } final double[] laserY = Utils.interp(laserT, ft, fy); for (int i = 0; i < laserY.length; i++) { laserEntries.add(new Entry((float) laserT[i], (float) laserY[i])); } final ScatterDataSet dataSetTouch = new ScatterDataSet(touchEntries, "Touch Events"); dataSetTouch.setScatterShape(ScatterChart.ScatterShape.CIRCLE); dataSetTouch.setScatterShapeSize(8f); final ScatterDataSet dataSetLaser = new ScatterDataSet(laserEntries, String.format(Locale.US, "Laser Events Latency=%.1f ms", averageBestShift)); dataSetLaser.setColor(Color.RED); dataSetLaser.setScatterShapeSize(10f); dataSetLaser.setScatterShape(ScatterChart.ScatterShape.X); final ScatterData scatterData = new ScatterData(dataSetTouch, dataSetLaser); final Description desc = new Description(); desc.setText("Y-Position [pixels] vs. Time [ms]"); desc.setTextSize(12f); latencyChart.setDescription(desc); latencyChart.setData(scatterData); latencyChartLayout.setVisibility(View.VISIBLE); }
@Test public void testGetEntryForXPos() { List<Entry> entries = new ArrayList<Entry>(); entries.add(new Entry(10, 10)); entries.add(new Entry(15, 5)); entries.add(new Entry(21, 5)); ScatterDataSet set = new ScatterDataSet(entries, ""); Entry closest = set.getEntryForXPos(17, DataSet.Rounding.CLOSEST); assertEquals(15, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXPos(17, DataSet.Rounding.DOWN); assertEquals(15, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXPos(15, DataSet.Rounding.DOWN); assertEquals(15, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXPos(14, DataSet.Rounding.DOWN); assertEquals(10, closest.getX(), 0.01f); assertEquals(10, closest.getY(), 0.01f); closest = set.getEntryForXPos(17, DataSet.Rounding.UP); assertEquals(21, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXPos(21, DataSet.Rounding.UP); assertEquals(21, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); closest = set.getEntryForXPos(21, DataSet.Rounding.CLOSEST); assertEquals(21, closest.getX(), 0.01f); assertEquals(5, closest.getY(), 0.01f); }
/** * Generate scatter data scatter data. * * @param dataSets the data sets * @param range the range * @param count the count * @return the scatter data */ protected ScatterData generateScatterData(int dataSets, float range, int count) { ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>(); ScatterChart.ScatterShape[] shapes = ScatterChart.ScatterShape.getAllDefaultShapes(); for(int i = 0; i < dataSets; i++) { ArrayList<Entry> entries = new ArrayList<Entry>(); for(int j = 0; j < count; j++) { entries.add(new Entry(j, (float) (Math.random() * range) + range / 4)); } ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i)); ds.setScatterShapeSize(12f); ds.setScatterShape(shapes[i % shapes.length]); ds.setColors(ColorTemplate.COLORFUL_COLORS); ds.setScatterShapeSize(9f); sets.add(ds); } ScatterData d = new ScatterData(sets); d.setValueTypeface(tf); return d; }
@Override protected void drawHighlights() { for (int i = 0; i < mIndicesToHightlight.length; i++) { ScatterDataSet set = mData.getDataSetByIndex(mIndicesToHightlight[i] .getDataSetIndex()); if (set == null) continue; mHighlightPaint.setColor(set.getHighLightColor()); int xIndex = mIndicesToHightlight[i].getXIndex(); // get the // x-position if (xIndex > mDeltaX * mPhaseX) continue; float y = set.getYValForXIndex(xIndex) * mPhaseY; // get the // y-position float[] pts = new float[] { xIndex, mYChartMax, xIndex, mYChartMin, 0, y, mDeltaX, y }; mTrans.pointValuesToPixel(pts); // draw the highlight lines mDrawCanvas.drawLines(pts, mHighlightPaint); } }
@Override protected void drawHighlights() { for (int i = 0; i < mIndicesToHightlight.length; i++) { ScatterDataSet set = mCurrentData.getDataSetByIndex(mIndicesToHightlight[i] .getDataSetIndex()); if (set == null) continue; mHighlightPaint.setColor(set.getHighLightColor()); int xIndex = mIndicesToHightlight[i].getXIndex(); // get the // x-position if (xIndex > mDeltaX * mPhaseX) continue; float y = set.getYValForXIndex(xIndex) * mPhaseY; // get the // y-position float[] pts = new float[] { xIndex, mYChartMax, xIndex, mYChartMin, 0, y, mDeltaX, y }; transformPointArray(pts); // draw the highlight lines mDrawCanvas.drawLines(pts, mHighlightPaint); } }
@Test public void testGetEntryForXValueWithDuplicates() { // sorted list of values (by x position) List<Entry> values = new ArrayList<Entry>(); values.add(new Entry(0, 10)); values.add(new Entry(1, 20)); values.add(new Entry(2, 30)); values.add(new Entry(3, 40)); values.add(new Entry(3, 50)); // duplicate values.add(new Entry(4, 60)); values.add(new Entry(4, 70)); // duplicate values.add(new Entry(5, 80)); values.add(new Entry(6, 90)); values.add(new Entry(7, 100)); values.add(new Entry(8, 110)); values.add(new Entry(8, 120)); // duplicate ScatterDataSet set = new ScatterDataSet(values, ""); Entry closest = set.getEntryForXValue(0, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(0, closest.getX(), 0.01f); assertEquals(10, closest.getY(), 0.01f); closest = set.getEntryForXValue(5, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(5.4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(4.6f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(5, closest.getX(), 0.01f); assertEquals(80, closest.getY(), 0.01f); closest = set.getEntryForXValue(7, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(7, closest.getX(), 0.01f); assertEquals(100, closest.getY(), 0.01f); closest = set.getEntryForXValue(4f, Float.NaN, DataSet.Rounding.CLOSEST); assertEquals(4, closest.getX(), 0.01f); assertEquals(60, closest.getY(), 0.01f); List<Entry> entries = set.getEntriesForXValue(4f); assertEquals(2, entries.size()); assertEquals(60, entries.get(0).getY(), 0.01f); assertEquals(70, entries.get(1).getY(), 0.01f); entries = set.getEntriesForXValue(3.5f); assertEquals(0, entries.size()); entries = set.getEntriesForXValue(2f); assertEquals(1, entries.size()); assertEquals(30, entries.get(0).getY(), 0.01f); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.actionToggleValues: { List<IScatterDataSet> sets = mChart.getData() .getDataSets(); for (IScatterDataSet iSet : sets) { ScatterDataSet set = (ScatterDataSet) iSet; set.setDrawValues(!set.isDrawValuesEnabled()); } mChart.invalidate(); break; } case R.id.actionToggleHighlight: { if(mChart.getData() != null) { mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled()); mChart.invalidate(); } break; } case R.id.actionTogglePinch: { if (mChart.isPinchZoomEnabled()) mChart.setPinchZoom(false); else mChart.setPinchZoom(true); mChart.invalidate(); break; } case R.id.actionToggleAutoScaleMinMax: { mChart.setAutoScaleMinMaxEnabled(!mChart.isAutoScaleMinMaxEnabled()); mChart.notifyDataSetChanged(); break; } case R.id.actionSave: { // mChart.saveToGallery("title"+System.currentTimeMillis()); mChart.saveToPath("title" + System.currentTimeMillis(), ""); break; } case R.id.animateX: { mChart.animateX(3000); break; } case R.id.animateY: { mChart.animateY(3000); break; } case R.id.animateXY: { mChart.animateXY(3000, 3000); break; } } return true; }
@Override public void drawValues(Canvas c) { // if values are drawn if (mChart.getScatterData().getYValCount() < mChart.getMaxVisibleCount() * mViewPortHandler.getScaleX()) { List<ScatterDataSet> dataSets = mChart.getScatterData().getDataSets(); for (int i = 0; i < mChart.getScatterData().getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); if (!dataSet.isDrawValuesEnabled() || dataSet.getEntryCount() == 0) continue; // apply the text-styling defined by the DataSet applyValueTextStyle(dataSet); List<Entry> entries = dataSet.getYVals(); float[] positions = mChart.getTransformer(dataSet.getAxisDependency()) .generateTransformedValuesScatter(entries, mAnimator.getPhaseY()); float shapeSize = dataSet.getScatterShapeSize(); for (int j = 0; j < positions.length * mAnimator.getPhaseX(); j += 2) { if (!mViewPortHandler.isInBoundsRight(positions[j])) break; // make sure the lines don't do shitty things outside bounds if ((!mViewPortHandler.isInBoundsLeft(positions[j]) || !mViewPortHandler.isInBoundsY(positions[j + 1]))) continue; Entry entry = entries.get(j / 2); drawValue(c, dataSet.getValueFormatter(), entry.getVal(), entry, i, positions[j], positions[j + 1] - shapeSize); } } } }
@Override IDataSet createDataSet(ArrayList<Entry> entries, String label) { return new ScatterDataSet(entries, label); }
@Override protected void drawData() { ArrayList<ScatterDataSet> dataSets = mData.getDataSets(); for (int i = 0; i < mData.getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); ArrayList<Entry> entries = dataSet.getYVals(); float shapeHalf = dataSet.getScatterShapeSize() / 2f; float[] valuePoints = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY); ScatterShape shape = dataSet.getScatterShape(); for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) { if (isOffContentRight(valuePoints[j])) break; // make sure the lines don't do shitty things outside bounds if (j != 0 && isOffContentLeft(valuePoints[j - 1]) && isOffContentTop(valuePoints[j + 1]) && isOffContentBottom(valuePoints[j + 1])) continue; // Set the color for the currently drawn value. If the index is // out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j)); if (shape == ScatterShape.SQUARE) { mDrawCanvas.drawRect(valuePoints[j] - shapeHalf, valuePoints[j + 1] - shapeHalf, valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf, mRenderPaint); } else if (shape == ScatterShape.CIRCLE) { mDrawCanvas.drawCircle(valuePoints[j], valuePoints[j + 1], shapeHalf, mRenderPaint); } else if (shape == ScatterShape.CROSS) { mDrawCanvas.drawLine(valuePoints[j] - shapeHalf, valuePoints[j + 1], valuePoints[j] + shapeHalf, valuePoints[j + 1], mRenderPaint); mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1] - shapeHalf, valuePoints[j], valuePoints[j + 1] + shapeHalf, mRenderPaint); } else if (shape == ScatterShape.TRIANGLE) { // create a triangle path Path tri = new Path(); tri.moveTo(valuePoints[j], valuePoints[j + 1] - shapeHalf); tri.lineTo(valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf); tri.lineTo(valuePoints[j] - shapeHalf, valuePoints[j + 1] + shapeHalf); tri.close(); mDrawCanvas.drawPath(tri, mRenderPaint); } else if (shape == ScatterShape.CUSTOM) { Path customShape = dataSet.getCustomScatterShape(); if (customShape == null) return; // transform the provided custom path mTrans.pathValueToPixel(customShape); mDrawCanvas.drawPath(customShape, mRenderPaint); } } } }
@Override protected void drawValues() { // if values are drawn if (mDrawYValues && mData.getYValCount() < mMaxVisibleCount * mTrans.getScaleX()) { ArrayList<ScatterDataSet> dataSets = mData .getDataSets(); for (int i = 0; i < mData.getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); ArrayList<Entry> entries = dataSet.getYVals(); float[] positions = mTrans.generateTransformedValuesLineScatter(entries, mPhaseY); float shapeSize = dataSet.getScatterShapeSize(); for (int j = 0; j < positions.length * mPhaseX; j += 2) { if (isOffContentRight(positions[j])) break; if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1])) continue; float val = entries.get(j / 2).getVal(); if (mDrawUnitInChart) { mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val) + mUnit, positions[j], positions[j + 1] - shapeSize, mValuePaint); } else { mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - shapeSize, mValuePaint); } } } } }
@Override protected void drawData() { ArrayList<ScatterDataSet> dataSets = mCurrentData.getDataSets(); for (int i = 0; i < mCurrentData.getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); ArrayList<Entry> entries = dataSet.getYVals(); float shapeHalf = dataSet.getScatterShapeSize() / 2f; float[] valuePoints = generateTransformedValuesLineScatter(entries); ScatterShape shape = dataSet.getScatterShape(); for (int j = 0; j < valuePoints.length * mPhaseX; j += 2) { if (isOffContentRight(valuePoints[j])) break; // make sure the lines don't do shitty things outside bounds if (j != 0 && isOffContentLeft(valuePoints[j - 1]) && isOffContentTop(valuePoints[j + 1]) && isOffContentBottom(valuePoints[j + 1])) continue; // Set the color for the currently drawn value. If the index is // out of bounds, reuse colors. mRenderPaint.setColor(dataSet.getColor(j)); if (shape == ScatterShape.SQUARE) { mDrawCanvas.drawRect(valuePoints[j] - shapeHalf, valuePoints[j + 1] - shapeHalf, valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf, mRenderPaint); } else if (shape == ScatterShape.CIRCLE) { mDrawCanvas.drawCircle(valuePoints[j], valuePoints[j + 1], shapeHalf, mRenderPaint); } else if (shape == ScatterShape.CROSS) { mDrawCanvas.drawLine(valuePoints[j] - shapeHalf, valuePoints[j + 1], valuePoints[j] + shapeHalf, valuePoints[j + 1], mRenderPaint); mDrawCanvas.drawLine(valuePoints[j], valuePoints[j + 1] - shapeHalf, valuePoints[j], valuePoints[j + 1] + shapeHalf, mRenderPaint); } else if (shape == ScatterShape.TRIANGLE) { // create a triangle path Path tri = new Path(); tri.moveTo(valuePoints[j], valuePoints[j + 1] - shapeHalf); tri.lineTo(valuePoints[j] + shapeHalf, valuePoints[j + 1] + shapeHalf); tri.lineTo(valuePoints[j] - shapeHalf, valuePoints[j + 1] + shapeHalf); tri.close(); mDrawCanvas.drawPath(tri, mRenderPaint); } else if (shape == ScatterShape.CUSTOM) { Path customShape = dataSet.getCustomScatterShape(); if (customShape == null) return; // transform the provided custom path transformPath(customShape); mDrawCanvas.drawPath(customShape, mRenderPaint); } } } }
@Override protected void drawValues() { // if values are drawn if (mDrawYValues && mCurrentData.getYValCount() < mMaxVisibleCount * mScaleX) { ArrayList<ScatterDataSet> dataSets = mCurrentData .getDataSets(); for (int i = 0; i < mCurrentData.getDataSetCount(); i++) { ScatterDataSet dataSet = dataSets.get(i); ArrayList<Entry> entries = dataSet.getYVals(); float[] positions = generateTransformedValuesLineScatter(entries); float shapeSize = dataSet.getScatterShapeSize(); for (int j = 0; j < positions.length * mPhaseX; j += 2) { if (isOffContentRight(positions[j])) break; if (isOffContentLeft(positions[j]) || isOffContentTop(positions[j + 1]) || isOffContentBottom(positions[j + 1])) continue; float val = entries.get(j / 2).getVal(); if (mDrawUnitInChart) { mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val) + mUnit, positions[j], positions[j + 1] - shapeSize, mValuePaint); } else { mDrawCanvas.drawText(mValueFormatter.getFormattedValue(val), positions[j], positions[j + 1] - shapeSize, mValuePaint); } } } } }
@Test public void testCalcMinMax() { List<Entry> entries = new ArrayList<Entry>(); entries.add(new Entry(10, 10)); entries.add(new Entry(15, 2)); entries.add(new Entry(21, 5)); ScatterDataSet set = new ScatterDataSet(entries, ""); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(21f, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(3, set.getEntryCount()); set.addEntry(new Entry(25, 1)); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(25f, set.getXMax(), 0.01f); assertEquals(1f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); assertEquals(4, set.getEntryCount()); set.removeEntry(3); assertEquals(10f, set.getXMin(), 0.01f); assertEquals(21, set.getXMax(), 0.01f); assertEquals(2f, set.getYMin(), 0.01f); assertEquals(10f, set.getYMax(), 0.01f); }
@Override public void drawHighlighted(Canvas c, Highlight[] indices) { for (int i = 0; i < indices.length; i++) { ScatterDataSet set = mChart.getScatterData().getDataSetByIndex(indices[i] .getDataSetIndex()); if (set == null || !set.isHighlightEnabled()) continue; int xIndex = indices[i].getXIndex(); // get the // x-position if (xIndex > mChart.getXChartMax() * mAnimator.getPhaseX()) continue; final float yVal = set.getYValForXIndex(xIndex); if (yVal == Float.NaN) continue; float y = yVal * mAnimator.getPhaseY(); float[] pts = new float[] { xIndex, y }; mChart.getTransformer(set.getAxisDependency()).pointValuesToPixel(pts); // draw the lines drawHighlightLines(c, pts, set); } }