List of usage examples for org.jfree.chart.axis CategoryLabelPosition getLabelAnchor
public TextBlockAnchor getLabelAnchor()
From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpressionTest.java
@Test public void testCreateUpRotationCategoryLabelPosition() { TestableCategoricalChartExpression e = new TestableCategoricalChartExpression(); {// ww w.j av a 2 s .c o m CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, 0.0); Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.TOP_CENTER, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.TOP_CENTER, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, 90.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.CENTER_RIGHT, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.CENTER_RIGHT, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, -90.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, 180.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.TOP, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.BOTTOM_CENTER, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.BOTTOM_CENTER, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, 0.0); Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.CENTER_RIGHT, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.CENTER_RIGHT, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, 90.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.BOTTOM_CENTER, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.BOTTOM_CENTER, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, -90.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.TOP_CENTER, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.TOP_CENTER, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, 180.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.RIGHT, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.TOP, 0.0); Assert.assertEquals(RectangleAnchor.BOTTOM, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.BOTTOM_CENTER, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.BOTTOM_CENTER, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.TOP, 90.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.BOTTOM, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, 0.0); Assert.assertEquals(RectangleAnchor.LEFT, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.CENTER_LEFT, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.CENTER_LEFT, c.getRotationAnchor()); } { CategoryLabelPosition c = e.createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, 90.0 * Math.PI / 180.0); Assert.assertEquals(RectangleAnchor.LEFT, c.getCategoryAnchor()); Assert.assertEquals(TextBlockAnchor.TOP_CENTER, c.getLabelAnchor()); Assert.assertEquals(TextAnchor.TOP_CENTER, c.getRotationAnchor()); } }
From source file:org.jfree.eastwood.GCategoryAxis.java
/** * 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./*ww w . jav a2s . co m*/ * @param dataArea the area inside the axes. * @param edge the location of the axis. * * @return A list of ticks. */ public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, 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 = null; if (this.labels == null) { categories = plot.getCategories(); } else { categories = new java.util.ArrayList(this.labels); // handle a little quirk in the Google Chart API - for a horizontal // bar chart, the labels on the axis get applied in reverse order // relative to the data values if (plot.getOrientation() == PlotOrientation.HORIZONTAL) { Collections.reverse(categories); } } double max = 0.0; if (categories != null) { CategoryLabelPosition position = getCategoryLabelPositions().getLabelPosition(edge); float r = getMaximumCategoryLabelWidthRatio(); 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; }
From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//w w w . j av a2s. c om public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, 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.getCategoriesForAxis(this); double max = 0.0; if (categories != null) { CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge); float r = this.getMaximumCategoryLabelWidthRatio(); 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(); try { Integer intcategory = Integer.valueOf(category.toString()); int modulus = intcategory % labelEveryXCategories; if (modulus != 0) category = " "; } catch (NumberFormatException e) { } 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; }
From source file:hudson.util.NoOverlapCategoryAxis.java
@Override protected AxisState drawCategoryLabels(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, RectangleEdge edge, AxisState state, PlotRenderingInfo plotState) { if (state == null) { throw new IllegalArgumentException("Null 'state' argument."); }// w w w. j a va 2s. c o m if (isTickLabelsVisible()) { java.util.List ticks = refreshTicks(g2, state, plotArea, edge); state.setTicks(ticks); // remember the last drawn label so that we can avoid drawing overlapping labels. Rectangle2D r = null; int categoryIndex = 0; Iterator iterator = ticks.iterator(); while (iterator.hasNext()) { CategoryTick tick = (CategoryTick) iterator.next(); g2.setFont(getTickLabelFont(tick.getCategory())); g2.setPaint(getTickLabelPaint(tick.getCategory())); CategoryLabelPosition position = this.getCategoryLabelPositions().getLabelPosition(edge); double x0 = 0.0; double x1 = 0.0; double y0 = 0.0; double y1 = 0.0; if (edge == RectangleEdge.TOP) { x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); y1 = state.getCursor() - this.getCategoryLabelPositionOffset(); y0 = y1 - state.getMax(); } else if (edge == RectangleEdge.BOTTOM) { x0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); x1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); y0 = state.getCursor() + this.getCategoryLabelPositionOffset(); y1 = y0 + state.getMax(); } else if (edge == RectangleEdge.LEFT) { y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); x1 = state.getCursor() - this.getCategoryLabelPositionOffset(); x0 = x1 - state.getMax(); } else if (edge == RectangleEdge.RIGHT) { y0 = getCategoryStart(categoryIndex, ticks.size(), dataArea, edge); y1 = getCategoryEnd(categoryIndex, ticks.size(), dataArea, edge); x0 = state.getCursor() + this.getCategoryLabelPositionOffset(); x1 = x0 - state.getMax(); } Rectangle2D area = new Rectangle2D.Double(x0, y0, (x1 - x0), (y1 - y0)); if (r == null || !r.intersects(area)) { Point2D anchorPoint = RectangleAnchor.coordinates(area, position.getCategoryAnchor()); TextBlock block = tick.getLabel(); block.draw(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); Shape bounds = block.calculateBounds(g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getLabelAnchor(), (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getAngle()); if (plotState != null && plotState.getOwner() != null) { EntityCollection entities = plotState.getOwner().getEntityCollection(); if (entities != null) { String tooltip = getCategoryLabelToolTip(tick.getCategory()); entities.add(new CategoryLabelEntity(tick.getCategory(), bounds, tooltip, null)); } } r = bounds.getBounds2D(); } categoryIndex++; } if (edge.equals(RectangleEdge.TOP)) { double h = state.getMax(); state.cursorUp(h); } else if (edge.equals(RectangleEdge.BOTTOM)) { double h = state.getMax(); state.cursorDown(h); } else if (edge == RectangleEdge.LEFT) { double w = state.getMax(); state.cursorLeft(w); } else if (edge == RectangleEdge.RIGHT) { double w = state.getMax(); state.cursorRight(w); } } return state; }