📄 categoryaxis.java
字号:
RectangleEdge edge) { List ticks = new java.util.ArrayList(); // sanity check for data area... if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) { return ticks; } CategoryPlot plot = (CategoryPlot) getPlot(); List categories = plot.getCategories(); double max = 0.0; if (categories != null) { CategoryLabelPosition position = this.categoryLabelPositions.getLabelPosition(edge); float r = this.maxCategoryLabelWidthRatio; if (r <= 0.0) { r = position.getWidthRatio(); } float l = 0.0f; if (position.getWidthType() == CategoryLabelWidthType.CATEGORY) { l = (float) calculateCategorySize(categories.size(), dataArea, edge); } else { if (RectangleEdge.isLeftOrRight(edge)) { l = (float) dataArea.getWidth(); } else { l = (float) dataArea.getHeight(); } } int categoryIndex = 0; Iterator iterator = categories.iterator(); while (iterator.hasNext()) { Comparable category = (Comparable) iterator.next(); TextBlock label = createLabel(category, l * r, edge, g2); if (edge == RectangleEdge.TOP || edge == RectangleEdge.BOTTOM) { max = Math.max(max, calculateTextBlockHeight(label, position, g2)); } else if (edge == RectangleEdge.LEFT || edge == RectangleEdge.RIGHT) { max = Math.max(max, calculateTextBlockWidth(label, position, g2)); } Tick tick = new CategoryTick( category, label, position.getLabelAnchor(), position.getRotationAnchor(), position.getAngle() ); ticks.add(tick); categoryIndex = categoryIndex + 1; } } state.setMax(max); return ticks; } /** * Creates a label. * * @param category the category. * @param width the available width. * @param edge the edge on which the axis appears. * @param g2 the graphics device. * * @return a label. */ protected TextBlock createLabel(Comparable category, float width, RectangleEdge edge, Graphics2D g2) { TextBlock label = TextUtilities.createTextBlock( category.toString(), getTickLabelFont(), getTickLabelPaint(), width, new G2TextMeasurer(g2) ); return label; } /** * A utility method for determining the width of a text block. * * @param block the text block. * @param position the position. * @param g2 the graphics device. * * @return the width. */ protected double calculateTextBlockWidth(TextBlock block, CategoryLabelPosition position, Graphics2D g2) { Insets insets = getTickLabelInsets(); Size2D size = block.calculateDimensions(g2); Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight()); Shape rotatedBox = ShapeUtils.rotateShape(box, position.getAngle(), 0.0f, 0.0f); double w = rotatedBox.getBounds2D().getWidth() + insets.top + insets.bottom; return w; } /** * A utility method for determining the height of a text block. * * @param block the text block. * @param position the label position. * @param g2 the graphics device. * * @return the height. */ protected double calculateTextBlockHeight(TextBlock block, CategoryLabelPosition position, Graphics2D g2) { Insets insets = getTickLabelInsets(); Size2D size = block.calculateDimensions(g2); Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight()); Shape rotatedBox = ShapeUtils.rotateShape(box, position.getAngle(), 0.0f, 0.0f); double h = rotatedBox.getBounds2D().getHeight() + insets.top + insets.bottom; return h; } /** * Creates a clone of the axis. * * @return a clone. * * @throws CloneNotSupportedException if some component of the axis does not support cloning. */ public Object clone() throws CloneNotSupportedException { Object clone = super.clone(); return clone; } /** * Tests this axis 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 CategoryAxis && super.equals(obj)) { CategoryAxis axis = (CategoryAxis) obj; boolean b0 = (axis.lowerMargin == this.lowerMargin); boolean b1 = (axis.upperMargin == this.upperMargin); boolean b2 = (axis.categoryMargin == this.categoryMargin); boolean b3 = (axis.maxCategoryLabelWidthRatio == this.maxCategoryLabelWidthRatio); boolean b4 = (axis.categoryLabelPositionOffset == this.categoryLabelPositionOffset); boolean b5 = ObjectUtils.equal( axis.categoryLabelPositions, this.categoryLabelPositions ); boolean b6 = ObjectUtils.equal( axis.categoryLabelToolTips, this.categoryLabelToolTips ); return b0 && b1 && b2 && b3 && b4 && b5 && b6; } return false; } /** * 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(); } /** * 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(); } //// DEPRECATED CODE //////////////////////////////////////////////////////////// /** * Returns a flag indicating whether the category labels are rotated to vertical. * * @return The flag. * * @deprecated Use the get/setXXXCategoryLabelPosition methods. */ public boolean isVerticalCategoryLabels() { return false; } /** * Sets the flag that determines whether the category labels are rotated to vertical. * * @param flag the flag. * * @deprecated Use the get/setXXXCategoryLabelPosition methods. */ public void setVerticalCategoryLabels(boolean flag) { if (flag) { this.categoryLabelPositions = CategoryLabelPositions.UP_90; } else { this.categoryLabelPositions = CategoryLabelPositions.STANDARD; } notifyListeners(new AxisChangeEvent(this)); } /** * Returns the flag that determines whether the category labels are to be * skipped to avoid overlapping. * * @return The flag. * * @deprecated No longer supported. */ public boolean getSkipCategoryLabelsToFit() { return false; } /** * Sets the flag that determines whether the category labels are to be * skipped to avoid overlapping. * * @param flag the new value of the flag. * * @deprecated No longer supported. */ public void setSkipCategoryLabelsToFit(boolean flag) { // not supported any more } /** * Returns the category label positioning info that applies when the axis is displayed * at the top of the plot area. * * @return the position info. * * @deprecated Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.TOP). */ public CategoryLabelPosition getTopCategoryLabelPosition() { return getCategoryLabelPositions().getLabelPosition(RectangleEdge.TOP); } /** * Sets the position info that applies when the axis is displayed at the top of the * plot area. * * @param position the position info. * * @deprecated Use setCategoryLabelPositions(...). */ public void setTopCategoryLabelPosition(CategoryLabelPosition position) { setCategoryLabelPositions(new CategoryLabelPositions( position, this.categoryLabelPositions.getLabelPosition(RectangleEdge.BOTTOM), this.categoryLabelPositions.getLabelPosition(RectangleEdge.LEFT), this.categoryLabelPositions.getLabelPosition(RectangleEdge.RIGHT) ) ); } /** * Returns the category label positioning info that applies when the axis is displayed * at the bottom of the plot area. * * @return the position info. * * @deprecated Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.BOTTOM). */ public CategoryLabelPosition getBottomCategoryLabelPosition() { return getCategoryLabelPositions().getLabelPosition(RectangleEdge.BOTTOM); } /** * Sets the position info that applies when the axis is displayed at the bottom of the * plot area. * * @param position the position info. * * @deprecated Use setCategoryLabelPositions(...). */ public void setBottomCategoryLabelPosition(CategoryLabelPosition position) { setCategoryLabelPositions(new CategoryLabelPositions( this.categoryLabelPositions.getLabelPosition(RectangleEdge.TOP), position, this.categoryLabelPositions.getLabelPosition(RectangleEdge.LEFT), this.categoryLabelPositions.getLabelPosition(RectangleEdge.RIGHT) ) ); } /** * Returns the category label positioning info that applies when the axis is displayed * at the left of the plot area. * * @return the position info. * * @deprecated Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT). */ public CategoryLabelPosition getLeftCategoryLabelPosition() { return getCategoryLabelPositions().getLabelPosition(RectangleEdge.LEFT); } /** * Sets the position info that applies when the axis is displayed at the left of the * plot area. * * @param position the position info. * * @deprecated Use setCategoryLabelPositions(...). */ public void setLeftCategoryLabelPosition(CategoryLabelPosition position) { setCategoryLabelPositions(new CategoryLabelPositions( this.categoryLabelPositions.getLabelPosition(RectangleEdge.TOP), this.categoryLabelPositions.getLabelPosition(RectangleEdge.BOTTOM), position, this.categoryLabelPositions.getLabelPosition(RectangleEdge.RIGHT) ) ); } /** * Returns the category label positioning info that applies when the axis is displayed * at the right of the plot area. * * @return the position info. * * @deprecated Use getCategoryLabelPositions().getLabelPosition(RectangleEdge.RIGHT). */ public CategoryLabelPosition getRightCategoryLabelPosition() { return getCategoryLabelPositions().getLabelPosition(RectangleEdge.RIGHT); } /** * Sets the position info that applies when the axis is displayed at the right of the * plot area. * * @param position the position info. * * @deprecated Use setLabelPositions(...). */ public void setRightCategoryLabelPosition(CategoryLabelPosition position) { setCategoryLabelPositions(new CategoryLabelPositions( this.categoryLabelPositions.getLabelPosition(RectangleEdge.TOP), this.categoryLabelPositions.getLabelPosition(RectangleEdge.BOTTOM), this.categoryLabelPositions.getLabelPosition(RectangleEdge.LEFT), position ) ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -