FastLineAndPointRenderer extends XYSeriesRenderer<XYSeries, FastLineAndPointRenderer.Formatter> { @Override protected void onRender(Canvas canvas, RectF plotArea, XYSeries series, Formatter formatter, RenderStack stack) { segmentOffsets.clear(); segmentLengths.clear(); final int numPoints = series.size() * 2; if(points == null || points.length != numPoints) { points = new float[series.size()*2]; } int segmentLen = 0; boolean isLastPointNull = true; PointF resultPoint = new PointF(); for (int i = 0, j = 0; i < series.size(); i++, j+=2) { Number y = series.getY(i); Number x = series.getX(i); if (y != null && x != null) { if(isLastPointNull) { segmentOffsets.add(j); segmentLen = 0; isLastPointNull = false; } getPlot().getBounds().transformScreen(resultPoint, x, y, plotArea); points[j] = resultPoint.x; points[j + 1] = resultPoint.y; segmentLen+=2; if(i == series.size()-1) { segmentLengths.add(segmentLen); } } else if(!isLastPointNull) { segmentLengths.add(segmentLen); isLastPointNull = true; } } if(formatter.linePaint != null || formatter.vertexPaint != null) { for (int i = 0; i < segmentOffsets.size(); i++) { final int len = segmentLengths.get(i); final int offset = segmentOffsets.get(i); drawSegment(canvas, points, offset, len, formatter); } } } FastLineAndPointRenderer(XYPlot plot);   }
@Test public void testOnRender() throws Exception { RectF gridRect = new RectF(5, 5, 105, 105); XYPlot plot = new XYPlot(getContext(), "Test"); FastLineAndPointRenderer.Formatter formatter = new FastLineAndPointRenderer.Formatter(Color.RED, Color.RED, null); XYSeries series = new SimpleXYSeries( SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "some data", 1, 2, null, 3, 4, 5, 6, 7, null, null, 8); FastLineAndPointRenderer renderer = Mockito.spy(new FastLineAndPointRenderer(plot)); Canvas canvas = mock(Canvas.class); renderer.onRender(canvas, gridRect, series, formatter, null); verify(renderer, times(1)).drawSegment( eq(canvas), any(float[].class), eq(0), eq(4), eq(formatter)); verify(canvas, times(1)).drawPoints( any(float[].class), eq(0), eq(4), eq(formatter.getVertexPaint())); verify(renderer, times(1)).drawSegment( eq(canvas), any(float[].class), eq(6), eq(10), eq(formatter)); verify(canvas, times(1)).drawPoints( any(float[].class), eq(6), eq(10), eq(formatter.getVertexPaint())); verify(renderer, times(1)).drawSegment( eq(canvas), any(float[].class), eq(20), eq(2), eq(formatter)); verify(canvas, times(1)).drawPoints( any(float[].class), eq(20), eq(2), eq(formatter.getVertexPaint())); }