Example usage for org.jfree.chart.axis CategoryTick getCategory

List of usage examples for org.jfree.chart.axis CategoryTick getCategory

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryTick getCategory.

Prototype

public Comparable getCategory() 

Source Link

Document

Returns the category.

Usage

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.  j  ava2  s.  co 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: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.");
    }/*from  ww w .j  a va  2  s.  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;
}

From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java

@SuppressWarnings("unchecked")
@Override/*from  w  w w. ja  v a2  s .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;
}