Search in sources :

Example 1 with NumberTickUnit

use of org.jfree.chart.axis.NumberTickUnit in project processdash by dtuma.

the class DiscLegendAxis method selectVerticalAutoTickUnit.

@Override
protected void selectVerticalAutoTickUnit(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // the font used to display tick marks requires labels to be placed
    // at least this far apart.
    double tickLabelHeight = estimateMaximumTickLabelHeight(g2);
    // our tick marks get closer together as the values get larger. So
    // if we have a collision, it would be at the very top end of the
    // axis. We want to calculate a tick unit that will avoid that
    // collision. So first, we will find the pixel position of a
    // hypothetical tick mark drawn for the largest domain value.
    Range r = getRange();
    double maxValue = r.getUpperBound();
    double maxY = valueToJava2D(maxValue, dataArea, edge);
    // So far, we've identified a hypothetical tick mark placed at the
    // highest known domain value. If we drew another tick mark just
    // underneath it (one tick label height away), what domain value would
    // that hypothetical second-to-largest tick mark represent?
    double nextY = maxY + tickLabelHeight;
    double nextValue = java2DToValue(nextY, dataArea, edge);
    // calculate the numerical difference between these two domain values.
    // Then pick the tick unit that is larger, to avoid collisions.
    double amountBetweenTicks = maxValue - nextValue;
    NumberTickUnit unit = (NumberTickUnit) getStandardTickUnits().getCeilingTickUnit(amountBetweenTicks);
    setTickUnit(unit, false, false);
}
Also used : Range(org.jfree.data.Range) NumberTickUnit(org.jfree.chart.axis.NumberTickUnit)

Aggregations

NumberTickUnit (org.jfree.chart.axis.NumberTickUnit)1 Range (org.jfree.data.Range)1