/** * Test that the equals() method distinguishes all fields. */ public void testEquals() { BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer(); BoxAndWhiskerRenderer r2 = new BoxAndWhiskerRenderer(); assertEquals(r1, r2); r1.setArtifactPaint(Color.yellow); assertFalse(r1.equals(r2)); r2.setArtifactPaint(Color.yellow); assertEquals(r1, r2); r1.setFillBox(!r1.getFillBox()); assertFalse(r1.equals(r2)); r2.setFillBox(!r2.getFillBox()); assertEquals(r1, r2); r1.setItemMargin(0.11); assertFalse(r1.equals(r2)); r2.setItemMargin(0.11); assertEquals(r1, r2); }
/** * Test that the equals() method distinguishes all fields. */ public void testEquals() { BoxAndWhiskerRenderer r1 = new BoxAndWhiskerRenderer(); BoxAndWhiskerRenderer r2 = new BoxAndWhiskerRenderer(); assertEquals(r1, r2); r1.setArtifactPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.blue)); assertFalse(r1.equals(r2)); r2.setArtifactPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.blue)); assertEquals(r1, r2); r1.setFillBox(!r1.getFillBox()); assertFalse(r1.equals(r2)); r2.setFillBox(!r2.getFillBox()); assertEquals(r1, r2); r1.setItemMargin(0.11); assertFalse(r1.equals(r2)); r2.setItemMargin(0.11); assertEquals(r1, r2); }
/** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (particularly by code in the renderer). */ public void testDrawWithNullInfo() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(0.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, null); success = true; } catch (NullPointerException e) { success = false; } assertTrue(success); }
/** * Creates and returns a default instance of a box and whisker chart * based on data from a {@link BoxAndWhiskerCategoryDataset}. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel a label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. * * @since 1.0.4 */ public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
/** * Creates and returns a default instance of a box and whisker chart * based on data from a {@link BoxAndWhiskerCategoryDataset}. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel a label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. * * @since 1.0.4 */ public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setBaseToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates and returns a default instance of a box and whisker chart * based on data from a {@link BoxAndWhiskerCategoryDataset}. * * @param title the chart title ({@code null} permitted). * @param categoryAxisLabel a label for the category axis * ({@code null} permitted). * @param valueAxisLabel a label for the value axis ({@code null} * permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A box and whisker chart. * * @since 1.0.4 */ public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a chart. * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(BoxAndWhiskerCategoryDataset dataset) { // create the chart... CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis("Value"); CategoryItemRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot( dataset, domainAxis, rangeAxis, renderer ); JFreeChart chart = new JFreeChart(chartTitle, plot); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
protected JFreeChart createLegend(BoxAndWhiskerCategoryDataset dataset) { CategoryAxis domainAxis = new CategoryAxis(null); NumberAxis rangeAxis = new NumberAxis("Value"); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot( dataset, domainAxis, rangeAxis, renderer ); JFreeChart chart = new JFreeChart(chartTitle, plot); System.out.println(SERIES_COUNT + ","+CATEGORY_COUNT); renderer.setLegendItemLabelGenerator(new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); return chart; }
public static JFreeChart createDumyChart() { final BoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); final CategoryAxis xAxis = new CategoryAxis( "Type" ); final NumberAxis yAxis = new NumberAxis( "Value" ); yAxis.setAutoRangeIncludesZero( false ); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox( true ); renderer.setMeanVisible( false ); renderer.setMedianVisible( false ); // renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final CategoryPlot plot = new CategoryPlot( dataset, xAxis, yAxis, renderer ); return new JFreeChart( plot ); }
public static JFreeChart createWhiskerChart( SuccessfulAttack sa ) { BoxAndWhiskerCategoryDataset boxandwhiskercategorydataset = createDataset( sa ); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setMaximumBarWidth( 0.05 ); renderer.setMeanVisible( false ); renderer.setSeriesPaint( 0, Color.GREEN ); renderer.setSeriesPaint( 1, Color.RED ); renderer.setSeriesPaint( 2, Color.BLUE ); NumberAxis numberAxis = new NumberAxis( "duration in ms" ); CategoryPlot categoryplot = new CategoryPlot( boxandwhiskercategorydataset, new CategoryAxis( "" ), numberAxis, renderer ); categoryplot.setDomainGridlinesVisible( true ); categoryplot.setRangePannable( true ); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits( NumberAxis.createIntegerTickUnits() ); JFreeChart jFreeChart = new JFreeChart( "", new Font( "SansSerif", Font.BOLD, 14 ), categoryplot, true ); jFreeChart.removeLegend(); return jFreeChart; }
/** * Some checks for the getLegendItem() method. */ public void testGetLegendItem() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); List values = new ArrayList(); values.add(new Double(1.10)); values.add(new Double(1.45)); values.add(new Double(1.33)); values.add(new Double(1.23)); dataset.add(values, "R1", "C1"); BoxAndWhiskerRenderer r = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("x"), new NumberAxis("y"), r); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(0, 0); assertNotNull(li); r.setSeriesVisibleInLegend(0, Boolean.FALSE); li = r.getLegendItem(0, 0); assertNull(li); }
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ public void testGetLegendItemSeriesIndex() { DefaultCategoryDataset dataset0 = new DefaultCategoryDataset(); dataset0.addValue(21.0, "R1", "C1"); dataset0.addValue(22.0, "R2", "C1"); DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); dataset1.addValue(23.0, "R3", "C1"); dataset1.addValue(24.0, "R4", "C1"); dataset1.addValue(25.0, "R5", "C1"); BoxAndWhiskerRenderer r = new BoxAndWhiskerRenderer(); CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, dataset1); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("R5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
/** * Draws a chart where the dataset contains a null mean value. */ public void testDrawWithNullMean() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(null, new Double(2.0), new Double(0.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; e.printStackTrace(); } assertTrue(success); }
/** * Draws a chart where the dataset contains a null median value. */ public void testDrawWithNullMedian() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), null, new Double(0.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null Q1 value. */ public void testDrawWithNullQ1() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), null, new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null Q3 value. */ public void testDrawWithNullQ3() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), null, new Double(0.5), new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null min regular value. */ public void testDrawWithNullMinRegular() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), null, new Double(4.5), new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null max regular value. */ public void testDrawWithNullMaxRegular() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), null, new Double(-0.5), new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null min outlier value. */ public void testDrawWithNullMinOutlier() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), new Double(4.5), null, new Double(5.5), null), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Draws a chart where the dataset contains a null max outlier value. */ public void testDrawWithNullMaxOutlier() { boolean success = false; try { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0), new Double(3.0), new Double(4.0), new Double(0.5), new Double(4.5), new Double(-0.5), null, new java.util.ArrayList()), "S1", "C1"); CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new BoxAndWhiskerRenderer()); ChartRenderingInfo info = new ChartRenderingInfo(); JFreeChart chart = new JFreeChart(plot); /* BufferedImage image = */ chart.createBufferedImage(300, 200, info); success = true; } catch (Exception e) { success = false; } assertTrue(success); }
/** * Plots Data for Chart */ private void boxWhiskerPlot() { BoxAndWhiskerCategoryDataset dataset = createDataset(); CategoryAxis xAxis = new CategoryAxis("Model"); NumberAxis yAxis = new NumberAxis("Fitness"); yAxis.setRange(0.0, 1.0); BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(false); renderer.setMaximumBarWidth(0.2); renderer.setItemMargin(0.5); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); chart = new JFreeChart( "Model comparison", new Font("Palatino", Font.BOLD, 14), plot, true ); chart.removeLegend(); // boxWhiskerPane.setCenter(viewer); }
@Override protected JFreeChart createChart(String title, Dataset dataset) { JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, X_AXIS_LABEL, getYAxisLabel(), (BoxAndWhiskerCategoryDataset) dataset, false); CategoryPlot p = chart.getCategoryPlot(); p.setForegroundAlpha(0.5f); p.setBackgroundPaint(Color.lightGray); p.setDomainGridlinesVisible(true); p.setDomainGridlinePaint(Color.white); p.setRangeGridlinesVisible(true); p.setRangeGridlinePaint(Color.white); BoxAndWhiskerRenderer renderer = (BoxAndWhiskerRenderer)p.getRenderer(); renderer.setSeriesPaint(0, new Color(40,234,115)); renderer.setMeanVisible(false); return chart; }
/** * Tests this renderer for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BoxAndWhiskerRenderer)) { return false; } if (!super.equals(obj)) { return false; } BoxAndWhiskerDotsRenderer that = (BoxAndWhiskerDotsRenderer) obj; if (!PaintUtilities.equal(this.artifactPaint, that.artifactPaint)) { return false; } if (!(this.fillBox == that.fillBox)) { return false; } if (!(this.itemMargin == that.itemMargin)) { return false; } return true; }