private void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double x0, double y0, double x1, double y1, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); boolean visible; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } visible = LineUtilities.clipLine(state.workingLine, dataArea); if (visible) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } }
/** * Draws the item (first pass). This method draws the lines * connecting the items. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); boolean visible; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } visible = LineUtilities.clipLine(state.workingLine, dataArea); if (visible) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } }
/** * Draws the annotation. This method is called by the {@link XYPlot} * class, you won't normally need to call it yourself. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float j2DX1 = 0.0f; float j2DX2 = 0.0f; float j2DY1 = 0.0f; float j2DY2 = 0.0f; if (orientation == PlotOrientation.VERTICAL) { j2DX1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); j2DY1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); j2DX2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge); j2DY2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.HORIZONTAL) { j2DY1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); j2DX1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); j2DY2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge); j2DX2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge); } g2.setPaint(this.paint); g2.setStroke(this.stroke); Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2); // line is clipped to avoid JRE bug 6574155, for more info // see JFreeChart bug 2221495 boolean visible = LineUtilities.clipLine(line, dataArea); if (visible) { g2.draw(line); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, ShapeUtilities.createLineRegion(line, 1.0f), rendererIndex, toolTip, url); } }
/** * Draws the annotation. This method is called by the {@link XYPlot} * class, you won't normally need to call it yourself. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float j2DX1 = 0.0f; float j2DX2 = 0.0f; float j2DY1 = 0.0f; float j2DY2 = 0.0f; if (orientation == PlotOrientation.VERTICAL) { j2DX1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); j2DY1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); j2DX2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge); j2DY2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.HORIZONTAL) { j2DY1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); j2DX1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); j2DY2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge); j2DX2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge); } g2.setPaint(this.paint); g2.setStroke(this.stroke); Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2); // line is clipped to avoid JRE bug 6574155, for more info // see JFreeChart bug 2221495 boolean visible = LineUtilities.clipLine(line, dataArea); if (visible) { g2.draw(line); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, ShapeUtilities.createLineRegion(line, 1.0f), rendererIndex, toolTip, url); } }
public void testClipLine() { Rectangle2D rect = new Rectangle2D.Double(1.0, 1.0, 1.0, 1.0); Line2D line = new Line2D.Double(); assertFalse(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 0.0, 0.0, 0.0, 0.0)); line.setLine(0.5, 0.5, 0.6, 0.6); assertFalse(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 0.5, 0.5, 0.6, 0.6)); line.setLine(0.5, 0.5, 1.6, 0.6); assertFalse(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 0.5, 0.5, 1.6, 0.6)); line.setLine(0.5, 0.5, 2.6, 0.6); assertFalse(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 0.5, 0.5, 2.6, 0.6)); line.setLine(0.5, 0.5, 0.6, 1.6); assertFalse(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 0.5, 0.5, 0.6, 1.6)); line.setLine(0.5, 0.5, 1.6, 1.6); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 1.0, 1.0, 1.6, 1.6)); line.setLine(0.5, 0.5, 2.6, 1.6); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 1.4545454545454546, 1.0, 2.0, 1.2857142857142858)); line.setLine(0.5, 0.5, 0.5, 2.6); assertFalse(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 0.5, 0.5, 0.5, 2.6)); line.setLine(0.5, 0.5, 1.5, 2.6); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 1.0, 1.55, 1.2142857142857142, 2.0)); line.setLine(0.5, 0.5, 2.5, 2.6); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 1.0, 1.025, 1.9285714285714284, 2.0)); line.setLine(0.5, 0.5, 1.5, 1.5); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 1.0, 1.0, 1.5, 1.5)); line.setLine(2.5, 1.0, 1.5, 1.5); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 2.0, 1.25, 1.5, 1.5)); line.setLine(1.5, 1.5, 2.5, 1.0); assertTrue(LineUtilities.clipLine(line, rect)); assertTrue(lineEquals(line, 1.5, 1.5, 2.0, 1.25)); }
/** * Draws the item (first pass). This method draws the lines * connecting the items. * * @param g2 the graphics device. * @param state the renderer state. * @param plot the plot (can be used to obtain standard color * information etc). * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param selected is the data item selected? * @param dataArea the area within which the data is being drawn. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * * @since 1.2.0 */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, boolean selected, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); boolean visible = false; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } visible = LineUtilities.clipLine(state.workingLine, dataArea); if (visible) { drawShape1(g2, pass, series, item, selected, state.workingLine); } }
/** * Draws the item (first pass). This method draws the lines * connecting the items. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). */ protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { if (item == 0) { return; } // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } PlotOrientation orientation = plot.getOrientation(); boolean visible = false; if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } visible = LineUtilities.clipLine(state.workingLine, dataArea); if (visible) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } }