List of usage examples for org.jfree.chart.plot CategoryPlot getCategoriesForAxis
public List getCategoriesForAxis(CategoryAxis axis)
From source file:org.fhaes.fhrecorder.util.NumericCategoryAxis.java
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*from w ww. j a v a 2s . co m*/
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:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java
@SuppressWarnings("unchecked") @Override/*from www. ja va 2 s . c om*/ 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 categories = plot.getCategoriesForAxis(this); int tickEvery = categories.size() / (maxLabeledTicks == 0 ? 1 : maxLabeledTicks); if (tickEvery < 1) { tickEvery = 1; } if (edge.equals(RectangleEdge.TOP)) { Iterator iterator = categories.iterator(); int i = 0; while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); if (i % tickEvery == 0) { double x = getCategoryMiddle(key, categories, dataArea, edge); g2.setPaint(getTickMarkPaint()); g2.setStroke(getTickMarkStroke()); line.setLine(x, cursor, x, cursor + il); g2.draw(line); line.setLine(x, cursor, x, cursor - ol); g2.draw(line); if (domainGridlinePaint != null) { drawDomainGridline(g2, plot, dataArea, x); } } i++; } state.cursorUp(ol); } else if (edge.equals(RectangleEdge.BOTTOM)) { Iterator iterator = categories.iterator(); int i = 0; while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); if (i % tickEvery == 0) { double x = getCategoryMiddle(key, categories, dataArea, edge); g2.setPaint(getTickMarkPaint()); g2.setStroke(getTickMarkStroke()); line.setLine(x, cursor, x, cursor - il); g2.draw(line); line.setLine(x, cursor, x, cursor + ol); g2.draw(line); if (domainGridlinePaint != null) { drawDomainGridline(g2, plot, dataArea, x); } } i++; } state.cursorDown(ol); } else if (edge.equals(RectangleEdge.LEFT)) { Iterator iterator = categories.iterator(); int i = 0; while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); if (i % tickEvery == 0) { double y = getCategoryMiddle(key, categories, dataArea, edge); g2.setPaint(getTickMarkPaint()); g2.setStroke(getTickMarkStroke()); line.setLine(cursor, y, cursor + il, y); g2.draw(line); line.setLine(cursor, y, cursor - ol, y); g2.draw(line); if (domainGridlinePaint != null) { drawDomainGridline(g2, plot, dataArea, y); } } i++; } state.cursorLeft(ol); } else if (edge.equals(RectangleEdge.RIGHT)) { Iterator iterator = categories.iterator(); int i = 0; while (iterator.hasNext()) { Comparable key = (Comparable) iterator.next(); if (i % tickEvery == 0) { double y = getCategoryMiddle(key, categories, dataArea, edge); g2.setPaint(getTickMarkPaint()); g2.setStroke(getTickMarkStroke()); line.setLine(cursor, y, cursor - il, y); g2.draw(line); line.setLine(cursor, y, cursor + ol, y); g2.draw(line); if (domainGridlinePaint != null) { drawDomainGridline(g2, plot, dataArea, y); } } i++; } state.cursorRight(ol); } }