@Override public Object convert(String value) throws ParamException { Map map = parseMap(value); DateFormat format; int unit = ((Integer) getChoiceArg(map, "unit", unitChoice)).intValue(); int count = getIntArg(map, "count"); try { return new DateTickUnit(unit, count, (DateFormat) super.convert(value)); } catch (MissingArgumentException e) { return new DateTickUnit(unit, count); } } }
/** * Calculates a new date by adding this unit to the base date, with * calculations performed in the default timezone and locale. * * @param base the base date. * * @return A new date one unit after the base date. * * @see #addToDate(Date, TimeZone) * * @deprecated As of JFreeChart 1.0.10, this method is deprecated - you * should use {@link #addToDate(Date, TimeZone)} instead. */ public Date addToDate(Date base) { return addToDate(base, TimeZone.getDefault()); }
/** * Returns the first "standard" date (based on the specified field and * units). * * @param date the reference date. * @param unit the date tick unit. * * @return The next "standard" date. */ protected Date nextStandardDate(Date date, DateTickUnit unit) { Date previous = previousStandardDate(date, unit); Calendar calendar = Calendar.getInstance(this.timeZone, this.locale); calendar.setTime(previous); calendar.add(unit.getCalendarField(), unit.getMultiple()); return calendar.getTime(); }
DateTickUnitType rollUnitType, int rollMultiple, DateFormat formatter) { super(DateTickUnit.getMillisecondCount(unitType, multiple)); if (formatter == null) { throw new IllegalArgumentException("Null 'formatter' argument."); this.unit = unitTypeToInt(unitType); this.rollUnit = unitTypeToInt(rollUnitType);
long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime; int minorTickSpaces = getMinorTickCount(); if (minorTickSpaces <= 0) { minorTickSpaces = unit.getMinorTickCount(); tickLabel = this.tickUnit.dateToString(tickDate); result.add(tick); long currentTickTime = tickDate.getTime(); tickDate = unit.addToDate(tickDate, this.timeZone); long nextTickTime = tickDate.getTime(); for (int minorTick = 1; minorTick < minorTickSpaces; tickDate = unit.rollDate(tickDate, this.timeZone);
int count = unit.getMultiple(); int current = calendar.get(unit.getCalendarField()); int value = count * (current / count); if (DateTickUnitType.MILLISECOND.equals(unit.getUnitType())) { years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); else if (DateTickUnitType.SECOND.equals(unit.getUnitType())) { years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); else if (DateTickUnitType.MINUTE.equals(unit.getUnitType())) { years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); else if (DateTickUnitType.HOUR.equals(unit.getUnitType())) { years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); else if (DateTickUnitType.DAY.equals(unit.getUnitType())) { years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); else if (DateTickUnitType.MONTH.equals(unit.getUnitType())) { value = count * ((current + 1) / count) - 1; years = calendar.get(Calendar.YEAR); else if (DateTickUnitType.YEAR.equals(unit.getUnitType())) {
int count = unit.getCount(); int current = calendar.get(unit.getCalendarField()); int value = count * (current / count); switch (unit.getUnit()) {
= (DateTickUnit) tickUnits.getCeilingTickUnit(estimate1); double labelHeight1 = estimateMaximumTickLabelHeight(g2, candidate1); double y1 = valueToJava2D(candidate1.getSize(), dataArea, edge); double candidate1UnitHeight = Math.abs(y1 - zero); = (labelHeight1 / candidate1UnitHeight) * candidate1.getSize(); DateTickUnit candidate2 = (DateTickUnit) tickUnits.getCeilingTickUnit(estimate2); double labelHeight2 = estimateMaximumTickLabelHeight(g2, candidate2); double y2 = valueToJava2D(candidate2.getSize(), dataArea, edge); double unit2Height = Math.abs(y2 - zero);
lowerStr = unit.dateToString(lower); upperStr = unit.dateToString(upper);
/** * Creates a new unit. * * The {@code rollUnitType} and {@code rollCount} are intended to roll the date forward when it falls on a "hidden" part of the DateAxis. For example, if the tick size is 1 week (7 days), but Saturday and Sunday are hidden, if the ticks happen to fall on Saturday, none of them will be visible. A sensible {@code rollUnitType}/{@code rollCount} would be 1 day, so that the date would roll forward to the following Monday, which is visible. * * @param unitType the unit. * @param multiple the multiple. * @param rollUnitType the roll unit. * @param rollMultiple the roll multiple. * @param formatter the date formatter ({@code null} not permitted). * * @since 1.0.13 */ public DateTickUnit(DateTickUnitType unitType, int multiple, DateTickUnitType rollUnitType, int rollMultiple, DateFormat formatter) { super(DateTickUnit.getMillisecondCount(unitType, multiple)); Args.nullNotPermitted(formatter, "formatter"); if (multiple <= 0) { throw new IllegalArgumentException("Requires 'multiple' > 0."); } if (rollMultiple <= 0) { throw new IllegalArgumentException("Requires 'rollMultiple' > 0."); } this.unitType = unitType; this.count = multiple; this.rollUnitType = rollUnitType; this.rollCount = rollMultiple; this.formatter = formatter; }
long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime; int minorTickSpaces = getMinorTickCount(); if (minorTickSpaces <= 0) { minorTickSpaces = unit.getMinorTickCount(); tickLabel = this.tickUnit.dateToString(tickDate); tickDate = unit.addToDate(tickDate, this.timeZone); long nextTickTime = tickDate.getTime(); for (int minorTick = 1; minorTick < minorTickSpaces; tickDate = unit.rollDate(tickDate, this.timeZone); hasRolled = true; continue;
= (DateTickUnit) tickUnits.getCeilingTickUnit(estimate1); double labelHeight1 = estimateMaximumTickLabelHeight(g2, candidate1); double y1 = valueToJava2D(candidate1.getSize(), dataArea, edge); double candidate1UnitHeight = Math.abs(y1 - zero); = (labelHeight1 / candidate1UnitHeight) * candidate1.getSize(); DateTickUnit candidate2 = (DateTickUnit) tickUnits.getCeilingTickUnit(estimate2); double labelHeight2 = estimateMaximumTickLabelHeight(g2, candidate2); double y2 = valueToJava2D(candidate2.getSize(), dataArea, edge); double unit2Height = Math.abs(y2 - zero);
lowerStr = unit.dateToString(lower); upperStr = unit.dateToString(upper);
/** * Creates a date axis. * * @param label the axis label ({@code null} permitted). * @param zone the time zone. * @param locale the locale ({@code null} not permitted). * * @since 1.0.11 */ public DateAxis(String label, TimeZone zone, Locale locale) { super(label, DateAxis.createStandardDateTickUnits(zone, locale)); this.tickUnit = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat()); setAutoRangeMinimumSize( DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS); setRange(DEFAULT_DATE_RANGE, false, false); this.dateFormatOverride = null; this.timeZone = zone; this.locale = locale; this.timeline = DEFAULT_TIMELINE; }
long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime; int minorTickSpaces = getMinorTickCount(); if (minorTickSpaces <= 0) { minorTickSpaces = unit.getMinorTickCount(); tickLabel = this.tickUnit.dateToString(tickDate); tickDate = unit.addToDate(tickDate, this.timeZone); long nextTickTime = tickDate.getTime(); for (int minorTick = 1; minorTick < minorTickSpaces; tickDate = unit.rollDate(tickDate, this.timeZone); hasRolled = true;
/** * Returns the first "standard" date (based on the specified field and * units). * * @param date the reference date. * @param unit the date tick unit. * * @return The next "standard" date. */ protected Date nextStandardDate(Date date, DateTickUnit unit) { Date previous = previousStandardDate(date, unit); Calendar calendar = Calendar.getInstance(this.timeZone, this.locale); calendar.setTime(previous); calendar.add(unit.getCalendarField(), unit.getMultiple()); return calendar.getTime(); }
/** * Selects an appropriate tick size for the axis. The strategy is to * display as many ticks as possible (selected from a collection of * 'standard' tick units) without the labels overlapping. * * @param g2 the graphics device. * @param dataArea the area defined by the axes. * @param edge the axis location. */ protected void selectHorizontalAutoTickUnit(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { double zero = valueToJava2D(0.0, dataArea, edge); double tickLabelWidth = estimateMaximumTickLabelWidth(g2, getTickUnit()); // start with the current tick unit... TickUnitSource tickUnits = getStandardTickUnits(); TickUnit unit1 = tickUnits.getCeilingTickUnit(getTickUnit()); double x1 = valueToJava2D(unit1.getSize(), dataArea, edge); double unit1Width = Math.abs(x1 - zero); // then extrapolate... double guess = (tickLabelWidth / unit1Width) * unit1.getSize(); DateTickUnit unit2 = (DateTickUnit) tickUnits.getCeilingTickUnit(guess); double x2 = valueToJava2D(unit2.getSize(), dataArea, edge); double unit2Width = Math.abs(x2 - zero); tickLabelWidth = estimateMaximumTickLabelWidth(g2, unit2); if (tickLabelWidth > unit2Width) { unit2 = (DateTickUnit) tickUnits.getLargerTickUnit(unit2); } setTickUnit(unit2, false, false); }
lowerStr = unit.dateToString(lower); upperStr = unit.dateToString(upper);
axis.setTickUnit(new DateTickUnit(unit, count));
long distance = unit.addToDate(tickDate, this.timeZone).getTime() - lowestTickTime; int minorTickSpaces = getMinorTickCount(); if (minorTickSpaces <= 0) { minorTickSpaces = unit.getMinorTickCount(); tickLabel = this.tickUnit.dateToString(tickDate); tickDate = unit.addToDate(tickDate, this.timeZone); long nextTickTime = tickDate.getTime(); for (int minorTick = 1; minorTick < minorTickSpaces; tickDate = unit.rollDate(tickDate, this.timeZone); continue;