public static void setTimeSeriesRender(Plot plot, boolean isShowData, boolean isShapesVisible) { XYPlot xyplot = (XYPlot) plot; xyplot.setNoDataMessage(NO_DATA_MSG); xyplot.setInsets(new RectangleInsets(10, 10, 5, 10)); XYLineAndShapeRenderer xyRenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xyRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xyRenderer.setBaseShapesVisible(false); if (isShowData) { xyRenderer.setBaseItemLabelsVisible(true); xyRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xyRenderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.BOTTOM_CENTER)); } xyRenderer.setBaseShapesVisible(isShapesVisible); DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis(); domainAxis.setAutoTickUnitSelection(false); DateTickUnit dateTickUnit = new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat("yyyy-MM")); domainAxis.setTickUnit(dateTickUnit); StandardXYToolTipGenerator xyTooltipGenerator = new StandardXYToolTipGenerator("{1}:{2}", new SimpleDateFormat("yyyy-MM-dd"), new DecimalFormat("0")); xyRenderer.setBaseToolTipGenerator(xyTooltipGenerator); setXY_XAixs(xyplot); setXY_YAixs(xyplot); }
/** * 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)); }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DateTickUnit t1 = new DateTickUnit(DateTickUnit.DAY, 1); DateTickUnit t2 = new DateTickUnit(DateTickUnit.DAY, 1); assertTrue(t1.equals(t2)); }
/** * 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)); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { DateTickUnit t1 = new DateTickUnit(DateTickUnit.DAY, 1); DateTickUnit t2 = new DateTickUnit(DateTickUnit.DAY, 1); assertTrue(t1.equals(t2)); int h1 = t1.hashCode(); int h2 = t2.hashCode(); assertEquals(h1, h2); }
/** * 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()); }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { DateTickUnit t1 = new DateTickUnit(DateTickUnitType.DAY, 1); DateTickUnit t2 = new DateTickUnit(DateTickUnitType.DAY, 1); assertTrue(t1.equals(t2)); int h1 = t1.hashCode(); int h2 = t2.hashCode(); assertEquals(h1, h2); }
private DateTickUnit getDateTickUnit(final TimeGranularity timeGranularity, final long windowMillis) { long windowBuckets = timeGranularity.convertToUnit(windowMillis); int tickSize = (int) Math.ceil(windowBuckets / (double) NUM_X_TICKS); DateTickUnitType unitType; switch (timeGranularity.getUnit()) { case DAYS: unitType = DateTickUnitType.DAY; break; case HOURS: unitType = DateTickUnitType.HOUR; break; case MILLISECONDS: unitType = DateTickUnitType.MILLISECOND; break; case MINUTES: unitType = DateTickUnitType.MINUTE; break; case SECONDS: unitType = DateTickUnitType.SECOND; break; default: throw new IllegalArgumentException( "Unsupported time unit granularity: " + timeGranularity.getUnit()); } return new DateTickUnit(unitType, tickSize); }
public Drawable createChart(final ATSCollection dataset, Dimension dimension) { JFreeChart chart = ChartFactory.createTimeSeriesChart( dataset.get(Attribute.TITLE), // title dataset.get(Attribute.X_AXIS_LABEL), // x-axis label dataset.get(Attribute.Y_AXIS_LABEL), // y-axis label dataset, // data false, // create legend? false, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(true); rangeAxis.setTickUnit(new NumberTickUnit( (Math.round(Math.floor(getMaxOutbreaks(dataset)))/20)+1, new DecimalFormat("0"))); XYItemRenderer r = plot.getRenderer(); r.setSeriesPaint(0, dataset.get(Attribute.SERIES_COLOR)); DateAxis axis = (DateAxis) plot.getDomainAxis(); final SimpleDateFormat dateFormatter = new SimpleDateFormat("yy"); axis.setDateFormatOverride(dateFormatter); DateTickUnit unit = new DateTickUnit(DateTickUnitType.YEAR, 1, dateFormatter); axis.setTickUnit(unit); return new JFreeChartDrawable(chart, dimension); }
public Date previousStandardDate(Date d, DateTickUnit unit) { return super.previousStandardDate(d, unit); }
public GraphGenerator(final String title, AthenaFeatures athenaFeatures, String feature) { super(title); this.feature = feature; final XYDataset dataset = createDatasetFromFeatureData(athenaFeatures, feature); final JFreeChart chart = createChart(dataset); chart.setTitle(""); LegendTitle legend = (LegendTitle) chart.getLegend(); chart.removeLegend(); Font nwfont = new Font("Arial",1,12); legend.setItemFont(nwfont); legend.setPosition(RectangleEdge.TOP); // legend.setWidth(200); legend.setItemLabelPadding(new RectangleInsets(3, 3, 3, 3)); legend.setHeight(10); // legend.setPadding(new RectangleInsets(10, 10, 10, 10)); XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.98, legend, RectangleAnchor.TOP_RIGHT); ta.setMaxWidth(0.95); // chart.addLegend(legend); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainZeroBaselinePaint(Color.gray); plot.setDomainGridlinePaint(Color.gray); plot.setDomainGridlineStroke(new BasicStroke(0.7f)); plot.setRangeGridlinePaint(Color.gray); plot.setRangeGridlineStroke(new BasicStroke(0.7f)); plot.setDomainMinorGridlinePaint(Color.black); plot.addAnnotation(ta); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.black); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(5)); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesShape(1, ShapeUtilities.createUpTriangle(5)); renderer.setSeriesPaint(2, Color.blue); Shape shape = new Ellipse2D.Double(-5.0,-5.0,10,10); renderer.setSeriesShape(2, shape); renderer.setShapesFilled(false); // renderer.setSeriesShapesVisible(1, false); //apply theme // StandardChartTheme.createJFreeTheme().apply(chart); plot.setRenderer(renderer); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel(feature + " (K)"); yAxis.setAxisLineVisible(false); yAxis.setTickUnit(new NumberTickUnit(50000)); yAxis.setNumberFormatOverride(new ByteFormat()); yAxis.setRange(new Range(0, 160000)); plot.getRenderer().setBaseItemLabelsVisible(true); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); xAxis.setAxisLineVisible(false); xAxis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss")); xAxis.setTickUnit(new DateTickUnit(DateTickUnit.MINUTE, 3)); xAxis.setLabelFont(new Font("Arial",1,12)); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(631, 381)); chartPanel.setMouseZoomable(true, true); setContentPane(chartPanel); try { ChartUtilities.saveChartAsPNG(new File("result.png"), chart, 631, 381); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
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()); }
/** * A basic check for the testPreviousStandardDate() method when the * tick unit is 5 seconds (just for the sake of having a multiple). */ public void testPreviousStandardDateSecondB() { 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, 5); 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()); }