📄 pieplot.java
字号:
return this.labelBackgroundPaint; } /** * Sets the section label background paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> permitted). */ public void setLabelBackgroundPaint(Paint paint) { this.labelBackgroundPaint = paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the section label outline paint. * * @return The paint (possibly <code>null</code>). */ public Paint getLabelOutlinePaint() { return this.labelOutlinePaint; } /** * Sets the section label outline paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> permitted). */ public void setLabelOutlinePaint(Paint paint) { this.labelOutlinePaint = paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the section label outline stroke. * * @return The stroke (possibly <code>null</code>). */ public Stroke getLabelOutlineStroke() { return this.labelOutlineStroke; } /** * Sets the section label outline stroke and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param stroke the stroke (<code>null</code> permitted). */ public void setLabelOutlineStroke(Stroke stroke) { this.labelOutlineStroke = stroke; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the section label shadow paint. * * @return The paint (possibly <code>null</code>). */ public Paint getLabelShadowPaint() { return this.labelShadowPaint; } /** * Sets the section label shadow paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> permitted). */ public void setLabelShadowPaint(Paint paint) { this.labelShadowPaint = paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the tool tip generator, an object that is responsible for generating the text items * used for tool tips by the plot. If the generator is <code>null</code>, no tool tips will be * created. * * @return The generator (possibly <code>null</code>). */ public PieToolTipGenerator getToolTipGenerator() { return this.toolTipGenerator; } /** * Sets the tool tip generator and sends a {@link PlotChangeEvent} to all registered listeners. * Set the generator to <code>null</code> if you don't want any tool tips. * * @param generator the generator (<code>null</code> permitted). */ public void setToolTipGenerator(PieToolTipGenerator generator) { this.toolTipGenerator = generator; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the URL generator. * * @return the generator (possibly <code>null</code>). */ public PieURLGenerator getURLGenerator() { return this.urlGenerator; } /** * Sets the URL generator and sends a {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). */ public void setURLGenerator(PieURLGenerator generator) { this.urlGenerator = generator; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the minimum arc angle that will be drawn. Pie sections for an angle smaller than * this are not drawn, to avoid a JDK bug. * * @return The minimum angle. */ public double getMinimumArcAngleToDraw() { return this.minimumArcAngleToDraw; } /** * Sets the minimum arc angle that will be drawn. Pie sections for an angle smaller than * this are not drawn, to avoid a JDK bug. See this link for details: * * http://www.jfree.org/phpBB2/viewtopic.php?t=2707 * * ...and this bug report in the Java Bug Parade: * * http://developer.java.sun.com/developer/bugParade/bugs/4836495.html * * @param angle the minimum angle. */ public void setMinimumArcAngleToDraw(double angle) { this.minimumArcAngleToDraw = angle; } /** * Returns the flag that controls whether <code>null</code> values in the dataset are * ignored. * * @return A boolean. */ public boolean getIgnoreNullValues() { return this.ignoreNullValues; } /** * Sets a flag that controls whether <code>null</code> values are ignored, and sends * a {@link PlotChangeEvent} to all registered listeners. At present, this only affects * whether or not the key is presented in the legend. * * @param flag the flag. */ public void setIgnoreNullValues(boolean flag) { this.ignoreNullValues = flag; notifyListeners(new PlotChangeEvent(this)); } /** * Initialises the drawing procedure. This method will be called before the first item is * rendered, giving the plot an opportunity to initialise any state information it wants * to maintain. * * @param g2 the graphics device. * @param plotArea the plot area (<code>null</code> not permitted). * @param plot the plot. * @param index the secondary index (<code>null</code> for primary renderer). * @param info collects chart rendering information for return to caller. * * @return A state object (maintains state information relevant to one chart drawing). */ public PiePlotState initialise(Graphics2D g2, Rectangle2D plotArea, PiePlot plot, Integer index, PlotRenderingInfo info) { PiePlotState state = new PiePlotState(info); state.setPassesRequired(2); state.setTotal(DatasetUtilities.calculatePieDatasetTotal(plot.getDataset())); state.setLatestAngle(plot.getStartAngle()); return state; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device. * @param plotArea the area within which the plot should be drawn. * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Entering draw() method, plot area = " + plotArea.toString()); } // adjust for insets... Insets insets = getInsets(); if (insets != null) { plotArea.setRect(plotArea.getX() + insets.left, plotArea.getY() + insets.top, plotArea.getWidth() - insets.left - insets.right, plotArea.getHeight() - insets.top - insets.bottom ); } if (info != null) { info.setPlotArea(plotArea); info.setDataArea(plotArea); } drawBackground(g2, plotArea); drawOutline(g2, plotArea); Shape savedClip = g2.getClip(); g2.clip(plotArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { drawPie(g2, plotArea, info); } else { drawNoDataMessage(g2, plotArea); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, plotArea); } /** * Draws the pie. * * @param g2 the graphics device. * @param plotArea the plot area. * @param info chart rendering info. */ protected void drawPie(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info) { PiePlotState state = initialise(g2, plotArea, this, null, info); // adjust the plot area for interior spacing and labels... double labelWidth = 0.0; if (this.labelGenerator != null) { labelWidth = this.labelGap + this.maximumLabelWidth + this.labelLinkMargin; } double gapHorizontal = plotArea.getWidth() * (this.interiorGap + labelWidth); double gapVertical = plotArea.getHeight() * this.interiorGap; double linkX = plotArea.getX() + gapHorizontal / 2; double linkY = plotArea.getY() + gapVertical / 2; double linkW = plotArea.getWidth() - gapHorizontal; double linkH = plotArea.getHeight() - gapVertical; // make the link area a square if the pie chart is to be circular... if (this.circular) { double min = Math.min(linkW, linkH) / 2; linkX = (linkX + linkX + linkW) / 2 - min; linkY = (linkY + linkY + linkH) / 2 - min; linkW = 2 * min; linkH = 2 * min; } // the link area defines the dog leg points for the linking lines to the labels Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW, linkH); state.setLinkArea(linkArea); // the explode area defines the max circle/ellipse for the exploded pie sections. // it is defined by shrinking the linkArea by the linkMargin factor. double hh = linkArea.getWidth() * this.labelLinkMargin; double vv = linkArea.getHeight() * this.labelLinkMargin; Rectangle2D explodeArea = new Rectangle2D.Double( linkX + hh / 2.0, linkY + vv / 2.0, linkW - hh, linkH - vv ); state.setExplodedPieArea(explodeArea); // the pie area defines the circle/ellipse for regular pie sections. // it is defined by shrinking the explodeArea by the explodeMargin factor. double maximumExplodePercent = getMaximumExplodePercent(); double percent = maximumExplodePercent / (1.0 + maximumExplodePercent); double h1 = explodeArea.getWidth() * percent; double v1 = explodeArea.getHeight() * percent; Rectangle2D pieArea = new Rectangle2D.Double( explodeArea.getX() + h1 / 2.0, explodeArea.getY() + v1 / 2.0, explodeArea.getWidth() - h1, explodeArea.getHeight() - v1 ); state.setPieArea(pieArea); state.setPieCenterX(pieArea.getCenterX()); state.setPieCenterY(pieArea.getCenterY()); state.setPieWRadius(pieArea.getWidth() / 2.0); state.setPieHRadius(pieArea.getHeight() / 2.0); // plot the data (unless the dataset is null)... if ((this.dataset != null) && (this.dataset.getKeys().size() > 0)) { List keys = this.dataset.getKeys(); double totalValue = DatasetUtilities.calculatePieDatasetTotal(this.dataset); int passesRequired = state.getPassesRequired(); for (int pass = 0; pass < passesRequired; pass++) { double runningTotal = 0.0; for (int section = 0; section < keys.size(); section++) { Number n = this.dataset.getValue(section); if (n != null) { double value = n.doubleValue(); if (value > 0.0) { runningTotal += value; drawItem(g2, section, explodeArea, state, pass); } } } } drawLabels(g2, keys, totalValue, plotArea, linkArea, state); } else { drawNoDataMessage(g2, plotArea); } } /** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -