/** * Some basic checks for the clone() method. * * @throws CloneNotSupportedException */ @Test public void testCloning() throws CloneNotSupportedException { PiePlot p1 = new PiePlot(); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); }
public String generatePieChart( String hitOrdNum, HttpSession session, PrintWriter pw, String courseId, int studentId) { /* int groupId=0; if (groupName.equals("All")){ groupId=0; }else{ groupId = studStatisticBean.getGroupIdByName(groupName); }*/ String filename = null; try { // Retrieve list of WebHits StudentsConceptChartDataSet whDataSet = new StudentsConceptChartDataSet(studStatisticBean, courseId, studentId); ArrayList list = whDataSet.getDataBySection(hitOrdNum); // Throw a custom NoDataException if there is no data if (list.size() == 0) { System.out.println("No data has been found"); throw new NoDataException(); } // Create and populate a PieDataSet DefaultPieDataset data = new DefaultPieDataset(); Iterator iter = list.listIterator(); while (iter.hasNext()) { StudentsConceptHit wh = (StudentsConceptHit) iter.next(); data.setValue(wh.getSection(), wh.getHitDegree()); } // Create the chart object PiePlot plot = new PiePlot(data); plot.setInsets(new Insets(0, 5, 5, 5)); plot.setURLGenerator(new StandardPieURLGenerator("xy_chart.jsp", "section")); plot.setToolTipGenerator(new StandardPieItemLabelGenerator()); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white); // Write the chart image to the temporary directory ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); filename = ServletUtilities.saveChartAsPNG(chart, 600, 400, info, session); // Write the image map to the PrintWriter ChartUtilities.writeImageMap(pw, filename, info); pw.flush(); } catch (NoDataException e) { System.out.println(e.toString()); filename = "public_nodata_500x300.png"; } catch (Exception e) { System.out.println("Exception - " + e.toString()); e.printStackTrace(System.out); filename = "public_error_500x300.png"; } return filename; }
/** Some checks for the getLegendItems() method. */ @Test public void testGetLegendItems() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Item 1", 1.0); dataset.setValue("Item 2", 2.0); dataset.setValue("Item 3", 0.0); dataset.setValue("Item 4", null); PiePlot plot = new PiePlot(dataset); plot.setIgnoreNullValues(false); plot.setIgnoreZeroValues(false); List<LegendItem> items = plot.getLegendItems(); assertEquals(4, items.size()); // check that null items are ignored if requested plot.setIgnoreNullValues(true); items = plot.getLegendItems(); assertEquals(3, items.size()); // check that zero items are ignored if requested plot.setIgnoreZeroValues(true); items = plot.getLegendItems(); assertEquals(2, items.size()); // check that negative items are always ignored dataset.setValue("Item 5", -1.0); items = plot.getLegendItems(); assertEquals(2, items.size()); }
@Test public void testBug1126_e() throws CloneNotSupportedException { DefaultPieDataset dataset1 = new DefaultPieDataset(); PiePlot plot1 = new PiePlot(dataset1); plot1.setLabelGenerator(new StandardPieSectionLabelGenerator()); PiePlot plot2 = (PiePlot) plot1.clone(); StandardPieSectionLabelGenerator g2 = (StandardPieSectionLabelGenerator) plot2.getLabelGenerator(); g2.setAttributedLabel(1, new AttributedString("TESTING")); assertNotEquals(plot1, plot2); }
/** * Check that the default base section paint is not null, and that you can never set it to null. */ @Test public void testGetBaseSectionPaint() { PiePlot plot = new PiePlot(); assertNotNull(plot.getBaseSectionPaint()); try { plot.setBaseSectionPaint(null); fail("Should have thrown a NullPointerException on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'paint' argument.", e.getMessage()); } }
/** Draws a pie chart where the label generator returns null. */ @Test public void testDrawWithNullLegendLabels() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("L1", 12.0); dataset.setValue("L2", 11.0); JFreeChart chart = ChartFactory.createPieChart("Test", dataset); PiePlot plot = (PiePlot) chart.getPlot(); plot.setLegendLabelGenerator(new NullLegendLabelGenerator()); BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); }
/** * Check cloning of the legendLabelURLGenerator field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendLabelURLGenerator() throws CloneNotSupportedException { CustomPieURLGenerator generator = new CustomPieURLGenerator(); PiePlot p1 = new PiePlot(); p1.setLegendLabelURLGenerator(generator); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // check that the URL generator has been cloned assertNotSame(p1.getLegendLabelURLGenerator(), p2.getLegendLabelURLGenerator()); }
@Test public void testBug1126_d() throws CloneNotSupportedException { DefaultPieDataset dataset1 = new DefaultPieDataset(); PiePlot plot1 = new PiePlot(dataset1); plot1.setExplodePercent("A", 0.1); plot1.setExplodePercent("B", 0.2); PiePlot plot2 = (PiePlot) plot1.clone(); plot2.setExplodePercent("A", 0.3); plot2.setExplodePercent("B", 0.4); assertEquals(0.1, plot1.getExplodePercent("A"), EPSILON); assertEquals(0.2, plot1.getExplodePercent("B"), EPSILON); assertEquals(0.3, plot2.getExplodePercent("A"), EPSILON); assertEquals(0.4, plot2.getExplodePercent("B"), EPSILON); }
@Test public void testBug1126_c() throws CloneNotSupportedException { DefaultPieDataset dataset1 = new DefaultPieDataset(); PiePlot plot1 = new PiePlot(dataset1); plot1.setSectionOutlineStroke("A", new BasicStroke(5.0f)); plot1.setSectionOutlineStroke("B", new BasicStroke(6.0f)); PiePlot plot2 = (PiePlot) plot1.clone(); plot2.setSectionOutlineStroke("A", new BasicStroke(7.0f)); plot2.setSectionOutlineStroke("B", new BasicStroke(8.0f)); assertEquals(new BasicStroke(5.0f), plot1.getSectionOutlineStroke("A")); assertEquals(new BasicStroke(6.0f), plot1.getSectionOutlineStroke("B")); assertEquals(new BasicStroke(7.0f), plot2.getSectionOutlineStroke("A")); assertEquals(new BasicStroke(8.0f), plot2.getSectionOutlineStroke("B")); }
/** * Check cloning of the legendLabelToolTipGenerator field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendLabelToolTipGenerator() throws CloneNotSupportedException { StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator(); PiePlot p1 = new PiePlot(); p1.setLegendLabelToolTipGenerator(generator); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // change the generator and make sure it only affects p1 generator.getNumberFormat().setMinimumFractionDigits(2); assertFalse(p1.equals(p2)); }
/** * Check cloning of the legendItemShape field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendItemShape() throws CloneNotSupportedException { Rectangle shape = new Rectangle(-4, -4, 8, 8); PiePlot p1 = new PiePlot(); p1.setLegendItemShape(shape); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // change the shape and make sure it only affects p1 shape.setRect(1.0, 2.0, 3.0, 4.0); assertFalse(p1.equals(p2)); }
/** Test the equals() method. */ @Test public void testEquals() { PiePlot plot1 = new PiePlot(); PiePlot plot2 = new PiePlot(); assertEquals(plot1, plot2); assertEquals(plot2, plot1); // pieIndex... plot1.setPieIndex(99); assertFalse(plot1.equals(plot2)); plot2.setPieIndex(99); assertEquals(plot1, plot2); // interiorGap... plot1.setInteriorGap(0.15); assertFalse(plot1.equals(plot2)); plot2.setInteriorGap(0.15); assertEquals(plot1, plot2); // circular plot1.setCircular(!plot1.isCircular()); assertFalse(plot1.equals(plot2)); plot2.setCircular(false); assertEquals(plot1, plot2); // startAngle plot1.setStartAngle(Math.PI); assertFalse(plot1.equals(plot2)); plot2.setStartAngle(Math.PI); assertEquals(plot1, plot2); // direction plot1.setDirection(Rotation.ANTICLOCKWISE); assertFalse(plot1.equals(plot2)); plot2.setDirection(Rotation.ANTICLOCKWISE); assertEquals(plot1, plot2); // ignoreZeroValues plot1.setIgnoreZeroValues(true); plot2.setIgnoreZeroValues(false); assertFalse(plot1.equals(plot2)); plot2.setIgnoreZeroValues(true); assertEquals(plot1, plot2); // ignoreNullValues plot1.setIgnoreNullValues(true); plot2.setIgnoreNullValues(false); assertFalse(plot1.equals(plot2)); plot2.setIgnoreNullValues(true); assertEquals(plot1, plot2); // sectionPaintMap plot1.setSectionPaint("A", new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setSectionPaint("A", new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // baseSectionPaint plot1.setBaseSectionPaint(new GradientPaint(1.0f, 2.0f, Color.BLACK, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setBaseSectionPaint(new GradientPaint(1.0f, 2.0f, Color.BLACK, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // sectionOutlinesVisible plot1.setSectionOutlinesVisible(false); assertFalse(plot1.equals(plot2)); plot2.setSectionOutlinesVisible(false); assertEquals(plot1, plot2); // sectionOutlinePaintList plot1.setSectionOutlinePaint( "A", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setSectionOutlinePaint( "A", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // baseSectionOutlinePaint plot1.setBaseSectionOutlinePaint( new GradientPaint(1.0f, 2.0f, Color.gray, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setBaseSectionOutlinePaint( new GradientPaint(1.0f, 2.0f, Color.gray, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // sectionOutlineStrokeList plot1.setSectionOutlineStroke("A", new BasicStroke(1.0f)); assertFalse(plot1.equals(plot2)); plot2.setSectionOutlineStroke("A", new BasicStroke(1.0f)); assertEquals(plot1, plot2); // baseSectionOutlineStroke plot1.setBaseSectionOutlineStroke(new BasicStroke(1.0f)); assertFalse(plot1.equals(plot2)); plot2.setBaseSectionOutlineStroke(new BasicStroke(1.0f)); assertEquals(plot1, plot2); // shadowPaint plot1.setShadowPaint(new GradientPaint(1.0f, 2.0f, Color.orange, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setShadowPaint(new GradientPaint(1.0f, 2.0f, Color.orange, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // shadowXOffset plot1.setShadowXOffset(4.4); assertFalse(plot1.equals(plot2)); plot2.setShadowXOffset(4.4); assertEquals(plot1, plot2); // shadowYOffset plot1.setShadowYOffset(4.4); assertFalse(plot1.equals(plot2)); plot2.setShadowYOffset(4.4); assertEquals(plot1, plot2); // labelFont plot1.setLabelFont(new Font("Serif", Font.PLAIN, 18)); assertFalse(plot1.equals(plot2)); plot2.setLabelFont(new Font("Serif", Font.PLAIN, 18)); assertEquals(plot1, plot2); // labelPaint plot1.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.darkGray, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.darkGray, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // labelBackgroundPaint plot1.setLabelBackgroundPaint( new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setLabelBackgroundPaint( new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // labelOutlinePaint plot1.setLabelOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setLabelOutlinePaint(new GradientPaint(1.0f, 2.0f, Color.BLUE, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // labelOutlineStroke Stroke s = new BasicStroke(1.1f); plot1.setLabelOutlineStroke(s); assertFalse(plot1.equals(plot2)); plot2.setLabelOutlineStroke(s); assertEquals(plot1, plot2); // labelShadowPaint plot1.setLabelShadowPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setLabelShadowPaint(new GradientPaint(1.0f, 2.0f, Color.yellow, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // explodePercentages plot1.setExplodePercent("A", 0.33); assertFalse(plot1.equals(plot2)); plot2.setExplodePercent("A", 0.33); assertEquals(plot1, plot2); // labelGenerator plot1.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}{1}{0}")); assertFalse(plot1.equals(plot2)); plot2.setLabelGenerator(new StandardPieSectionLabelGenerator("{2}{1}{0}")); assertEquals(plot1, plot2); // labelFont Font f = new Font("SansSerif", Font.PLAIN, 20); plot1.setLabelFont(f); assertFalse(plot1.equals(plot2)); plot2.setLabelFont(f); assertEquals(plot1, plot2); // labelPaint plot1.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.magenta, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.magenta, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // maximumLabelWidth plot1.setMaximumLabelWidth(0.33); assertFalse(plot1.equals(plot2)); plot2.setMaximumLabelWidth(0.33); assertEquals(plot1, plot2); // labelGap plot1.setLabelGap(0.11); assertFalse(plot1.equals(plot2)); plot2.setLabelGap(0.11); assertEquals(plot1, plot2); // links visible plot1.setLabelLinksVisible(false); assertFalse(plot1.equals(plot2)); plot2.setLabelLinksVisible(false); assertEquals(plot1, plot2); plot1.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE); assertFalse(plot1.equals(plot2)); plot2.setLabelLinkStyle(PieLabelLinkStyle.QUAD_CURVE); assertEquals(plot1, plot2); // linkMargin plot1.setLabelLinkMargin(0.11); assertFalse(plot1.equals(plot2)); plot2.setLabelLinkMargin(0.11); assertEquals(plot1, plot2); // labelLinkPaint plot1.setLabelLinkPaint(new GradientPaint(1.0f, 2.0f, Color.magenta, 3.0f, 4.0f, Color.WHITE)); assertFalse(plot1.equals(plot2)); plot2.setLabelLinkPaint(new GradientPaint(1.0f, 2.0f, Color.magenta, 3.0f, 4.0f, Color.WHITE)); assertEquals(plot1, plot2); // labelLinkStroke plot1.setLabelLinkStroke(new BasicStroke(1.0f)); assertFalse(plot1.equals(plot2)); plot2.setLabelLinkStroke(new BasicStroke(1.0f)); assertEquals(plot1, plot2); // toolTipGenerator plot1.setToolTipGenerator(new StandardPieToolTipGenerator("{2}{1}{0}")); assertFalse(plot1.equals(plot2)); plot2.setToolTipGenerator(new StandardPieToolTipGenerator("{2}{1}{0}")); assertEquals(plot1, plot2); // urlGenerator plot1.setURLGenerator(new StandardPieURLGenerator("xx")); assertFalse(plot1.equals(plot2)); plot2.setURLGenerator(new StandardPieURLGenerator("xx")); assertEquals(plot1, plot2); // minimumArcAngleToDraw plot1.setMinimumArcAngleToDraw(1.0); assertFalse(plot1.equals(plot2)); plot2.setMinimumArcAngleToDraw(1.0); assertEquals(plot1, plot2); // legendItemShape plot1.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertFalse(plot1.equals(plot2)); plot2.setLegendItemShape(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertEquals(plot1, plot2); // legendLabelGenerator plot1.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} --> {1}")); assertFalse(plot1.equals(plot2)); plot2.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} --> {1}")); assertEquals(plot1, plot2); // legendLabelToolTipGenerator plot1.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} is {1}")); assertFalse(plot1.equals(plot2)); plot2.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("{0} is {1}")); assertEquals(plot1, plot2); // legendLabelURLGenerator plot1.setLegendLabelURLGenerator(new StandardPieURLGenerator("index.html")); assertFalse(plot1.equals(plot2)); plot2.setLegendLabelURLGenerator(new StandardPieURLGenerator("index.html")); assertEquals(plot1, plot2); // autoPopulateSectionPaint plot1.setAutoPopulateSectionPaint(false); assertFalse(plot1.equals(plot2)); plot2.setAutoPopulateSectionPaint(false); assertEquals(plot1, plot2); // autoPopulateSectionOutlinePaint plot1.setAutoPopulateSectionOutlinePaint(true); assertFalse(plot1.equals(plot2)); plot2.setAutoPopulateSectionOutlinePaint(true); assertEquals(plot1, plot2); // autoPopulateSectionOutlineStroke plot1.setAutoPopulateSectionOutlineStroke(true); assertFalse(plot1.equals(plot2)); plot2.setAutoPopulateSectionOutlineStroke(true); assertEquals(plot1, plot2); // shadowGenerator plot1.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4)); assertFalse(plot1.equals(plot2)); plot2.setShadowGenerator(new DefaultShadowGenerator(5, Color.gray, 0.6f, 4, -Math.PI / 4)); assertEquals(plot1, plot2); plot1.setShadowGenerator(null); assertFalse(plot1.equals(plot2)); plot2.setShadowGenerator(null); assertEquals(plot1, plot2); }
@Test public void testBug1126_b() throws CloneNotSupportedException { DefaultPieDataset dataset1 = new DefaultPieDataset(); PiePlot plot1 = new PiePlot(dataset1); plot1.setSectionOutlinePaint("A", Color.RED); plot1.setSectionOutlinePaint("B", Color.GREEN); PiePlot plot2 = (PiePlot) plot1.clone(); plot2.setSectionOutlinePaint("A", Color.BLUE); plot2.setSectionOutlinePaint("B", Color.YELLOW); assertEquals(Color.RED, plot1.getSectionOutlinePaint("A")); assertEquals(Color.GREEN, plot1.getSectionOutlinePaint("B")); assertEquals(Color.BLUE, plot2.getSectionOutlinePaint("A")); assertEquals(Color.YELLOW, plot2.getSectionOutlinePaint("B")); }
protected void buildChart() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); chart = ChartFactory.createMultiplePieChart( "Untitled Chart", dataset, org.jfree.util.TableOrder.BY_COLUMN, false, true, false); chart.setAntiAlias(true); // chartPanel = new ScrollableChartPanel(chart, true); chartPanel = buildChartPanel(chart); // chartHolder.getViewport().setView(chartPanel); setChartPanel(chartPanel); JFreeChart baseChart = (JFreeChart) ((MultiplePiePlot) (chart.getPlot())).getPieChart(); PiePlot base = (PiePlot) (baseChart.getPlot()); base.setIgnoreZeroValues(true); base.setLabelOutlinePaint(java.awt.Color.WHITE); base.setLabelShadowPaint(java.awt.Color.WHITE); base.setMaximumLabelWidth( 0.25); // allow bigger labels by a bit (this will make the chart smaller) base.setInteriorGap(0.000); // allow stretch to compensate for the bigger label width base.setLabelBackgroundPaint(java.awt.Color.WHITE); base.setOutlinePaint(null); base.setBackgroundPaint(null); base.setShadowPaint(null); base.setSimpleLabels(false); // I think they're false anyway // change the look of the series title to be smaller StandardChartTheme theme = new StandardChartTheme("Hi"); TextTitle title = new TextTitle("Whatever", theme.getLargeFont()); title.setPaint(theme.getAxisLabelPaint()); title.setPosition(RectangleEdge.BOTTOM); baseChart.setTitle(title); // this must come last because the chart must exist for us to set its dataset setSeriesDataset(dataset); }