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

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

Introduction

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

Prototype

public DateTick(Date date, String label, TextAnchor textAnchor, TextAnchor rotationAnchor, double angle) 

Source Link

Document

Creates a new date tick.

Usage

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.DashDateAxis.java

/**
 * @see org.jfree.chart.axis.DateAxis#refreshTicksHorizontal(java.awt.Graphics2D, java.awt.geom.Rectangle2D,
 *      org.jfree.ui.RectangleEdge)//  www.  jav  a 2  s .c  o m
 */

protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

    if (getDateTickLabelAngle() == 0.0) {
        return super.refreshTicksHorizontal(g2, dataArea, edge);
    } else {
        setVerticalTickLabels(true);
        List ticks = super.refreshTicksHorizontal(g2, dataArea, edge);
        List ret = new ArrayList();

        for (int i = 0; i < ticks.size(); i++) {
            Object tick = ticks.get(i);
            if (tick instanceof DateTick) {
                DateTick dateTick = (DateTick) tick;
                ret.add(new DateTick(dateTick.getDate(), dateTick.getText(), dateTick.getTextAnchor(),
                        dateTick.getRotationAnchor(), getDateTickLabelAngle()));
            } else {
                ret.add(tick);
            }
        }
        return ret;
    }
}

From source file:grafix.graficos.eixos.EixoHorizontalComLabels.java

@Override
public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) {
    try {//  ww  w . ja v a 2 s.  c  om
        long l1 = this.getMaximumDate().getTime();
        long l2 = this.getMinimumDate().getTime();
        int diasExibidos = (int) ((l1 - l2) / ref);
        if (diasExibidos == diasExibidosAnterior && ticksAnteriores != null) {
            return ticksAnteriores; // otimizacao
        } else {
            List result = new ArrayList();
            int j = 0;
            for (int i = acao.getNumeroRegistros() - 1; i >= 0; i--) {
                int n = (int) (diasExibidos / QUANTIDADE_DATAS);
                if (j++ % n == 0) {
                    result.add(new DateTick(acao.getRegistro(i).getDataCorrida().getStart(),
                            new DateFormatter(new SimpleDateFormat("dd/MM/yy"))
                                    .valueToString(acao.getRegistro(i).getData().getStart()),
                            TextAnchor.TOP_CENTER, TextAnchor.TOP_RIGHT, 0));
                } else {
                    result.add(new DateTick(acao.getRegistro(i).getDataCorrida().getStart(), "",
                            TextAnchor.TOP_CENTER, TextAnchor.TOP_RIGHT, 0));
                }
            }
            ticksAnteriores = result;
            diasExibidosAnterior = diasExibidos;
            return result;
        }
    } catch (Exception e) {
        return new ArrayList();
    }
}

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

private static List<Tick> createTicksHorizontal(List<LogicDateTick> logicDateTicks, TextAnchor anchor,
        TextAnchor rotationAnchor, double angle) {
    List<Tick> result = new ArrayList<Tick>();
    for (int i = 0; i < logicDateTicks.size(); i++) {
        LogicDateTick buf = (LogicDateTick) logicDateTicks.get(i);
        TickAlignment tickAlignment = buf.getTickAlignment();
        result.add(new DateTick(buf.getTickDate(), buf.getTickLabel(),
                adjustAnchorHorizontal(anchor, tickAlignment),
                adjustAnchorHorizontal(rotationAnchor, tickAlignment), angle));
    }//from   w w  w .  j av  a  2s  .  co  m

    return result;
}

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

@SuppressWarnings("unchecked")
@Override/*from ww w.  jav a2s  .c o m*/
protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {
    double rotationAngleInRad = Math.toRadians(tickLabelAngle);
    //Template types are specified here for additional type safety.
    List<Tick> ticks = (List<Tick>) super.refreshTicksHorizontal(g2, dataArea, edge);
    List<Tick> ret = new ArrayList<Tick>();
    for (Tick tick : ticks) {
        if (tick instanceof DateTick) {
            DateTick dateTick = (DateTick) tick;

            //The anchor used depends on the label angle, as follows:
            TextAnchor textAnchor, rotationAnchor;

            double modRadians = rotationAngleInRad % (2 * Math.PI);
            //Handle case where user provided a negative angle value.
            if (modRadians < 0) {
                modRadians += 2 * Math.PI;
            }

            //For angles between 0-180 degrees:
            if (modRadians <= Math.PI) {
                textAnchor = TextAnchor.CENTER_LEFT;
                rotationAnchor = TextAnchor.CENTER_LEFT;
            }
            //For angles between 180-360 degrees:
            else {
                textAnchor = TextAnchor.CENTER_RIGHT;
                rotationAnchor = TextAnchor.CENTER_RIGHT;
            }
            ret.add(new DateTick(dateTick.getDate(), dateTick.getText(), textAnchor, rotationAnchor,
                    rotationAngleInRad));
        } else {
            ret.add(tick);
        }
    }

    return ret;
}

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

private static List<Tick> createTicksVertical(List<LogicDateTick> logicDateTicks, TextAnchor anchor,
        TextAnchor rotationAnchor, double angle) {
    List<Tick> result = new ArrayList<Tick>();
    for (int i = 0; i < logicDateTicks.size(); i++) {
        LogicDateTick buf = logicDateTicks.get(i);
        TickAlignment tickAlignment = buf.getTickAlignment();
        result.add(/*  w ww .  j  a v  a2s  .  c om*/
                new DateTick(buf.getTickDate(), buf.getTickLabel(), adjustAnchorVertical(anchor, tickAlignment),
                        adjustAnchorVertical(rotationAnchor, tickAlignment), angle));
    }

    return result;
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java

/**
 * Make the plot// w w  w .java2  s .  c  o  m
 *
 * @return The plot_
 */
public Plot doMakePlot() {

    IdvPreferenceManager pref = control.getControlContext().getIdv().getPreferenceManager();
    TimeZone timeZone = pref.getDefaultTimeZone();
    NumberAxis valueAxis = new FixedWidthNumberAxis("");
    final SimpleDateFormat sdf = new SimpleDateFormat(
            ((dateFormat != null) ? dateFormat : pref.getDefaultDateFormat()));
    sdf.setTimeZone(timeZone);
    DateAxis timeAxis = new DateAxis("Time (" + timeZone.getID() + ")", timeZone) {

        protected List xxxxxrefreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) {

            List ticks = super.refreshTicksHorizontal(g2, dataArea, edge);

            List<Tick> result = new java.util.ArrayList<Tick>();

            Font tickLabelFont = getTickLabelFont();
            g2.setFont(tickLabelFont);

            if (isAutoTickUnitSelection()) {
                selectAutoTickUnit(g2, dataArea, edge);
            }

            DateTickUnit unit = getTickUnit();
            Date tickDate = calculateLowestVisibleTickValue(unit);
            Date upperDate = getMaximumDate();

            Date firstDate = null;
            while (tickDate.before(upperDate)) {

                if (!isHiddenValue(tickDate.getTime())) {
                    // work out the value, label and position
                    String tickLabel;
                    DateFormat formatter = getDateFormatOverride();
                    if (firstDate == null) {
                        if (formatter != null) {
                            tickLabel = formatter.format(tickDate);
                        } else {
                            tickLabel = getTickUnit().dateToString(tickDate);
                        }
                        firstDate = tickDate;
                    } else {
                        double msdiff = tickDate.getTime() - firstDate.getTime();
                        int hours = (int) (msdiff / 1000 / 60 / 60);
                        tickLabel = hours + "H";
                    }
                    //                tickLabel = tickLabel;
                    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;
                        }
                    }

                    Tick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
                    result.add(tick);
                    tickDate = unit.addToDate(tickDate, getTimeZone());
                } else {
                    tickDate = unit.rollDate(tickDate, getTimeZone());

                    continue;
                }

                // could add a flag to make the following correction optional...
                switch (unit.getUnit()) {

                case (DateTickUnit.MILLISECOND):
                case (DateTickUnit.SECOND):
                case (DateTickUnit.MINUTE):
                case (DateTickUnit.HOUR):
                case (DateTickUnit.DAY):
                    break;

                case (DateTickUnit.MONTH):
                    tickDate = calculateDateForPositionX(new Month(tickDate, getTimeZone()),
                            getTickMarkPosition());

                    break;

                case (DateTickUnit.YEAR):
                    tickDate = calculateDateForPositionX(new Year(tickDate, getTimeZone()),
                            getTickMarkPosition());

                    break;

                default:
                    break;

                }

            }

            return result;

        }

        private Date calculateDateForPositionX(RegularTimePeriod period, DateTickMarkPosition position) {

            if (position == null) {
                throw new IllegalArgumentException("Null 'position' argument.");
            }
            Date result = null;
            if (position == DateTickMarkPosition.START) {
                result = new Date(period.getFirstMillisecond());
            } else if (position == DateTickMarkPosition.MIDDLE) {
                result = new Date(period.getMiddleMillisecond());
            } else if (position == DateTickMarkPosition.END) {
                result = new Date(period.getLastMillisecond());
            }

            return result;

        }

    };
    timeAxis.setDateFormatOverride(sdf);

    final XYPlot[] xyPlotHolder = { null };

    xyPlotHolder[0] = new MyXYPlot(new TimeSeriesCollection(), timeAxis, valueAxis, null) {
        public void drawBackground(Graphics2D g2, Rectangle2D area) {
            super.drawBackground(g2, area);
            drawSunriseSunset(g2, xyPlotHolder[0], area);
        }
    };

    if (animationTimeAnnotation != null) {
        xyPlotHolder[0].addAnnotation(animationTimeAnnotation);
    }

    return xyPlotHolder[0];

}

From source file:figs.treeVisualization.gui.PhyloDateAxis.java

protected List<DateTick> refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea) {

    List<DateTick> result = new ArrayList<DateTick>();
    DateFormat formatter = getDateFormatOverride();

    Font tickLabelFont = getTickLabelFont();
    g2.setFont(tickLabelFont);//ww w .  jav  a2s.co  m

    if (isAutoTickUnitSelection()) {
        selectAutoTickUnit(g2, dataArea, RectangleEdge.RIGHT);
    }
    DateTickUnit unit = getTickUnit();

    // nextStandardDate is adding to the min which makes no sense, so just call previous
    Date tickDate = previousStandardDate(getMinimumDate(), unit);
    Date upperDate = getMaximumDate();
    while (!tickDate.after(upperDate)) {

        if (!isHiddenValue(tickDate.getTime())) {
            // work out the value, label and position
            String tickLabel;
            if (formatter != null) {
                tickLabel = formatter.format(tickDate);
            } else {
                tickLabel = this.getTickUnit().dateToString(tickDate);
            }
            TextAnchor anchor = null;
            TextAnchor rotationAnchor = null;
            double angle = 0.0;
            if (isVerticalTickLabels()) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                // RectangeEdge.RIGHT
                angle = Math.PI / 2.0;
            } else {
                // RectangeEdge.RIGHT
                anchor = TextAnchor.CENTER_LEFT;
                rotationAnchor = TextAnchor.CENTER_LEFT;
            }

            DateTick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle);
            result.add(tick);
            tickDate = unit.addToDate(tickDate);
        } else {
            tickDate = unit.rollDate(tickDate);
        }
    }

    return result;
}