Example usage for org.jfree.chart.axis NumberTick NumberTick

List of usage examples for org.jfree.chart.axis NumberTick NumberTick

Introduction

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

Prototype

public NumberTick(Number number, String label, TextAnchor textAnchor, TextAnchor rotationAnchor, double angle) 

Source Link

Document

Creates a new tick.

Usage

From source file:com.epiq.bitshark.ui.PowerAxis.java

/**
 * //from   w ww.  ja v a2  s. com
 * @param g2
 * @param state
 * @param dataArea
 * @param edge
 * @return
 */
@Override
public List refreshTicks(java.awt.Graphics2D g2, AxisState state, java.awt.geom.Rectangle2D dataArea,
        org.jfree.ui.RectangleEdge edge) {

    List<NumberTick> tickList = new ArrayList<NumberTick>();

    for (int i = -50; i < 180; i += 10) {
        tickList.add(new NumberTick(new Double(i), String.format("%d dB", (int) Math.round(valueToDb(i))),
                TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0));
    }

    return tickList;
}

From source file:inflor.core.plots.CategoricalNumberAxis.java

@Override
public List<NumberTick> refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
    List<NumberTick> ticks = new ArrayList<>();
    for (Entry<Integer, String> entry : labelMap.entrySet()) {
        ticks.add(new NumberTick(entry.getKey(), entry.getValue(), TextAnchor.CENTER_RIGHT, TextAnchor.CENTER,
                0));//from w w w .java 2 s. com
    }
    return ticks;
}

From source file:inflor.core.plots.LogicleNumberAxis.java

@Override
public List<NumberTick> refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
    List<NumberTick> ticks = new ArrayList<>();
    double[] suggestedTicks = logicle.getAxisValues();
    if (suggestedTicks[0] >= 0) {
        double tick1Value = logicle.getMinTranformedValue();
        double tick2Value = logicle.transform(Math.abs(logicle.getMinRawValue()));

        String label1 = this.getNumberFormatOverride().format(tick1Value);
        String label2 = this.getNumberFormatOverride().format(tick2Value);

        ticks.add(new NumberTick(tick1Value, label1, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER, 0));
        ticks.add(new NumberTick(tick2Value, label2, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER, 0));
    }/*from   w  ww . j a  va  2s . c om*/

    for (double value : suggestedTicks) {
        double td = logicle.transform(value);
        double tickDangerRatio = 0;
        if (ticks.size() >= 2) {
            double firstPositiveTick = logicle.inverse(ticks.get(1).getValue());
            tickDangerRatio = value / firstPositiveTick;
        }
        if (tickDangerRatio < 0.5 || tickDangerRatio > 2) {
            String label = this.getNumberFormatOverride().format(td);
            NumberTick tick = new NumberTick(td, label, TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER, 0);
            ticks.add(tick);
        }
    }
    return ticks;
}

From source file:com.epiq.bitshark.ui.FrequencyAxis.java

/**
 * //ww w  .j  a  v  a2 s. c  o  m
 * @param g2
 * @param state
 * @param dataArea
 * @param edge
 * @return
 */
@Override
public List refreshTicks(java.awt.Graphics2D g2, AxisState state, java.awt.geom.Rectangle2D dataArea,
        org.jfree.ui.RectangleEdge edge) {

    List<NumberTick> tickList = new ArrayList<NumberTick>();

    // start
    tickList.add(new NumberTick(0, toMhzString(center - (rate / 2.0)), TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER, 0));

    // half down
    tickList.add(new NumberTick((FMCUartClient.BLOCK_SIZE - 1) * .25, toMhzString(center - (rate / 4.0)),
            TextAnchor.CENTER, TextAnchor.CENTER, 0));

    // center
    tickList.add(new NumberTick((FMCUartClient.BLOCK_SIZE - 1) * .5, toMhzString(center), TextAnchor.CENTER,
            TextAnchor.CENTER, 0));

    // half up
    tickList.add(new NumberTick((FMCUartClient.BLOCK_SIZE - 1) * .75, toMhzString(center + (rate / 4.0)),
            TextAnchor.CENTER, TextAnchor.CENTER, 0));

    // end
    tickList.add(new NumberTick(FMCUartClient.BLOCK_SIZE - 1, toMhzString(center + (rate / 2.0)),
            TextAnchor.CENTER_RIGHT, TextAnchor.CENTER, 0));

    return tickList;
}

From source file:org.jstockchart.axis.TimeseriesNumberAxis.java

private static List<Tick> createTicks(List<LogicNumberTick> logicNumberTicks, TextAnchor anchor,
        TextAnchor rotationAnchor, double angle) {
    List<Tick> result = new ArrayList<Tick>();
    for (int i = 0; i < logicNumberTicks.size(); i++) {
        LogicNumberTick buf = (LogicNumberTick) logicNumberTicks.get(i);
        result.add(new NumberTick(buf.getTickNumber(), buf.getTickLabel(), anchor, rotationAnchor, angle));
    }/*from  w w w .jav a  2s.  co  m*/

    return result;
}

From source file:de.cebitec.readXplorer.plotting.CreatePlots.java

private synchronized static JFreeChart createCombinedChart(XYSeriesCollection normal, XYSeriesCollection posInf,
        XYSeriesCollection negInf, String xName, String yName, XYToolTipGenerator toolTip) {

    final NumberAxis domainAxis = new NumberAxis(xName);

    // create subplot 1...
    final XYDataset data1 = normal;
    final XYItemRenderer renderer1 = new XYShapeRenderer();
    renderer1.setBaseToolTipGenerator(toolTip);
    final NumberAxis rangeAxis1 = new NumberAxis(yName);
    final XYPlot subplot1 = new XYPlot(data1, domainAxis, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // create subplot 2...
    final XYDataset data2 = negInf;
    final XYItemRenderer renderer2 = new XYShapeRenderer();
    renderer2.setBaseToolTipGenerator(toolTip);
    final NumberAxis rangeAxis2 = new NumberAxis() {
        @Override//from ww w.j  ava  2 s. com
        public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
            List myTicks = new ArrayList();
            myTicks.add(new NumberTick(0, "-Inf", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
            return myTicks;
        }
    };
    rangeAxis2.setAutoRangeIncludesZero(false);
    final XYPlot subplot2 = new XYPlot(data2, domainAxis, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // create subplot 3...
    final XYDataset data3 = posInf;
    final XYItemRenderer renderer3 = new XYShapeRenderer();
    renderer3.setBaseToolTipGenerator(toolTip);
    final NumberAxis rangeAxis3 = new NumberAxis() {
        @Override
        public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
            List myTicks = new ArrayList();
            myTicks.add(new NumberTick(0, "Inf", TextAnchor.CENTER_RIGHT, TextAnchor.CENTER_RIGHT, 0.0));
            return myTicks;
        }
    };
    rangeAxis3.setAutoRangeIncludesZero(false);
    final XYPlot subplot3 = new XYPlot(data3, domainAxis, rangeAxis3, renderer3);
    subplot2.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // parent plot...
    final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domainAxis);
    plot.setGap(0);

    // add the subplots...
    plot.add(subplot3, 1);
    plot.add(subplot1, 10);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);

    // return a new chart containing the overlaid plot...
    return new JFreeChart(plot);

}

From source file:org.jfree.eastwood.GValueAxis.java

