@Test public void testDrawSeries() throws Exception { plotArea = new RectF(0, 0, 99, 99); FastLineAndPointRenderer.Formatter formatter = new FastLineAndPointRenderer.Formatter(Color.RED, Color.RED, null); XYSeries series = new SimpleXYSeries( SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "some data", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); LineAndPointRenderer renderer = Mockito.spy(new LineAndPointRenderer(xyPlot)); xyPlot.addSeries(series, formatter); xyPlot.calculateMinMaxVals(); renderer.drawSeries(canvas, plotArea, series, formatter); PointF[] expectedPoints = new PointF[] { new PointF(0, 99), new PointF(11, 88), new PointF(22, 77), new PointF(33, 66), new PointF(44, 55), new PointF(55, 44), new PointF(66, 33), new PointF(77, 22), new PointF(88, 11), new PointF(99, 0) }; ArgumentCaptor<List> capturedPoints= ArgumentCaptor.forClass(List.class); verify(renderer, times(1)).renderPoints( eq(canvas), eq(plotArea), eq(series), eq(0), eq(expectedPoints.length), capturedPoints.capture(), eq(formatter)); List<PointF> pList = capturedPoints.getValue(); assertEquals(expectedPoints[0].x, pList.get(0).x); assertEquals(expectedPoints[0].y, pList.get(0).y); assertEquals(expectedPoints[1].x, pList.get(1).x); assertEquals(expectedPoints[1].y, pList.get(1).y); assertEquals(expectedPoints[2].x, pList.get(2).x); assertEquals(expectedPoints[2].y, pList.get(2).y); assertEquals(expectedPoints[3].x, pList.get(3).x); assertEquals(expectedPoints[3].y, pList.get(3).y); assertEquals(expectedPoints[4].x, pList.get(4).x); assertEquals(expectedPoints[4].y, pList.get(4).y); assertEquals(expectedPoints[5].x, pList.get(5).x); assertEquals(expectedPoints[5].y, pList.get(5).y); assertEquals(expectedPoints[6].x, pList.get(6).x); assertEquals(expectedPoints[6].y, pList.get(6).y); assertEquals(expectedPoints[7].x, pList.get(7).x); assertEquals(expectedPoints[7].y, pList.get(7).y); assertEquals(expectedPoints[8].x, pList.get(8).x); assertEquals(expectedPoints[8].y, pList.get(8).y); assertEquals(expectedPoints[9].x, pList.get(9).x); assertEquals(expectedPoints[9].y, pList.get(9).y); }
protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) { PointF thisPoint; PointF lastPoint = null; PointF firstPoint = null; path.reset(); final List<PointF> points = getPointsCache(series); int iStart = 0; int iEnd = series.size(); if(SeriesUtils.getXYOrder(series) == OrderedXYSeries.XOrder.ASCENDING) { final Region iBounds = SeriesUtils.iBounds(series, getPlot().getBounds()); iStart = iBounds.getMin().intValue(); if(iStart > 0) { iStart--; } iEnd = iBounds.getMax().intValue() + 1; if(iEnd < series.size() - 1) { iEnd++; } } for (int i = iStart; i < iEnd; i++) { final Number y = series.getY(i); final Number x = series.getX(i); PointF iPoint = points.get(i); if (y != null && x != null) { if(iPoint == null) { iPoint = new PointF(); points.set(i, iPoint); } thisPoint = iPoint; getPlot().getBounds().transformScreen(thisPoint, x, y, plotArea); } else { thisPoint = null; iPoint = null; points.set(i, iPoint); } if(formatter.hasLinePaint() && formatter.getInterpolationParams() == null) { if (thisPoint != null) { if (firstPoint == null) { path.reset(); firstPoint = thisPoint; path.moveTo(firstPoint.x, firstPoint.y); } if (lastPoint != null) { appendToPath(path, thisPoint, lastPoint); } lastPoint = thisPoint; } else { if (lastPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } firstPoint = null; lastPoint = null; } } } if(formatter.hasLinePaint()) { if(formatter.getInterpolationParams() != null) { List<XYCoords> interpolatedPoints = getInterpolator( formatter.getInterpolationParams()).interpolate(series, formatter.getInterpolationParams()); firstPoint = convertPoint(interpolatedPoints.get(ZERO), plotArea); lastPoint = convertPoint(interpolatedPoints.get(interpolatedPoints.size()-ONE), plotArea); path.reset(); path.moveTo(firstPoint.x, firstPoint.y); for(int i = 1; i < interpolatedPoints.size(); i++) { thisPoint = convertPoint(interpolatedPoints.get(i), plotArea); path.lineTo(thisPoint.x, thisPoint.y); } } if(firstPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } } renderPoints(canvas, plotArea, series, iStart, iEnd, points, formatter); }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) { PointF thisPoint; PointF lastPoint = null; PointF firstPoint = null; path.reset(); final List<PointF> points = getPointsCache(series); int iStart = 0; int iEnd = series.size(); if(SeriesUtils.getXYOrder(series) == OrderedXYSeries.XOrder.ASCENDING) { final Region iBounds = SeriesUtils.iBounds(series, getPlot().getBounds()); iStart = iBounds.getMin().intValue(); if(iStart > 0) { iStart--; } iEnd = iBounds.getMax().intValue() + 1; if(iEnd < series.size() - 1) { iEnd++; } } for (int i = iStart; i < iEnd; i++) { final Number y = series.getY(i); final Number x = series.getX(i); PointF iPoint = points.get(i); if (y != null && x != null) { if(iPoint == null) { iPoint = new PointF(); points.set(i, iPoint); } thisPoint = iPoint; getPlot().getBounds().transformScreen(thisPoint, x, y, plotArea); } else { thisPoint = null; iPoint = null; points.set(i, iPoint); } if(formatter.hasLinePaint() && formatter.getInterpolationParams() == null) { if (thisPoint != null) { if (firstPoint == null) { path.reset(); firstPoint = thisPoint; path.moveTo(firstPoint.x, firstPoint.y); } if (lastPoint != null) { appendToPath(path, thisPoint, lastPoint); } lastPoint = thisPoint; } else { if (lastPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } firstPoint = null; lastPoint = null; } } } if(formatter.hasLinePaint()) { if(formatter.getInterpolationParams() != null) { List<XYCoords> interpolatedPoints = getInterpolator( formatter.getInterpolationParams()).interpolate(series, formatter.getInterpolationParams()); firstPoint = convertPoint(interpolatedPoints.get(ZERO), plotArea); lastPoint = convertPoint(interpolatedPoints.get(interpolatedPoints.size()-ONE), plotArea); path.reset(); path.moveTo(firstPoint.x, firstPoint.y); for(int i = 1; i < interpolatedPoints.size(); i++) { thisPoint = convertPoint(interpolatedPoints.get(i), plotArea); path.lineTo(thisPoint.x, thisPoint.y); } } if(firstPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } } renderPoints(canvas, plotArea, series, iStart, iEnd, points, formatter); } }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) { PointF thisPoint; PointF lastPoint = null; PointF firstPoint = null; path.reset(); final List<PointF> points = getPointsCache(series); int iStart = 0; int iEnd = series.size(); if(SeriesUtils.getXYOrder(series) == OrderedXYSeries.XOrder.ASCENDING) { final Region iBounds = SeriesUtils.iBounds(series, getPlot().getBounds()); iStart = iBounds.getMin().intValue(); if(iStart > 0) { iStart--; } iEnd = iBounds.getMax().intValue() + 1; if(iEnd < series.size() - 1) { iEnd++; } } for (int i = iStart; i < iEnd; i++) { final Number y = series.getY(i); final Number x = series.getX(i); PointF iPoint = points.get(i); if (y != null && x != null) { if(iPoint == null) { iPoint = new PointF(); points.set(i, iPoint); } thisPoint = iPoint; getPlot().getBounds().transformScreen(thisPoint, x, y, plotArea); } else { thisPoint = null; iPoint = null; points.set(i, iPoint); } if(formatter.hasLinePaint() && formatter.getInterpolationParams() == null) { if (thisPoint != null) { if (firstPoint == null) { path.reset(); firstPoint = thisPoint; path.moveTo(firstPoint.x, firstPoint.y); } if (lastPoint != null) { appendToPath(path, thisPoint, lastPoint); } lastPoint = thisPoint; } else { if (lastPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } firstPoint = null; lastPoint = null; } } } if(formatter.hasLinePaint()) { if(formatter.getInterpolationParams() != null) { List<XYCoords> interpolatedPoints = getInterpolator( formatter.getInterpolationParams()).interpolate(series, formatter.getInterpolationParams()); firstPoint = convertPoint(interpolatedPoints.get(ZERO), plotArea); lastPoint = convertPoint(interpolatedPoints.get(interpolatedPoints.size()-ONE), plotArea); path.reset(); path.moveTo(firstPoint.x, firstPoint.y); for(int i = 1; i < interpolatedPoints.size(); i++) { thisPoint = convertPoint(interpolatedPoints.get(i), plotArea); path.lineTo(thisPoint.x, thisPoint.y); } } if(firstPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } } renderPoints(canvas, plotArea, series, iStart, iEnd, points, formatter); } LineAndPointRenderer(XYPlot plot); }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) { PointF thisPoint; PointF lastPoint = null; PointF firstPoint = null; path.reset(); final List<PointF> points = getPointsCache(series); int iStart = 0; int iEnd = series.size(); if(SeriesUtils.getXYOrder(series) == OrderedXYSeries.XOrder.ASCENDING) { final Region iBounds = SeriesUtils.iBounds(series, getPlot().getBounds()); iStart = iBounds.getMin().intValue(); if(iStart > 0) { iStart--; } iEnd = iBounds.getMax().intValue() + 1; if(iEnd < series.size() - 1) { iEnd++; } } for (int i = iStart; i < iEnd; i++) { final Number y = series.getY(i); final Number x = series.getX(i); PointF iPoint = points.get(i); if (y != null && x != null) { if(iPoint == null) { iPoint = new PointF(); points.set(i, iPoint); } thisPoint = iPoint; getPlot().getBounds().transformScreen(thisPoint, x, y, plotArea); } else { thisPoint = null; iPoint = null; points.set(i, iPoint); } if(formatter.hasLinePaint() && formatter.getInterpolationParams() == null) { if (thisPoint != null) { if (firstPoint == null) { path.reset(); firstPoint = thisPoint; path.moveTo(firstPoint.x, firstPoint.y); } if (lastPoint != null) { appendToPath(path, thisPoint, lastPoint); } lastPoint = thisPoint; } else { if (lastPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } firstPoint = null; lastPoint = null; } } } if(formatter.hasLinePaint()) { if(formatter.getInterpolationParams() != null) { List<XYCoords> interpolatedPoints = getInterpolator( formatter.getInterpolationParams()).interpolate(series, formatter.getInterpolationParams()); firstPoint = convertPoint(interpolatedPoints.get(ZERO), plotArea); lastPoint = convertPoint(interpolatedPoints.get(interpolatedPoints.size()-ONE), plotArea); path.reset(); path.moveTo(firstPoint.x, firstPoint.y); for(int i = 1; i < interpolatedPoints.size(); i++) { thisPoint = convertPoint(interpolatedPoints.get(i), plotArea); path.lineTo(thisPoint.x, thisPoint.y); } } if(firstPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } } renderPoints(canvas, plotArea, series, iStart, iEnd, points, formatter); } LineAndPointRenderer(XYPlot plot); @Override void onRender(Canvas canvas, RectF plotArea, XYSeries series, FormatterType formatter, RenderStack stack); @Override void doDrawLegendIcon(Canvas canvas, RectF rect, LineAndPointFormatter formatter); }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void drawSeries(Canvas canvas, RectF plotArea, XYSeries series, LineAndPointFormatter formatter) { PointF thisPoint; PointF lastPoint = null; PointF firstPoint = null; path.reset(); final List<PointF> points = getPointsCache(series); int iStart = 0; int iEnd = series.size(); if(SeriesUtils.getXYOrder(series) == OrderedXYSeries.XOrder.ASCENDING) { final Region iBounds = SeriesUtils.iBounds(series, getPlot().getBounds()); iStart = iBounds.getMin().intValue(); if(iStart > 0) { iStart--; } iEnd = iBounds.getMax().intValue() + 1; if(iEnd < series.size() - 1) { iEnd++; } } for (int i = iStart; i < iEnd; i++) { final Number y = series.getY(i); final Number x = series.getX(i); PointF iPoint = points.get(i); if (y != null && x != null) { if(iPoint == null) { iPoint = new PointF(); points.set(i, iPoint); } thisPoint = iPoint; getPlot().getBounds().transformScreen(thisPoint, x, y, plotArea); } else { thisPoint = null; iPoint = null; points.set(i, iPoint); } if(formatter.hasLinePaint() && formatter.getInterpolationParams() == null) { if (thisPoint != null) { if (firstPoint == null) { path.reset(); firstPoint = thisPoint; path.moveTo(firstPoint.x, firstPoint.y); } if (lastPoint != null) { appendToPath(path, thisPoint, lastPoint); } lastPoint = thisPoint; } else { if (lastPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } firstPoint = null; lastPoint = null; } } } if(formatter.hasLinePaint()) { if(formatter.getInterpolationParams() != null) { List<XYCoords> interpolatedPoints = getInterpolator( formatter.getInterpolationParams()).interpolate(series, formatter.getInterpolationParams()); firstPoint = convertPoint(interpolatedPoints.get(ZERO), plotArea); lastPoint = convertPoint(interpolatedPoints.get(interpolatedPoints.size()-ONE), plotArea); path.reset(); path.moveTo(firstPoint.x, firstPoint.y); for(int i = 1; i < interpolatedPoints.size(); i++) { thisPoint = convertPoint(interpolatedPoints.get(i), plotArea); path.lineTo(thisPoint.x, thisPoint.y); } } if(firstPoint != null) { renderPath(canvas, plotArea, path, firstPoint, lastPoint, formatter); } } renderPoints(canvas, plotArea, series, iStart, iEnd, points, formatter); } LineAndPointRenderer(XYPlot plot); @Override void onRender(Canvas canvas, RectF plotArea, XYSeries series, FormatterType formatter, RenderStack stack); @Override void doDrawLegendIcon(Canvas canvas, RectF rect, LineAndPointFormatter formatter);  }