xylineandshaperenderer.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,233 行 · 第 1/3 页
JAVA
1,233 行
* * @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(); if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { drawFirstPassShape(g2, pass, series, item, state.workingLine); } } /** * Draws the first pass shape. * * @param g2 the graphics device. * @param pass the pass. * @param series the series index. * @param item the item index. * @param shape the shape. */ protected void drawFirstPassShape(Graphics2D g2, int pass, int series, int item, Shape shape) { g2.setStroke(getItemStroke(series, item)); g2.setPaint(getItemPaint(series, item)); g2.draw(shape); } /** * Draws the item (first pass). This method draws the lines * connecting the items. Instead of drawing separate lines, * a GeneralPath is constructed and drawn at the end of * the series painting. * * @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 domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataArea the area within which the data is being drawn. */ protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) { RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); State s = (State) state; // update path to reflect latest point if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.isLastPointGood()) { s.seriesPath.lineTo(x, y); } else { s.seriesPath.moveTo(x, y); } s.setLastPointGood(true); } else { s.setLastPointGood(false); } // if this is the last item, draw the path ... if (item == dataset.getItemCount(series) - 1) { // draw path drawFirstPassShape(g2, pass, series, item, s.seriesPath); } } /** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information. * * @param g2 the graphics device. * @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). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape( shape, transY1, transX1 ); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape( shape, transX1, transY1 ); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } updateCrosshairValues( crosshairState, x1, y1, transX1, transY1, plot.getOrientation() ); // add an entity for the item... if (entities != null) { addEntity( entities, entityArea, dataset, series, item, transX1, transY1 ); } } /** * Returns a legend item for the specified series. * * @param datasetIndex the dataset index (zero-based). * @param series the series index (zero-based). * * @return A legend item for the series. */ public LegendItem getLegendItem(int datasetIndex, int series) { XYPlot plot = getPlot(); if (plot == null) { return null; } LegendItem result = null; XYDataset dataset = plot.getDataset(datasetIndex); if (dataset != null) { if (getItemVisible(series, 0)) { String label = getLegendItemLabelGenerator().generateLabel( dataset, series ); String description = label; String toolTipText = null; if (getLegendItemToolTipGenerator() != null) { toolTipText = getLegendItemToolTipGenerator().generateLabel( dataset, series ); } String urlText = null; if (getLegendItemURLGenerator() != null) { urlText = getLegendItemURLGenerator().generateLabel( dataset, series ); } boolean shapeIsVisible = getItemShapeVisible(series, 0); Shape shape = getSeriesShape(series); boolean shapeIsFilled = getItemShapeFilled(series, 0); Paint fillPaint = (this.useFillPaint ? getSeriesFillPaint(series) : getSeriesPaint(series)); boolean shapeOutlineVisible = this.drawOutlines; Paint outlinePaint = (this.useOutlinePaint ? getSeriesOutlinePaint(series) : getSeriesPaint(series)); Stroke outlineStroke = getSeriesOutlineStroke(series); boolean lineVisible = getItemLineVisible(series, 0); Stroke lineStroke = getSeriesStroke(series); Paint linePaint = getSeriesPaint(series); result = new LegendItem( label, description, toolTipText, urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, this.legendLine, lineStroke, linePaint ); } } return result; } /** * Returns a clone of the renderer. * * @return A clone. * * @throws CloneNotSupportedException if the clone cannot be created. */ public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Tests this renderer for equality with another object. * * @param obj the object. * * @return <code>true</code> or <code>false</code>. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYLineAndShapeRenderer)) { return false; } if (!super.equals(obj)) { return false; } XYLineAndShapeRenderer that = (XYLineAndShapeRenderer) obj; if (!ObjectUtilities.equal(this.linesVisible, that.linesVisible)) { return false; } if (!ObjectUtilities.equal( this.seriesLinesVisible, that.seriesLinesVisible) ) { return false; } if (this.defaultLinesVisible != that.defaultLinesVisible) { return false; } if (!ShapeUtilities.equal(this.legendLine, that.legendLine)) { return false; } if (!ObjectUtilities.equal(this.shapesVisible, that.shapesVisible)) { return false; } if (!ObjectUtilities.equal( this.seriesShapesVisible, that.seriesShapesVisible) ) { return false; } if (this.defaultShapesVisible != that.defaultShapesVisible) { return false; } if (!ObjectUtilities.equal(this.shapesFilled, that.shapesFilled)) { return false; } if (!ObjectUtilities.equal( this.seriesShapesFilled, that.seriesShapesFilled) ) { return false; } if (this.defaultShapesFilled != that.defaultShapesFilled) { return false; } if (this.drawOutlines != that.drawOutlines) { return false; } if (this.useOutlinePaint != that.useOutlinePaint) { return false; } return true; } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.legendLine = SerialUtilities.readShape(stream); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeShape(this.legendLine, stream); } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?