List of usage examples for org.jfree.chart.axis CategoryTick CategoryTick
public CategoryTick(Comparable category, TextBlock label, TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, double angle)
From source file:dk.sdu.mmmi.featureous.views.codecharacterization.SparselyLabeledCategoryAxis.java
@Override @SuppressWarnings("unchecked") public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List<CategoryTick> standardTicks = super.refreshTicks(g2, state, dataArea, edge); if (standardTicks.isEmpty()) { return standardTicks; }/*from w w w . ja v a 2 s.c o m*/ int tickEvery = standardTicks.size() / labeledTicks; if (tickEvery < 1) { return standardTicks; } //Replace a few labels with blank ones List<CategoryTick> fixedTicks = new ArrayList<CategoryTick>(standardTicks.size()); //Skip the first tick so your 45degree labels don't fall of the edge CategoryTick tick = standardTicks.get(0); fixedTicks.add(new CategoryTick(tick.getCategory(), new TextBlock(), tick.getLabelAnchor(), tick.getRotationAnchor(), tick.getAngle())); for (int i = 1; i < standardTicks.size(); i++) { tick = standardTicks.get(i); if (i % tickEvery == 0) { fixedTicks.add(tick); } else { fixedTicks.add(new CategoryTick(tick.getCategory(), new TextBlock(), tick.getLabelAnchor(), tick.getRotationAnchor(), tick.getAngle())); } } return fixedTicks; }
From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*ww w .j ava 2s . 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: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.//from w w w. j a v a2s . com * @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:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java
@SuppressWarnings("unchecked") @Override//from w w w .j a va2s . c o m public List<CategoryTick> refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { List<CategoryTick> standardTicks = super.refreshTicks(g2, state, dataArea, edge); if (standardTicks.isEmpty()) { return standardTicks; } int tickEvery = standardTicks.size() / (maxLabeledTicks == 0 ? 1 : maxLabeledTicks); if (tickEvery < 1) { return standardTicks; } // replace some labels with blank ones List<CategoryTick> fixedTicks = new ArrayList<CategoryTick>(standardTicks.size()); for (int i = 0; i < standardTicks.size(); i++) { CategoryTick tick = standardTicks.get(i); if (i % tickEvery == 0) { fixedTicks.add(tick); } else { fixedTicks.add(new CategoryTick(tick.getCategory(), new TextBlock(), tick.getLabelAnchor(), tick.getRotationAnchor(), tick.getAngle())); } } return fixedTicks; }