📄 combinedrangecategoryplot.java
字号:
return space; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * Will perform all the placement calculations for each sub-plots and then tell these to draw * themselves. * * @param g2 the graphics device. * @param plotArea the area within which the plot (including axis labels) should be drawn. * @param parentState the parent state. * @param info collects information about the drawing (<code>null</code> permitted). */ public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(plotArea); } // adjust the drawing area for plot insets (if any)... 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 ); } // calculate the data area... AxisSpace space = calculateAxisSpace(g2, plotArea); Rectangle2D dataArea = space.shrink(plotArea, null); // set the width and height of non-shared axis of all sub-plots setFixedDomainAxisSpaceForSubplots(space); // draw the shared axis ValueAxis axis = getRangeAxis(); RectangleEdge rangeEdge = getRangeAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, rangeEdge); AxisState state = axis.draw(g2, cursor, plotArea, dataArea, rangeEdge, info); if (parentState == null) { parentState = new PlotState(); } parentState.getSharedAxisStates().put(axis, state); // draw all the charts for (int i = 0; i < this.subplots.size(); i++) { CategoryPlot plot = (CategoryPlot) this.subplots.get(i); PlotRenderingInfo subplotInfo = null; if (info != null) { subplotInfo = new PlotRenderingInfo(info.getOwner()); info.addSubplotInfo(subplotInfo); } plot.draw(g2, this.subplotArea[i], parentState, subplotInfo); } if (info != null) { info.setDataArea(dataArea); } } /** * Sets the orientation for the plot (and all the subplots). * * @param orientation the orientation. */ public void setOrientation(PlotOrientation orientation) { super.setOrientation(orientation); Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { CategoryPlot plot = (CategoryPlot) iterator.next(); plot.setOrientation(orientation); } } /** * Returns the range for the axis. This is the combined range of all the subplots. * * @param axis the axis. * * @return the range. */ public Range getDataRange(ValueAxis axis) { Range result = null; if (this.subplots != null) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { CategoryPlot subplot = (CategoryPlot) iterator.next(); result = Range.combine(result, subplot.getDataRange(axis)); } } return result; } /** * Returns a collection of legend items for the plot. * * @return the legend items. */ public LegendItemCollection getLegendItems() { LegendItemCollection result = new LegendItemCollection(); if (this.subplots != null) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { CategoryPlot plot = (CategoryPlot) iterator.next(); LegendItemCollection more = plot.getLegendItems(); result.addAll(more); } } return result; } /** * Sets the size (width or height, depending on the orientation of the plot) for the domain * axis of each subplot. * * @param space the space. */ protected void setFixedDomainAxisSpaceForSubplots(AxisSpace space) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { CategoryPlot plot = (CategoryPlot) iterator.next(); plot.setFixedDomainAxisSpace(space); } } /** * Handles a 'click' on the plot by updating the anchor value. * * @param x x-coordinate of the click. * @param y y-coordinate of the click. * @param info information about the plot's dimensions. * */ public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { for (int i = 0; i < this.subplots.size(); i++) { CategoryPlot subplot = (CategoryPlot) this.subplots.get(i); PlotRenderingInfo subplotInfo = info.getSubplotInfo(i); subplot.handleClick(x, y, subplotInfo); } } } /** * Receives a {@link PlotChangeEvent} and responds by notifying all listeners. * * @param event the event. */ public void plotChanged(PlotChangeEvent event) { notifyListeners(event); } /** * Tests the plot for equality with an arbitrary object. * * @param object the object to test against. * * @return <code>true</code> or <code>false</code>. */ public boolean equals(Object object) { if (object == null) { return false; } if (object == this) { return true; } if (object instanceof CombinedRangeCategoryPlot) { CombinedRangeCategoryPlot plot = (CombinedRangeCategoryPlot) object; if (super.equals(object)) { boolean b0 = ObjectUtils.equal(this.subplots, plot.subplots); boolean b1 = (this.totalWeight == plot.totalWeight); boolean b2 = (this.gap == plot.gap); return b0 && b1 && b2; } } return false; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this exception, but subclasses * (if any) might. */ public Object clone() throws CloneNotSupportedException { CombinedRangeCategoryPlot result = (CombinedRangeCategoryPlot) super.clone(); result.subplots = ObjectUtils.clone(this.subplots); for (Iterator it = result.subplots.iterator(); it.hasNext();) { Plot child = (Plot) it.next(); child.setParent(result); } // after setting up all the subplots, the shared range axis may need reconfiguring ValueAxis rangeAxis = result.getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } return result; } /** * 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(); // the range axis is deserialized before the subplots, so its value range // is likely to be incorrect... ValueAxis rangeAxis = getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -