Mercurial > dive4elements > gnv-client
changeset 526:4cbcc130cffc
Copied method from JFreeChart to adapt date formats.
gnv-artifacts/trunk@622 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 25 Jan 2010 16:15:31 +0000 |
parents | 0eba2f032e0d |
children | f598702b2a10 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java |
diffstat | 2 files changed, 148 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Mon Jan 25 13:48:52 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Jan 25 16:15:31 2010 +0000 @@ -1,3 +1,10 @@ +2010-01-25 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue160 + + * src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java: Copied a + method from JFreeChart and adapted date formats. + 2010-01-25 Sascha L. Teichmann <sascha.teichmann@intevation.de> * doc/conf/arcsdeconnectionpool.properties: Set serverRoundtripInterval
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Jan 25 13:48:52 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/TimeSeriesChart.java Mon Jan 25 16:15:31 2010 +0000 @@ -8,6 +8,9 @@ import de.intevation.gnv.timeseries.gap.TimeGap; +import java.text.DateFormat; +import java.text.SimpleDateFormat; + import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -22,6 +25,11 @@ import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.DateAxis; +import org.jfree.chart.axis.DateTickUnit; +import org.jfree.chart.axis.DateTickUnitType; +import org.jfree.chart.axis.TickUnits; +import org.jfree.chart.axis.TickUnitSource; +import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; @@ -225,7 +233,139 @@ protected void localizeDomainAxis(Axis axis, Locale locale) { - // do nothing + ((ValueAxis)axis).setStandardTickUnits(createStandardDateTickUnits( + TimeZone.getDefault(), + locale)); + } + + + public static TickUnitSource createStandardDateTickUnits( + TimeZone zone, + Locale locale) + { + /* + * This method have been copied from JFreeChart's DateAxis class. + * DateFormat objects are hard coded in DateAxis and cannot be adjusted. + */ + if (zone == null) { + throw new IllegalArgumentException("Null 'zone' argument."); + } + if (locale == null) { + throw new IllegalArgumentException("Null 'locale' argument."); + } + TickUnits units = new TickUnits(); + + // date formatters + DateFormat f1 = new SimpleDateFormat("HH:mm:ss.SSS", locale); + DateFormat f2 = new SimpleDateFormat("HH:mm:ss", locale); + DateFormat f3 = new SimpleDateFormat("HH:mm", locale); + DateFormat f4 = new SimpleDateFormat("d-MMM, HH:mm", locale); + DateFormat f5 = new SimpleDateFormat("d-MMM yyyy", locale); + DateFormat f6 = new SimpleDateFormat("MMM-yyyy", locale); + DateFormat f7 = new SimpleDateFormat("yyyy", locale); + + f1.setTimeZone(zone); + f2.setTimeZone(zone); + f3.setTimeZone(zone); + f4.setTimeZone(zone); + f5.setTimeZone(zone); + f6.setTimeZone(zone); + f7.setTimeZone(zone); + + // milliseconds + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 1, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 5, + DateTickUnitType.MILLISECOND, 1, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 10, + DateTickUnitType.MILLISECOND, 1, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 25, + DateTickUnitType.MILLISECOND, 5, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 50, + DateTickUnitType.MILLISECOND, 10, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 100, + DateTickUnitType.MILLISECOND, 10, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 250, + DateTickUnitType.MILLISECOND, 10, f1)); + units.add(new DateTickUnit(DateTickUnitType.MILLISECOND, 500, + DateTickUnitType.MILLISECOND, 50, f1)); + + // seconds + units.add(new DateTickUnit(DateTickUnitType.SECOND, 1, + DateTickUnitType.MILLISECOND, 50, f2)); + units.add(new DateTickUnit(DateTickUnitType.SECOND, 5, + DateTickUnitType.SECOND, 1, f2)); + units.add(new DateTickUnit(DateTickUnitType.SECOND, 10, + DateTickUnitType.SECOND, 1, f2)); + units.add(new DateTickUnit(DateTickUnitType.SECOND, 30, + DateTickUnitType.SECOND, 5, f2)); + + // minutes + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 1, + DateTickUnitType.SECOND, 5, f3)); + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 2, + DateTickUnitType.SECOND, 10, f3)); + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 5, + DateTickUnitType.MINUTE, 1, f3)); + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 10, + DateTickUnitType.MINUTE, 1, f3)); + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 15, + DateTickUnitType.MINUTE, 5, f3)); + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 20, + DateTickUnitType.MINUTE, 5, f3)); + units.add(new DateTickUnit(DateTickUnitType.MINUTE, 30, + DateTickUnitType.MINUTE, 5, f3)); + + // hours + units.add(new DateTickUnit(DateTickUnitType.HOUR, 1, + DateTickUnitType.MINUTE, 5, f3)); + units.add(new DateTickUnit(DateTickUnitType.HOUR, 2, + DateTickUnitType.MINUTE, 10, f3)); + units.add(new DateTickUnit(DateTickUnitType.HOUR, 4, + DateTickUnitType.MINUTE, 30, f3)); + units.add(new DateTickUnit(DateTickUnitType.HOUR, 6, + DateTickUnitType.HOUR, 1, f3)); + units.add(new DateTickUnit(DateTickUnitType.HOUR, 12, + DateTickUnitType.HOUR, 1, f4)); + + // days + units.add(new DateTickUnit(DateTickUnitType.DAY, 1, + DateTickUnitType.HOUR, 1, f5)); + units.add(new DateTickUnit(DateTickUnitType.DAY, 2, + DateTickUnitType.HOUR, 1, f5)); + units.add(new DateTickUnit(DateTickUnitType.DAY, 7, + DateTickUnitType.DAY, 1, f5)); + units.add(new DateTickUnit(DateTickUnitType.DAY, 15, + DateTickUnitType.DAY, 1, f5)); + + // months + units.add(new DateTickUnit(DateTickUnitType.MONTH, 1, + DateTickUnitType.DAY, 1, f6)); + units.add(new DateTickUnit(DateTickUnitType.MONTH, 2, + DateTickUnitType.DAY, 1, f6)); + units.add(new DateTickUnit(DateTickUnitType.MONTH, 3, + DateTickUnitType.MONTH, 1, f6)); + units.add(new DateTickUnit(DateTickUnitType.MONTH, 4, + DateTickUnitType.MONTH, 1, f6)); + units.add(new DateTickUnit(DateTickUnitType.MONTH, 6, + DateTickUnitType.MONTH, 1, f6)); + + // years + units.add(new DateTickUnit(DateTickUnitType.YEAR, 1, + DateTickUnitType.MONTH, 1, f7)); + units.add(new DateTickUnit(DateTickUnitType.YEAR, 2, + DateTickUnitType.MONTH, 3, f7)); + units.add(new DateTickUnit(DateTickUnitType.YEAR, 5, + DateTickUnitType.YEAR, 1, f7)); + units.add(new DateTickUnit(DateTickUnitType.YEAR, 10, + DateTickUnitType.YEAR, 1, f7)); + units.add(new DateTickUnit(DateTickUnitType.YEAR, 25, + DateTickUnitType.YEAR, 5, f7)); + units.add(new DateTickUnit(DateTickUnitType.YEAR, 50, + DateTickUnitType.YEAR, 10, f7)); + units.add(new DateTickUnit(DateTickUnitType.YEAR, 100, + DateTickUnitType.YEAR, 20, f7)); + + return units; }