@Test public void renderPath_rendersRegions() { LineAndPointFormatter formatter = new LineAndPointFormatter(0, 0, 0, null); XYRegionFormatter r1 = new XYRegionFormatter(Color.RED); formatter.addRegion(new RectRegion(0, 2, 0, 2, "region1"), r1); XYRegionFormatter r2 = new XYRegionFormatter(Color.GREEN); formatter.addRegion(new RectRegion(0, 2, 0, 2, "region2"), r2); SimpleXYSeries series = new SimpleXYSeries( SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "some data", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); xyPlot.addSeries(series, formatter); LineAndPointRenderer renderer = xyPlot.getRenderer(LineAndPointRenderer.class); renderer.renderPath(canvas, plotArea, new Path(), mock(PointF.class), mock(PointF.class), formatter); verify(canvas).drawRect(any(RectF.class), eq(r1.getPaint())); verify(canvas).drawRect(any(RectF.class), eq(r2.getPaint())); }
protected void renderPath(Canvas canvas, RectF plotArea, Path path, PointF firstPoint, PointF lastPoint, LineAndPointFormatter formatter) { Path outlinePath = new Path(path); switch (formatter.getFillDirection()) { case BOTTOM: path.lineTo(lastPoint.x, plotArea.bottom); path.lineTo(firstPoint.x, plotArea.bottom); path.close(); break; case TOP: path.lineTo(lastPoint.x, plotArea.top); path.lineTo(firstPoint.x, plotArea.top); path.close(); break; case RANGE_ORIGIN: float originPix = (float) getPlot().getBounds().getxRegion() .transform(getPlot().getRangeOrigin() .doubleValue(), plotArea.top, plotArea.bottom, true); path.lineTo(lastPoint.x, originPix); path.lineTo(firstPoint.x, originPix); path.close(); break; default: throw new UnsupportedOperationException( "Fill direction not yet implemented: " + formatter.getFillDirection()); } if (formatter.getFillPaint() != null) { canvas.drawPath(path, formatter.getFillPaint()); } final RectRegion bounds = getPlot().getBounds(); final RectRegion plotRegion = new RectRegion(plotArea); for (RectRegion thisRegion : bounds.intersects(formatter.getRegions().elements())) { XYRegionFormatter regionFormatter = formatter.getRegionFormatter(thisRegion); RectRegion thisRegionTransformed = bounds .transform(thisRegion, plotRegion, false, true); thisRegionTransformed.intersect(plotRegion); if(thisRegion.isFullyDefined()) { RectF thisRegionRectF = thisRegionTransformed.asRectF(); if (thisRegionRectF != null) { try { canvas.save(); canvas.clipPath(path); canvas.drawRect(thisRegionRectF, regionFormatter.getPaint()); } finally { canvas.restore(); } } } } if(formatter.hasLinePaint()) { canvas.drawPath(outlinePath, formatter.getLinePaint()); } path.rewind(); }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void renderPath(Canvas canvas, RectF plotArea, Path path, PointF firstPoint, PointF lastPoint, LineAndPointFormatter formatter) { Path outlinePath = new Path(path); switch (formatter.getFillDirection()) { case BOTTOM: path.lineTo(lastPoint.x, plotArea.bottom); path.lineTo(firstPoint.x, plotArea.bottom); path.close(); break; case TOP: path.lineTo(lastPoint.x, plotArea.top); path.lineTo(firstPoint.x, plotArea.top); path.close(); break; case RANGE_ORIGIN: float originPix = (float) getPlot().getBounds().getxRegion() .transform(getPlot().getRangeOrigin() .doubleValue(), plotArea.top, plotArea.bottom, true); path.lineTo(lastPoint.x, originPix); path.lineTo(firstPoint.x, originPix); path.close(); break; default: throw new UnsupportedOperationException( "Fill direction not yet implemented: " + formatter.getFillDirection()); } if (formatter.getFillPaint() != null) { canvas.drawPath(path, formatter.getFillPaint()); } final RectRegion bounds = getPlot().getBounds(); final RectRegion plotRegion = new RectRegion(plotArea); for (RectRegion thisRegion : bounds.intersects(formatter.getRegions().elements())) { XYRegionFormatter regionFormatter = formatter.getRegionFormatter(thisRegion); RectRegion thisRegionTransformed = bounds .transform(thisRegion, plotRegion, false, true); thisRegionTransformed.intersect(plotRegion); if(thisRegion.isFullyDefined()) { RectF thisRegionRectF = thisRegionTransformed.asRectF(); if (thisRegionRectF != null) { try { canvas.save(); canvas.clipPath(path); canvas.drawRect(thisRegionRectF, regionFormatter.getPaint()); } finally { canvas.restore(); } } } } if(formatter.hasLinePaint()) { canvas.drawPath(outlinePath, formatter.getLinePaint()); } path.rewind(); } }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void renderPath(Canvas canvas, RectF plotArea, Path path, PointF firstPoint, PointF lastPoint, LineAndPointFormatter formatter) { Path outlinePath = new Path(path); switch (formatter.getFillDirection()) { case BOTTOM: path.lineTo(lastPoint.x, plotArea.bottom); path.lineTo(firstPoint.x, plotArea.bottom); path.close(); break; case TOP: path.lineTo(lastPoint.x, plotArea.top); path.lineTo(firstPoint.x, plotArea.top); path.close(); break; case RANGE_ORIGIN: float originPix = (float) getPlot().getBounds().getxRegion() .transform(getPlot().getRangeOrigin() .doubleValue(), plotArea.top, plotArea.bottom, true); path.lineTo(lastPoint.x, originPix); path.lineTo(firstPoint.x, originPix); path.close(); break; default: throw new UnsupportedOperationException( "Fill direction not yet implemented: " + formatter.getFillDirection()); } if (formatter.getFillPaint() != null) { canvas.drawPath(path, formatter.getFillPaint()); } final RectRegion bounds = getPlot().getBounds(); final RectRegion plotRegion = new RectRegion(plotArea); for (RectRegion thisRegion : bounds.intersects(formatter.getRegions().elements())) { XYRegionFormatter regionFormatter = formatter.getRegionFormatter(thisRegion); RectRegion thisRegionTransformed = bounds .transform(thisRegion, plotRegion, false, true); thisRegionTransformed.intersect(plotRegion); if(thisRegion.isFullyDefined()) { RectF thisRegionRectF = thisRegionTransformed.asRectF(); if (thisRegionRectF != null) { try { canvas.save(); canvas.clipPath(path); canvas.drawRect(thisRegionRectF, regionFormatter.getPaint()); } finally { canvas.restore(); } } } } if(formatter.hasLinePaint()) { canvas.drawPath(outlinePath, formatter.getLinePaint()); } path.rewind(); } LineAndPointRenderer(XYPlot plot); }
LineAndPointRenderer extends XYSeriesRenderer<XYSeries, FormatterType> { protected void renderPath(Canvas canvas, RectF plotArea, Path path, PointF firstPoint, PointF lastPoint, LineAndPointFormatter formatter) { Path outlinePath = new Path(path); switch (formatter.getFillDirection()) { case BOTTOM: path.lineTo(lastPoint.x, plotArea.bottom); path.lineTo(firstPoint.x, plotArea.bottom); path.close(); break; case TOP: path.lineTo(lastPoint.x, plotArea.top); path.lineTo(firstPoint.x, plotArea.top); path.close(); break; case RANGE_ORIGIN: float originPix = (float) getPlot().getBounds().getxRegion() .transform(getPlot().getRangeOrigin() .doubleValue(), plotArea.top, plotArea.bottom, true); path.lineTo(lastPoint.x, originPix); path.lineTo(firstPoint.x, originPix); path.close(); break; default: throw new UnsupportedOperationException( "Fill direction not yet implemented: " + formatter.getFillDirection()); } if (formatter.getFillPaint() != null) { canvas.drawPath(path, formatter.getFillPaint()); } final RectRegion bounds = getPlot().getBounds(); final RectRegion plotRegion = new RectRegion(plotArea); for (RectRegion thisRegion : bounds.intersects(formatter.getRegions().elements())) { XYRegionFormatter regionFormatter = formatter.getRegionFormatter(thisRegion); RectRegion thisRegionTransformed = bounds .transform(thisRegion, plotRegion, false, true); thisRegionTransformed.intersect(plotRegion); if(thisRegion.isFullyDefined()) { RectF thisRegionRectF = thisRegionTransformed.asRectF(); if (thisRegionRectF != null) { try { canvas.save(); canvas.clipPath(path); canvas.drawRect(thisRegionRectF, regionFormatter.getPaint()); } finally { canvas.restore(); } } } } if(formatter.hasLinePaint()) { canvas.drawPath(outlinePath, formatter.getLinePaint()); } path.rewind(); } 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 renderPath(Canvas canvas, RectF plotArea, Path path, PointF firstPoint, PointF lastPoint, LineAndPointFormatter formatter) { Path outlinePath = new Path(path); switch (formatter.getFillDirection()) { case BOTTOM: path.lineTo(lastPoint.x, plotArea.bottom); path.lineTo(firstPoint.x, plotArea.bottom); path.close(); break; case TOP: path.lineTo(lastPoint.x, plotArea.top); path.lineTo(firstPoint.x, plotArea.top); path.close(); break; case RANGE_ORIGIN: float originPix = (float) getPlot().getBounds().getxRegion() .transform(getPlot().getRangeOrigin() .doubleValue(), plotArea.top, plotArea.bottom, true); path.lineTo(lastPoint.x, originPix); path.lineTo(firstPoint.x, originPix); path.close(); break; default: throw new UnsupportedOperationException( "Fill direction not yet implemented: " + formatter.getFillDirection()); } if (formatter.getFillPaint() != null) { canvas.drawPath(path, formatter.getFillPaint()); } final RectRegion bounds = getPlot().getBounds(); final RectRegion plotRegion = new RectRegion(plotArea); for (RectRegion thisRegion : bounds.intersects(formatter.getRegions().elements())) { XYRegionFormatter regionFormatter = formatter.getRegionFormatter(thisRegion); RectRegion thisRegionTransformed = bounds .transform(thisRegion, plotRegion, false, true); thisRegionTransformed.intersect(plotRegion); if(thisRegion.isFullyDefined()) { RectF thisRegionRectF = thisRegionTransformed.asRectF(); if (thisRegionRectF != null) { try { canvas.save(); canvas.clipPath(path); canvas.drawRect(thisRegionRectF, regionFormatter.getPaint()); } finally { canvas.restore(); } } } } if(formatter.hasLinePaint()) { canvas.drawPath(outlinePath, formatter.getLinePaint()); } path.rewind(); } 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);  }