/**
 * Creates and returns a list of ticks to display for the
 * axis.//from w  w w.  j av a 2s .  c om
 *
 * @param g2  the graphics target.
 * @param state
 * @param dataArea
 * @param edge
 *
 * @return The list.
 */
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

    if (this.tickLabels.isEmpty()) {

        // here we auto-generate the axis labels using a non-visible axis
        // first we must align the axis range
        boolean inverted = (this.labelAxisStart > this.labelAxisEnd);
        double range = this.labelAxisEnd - this.labelAxisStart;
        double v0 = this.labelAxisStart + getLowerBound() * range;
        double v1 = this.labelAxisStart + getUpperBound() * range;
        this.axisForAutoLabels.setRange(Math.min(v0, v1), Math.max(v0, v1));
        this.axisForAutoLabels.setInverted(inverted);

        List ticks = this.axisForAutoLabels.refreshTicks(g2, state, dataArea, edge);
        // now we must 'normalise' the tick positions into the range
        // 0.0 to 1.0
        List normalisedTicks = new java.util.ArrayList();
        double min = Math.min(this.labelAxisStart, this.labelAxisEnd);
        double max = Math.max(this.labelAxisStart, this.labelAxisEnd);
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            NumberTick tick = (NumberTick) iterator.next();
            double v = tick.getValue();
            double vv = (v - min) / (max - min);
            if (this.axisForAutoLabels.isInverted()) {
                vv = 1.0 - vv;
            }
            normalisedTicks.add(new NumberTick(new Double(vv), tick.getText(), tick.getTextAnchor(),
                    tick.getRotationAnchor(), tick.getAngle()));
        }
        return normalisedTicks;
    }

    List result = new java.util.ArrayList();
    int labelCount = this.tickLabels.size();
    int positionCount = this.tickLabelPositions.size();
    int tickCount = Math.max(labelCount, positionCount);

    // work out the label anchor points according to which side of the
    // chart the axis lies on...
    TextAnchor anchor = null;
    TextAnchor rotationAnchor = TextAnchor.CENTER;
    if (edge == RectangleEdge.LEFT) {
        anchor = TextAnchor.CENTER_RIGHT;
    } else if (edge == RectangleEdge.BOTTOM) {
        anchor = TextAnchor.TOP_CENTER;
    } else if (edge == RectangleEdge.TOP) {
        anchor = TextAnchor.BOTTOM_CENTER;
    } else if (edge == RectangleEdge.RIGHT) {
        anchor = TextAnchor.CENTER_LEFT;
    }

    for (int i = 0; i < tickCount; i++) {
        String tickLabel = null;
        if (i < labelCount) {
            tickLabel = this.tickLabels.get(i).toString();
        } else {
            tickLabel = String.valueOf(this.tickLabelPositions.get(i));
        }

        // is there a value specified
        double tickValue = Double.NaN;
        if (i < positionCount) {
            Number tv = (Number) this.tickLabelPositions.get(i);
            if (tv != null) {
                tickValue = (tv.doubleValue() - this.labelAxisStart)
                        / (this.labelAxisEnd - this.labelAxisStart);
            }
        }
        if (Double.isNaN(tickValue)) {
            tickValue = (i * (1.0 / (Math.max(labelCount - 1, 1))));
        }
        Tick tick = new NumberTick(new Double(tickValue), tickLabel, anchor, rotationAnchor, 0.0);

        result.add(tick);
    }
    return result;
}

From source file:org.gumtree.vis.plot1d.KLogarithmicAxis.java

