BubbleRenderer extends XYSeriesRenderer<BubbleSeries, FormatterType> { @Override protected void onRender(Canvas canvas, RectF plotArea, BubbleSeries series, FormatterType formatter, RenderStack stack) { Region magnitudeBounds = calculateBounds(); for(int i = 0; i < series.size(); i++) { if(series.getY(i) != null && series.getZ(i).doubleValue() > 0) { final PointF centerPoint = getPlot().getBounds(). transform(series.getX(i), series.getY(i), plotArea, false, true); float bubbleRadius = magnitudeBounds. transform(bubbleScaleMode == BubbleScaleMode.SQUARE_ROOT ? Math.sqrt(series.getZ(i).doubleValue()) : series.getZ(i).doubleValue(), bubbleBounds).floatValue(); drawBubble(canvas, formatter, series, i, centerPoint, bubbleRadius); } } } BubbleRenderer(XYPlot plot); float getMinBubbleRadius(); void setMinBubbleRadius(float minBubbleRadius); float getMaxBubbleRadius(); void setMaxBubbleRadius(float maxBubbleRadius); BubbleScaleMode getBubbleScaleMode(); void setBubbleScaleMode(BubbleScaleMode bubbleScaleMode);  }
@Test public void testOnRender() throws Exception { BubbleFormatter formatter = spy(new BubbleFormatter()); BubbleRenderer br = formatter.getRendererInstance(xyPlot); BubbleRenderer renderer = spy(br); doReturn(renderer.getClass()).when(formatter).getRendererClass(); doReturn(renderer).when(formatter).getRendererInstance(any(XYPlot.class)); BubbleSeries bs = new BubbleSeries(1, 2, 3, 4, 5, 6, 7, 8, 9); xyPlot.addSeries(bs, formatter); renderer.onRender(canvas, plotArea, bs, formatter, renderStack); }
@Test public void testOnRender_withPointLabeler() throws Exception { BubbleFormatter formatter = spy(new BubbleFormatter()); PointLabelFormatter plf = new PointLabelFormatter(Color.MAGENTA); formatter.setPointLabelFormatter(plf); BubbleRenderer br = formatter.getRendererInstance(xyPlot); BubbleRenderer renderer = spy(br); doReturn(renderer.getClass()).when(formatter).getRendererClass(); doReturn(renderer).when(formatter).getRendererInstance(any(XYPlot.class)); BubbleSeries bs = new BubbleSeries(2, 2, 22); xyPlot.addSeries(bs, formatter); renderer.onRender(canvas, plotArea, bs, formatter, renderStack); verify(canvas).drawText(eq("22"), anyFloat(), anyFloat(), eq(plf.getTextPaint())); }