/** * Creates a temporary list of ticks that can be used when drawing the axis. * * @param g2 the graphics device (used to get font measurements). * @param state the axis state. * @param dataArea the area inside the axes. * @param edge the location of the axis. * @return A list of ticks. */ @Override public List<CategoryTick> refreshTicks( Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List<CategoryTick> ticks = new java.util.ArrayList<CategoryTick>(); // sanity check for data area... if (dataArea.getHeight() <= 0.0 || dataArea.getWidth() < 0.0) { return ticks; } CategoryPlot plot = (CategoryPlot) getPlot(); List<Comparable> categories = plot.getCategoriesForAxis(this); double max = 0.0; if (categories != null) { CategoryLabelPosition position = this.categoryLabelPositions.getLabelPosition(edge); float r = this.maximumCategoryLabelWidthRatio; if (r <= 0.0) { r = position.getWidthRatio(); } float l; 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; for (Comparable category : categories) { g2.setFont(getTickLabelFont(category)); 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)); } ticks.add( new CategoryTick( category, label, position.getLabelAnchor(), position.getRotationAnchor(), position.getAngle())); categoryIndex = categoryIndex + 1; } } state.setMax(max); return ticks; }
/** * Draws the tick marks. This method is called during chart rendering, you normally would not call * this method yourself. * * @param g2 the graphics target ({@code null} not permitted) * @param cursor the current offset from the edge of the dataArea * @param dataArea the area used for plotting data ({@code null} not permitted) * @param edge the location of the axis ({@code null} not permitted) * @param state axis state information ({@code null} not permitted) * @since 1.0.13 */ public void drawTickMarks( Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge, AxisState state) { Plot p = getPlot(); if (p == null) { return; } CategoryPlot plot = (CategoryPlot) p; double il = getTickMarkInsideLength(); double ol = getTickMarkOutsideLength(); Line2D line = new Line2D.Double(); List<Comparable> categories = plot.getCategoriesForAxis(this); g2.setPaint(getTickMarkPaint()); g2.setStroke(getTickMarkStroke()); if (edge.equals(RectangleEdge.TOP)) { for (Comparable key : categories) { double x = getCategoryMiddle(key, categories, dataArea, edge); line.setLine(x, cursor, x, cursor + il); g2.draw(line); line.setLine(x, cursor, x, cursor - ol); g2.draw(line); } state.cursorUp(ol); } else if (edge.equals(RectangleEdge.BOTTOM)) { for (Comparable key : categories) { double x = getCategoryMiddle(key, categories, dataArea, edge); line.setLine(x, cursor, x, cursor - il); g2.draw(line); line.setLine(x, cursor, x, cursor + ol); g2.draw(line); } state.cursorDown(ol); } else if (edge.equals(RectangleEdge.LEFT)) { for (Comparable key : categories) { double y = getCategoryMiddle(key, categories, dataArea, edge); line.setLine(cursor, y, cursor + il, y); g2.draw(line); line.setLine(cursor, y, cursor - ol, y); g2.draw(line); } state.cursorLeft(ol); } else if (edge.equals(RectangleEdge.RIGHT)) { for (Comparable key : categories) { double y = getCategoryMiddle(key, categories, dataArea, edge); line.setLine(cursor, y, cursor - il, y); g2.draw(line); line.setLine(cursor, y, cursor + ol, y); g2.draw(line); } state.cursorRight(ol); } }