@Override
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    // TODO Auto-generated method stub
    List ticks = new java.util.ArrayList();
    Range range = getRange();//from  w ww  .  j  a  v  a2  s .c o  m

    //get lower bound value:
    double lowerBoundVal = range.getLowerBound();
    //if small log values and lower bound value too small
    // then set to a small value (don't allow <= 0):
    if (this.smallLogFlag && lowerBoundVal < SMALL_LOG_VALUE) {
        lowerBoundVal = SMALL_LOG_VALUE;
    }

    //get upper bound value
    double upperBoundVal = range.getUpperBound();

    //get log10 version of lower bound and round to integer:
    int iBegCount = (int) Math.rint(switchedLog10(lowerBoundVal));
    //get log10 version of upper bound and round to integer:
    int iEndCount = (int) Math.rint(switchedLog10(upperBoundVal));

    //        if (iBegCount == iEndCount && iBegCount >= 0
    if (iBegCount == iEndCount && Math.pow(10, iBegCount) > lowerBoundVal) {
        //only 1 power of 10 value, it's > 0 and its resulting
        // tick value will be larger than lower bound of data
        --iBegCount; //decrement to generate more ticks
    }

    int numberOfGrids = 0;
    int numberOfTicks = 0;
    NumberTick lastTick = null;

    double currentTickValue;
    String tickLabel;
    boolean zeroTickFlag = false;
    for (int i = iBegCount; i <= iEndCount; i++) {
        //for each power of 10 value; create ten ticks
        for (int j = 0; j < 10; ++j) {
            //for each tick to be displayed
            if (this.smallLogFlag) {
                //small log values in use; create numeric value for tick
                currentTickValue = Math.pow(10, i) + (Math.pow(10, i) * j);
                if (this.expTickLabelsFlag || (i < 0 && currentTickValue > 0.0 && currentTickValue < 1.0)) {
                    //showing "1e#"-style ticks or negative exponent
                    // generating tick value between 0 & 1; show fewer
                    if (j == 0 || (i > -4 && (j < 2 || j == 4)) || currentTickValue >= upperBoundVal) {
                        //first tick of series, or not too small a value and
                        // one of first 3 ticks, or last tick to be displayed
                        // set exact number of fractional digits to be shown
                        // (no effect if showing "1e#"-style ticks):
                        this.numberFormatterObj.setMaximumFractionDigits(-i);
                        //create tick label (force use of fmt obj):
                        tickLabel = makeTickLabel(currentTickValue, true);
                    } else { //no tick label to be shown
                        //                            tickLabel = "";
                        if (numberOfTicks == 0) {
                            tickLabel = makeTickLabel(currentTickValue, true);
                        } else
                            tickLabel = "";
                    }
                } else { //tick value not between 0 & 1
                         //show tick label if it's the first or last in
                         // the set, or if it's 1-5; beyond that show
                         // fewer as the values get larger:
                    tickLabel = (j < 1 || (i < 1 && j < 5) || (j < 4 - i) || currentTickValue >= upperBoundVal
                            || numberOfTicks == 0) ? makeTickLabel(currentTickValue) : "";
                }
            } else { //not small log values in use; allow for values <= 0
                if (zeroTickFlag) { //if did zero tick last iter then
                    --j; //decrement to do 1.0 tick now
                } //calculate power-of-ten value for tick:
                currentTickValue = (i >= 0) ? Math.pow(10, i) + (Math.pow(10, i) * j)
                        : -(Math.pow(10, -i) - (Math.pow(10, -i - 1) * j));
                if (!zeroTickFlag) { // did not do zero tick last iteration
                    if (Math.abs(currentTickValue - 1.0) < 0.0001 && lowerBoundVal <= 0.0
                            && upperBoundVal >= 0.0) {
                        //tick value is 1.0 and 0.0 is within data range
                        currentTickValue = 0.0; //set tick value to zero
                        zeroTickFlag = true; //indicate zero tick
                    }
                } else { //did zero tick last iteration
                    zeroTickFlag = false; //clear flag
                } //create tick label string:
                //show tick label if "1e#"-style and it's one
                // of the first two, if it's the first or last
                // in the set, or if it's 1-5; beyond that
                // show fewer as the values get larger:
                tickLabel = ((this.expTickLabelsFlag && j < 2) || j < 1 || (i < 1 && j < 5) || (j < 4 - i)
                        || currentTickValue >= upperBoundVal || numberOfTicks == 0)
                                ? makeTickLabel(currentTickValue)
                                : "";
            }

            if (currentTickValue > upperBoundVal) {
                if (lastTick != null) {
                    String lastTickText = lastTick.getText();
                    if (lastTickText == null || lastTickText.trim().length() == 0) {
                        ticks.remove(lastTick);
                        ticks.add(new NumberTick(lastTick.getValue(),
                                createTickLabel(lastTick.getValue(), i - 1), lastTick.getTextAnchor(),
                                lastTick.getRotationAnchor(), lastTick.getAngle()));
                    }
                }
                if (numberOfTicks < 4) {
                    return getAllTicksHorizontal(g2, dataArea, edge);
                }
                return ticks; // if past highest data value then exit
                              // method
            }

            if (currentTickValue >= lowerBoundVal - SMALL_LOG_VALUE) {
                //tick value not below lowest data value
                TextAnchor anchor = null;
                TextAnchor rotationAnchor = null;
                double angle = 0.0;
                if (isVerticalTickLabels()) {
                    anchor = TextAnchor.CENTER_RIGHT;
                    rotationAnchor = TextAnchor.CENTER_RIGHT;
                    if (edge == RectangleEdge.TOP) {
                        angle = Math.PI / 2.0;
                    } else {
                        angle = -Math.PI / 2.0;
                    }
                } else {
                    if (edge == RectangleEdge.TOP) {
                        anchor = TextAnchor.BOTTOM_CENTER;
                        rotationAnchor = TextAnchor.BOTTOM_CENTER;
                    } else {
                        anchor = TextAnchor.TOP_CENTER;
                        rotationAnchor = TextAnchor.TOP_CENTER;
                    }
                }

                lastTick = new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor,
                        angle);
                ticks.add(lastTick);
                if (tickLabel != null && tickLabel.trim().length() > 0)
                    numberOfTicks++;
                numberOfGrids++;
            }
        }
    }
    if (numberOfTicks < 4) {
        return getAllTicksHorizontal(g2, dataArea, edge);
    }
    return ticks;
}

