/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DateAxis a1 = new DateAxis("Test"); DateAxis a2 = new DateAxis("Test"); assertTrue(a1.equals(a2)); // tickUnit a1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertFalse(a1.equals(a2)); a2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertTrue(a1.equals(a2)); // dateFormatOverride a1.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertFalse(a1.equals(a2)); a2.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertTrue(a1.equals(a2)); // tickMarkPosition a1.setTickMarkPosition(DateTickMarkPosition.END); assertFalse(a1.equals(a2)); a2.setTickMarkPosition(DateTickMarkPosition.END); assertTrue(a1.equals(a2)); // timeline a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertFalse(a1.equals(a2)); a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertTrue(a1.equals(a2)); }
/** * Test equals() method. */ public void testEquals() { assertEquals(DateTickMarkPosition.START, DateTickMarkPosition.START); assertEquals(DateTickMarkPosition.MIDDLE, DateTickMarkPosition.MIDDLE); assertEquals(DateTickMarkPosition.END, DateTickMarkPosition.END); assertFalse(DateTickMarkPosition.START.equals(null)); assertFalse(DateTickMarkPosition.START.equals(DateTickMarkPosition.END)); assertFalse(DateTickMarkPosition.MIDDLE.equals(DateTickMarkPosition.END)); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DateAxis a1 = new DateAxis("Test"); DateAxis a2 = new DateAxis("Test"); assertTrue(a1.equals(a2)); assertFalse(a1.equals(null)); assertFalse(a1.equals("Some non-DateAxis object")); // tickUnit a1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertFalse(a1.equals(a2)); a2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertTrue(a1.equals(a2)); // dateFormatOverride a1.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertFalse(a1.equals(a2)); a2.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertTrue(a1.equals(a2)); // tickMarkPosition a1.setTickMarkPosition(DateTickMarkPosition.END); assertFalse(a1.equals(a2)); a2.setTickMarkPosition(DateTickMarkPosition.END); assertTrue(a1.equals(a2)); // timeline a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertFalse(a1.equals(a2)); a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertTrue(a1.equals(a2)); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 year. */ public void testPreviousStandardDateYear() { MyDateAxis axis = new MyDateAxis("Year"); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(2006, Calendar.AUGUST, 25, 12, 0); Date d1 = calendar.getTime(); calendar.set(2007, Calendar.MAY, 20, 12, 0); Date d2 = calendar.getTime(); axis.setRange(d1, d2); DateTickUnit unit = new DateTickUnit(DateTickUnit.YEAR, 1); axis.setTickUnit(unit); axis.setTickMarkPosition(DateTickMarkPosition.START); Date psd1 = axis.previousStandardDate(d1, unit); calendar.setTime(psd1); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.JANUARY, calendar.get(Calendar.MONTH)); assertEquals(1, calendar.get(Calendar.DATE)); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); Date psd2 = axis.previousStandardDate(d1, unit); calendar.setTime(psd2); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.JULY, calendar.get(Calendar.MONTH)); assertEquals(1, calendar.get(Calendar.DATE)); axis.setTickMarkPosition(DateTickMarkPosition.END); Date psd3 = axis.previousStandardDate(d1, unit); calendar.setTime(psd3); assertEquals(2005, calendar.get(Calendar.YEAR)); assertEquals(Calendar.DECEMBER, calendar.get(Calendar.MONTH)); assertEquals(31, calendar.get(Calendar.DATE)); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 month. */ public void testPreviousStandardDateMonth() { MyDateAxis axis = new MyDateAxis("Month"); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(2006, Calendar.AUGUST, 25, 12, 0); Date d1 = calendar.getTime(); calendar.set(2007, Calendar.MAY, 20, 12, 0); Date d2 = calendar.getTime(); axis.setRange(d1, d2); DateTickUnit unit = new DateTickUnit(DateTickUnit.MONTH, 1); axis.setTickUnit(unit); axis.setTickMarkPosition(DateTickMarkPosition.START); Date psd1 = axis.previousStandardDate(d1, unit); calendar.setTime(psd1); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(1, calendar.get(Calendar.DATE)); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); Date psd2 = axis.previousStandardDate(d1, unit); calendar.setTime(psd2); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(16, calendar.get(Calendar.DATE)); axis.setTickMarkPosition(DateTickMarkPosition.END); Date psd3 = axis.previousStandardDate(d1, unit); calendar.setTime(psd3); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.JULY, calendar.get(Calendar.MONTH)); assertEquals(31, calendar.get(Calendar.DATE)); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 day. */ public void testPreviousStandardDateDay() { MyDateAxis axis = new MyDateAxis("Day"); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(2006, Calendar.AUGUST, 25, 12, 0); Date d1 = calendar.getTime(); calendar.set(2007, Calendar.MAY, 20, 12, 0); Date d2 = calendar.getTime(); axis.setRange(d1, d2); DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1); axis.setTickUnit(unit); axis.setTickMarkPosition(DateTickMarkPosition.START); Date psd1 = axis.previousStandardDate(d1, unit); calendar.setTime(psd1); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); Date psd2 = axis.previousStandardDate(d1, unit); calendar.setTime(psd2); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); axis.setTickMarkPosition(DateTickMarkPosition.END); Date psd3 = axis.previousStandardDate(d1, unit); calendar.setTime(psd3); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(24, calendar.get(Calendar.DATE)); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 hour. */ public void testPreviousStandardDateHour() { MyDateAxis axis = new MyDateAxis("Hour"); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(2006, Calendar.AUGUST, 25, 12, 0); Date d1 = calendar.getTime(); calendar.set(2007, Calendar.MAY, 20, 12, 0); Date d2 = calendar.getTime(); axis.setRange(d1, d2); DateTickUnit unit = new DateTickUnit(DateTickUnit.HOUR, 1); axis.setTickUnit(unit); axis.setTickMarkPosition(DateTickMarkPosition.START); Date psd1 = axis.previousStandardDate(d1, unit); calendar.setTime(psd1); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); assertEquals(12, calendar.get(Calendar.HOUR_OF_DAY)); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); Date psd2 = axis.previousStandardDate(d1, unit); calendar.setTime(psd2); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY)); axis.setTickMarkPosition(DateTickMarkPosition.END); Date psd3 = axis.previousStandardDate(d1, unit); calendar.setTime(psd3); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY)); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 minute. */ public void testPreviousStandardDateMinute() { MyDateAxis axis = new MyDateAxis("Minute"); GregorianCalendar calendar = new GregorianCalendar(); calendar.set(2006, Calendar.AUGUST, 25, 12, 0, 10); Date d1 = calendar.getTime(); calendar.set(2007, Calendar.MAY, 20, 12, 0, 10); Date d2 = calendar.getTime(); axis.setRange(d1, d2); DateTickUnit unit = new DateTickUnit(DateTickUnit.MINUTE, 1); axis.setTickUnit(unit); axis.setTickMarkPosition(DateTickMarkPosition.START); Date psd1 = axis.previousStandardDate(d1, unit); calendar.setTime(psd1); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); assertEquals(12, calendar.get(Calendar.HOUR_OF_DAY)); assertEquals(0, calendar.get(Calendar.MINUTE)); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); Date psd2 = axis.previousStandardDate(d1, unit); calendar.setTime(psd2); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY)); assertEquals(59, calendar.get(Calendar.MINUTE)); axis.setTickMarkPosition(DateTickMarkPosition.END); Date psd3 = axis.previousStandardDate(d1, unit); calendar.setTime(psd3); assertEquals(2006, calendar.get(Calendar.YEAR)); assertEquals(Calendar.AUGUST, calendar.get(Calendar.MONTH)); assertEquals(25, calendar.get(Calendar.DATE)); assertEquals(11, calendar.get(Calendar.HOUR_OF_DAY)); assertEquals(59, calendar.get(Calendar.MINUTE)); }
/** * Test equals() method. */ public void testEquals() { assertEquals(DateTickMarkPosition.START, DateTickMarkPosition.START); assertEquals(DateTickMarkPosition.MIDDLE, DateTickMarkPosition.MIDDLE); assertEquals(DateTickMarkPosition.END, DateTickMarkPosition.END); assertFalse(DateTickMarkPosition.START.equals(null)); assertFalse( DateTickMarkPosition.START.equals(DateTickMarkPosition.END) ); assertFalse( DateTickMarkPosition.MIDDLE.equals(DateTickMarkPosition.END) ); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { DateTickMarkPosition a1 = DateTickMarkPosition.END; DateTickMarkPosition a2 = DateTickMarkPosition.END; assertTrue(a1.equals(a2)); int h1 = a1.hashCode(); int h2 = a2.hashCode(); assertEquals(h1, h2); }
public static JFreeChart createAverageTeamDistanceGraph( AppState state ) { final JFreeChart chart = ChartFactory.createTimeSeriesChart( GameStatisticsComponent.AVERAGE_TEAM_DISTANCE, // chart title Statics.MILISECONDS, // x axis label "", // y axis label createAverageTeamDistanceDataSet( state ), // data true, // include legend true, // tooltips false // urls ); final XYPlot plot = chart.getXYPlot(); final DateAxis domainAxis = new DateAxis( Statics.TIME ); domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE ); domainAxis.setLowerMargin( 0.0 ); domainAxis.setUpperMargin( 0.0 ); plot.setDomainAxis( domainAxis ); plot.setForegroundAlpha( 0.5f ); plot.setDomainPannable( false ); plot.setRangePannable( false ); final NumberAxis rangeAxis = new NumberAxis( GameStatisticsComponent.AVERAGE_TEAM_DISTANCE ); rangeAxis.setLowerMargin( 0.15 ); rangeAxis.setUpperMargin( 0.15 ); plot.setRangeAxis( rangeAxis ); return chart; }
public static JFreeChart createPlayerHistogram( String selectedItem, List<String> selectedValuesList, AppState state ) { final JFreeChart chart = ChartFactory.createXYLineChart( selectedItem, // chart title Statics.MILISECONDS, // x axis label "", // y axis label createPlayerDataSet( selectedItem, selectedValuesList, state ), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); final XYPlot plot = chart.getXYPlot(); final DateAxis domainAxis = new DateAxis( Statics.TIME ); domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE ); domainAxis.setLowerMargin( 0.0 ); domainAxis.setUpperMargin( 0.0 ); plot.setDomainAxis( domainAxis ); plot.setForegroundAlpha( 0.5f ); plot.setDomainPannable( false ); plot.setRangePannable( false ); final NumberAxis rangeAxis = new NumberAxis( selectedItem ); rangeAxis.setLowerMargin( 0.15 ); rangeAxis.setUpperMargin( 0.15 ); plot.setRangeAxis( rangeAxis ); return chart; }
public static JFreeChart createTeamGoldDifferenceGraph( AppState appState ) { final JFreeChart chart = ChartFactory.createTimeSeriesChart( GameStatisticsComponent.TEAM_XP, Statics.EXPERIENCE, "Time", createTeamGoldDiffDataSet( appState ), true, // legend true, // tool tips false // URLs ); final XYDifferenceRenderer renderer = new XYDifferenceRenderer( Color.GREEN, Color.RED, false ); renderer.setSeriesPaint( 0, Color.GREEN ); renderer.setSeriesPaint( 1, Color.RED ); final XYPlot plot = chart.getXYPlot(); plot.setRenderer( renderer ); final DateAxis domainAxis = new DateAxis( Statics.TIME ); domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE ); domainAxis.setLowerMargin( 0.0 ); domainAxis.setUpperMargin( 0.0 ); plot.setDomainAxis( domainAxis ); plot.setForegroundAlpha( 0.5f ); final NumberAxis rangeAxis = new NumberAxis( Statics.GOLD ); rangeAxis.setLowerMargin( 0.15 ); rangeAxis.setUpperMargin( 0.15 ); plot.setRangeAxis( rangeAxis ); return chart; }
public static JFreeChart createTeamXpDifferenceGraph( AppState state ) { final JFreeChart chart = ChartFactory.createTimeSeriesChart( GameStatisticsComponent.TEAM_XP, Statics.EXPERIENCE, "Time", createTeamXPDiffDataSet( state ), true, // legend true, // tool tips false // URLs ); final XYDifferenceRenderer renderer = new XYDifferenceRenderer( Color.GREEN, Color.RED, false ); renderer.setSeriesPaint( 0, Color.GREEN ); renderer.setSeriesPaint( 1, Color.RED ); final XYPlot plot = chart.getXYPlot(); plot.setRenderer( renderer ); final DateAxis domainAxis = new DateAxis( Statics.TIME ); domainAxis.setTickMarkPosition( DateTickMarkPosition.MIDDLE ); domainAxis.setLowerMargin( 0.0 ); domainAxis.setUpperMargin( 0.0 ); plot.setDomainAxis( domainAxis ); plot.setForegroundAlpha( 0.5f ); final NumberAxis rangeAxis = new NumberAxis( Statics.EXPERIENCE ); rangeAxis.setLowerMargin( 0.15 ); rangeAxis.setUpperMargin( 0.15 ); plot.setRangeAxis( rangeAxis ); return chart; }
protected JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createXYBarChart( chartTitle, domainLabel, true, rangeLabel, dataset, PlotOrientation.VERTICAL, false,// !legendPanelOn, true, false ); // then customise it a little... // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do")); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer(new ClusteredXYBarRenderer()); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator( "{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0") ); renderer.setBaseToolTipGenerator(generator); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setLowerMargin(0.01); axis.setUpperMargin(0.01); // setXSummary(dataset); X is time return chart; }
protected JFreeChart createChart(IntervalXYDataset dataset) { JFreeChart chart = ChartFactory.createXYBarChart( chartTitle, domainLabel, true, rangeLabel, dataset, PlotOrientation.VERTICAL, !legendPanelOn, true, false ); // then customise it a little... // chart.addSubtitle(new TextTitle("Source: http://www.amnestyusa.org/abolish/listbyyear.do")); chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setRenderer(new ClusteredXYBarRenderer()); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator( "{1} = {2}", new SimpleDateFormat("yyyy"), new DecimalFormat("0") ); renderer.setBaseToolTipGenerator(generator); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setLowerMargin(0.01); axis.setUpperMargin(0.01); // setXSummary(dataset); X is time return chart; }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DateAxis a1 = new DateAxis("Test"); DateAxis a2 = new DateAxis("Test"); assertTrue(a1.equals(a2)); assertFalse(a1.equals(null)); assertFalse(a1.equals("Some non-DateAxis object")); // tickUnit a1.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 7)); assertFalse(a1.equals(a2)); a2.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 7)); assertTrue(a1.equals(a2)); // dateFormatOverride a1.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertFalse(a1.equals(a2)); a2.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertTrue(a1.equals(a2)); // tickMarkPosition a1.setTickMarkPosition(DateTickMarkPosition.END); assertFalse(a1.equals(a2)); a2.setTickMarkPosition(DateTickMarkPosition.END); assertTrue(a1.equals(a2)); // timeline a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertFalse(a1.equals(a2)); a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertTrue(a1.equals(a2)); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 millisecond. */ public void testPreviousStandardDateMillisecondA() { MyDateAxis axis = new MyDateAxis("Millisecond"); Millisecond m0 = new Millisecond(458, 58, 31, 12, 1, 4, 2007); Millisecond m1 = new Millisecond(459, 58, 31, 12, 1, 4, 2007); Date d0 = new Date(m0.getFirstMillisecond()); Date end = new Date(m1.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.MILLISECOND, 1); axis.setTickUnit(unit); // START: check d0 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); // MIDDLE: check d0 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); // END: check d0 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 10 milliseconds (just for the sake of having a multiple). */ public void testPreviousStandardDateMillisecondB() { MyDateAxis axis = new MyDateAxis("Millisecond"); Millisecond m0 = new Millisecond(458, 58, 31, 12, 1, 4, 2007); Millisecond m1 = new Millisecond(459, 58, 31, 12, 1, 4, 2007); Date d0 = new Date(m0.getFirstMillisecond()); Date end = new Date(m1.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.MILLISECOND, 10); axis.setTickUnit(unit); // START: check d0 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); // MIDDLE: check d0 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); // END: check d0 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d0, end); psd = axis.previousStandardDate(d0, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); }
/** * Test equals() method. */ public void testEquals() { assertEquals(DateTickMarkPosition.START, DateTickMarkPosition.START); assertEquals(DateTickMarkPosition.MIDDLE, DateTickMarkPosition.MIDDLE); assertEquals(DateTickMarkPosition.END, DateTickMarkPosition.END); assertFalse(DateTickMarkPosition.START.equals(null)); assertFalse(DateTickMarkPosition.START.equals( DateTickMarkPosition.END)); assertFalse(DateTickMarkPosition.MIDDLE.equals( DateTickMarkPosition.END)); }
public XYChartBuilder setDateXAxis(final boolean showAxisValues) { xAxis = new DateAxis(); ((DateAxis) xAxis).setTickMarkPosition(DateTickMarkPosition.MIDDLE); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); xAxis.setVisible(showAxisValues); plot.setDomainAxis(xAxis); return this; }
private byte[] createWeeklyLoginChart (int width, int height) { IntervalXYDataset dataset1 = getWeeklyLoginsDataSet (); IntervalXYDataset dataset2 = getWeeklySiteUserDataSet (); if ((dataset1 == null) || (dataset2 == null)) { return generateNoDataChart(width, height); } // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesPaint(0, Color.BLUE); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit (new DateTickUnit (DateTickUnit.DAY, 7, new SimpleDateFormat ("yyyy-MM-dd"))); domainAxis.setTickMarkPosition (DateTickMarkPosition.START); domainAxis.setVerticalTickLabels (true); domainAxis.setLowerMargin (0.01); domainAxis.setUpperMargin (0.01); NumberAxis rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint(0, Color.GREEN); renderer2.setSeriesPaint(1, Color.BLACK); renderer2.setSeriesPaint(2, Color.CYAN); rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits (NumberAxis.createIntegerTickUnits ()); XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint (parseColor (statsManager.getChartBackgroundColor ())); // set chart border chart.setPadding (new RectangleInsets (10, 5, 5, 5)); chart.setBorderVisible (true); chart.setBorderPaint (parseColor ("#cccccc")); // set anti alias chart.setAntiAlias (true); BufferedImage img = chart.createBufferedImage (width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ ImageIO.write(img, "png", out); }catch(IOException e){ log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 year. */ public void testPreviousStandardDateYearA() { MyDateAxis axis = new MyDateAxis("Year"); Year y2006 = new Year(2006); Year y2007 = new Year(2007); // five dates to check... Date d0 = new Date(y2006.getFirstMillisecond()); Date d1 = new Date(y2006.getFirstMillisecond() + 500L); Date d2 = new Date(y2006.getMiddleMillisecond()); Date d3 = new Date(y2006.getMiddleMillisecond() + 500L); Date d4 = new Date(y2006.getLastMillisecond()); Date end = new Date(y2007.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.YEAR, 1); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 10 years (just for the sake of having a multiple). */ public void testPreviousStandardDateYearB() { MyDateAxis axis = new MyDateAxis("Year"); Year y2006 = new Year(2006); Year y2007 = new Year(2007); // five dates to check... Date d0 = new Date(y2006.getFirstMillisecond()); Date d1 = new Date(y2006.getFirstMillisecond() + 500L); Date d2 = new Date(y2006.getMiddleMillisecond()); Date d3 = new Date(y2006.getMiddleMillisecond() + 500L); Date d4 = new Date(y2006.getLastMillisecond()); Date end = new Date(y2007.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.YEAR, 10); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 month. */ public void testPreviousStandardDateMonthA() { MyDateAxis axis = new MyDateAxis("Month"); Month nov2006 = new Month(11, 2006); Month dec2006 = new Month(12, 2006); // five dates to check... Date d0 = new Date(nov2006.getFirstMillisecond()); Date d1 = new Date(nov2006.getFirstMillisecond() + 500L); Date d2 = new Date(nov2006.getMiddleMillisecond()); Date d3 = new Date(nov2006.getMiddleMillisecond() + 500L); Date d4 = new Date(nov2006.getLastMillisecond()); Date end = new Date(dec2006.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.MONTH, 1); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 3 months (just for the sake of having a multiple). */ public void testPreviousStandardDateMonthB() { MyDateAxis axis = new MyDateAxis("Month"); Month nov2006 = new Month(11, 2006); Month dec2006 = new Month(12, 2006); // five dates to check... Date d0 = new Date(nov2006.getFirstMillisecond()); Date d1 = new Date(nov2006.getFirstMillisecond() + 500L); Date d2 = new Date(nov2006.getMiddleMillisecond()); Date d3 = new Date(nov2006.getMiddleMillisecond() + 500L); Date d4 = new Date(nov2006.getLastMillisecond()); Date end = new Date(dec2006.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.MONTH, 3); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 day. */ public void testPreviousStandardDateDayA() { MyDateAxis axis = new MyDateAxis("Day"); Day apr12007 = new Day(1, 4, 2007); Day apr22007 = new Day(2, 4, 2007); // five dates to check... Date d0 = new Date(apr12007.getFirstMillisecond()); Date d1 = new Date(apr12007.getFirstMillisecond() + 500L); Date d2 = new Date(apr12007.getMiddleMillisecond()); Date d3 = new Date(apr12007.getMiddleMillisecond() + 500L); Date d4 = new Date(apr12007.getLastMillisecond()); Date end = new Date(apr22007.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.DAY, 1); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 7 days (just for the sake of having a multiple). */ public void testPreviousStandardDateDayB() { MyDateAxis axis = new MyDateAxis("Day"); Day apr12007 = new Day(1, 4, 2007); Day apr22007 = new Day(2, 4, 2007); // five dates to check... Date d0 = new Date(apr12007.getFirstMillisecond()); Date d1 = new Date(apr12007.getFirstMillisecond() + 500L); Date d2 = new Date(apr12007.getMiddleMillisecond()); Date d3 = new Date(apr12007.getMiddleMillisecond() + 500L); Date d4 = new Date(apr12007.getLastMillisecond()); Date end = new Date(apr22007.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.DAY, 7); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 hour. */ public void testPreviousStandardDateHourA() { MyDateAxis axis = new MyDateAxis("Hour"); Hour h0 = new Hour(12, 1, 4, 2007); Hour h1 = new Hour(13, 1, 4, 2007); // five dates to check... Date d0 = new Date(h0.getFirstMillisecond()); Date d1 = new Date(h0.getFirstMillisecond() + 500L); Date d2 = new Date(h0.getMiddleMillisecond()); Date d3 = new Date(h0.getMiddleMillisecond() + 500L); Date d4 = new Date(h0.getLastMillisecond()); Date end = new Date(h1.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.HOUR, 1); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 6 hours (just for the sake of having a multiple). */ public void testPreviousStandardDateHourB() { MyDateAxis axis = new MyDateAxis("Hour"); Hour h0 = new Hour(12, 1, 4, 2007); Hour h1 = new Hour(13, 1, 4, 2007); // five dates to check... Date d0 = new Date(h0.getFirstMillisecond()); Date d1 = new Date(h0.getFirstMillisecond() + 500L); Date d2 = new Date(h0.getMiddleMillisecond()); Date d3 = new Date(h0.getMiddleMillisecond() + 500L); Date d4 = new Date(h0.getLastMillisecond()); Date end = new Date(h1.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.HOUR, 6); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 1 second. */ public void testPreviousStandardDateSecondA() { MyDateAxis axis = new MyDateAxis("Second"); Second s0 = new Second(58, 31, 12, 1, 4, 2007); Second s1 = new Second(59, 31, 12, 1, 4, 2007); // five dates to check... Date d0 = new Date(s0.getFirstMillisecond()); Date d1 = new Date(s0.getFirstMillisecond() + 50L); Date d2 = new Date(s0.getMiddleMillisecond()); Date d3 = new Date(s0.getMiddleMillisecond() + 50L); Date d4 = new Date(s0.getLastMillisecond()); Date end = new Date(s1.getLastMillisecond()); DateTickUnit unit = new DateTickUnit(DateTickUnitType.SECOND, 1); axis.setTickUnit(unit); // START: check d0 and d1 axis.setTickMarkPosition(DateTickMarkPosition.START); axis.setRange(d0, end); Date psd = axis.previousStandardDate(d0, unit); Date nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d0.getTime()); assertTrue(nsd.getTime() >= d0.getTime()); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); // MIDDLE: check d1, d2 and d3 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); axis.setRange(d1, end); psd = axis.previousStandardDate(d1, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d1.getTime()); assertTrue(nsd.getTime() >= d1.getTime()); axis.setRange(d2, end); psd = axis.previousStandardDate(d2, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d2.getTime()); assertTrue(nsd.getTime() >= d2.getTime()); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); // END: check d3 and d4 axis.setTickMarkPosition(DateTickMarkPosition.END); axis.setRange(d3, end); psd = axis.previousStandardDate(d3, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d3.getTime()); assertTrue(nsd.getTime() >= d3.getTime()); axis.setRange(d4, end); psd = axis.previousStandardDate(d4, unit); nsd = unit.addToDate(psd, TimeZone.getDefault()); assertTrue(psd.getTime() < d4.getTime()); assertTrue(nsd.getTime() >= d4.getTime()); }