combineddomaincategoryplot.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 598 行 · 第 1/2 页
JAVA
598 行
CategoryAxis categoryAxis = getDomainAxis(); RectangleEdge categoryEdge = Plot.resolveDomainAxisLocation( getDomainAxisLocation(), orientation ); if (categoryAxis != null) { space = categoryAxis.reserveSpace( g2, this, plotArea, categoryEdge, space ); } else { if (getDrawSharedDomainAxis()) { space = getDomainAxis().reserveSpace( g2, this, plotArea, categoryEdge, space ); } } } Rectangle2D adjustedPlotArea = space.shrink(plotArea, null); // work out the maximum height or width of the non-shared axes... int n = this.subplots.size(); this.subplotAreas = new Rectangle2D[n]; double x = adjustedPlotArea.getX(); double y = adjustedPlotArea.getY(); double usableSize = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1); } else if (orientation == PlotOrientation.VERTICAL) { usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1); } for (int i = 0; i < n; i++) { CategoryPlot plot = (CategoryPlot) this.subplots.get(i); // calculate sub-plot area if (orientation == PlotOrientation.HORIZONTAL) { double w = usableSize * plot.getWeight() / this.totalWeight; this.subplotAreas[i] = new Rectangle2D.Double( x, y, w, adjustedPlotArea.getHeight() ); x = x + w + this.gap; } else if (orientation == PlotOrientation.VERTICAL) { double h = usableSize * plot.getWeight() / this.totalWeight; this.subplotAreas[i] = new Rectangle2D.Double( x, y, adjustedPlotArea.getWidth(), h ); y = y + h + this.gap; } AxisSpace subSpace = plot.calculateRangeAxisSpace( g2, this.subplotAreas[i], null ); space.ensureAtLeast(subSpace); } 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 of the * sub-plots and then tell these to draw themselves. * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects information about the drawing (<code>null</code> * permitted). */ public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); area.setRect( area.getX() + insets.getLeft(), area.getY() + insets.getTop(), area.getWidth() - insets.getLeft() - insets.getRight(), area.getHeight() - insets.getTop() - insets.getBottom() ); // calculate the data area... setFixedRangeAxisSpaceForSubplots(null); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); // set the width and height of non-shared axis of all sub-plots setFixedRangeAxisSpaceForSubplots(space); // draw the shared axis CategoryAxis axis = getDomainAxis(); RectangleEdge domainEdge = getDomainAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, domainEdge); AxisState axisState = axis.draw( g2, cursor, area, dataArea, domainEdge, info ); if (parentState == null) { parentState = new PlotState(); } parentState.getSharedAxisStates().put(axis, axisState); // draw all the subplots 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.subplotAreas[i], null, parentState, subplotInfo); } if (info != null) { info.setDataArea(dataArea); } } /** * Sets the size (width or height, depending on the orientation of the * plot) for the range axis of each subplot. * * @param space the space (<code>null</code> permitted). */ protected void setFixedRangeAxisSpaceForSubplots(AxisSpace space) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { CategoryPlot plot = (CategoryPlot) iterator.next(); plot.setFixedRangeAxisSpace(space); } } /** * Sets the orientation of the plot (and all subplots). * * @param orientation the orientation (<code>null</code> not permitted). */ 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 a collection of legend items for the plot. * * @return The legend items. */ public LegendItemCollection getLegendItems() { LegendItemCollection result = getFixedLegendItems(); if (result == null) { 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; } /** * Returns an unmodifiable list of the categories contained in all the * subplots. * * @return The list. */ public List getCategories() { List result = new java.util.ArrayList(); if (this.subplots != null) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { CategoryPlot plot = (CategoryPlot) iterator.next(); List more = plot.getCategories(); Iterator moreIterator = more.iterator(); while (moreIterator.hasNext()) { Comparable category = (Comparable) moreIterator.next(); if (!result.contains(category)) { result.add(category); } } } } return Collections.unmodifiableList(result); } /** * Handles a 'click' on the plot. * * @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 obj the object (<code>null</code> permitted). * * @return A boolean. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CombinedDomainCategoryPlot)) { return false; } if (!super.equals(obj)) { return false; } CombinedDomainCategoryPlot plot = (CombinedDomainCategoryPlot) obj; if (!ObjectUtilities.equal(this.subplots, plot.subplots)) { return false; } if (this.totalWeight != plot.totalWeight) { return false; } if (this.gap != plot.gap) { return false; } return true; } /** * 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 { CombinedDomainCategoryPlot result = (CombinedDomainCategoryPlot) super.clone(); result.subplots = (List) ObjectUtilities.deepClone(this.subplots); for (Iterator it = result.subplots.iterator(); it.hasNext();) { Plot child = (Plot) it.next(); child.setParent(result); } return result; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?