From source file:userinterface.graph.Histogram.java

/**
 * Make a custom X axis so that we can control the tick marker locations
 *//*from  w  w  w.jav a2s.  c o  m*/
public void setCustomDomainAxis() {

    plot.setDomainAxis(new NumberAxis("Probability") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings({ "rawtypes", "unchecked" })
        @Override
        public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {

            List list = new ArrayList<>();

            for (Double d : ticks) {

                double rounded = Math.round(d * 1000);

                rounded = rounded / 1000;

                list.add(new NumberTick(rounded, rounded + "", TextAnchor.TOP_CENTER, TextAnchor.TOP_CENTER,
                        0.0));

            }

            return list;
        }

    });
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.charts.MyLogarithmicAxis.java

/**
 * Main change of Logarithmic class that overwrites super method. Calculates the values of the
 * System.out.println("Upper = " + aUpper + "\tCeiling = " + ceiling); tick labels for the axis, storing
 * the results in the tick label list (ready for drawing).
 * //  w  w w  .  j  ava2 s . c  o m
 * @param g2 the graphics device.
 * @param dataArea the area in which the plot should be drawn.
 * @param edge Rectangle edge for axis location.
 * @return A list of ticks.
 */
@Override
public List<?> refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

    // Ticklist that has to be filled with sensible values
    List<Tick> ticks = new ArrayList<Tick>();

    // Formatting of the tick labels
    TextAnchor anchor = null;
    TextAnchor rotationAnchor = null;
    double angle = 0.0;
    if (isVerticalTickLabels()) {
        if (edge == RectangleEdge.LEFT) {
            anchor = TextAnchor.BOTTOM_CENTER;
            rotationAnchor = TextAnchor.BOTTOM_CENTER;
            angle = -Math.PI / 2.0;
        } else {
            anchor = TextAnchor.BOTTOM_CENTER;
            rotationAnchor = TextAnchor.BOTTOM_CENTER;
            angle = Math.PI / 2.0;
        }
    } else {
        if (edge == RectangleEdge.LEFT) {
            anchor = TextAnchor.CENTER_RIGHT;
            rotationAnchor = TextAnchor.CENTER_RIGHT;
        } else {
            anchor = TextAnchor.TOP_CENTER;
            rotationAnchor = TextAnchor.TOP_CENTER;
        }
    }

    List<Double> myticks = new ArrayList<Double>();

    double lowerBound = dataRange.getLowerBound();
    double upperBound = dataRange.getUpperBound();

    // Select minimal tick set that fully contains the data range
    for (int i = 0; i < allticks.length - 1; i++) {
        if (allticks[i + 1] > lowerBound && allticks[i] <= upperBound) {
            myticks.add(new Double(allticks[i]));
        }
    }

    boolean isLastTickAdded = false;
    final boolean sci = (myticks.size() > 4);

    // Add all ticks that were selected before and their eight following unlabeled subticks
    for (final Double tick : myticks) {
        final double t = tick.doubleValue();
        ticks.add(new NumberTick(tick, toString(t, sci), anchor, rotationAnchor, angle));
        if (t < upperBound) {
            for (int j = 2; j < 10; j++) {
                double s = (t == 0.0 ? allticks[1] / 10.0 : t) * j; // to allows subticks from 0
                String label = "";
                if (s >= upperBound) {
                    isLastTickAdded = true;
                    label = toString(s, sci);
                }
                ticks.add(new NumberTick(new Double(s), label, anchor, rotationAnchor, angle));
                if (isLastTickAdded) {
                    break;
                }
            }
        }
    }

    // Add the very last tick value
    if (!isLastTickAdded) {
        Double t = new Double(computeLogCeil(upperBound));
        ticks.add(new NumberTick(t, toString(t, sci), anchor, rotationAnchor, angle));
    }

    return ticks;
}