@Test public void testOnRender() throws Exception { Segment segment = spy(new Segment("My Segment", 100)); SegmentFormatter formatter = spy( new SegmentFormatter(Color.GREEN, Color.GREEN, Color.GREEN, Color.GREEN)); PieRenderer pr = formatter.getRendererInstance(pieChart); PieRenderer renderer = spy(pr); doReturn(renderer.getClass()).when(formatter).getRendererClass(); doReturn(renderer).when(formatter).getRendererInstance(any(PieChart.class)); pieChart.addSegment(segment, formatter); renderer.onRender(canvas, plotArea, segment, formatter, renderStack); }
@Override public void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter, RenderStack stack) { stack.disable(getClass()); float radius = getRadius(plotArea); PointF origin = new PointF(plotArea.centerX(), plotArea.centerY()); double[] values = getValues(); double scale = calculateScale(values); float offset = degsToScreenDegs(startDegs); RectF rec = new RectF(origin.x - radius, origin.y - radius, origin.x + radius, origin.y + radius); int i = 0; for (SeriesBundle<Segment, ? extends SegmentFormatter> sfPair : getSeriesAndFormatterList()) { float lastOffset = offset; float sweep = (float) (scale * (values[i]) * extentDegs); offset += sweep; drawSegment(canvas, rec, sfPair.getSeries(), sfPair.getFormatter(), radius, lastOffset, sweep); i++; } }
PieRenderer extends SeriesRenderer<PieChart, Segment, SegmentFormatter> { @Override public void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter, RenderStack stack) { stack.disable(getClass()); float radius = getRadius(plotArea); PointF origin = new PointF(plotArea.centerX(), plotArea.centerY()); double[] values = getValues(); double scale = calculateScale(values); float offset = degsToScreenDegs(startDegs); RectF rec = new RectF(origin.x - radius, origin.y - radius, origin.x + radius, origin.y + radius); int i = 0; for (SeriesBundle<Segment, ? extends SegmentFormatter> sfPair : getSeriesAndFormatterList()) { float lastOffset = offset; float sweep = (float) (scale * (values[i]) * extentDegs); offset += sweep; drawSegment(canvas, rec, sfPair.getSeries(), sfPair.getFormatter(), radius, lastOffset, sweep); i++; } } }
PieRenderer extends SeriesRenderer<PieChart, Segment, SegmentFormatter> { @Override public void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter, RenderStack stack) { stack.disable(getClass()); float radius = getRadius(plotArea); PointF origin = new PointF(plotArea.centerX(), plotArea.centerY()); double[] values = getValues(); double scale = calculateScale(values); float offset = degsToScreenDegs(startDegs); RectF rec = new RectF(origin.x - radius, origin.y - radius, origin.x + radius, origin.y + radius); int i = 0; for (SeriesBundle<Segment, ? extends SegmentFormatter> sfPair : getSeriesAndFormatterList()) { float lastOffset = offset; float sweep = (float) (scale * (values[i]) * extentDegs); offset += sweep; drawSegment(canvas, rec, sfPair.getSeries(), sfPair.getFormatter(), radius, lastOffset, sweep); i++; } } PieRenderer(PieChart plot); }
PieRenderer extends SeriesRenderer<PieChart, Segment, SegmentFormatter> { @Override public void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter, RenderStack stack) { stack.disable(getClass()); float radius = getRadius(plotArea); PointF origin = new PointF(plotArea.centerX(), plotArea.centerY()); double[] values = getValues(); double scale = calculateScale(values); float offset = degsToScreenDegs(startDegs); RectF rec = new RectF(origin.x - radius, origin.y - radius, origin.x + radius, origin.y + radius); int i = 0; for (SeriesBundle<Segment, ? extends SegmentFormatter> sfPair : getSeriesAndFormatterList()) { float lastOffset = offset; float sweep = (float) (scale * (values[i]) * extentDegs); offset += sweep; drawSegment(canvas, rec, sfPair.getSeries(), sfPair.getFormatter(), radius, lastOffset, sweep); i++; } } PieRenderer(PieChart plot); float getRadius(RectF rect); @Override void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter,
            RenderStack stack); void setDonutSize(float size, DonutMode mode); Segment getContainingSegment(PointF point); void setStartDegs(float degs); float getStartDegs(); void setExtentDegs(float degs); float getExtentDegs(); }
PieRenderer extends SeriesRenderer<PieChart, Segment, SegmentFormatter> { @Override public void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter, RenderStack stack) { stack.disable(getClass()); float radius = getRadius(plotArea); PointF origin = new PointF(plotArea.centerX(), plotArea.centerY()); double[] values = getValues(); double scale = calculateScale(values); float offset = degsToScreenDegs(startDegs); RectF rec = new RectF(origin.x - radius, origin.y - radius, origin.x + radius, origin.y + radius); int i = 0; for (SeriesBundle<Segment, ? extends SegmentFormatter> sfPair : getSeriesAndFormatterList()) { float lastOffset = offset; float sweep = (float) (scale * (values[i]) * extentDegs); offset += sweep; drawSegment(canvas, rec, sfPair.getSeries(), sfPair.getFormatter(), radius, lastOffset, sweep); i++; } } PieRenderer(PieChart plot); float getRadius(RectF rect); @Override void onRender(Canvas canvas, RectF plotArea, Segment series, SegmentFormatter formatter,
            RenderStack stack); void setDonutSize(float size, DonutMode mode); Segment getContainingSegment(PointF point); void setStartDegs(float degs); float getStartDegs(); void setExtentDegs(float degs); float getExtentDegs();  }