use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class JFreeChartTest method testEquals.
/**
* Check that the equals() method can distinguish all fields.
*/
@Test
public void testEquals() {
JFreeChart chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true);
JFreeChart chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true);
assertEquals(chart1, chart2);
assertEquals(chart2, chart1);
// renderingHints
chart1.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
assertNotEquals(chart1, chart2);
chart2.setRenderingHints(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
assertEquals(chart1, chart2);
// borderVisible
chart1.setBorderVisible(true);
assertNotEquals(chart1, chart2);
chart2.setBorderVisible(true);
assertEquals(chart1, chart2);
// borderStroke
BasicStroke s = new BasicStroke(2.0f);
chart1.setBorderStroke(s);
assertNotEquals(chart1, chart2);
chart2.setBorderStroke(s);
assertEquals(chart1, chart2);
// borderPaint
chart1.setBorderPaint(Color.RED);
assertNotEquals(chart1, chart2);
chart2.setBorderPaint(Color.RED);
assertEquals(chart1, chart2);
// padding
chart1.setPadding(new RectangleInsets(1, 2, 3, 4));
assertNotEquals(chart1, chart2);
chart2.setPadding(new RectangleInsets(1, 2, 3, 4));
assertEquals(chart1, chart2);
// title
chart1.setTitle("XYZ");
assertNotEquals(chart1, chart2);
chart2.setTitle("XYZ");
assertEquals(chart1, chart2);
// subtitles
chart1.addSubtitle(new TextTitle("Subtitle"));
assertNotEquals(chart1, chart2);
chart2.addSubtitle(new TextTitle("Subtitle"));
assertEquals(chart1, chart2);
// plot
chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new RingPlot(), false);
chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), false);
assertNotEquals(chart1, chart2);
chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new RingPlot(), false);
assertEquals(chart1, chart2);
// backgroundPaint
chart1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE));
assertNotEquals(chart1, chart2);
chart2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE));
assertEquals(chart1, chart2);
// // backgroundImage
// chart1.setBackgroundImage(JFreeChart.INFO.getLogo());
// assertFalse(chart1.equals(chart2));
// chart2.setBackgroundImage(JFreeChart.INFO.getLogo());
// assertEquals(chart1, chart2);
// backgroundImageAlignment
chart1.setBackgroundImageAlignment(RectangleAlignment.BOTTOM_LEFT);
assertNotEquals(chart1, chart2);
chart2.setBackgroundImageAlignment(RectangleAlignment.BOTTOM_LEFT);
assertEquals(chart1, chart2);
// backgroundImageAlpha
chart1.setBackgroundImageAlpha(0.1f);
assertNotEquals(chart1, chart2);
chart2.setBackgroundImageAlpha(0.1f);
assertEquals(chart1, chart2);
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class StandardChartThemeTest method testEquals.
/**
* Confirm that the equals method can distinguish all the required fields.
*/
@Test
public void testEquals() {
StandardChartTheme t1 = new StandardChartTheme("Name");
StandardChartTheme t2 = new StandardChartTheme("Name");
assertEquals(t1, t2);
// name
t1 = new StandardChartTheme("t1");
assertNotEquals(t1, t2);
t2 = new StandardChartTheme("t1");
assertEquals(t1, t2);
// extraLargeFont
t1.setExtraLargeFont(new Font("Dialog", Font.PLAIN, 21));
assertNotEquals(t1, t2);
t2.setExtraLargeFont(new Font("Dialog", Font.PLAIN, 21));
assertEquals(t1, t2);
// largeFont
t1.setLargeFont(new Font("Dialog", Font.PLAIN, 19));
assertNotEquals(t1, t2);
t2.setLargeFont(new Font("Dialog", Font.PLAIN, 19));
assertEquals(t1, t2);
// regularFont;
t1.setRegularFont(new Font("Dialog", Font.PLAIN, 17));
assertNotEquals(t1, t2);
t2.setRegularFont(new Font("Dialog", Font.PLAIN, 17));
assertEquals(t1, t2);
// titlePaint;
t1.setTitlePaint(new GradientPaint(0f, 1f, Color.RED, 2f, 3f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setTitlePaint(new GradientPaint(0f, 1f, Color.RED, 2f, 3f, Color.BLUE));
assertEquals(t1, t2);
// subtitlePaint;
t1.setSubtitlePaint(new GradientPaint(1f, 2f, Color.RED, 3f, 4f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setSubtitlePaint(new GradientPaint(1f, 2f, Color.RED, 3f, 4f, Color.BLUE));
assertEquals(t1, t2);
// chartBackgroundPaint;
t1.setChartBackgroundPaint(new GradientPaint(2f, 3f, Color.BLUE, 4f, 5f, Color.RED));
assertNotEquals(t1, t2);
t2.setChartBackgroundPaint(new GradientPaint(2f, 3f, Color.BLUE, 4f, 5f, Color.RED));
assertEquals(t1, t2);
// legendBackgroundPaint;
t1.setLegendBackgroundPaint(new GradientPaint(3f, 4f, Color.GRAY, 1f, 2f, Color.RED));
assertNotEquals(t1, t2);
t2.setLegendBackgroundPaint(new GradientPaint(3f, 4f, Color.GRAY, 1f, 2f, Color.RED));
assertEquals(t1, t2);
// legendItemPaint;
t1.setLegendItemPaint(new GradientPaint(9f, 8f, Color.RED, 7f, 6f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setLegendItemPaint(new GradientPaint(9f, 8f, Color.RED, 7f, 6f, Color.BLUE));
assertEquals(t1, t2);
// drawingSupplier;
t1.setDrawingSupplier(new DefaultDrawingSupplier(new Paint[] { Color.RED }, new Paint[] { Color.BLUE }, new Stroke[] { new BasicStroke(1.0f) }, new Stroke[] { new BasicStroke(1.0f) }, new Shape[] { new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0) }));
assertNotEquals(t1, t2);
t2.setDrawingSupplier(new DefaultDrawingSupplier(new Paint[] { Color.RED }, new Paint[] { Color.BLUE }, new Stroke[] { new BasicStroke(1.0f) }, new Stroke[] { new BasicStroke(1.0f) }, new Shape[] { new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0) }));
assertEquals(t1, t2);
// plotBackgroundPaint;
t1.setPlotBackgroundPaint(new GradientPaint(4f, 3f, Color.RED, 6f, 7f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setPlotBackgroundPaint(new GradientPaint(4f, 3f, Color.RED, 6f, 7f, Color.BLUE));
assertEquals(t1, t2);
// plotOutlinePaint;
t1.setPlotOutlinePaint(new GradientPaint(5f, 2f, Color.BLUE, 6f, 7f, Color.RED));
assertNotEquals(t1, t2);
t2.setPlotOutlinePaint(new GradientPaint(5f, 2f, Color.BLUE, 6f, 7f, Color.RED));
assertEquals(t1, t2);
// labelLinkStyle;
t1.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
assertNotEquals(t1, t2);
t2.setLabelLinkStyle(PieLabelLinkStyle.STANDARD);
assertEquals(t1, t2);
// labelLinkPaint;
t1.setLabelLinkPaint(new GradientPaint(4f, 3f, Color.RED, 2f, 9f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setLabelLinkPaint(new GradientPaint(4f, 3f, Color.RED, 2f, 9f, Color.BLUE));
assertEquals(t1, t2);
// domainGridlinePaint;
t1.setDomainGridlinePaint(Color.BLUE);
assertNotEquals(t1, t2);
t2.setDomainGridlinePaint(Color.BLUE);
assertEquals(t1, t2);
// rangeGridlinePaint;
t1.setRangeGridlinePaint(Color.RED);
assertNotEquals(t1, t2);
t2.setRangeGridlinePaint(Color.RED);
assertEquals(t1, t2);
// axisOffset;
t1.setAxisOffset(new RectangleInsets(1, 2, 3, 4));
assertNotEquals(t1, t2);
t2.setAxisOffset(new RectangleInsets(1, 2, 3, 4));
assertEquals(t1, t2);
// axisLabelPaint;
t1.setAxisLabelPaint(new GradientPaint(8f, 4f, Color.GRAY, 2f, 9f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setAxisLabelPaint(new GradientPaint(8f, 4f, Color.GRAY, 2f, 9f, Color.BLUE));
assertEquals(t1, t2);
// tickLabelPaint;
t1.setTickLabelPaint(new GradientPaint(3f, 4f, Color.RED, 5f, 6f, Color.YELLOW));
assertNotEquals(t1, t2);
t2.setTickLabelPaint(new GradientPaint(3f, 4f, Color.RED, 5f, 6f, Color.YELLOW));
assertEquals(t1, t2);
// itemLabelPaint;
t1.setItemLabelPaint(new GradientPaint(2f, 5f, Color.GRAY, 1f, 2f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setItemLabelPaint(new GradientPaint(2f, 5f, Color.GRAY, 1f, 2f, Color.BLUE));
assertEquals(t1, t2);
// shadowVisible;
t1.setShadowVisible(!t1.isShadowVisible());
assertNotEquals(t1, t2);
t2.setShadowVisible(t1.isShadowVisible());
assertEquals(t1, t2);
// shadowPaint;
t1.setShadowPaint(new GradientPaint(7f, 1f, Color.BLUE, 4f, 6f, Color.RED));
assertNotEquals(t1, t2);
t2.setShadowPaint(new GradientPaint(7f, 1f, Color.BLUE, 4f, 6f, Color.RED));
assertEquals(t1, t2);
// barPainter;
t1.setBarPainter(new StandardBarPainter());
assertNotEquals(t1, t2);
t2.setBarPainter(new StandardBarPainter());
assertEquals(t1, t2);
// xyBarPainter;
t1.setXYBarPainter(new StandardXYBarPainter());
assertNotEquals(t1, t2);
t2.setXYBarPainter(new StandardXYBarPainter());
assertEquals(t1, t2);
// thermometerPaint;
t1.setThermometerPaint(new GradientPaint(9f, 7f, Color.RED, 5f, 1f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setThermometerPaint(new GradientPaint(9f, 7f, Color.RED, 5f, 1f, Color.BLUE));
assertEquals(t1, t2);
// errorIndicatorPaint;
t1.setErrorIndicatorPaint(new GradientPaint(0f, 1f, Color.WHITE, 2f, 3f, Color.BLUE));
assertNotEquals(t1, t2);
t2.setErrorIndicatorPaint(new GradientPaint(0f, 1f, Color.WHITE, 2f, 3f, Color.BLUE));
assertEquals(t1, t2);
// gridBandPaint
t1.setGridBandPaint(new GradientPaint(1f, 2f, Color.WHITE, 4f, 8f, Color.RED));
assertNotEquals(t1, t2);
t2.setGridBandPaint(new GradientPaint(1f, 2f, Color.WHITE, 4f, 8f, Color.RED));
assertEquals(t1, t2);
// gridBandAlternatePaint
t1.setGridBandAlternatePaint(new GradientPaint(1f, 4f, Color.GREEN, 1f, 2f, Color.RED));
assertNotEquals(t1, t2);
t2.setGridBandAlternatePaint(new GradientPaint(1f, 4f, Color.GREEN, 1f, 2f, Color.RED));
assertEquals(t1, t2);
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class CompositeTitleTest method testEquals.
/**
* Check that the equals() method distinguishes all fields.
*/
@Test
public void testEquals() {
CompositeTitle t1 = new CompositeTitle(new BlockContainer());
CompositeTitle t2 = new CompositeTitle(new BlockContainer());
assertEquals(t1, t2);
assertEquals(t2, t1);
// margin
t1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertNotEquals(t1, t2);
t2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertEquals(t1, t2);
// frame
t1.setFrame(new BlockBorder(Color.RED));
assertNotEquals(t1, t2);
t2.setFrame(new BlockBorder(Color.RED));
assertEquals(t1, t2);
// padding
t1.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertNotEquals(t1, t2);
t2.setPadding(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
assertEquals(t1, t2);
// contained titles
t1.getContainer().add(new TextTitle("T1"));
assertNotEquals(t1, t2);
t2.getContainer().add(new TextTitle("T1"));
assertEquals(t1, t2);
t1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.YELLOW));
assertNotEquals(t1, t2);
t2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.YELLOW));
assertEquals(t1, t2);
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ChartFactory method createPieChart.
/**
* Creates a pie chart with default settings that compares 2 datasets.
* The colour of each section will be determined by the move from the value
* for the same key in {@code previousDataset}. ie if value1 >
* value2 then the section will be in green (unless
* {@code greenForIncrease} is {@code false}, in which case it
* would be {@code red}). Each section can have a shade of red or
* green as the difference can be tailored between 0% (black) and
* percentDiffForMaxScale% (bright red/green).
* <p>
* For instance if {@code percentDiffForMaxScale} is 10 (10%), a
* difference of 5% will have a half shade of red/green, a difference of
* 10% or more will have a maximum shade/brightness of red/green.
* <P>
* The chart object returned by this method uses a {@link PiePlot} instance
* as the plot.
* <p>
* Written by <a href="mailto:opensource@objectlab.co.uk">Benoit
* Xhenseval</a>.
*
* @param title the chart title ({@code null} permitted).
* @param dataset the dataset for the chart ({@code null} permitted).
* @param previousDataset the dataset for the last run, this will be used
* to compare each key in the dataset
* @param percentDiffForMaxScale scale goes from bright red/green to black,
* percentDiffForMaxScale indicate the change
* required to reach top scale.
* @param greenForIncrease an increase since previousDataset will be
* displayed in green (decrease red) if true.
* @param legend a flag specifying whether or not a legend is required.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
* @param subTitle displays a subtitle with colour scheme if true
* @param showDifference create a new dataset that will show the %
* difference between the two datasets.
*
* @return A pie chart.
*/
public static JFreeChart createPieChart(String title, PieDataset dataset, PieDataset previousDataset, int percentDiffForMaxScale, boolean greenForIncrease, boolean legend, boolean tooltips, boolean urls, boolean subTitle, boolean showDifference) {
PiePlot plot = new PiePlot(dataset);
plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
if (tooltips) {
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
}
if (urls) {
plot.setURLGenerator(new StandardPieURLGenerator());
}
List keys = dataset.getKeys();
DefaultPieDataset series = null;
if (showDifference) {
series = new DefaultPieDataset();
}
double colorPerPercent = 255.0 / percentDiffForMaxScale;
for (Iterator it = keys.iterator(); it.hasNext(); ) {
Comparable key = (Comparable) it.next();
Number newValue = dataset.getValue(key);
Number oldValue = previousDataset.getValue(key);
if (oldValue == null) {
if (greenForIncrease) {
plot.setSectionPaint(key, Color.GREEN);
} else {
plot.setSectionPaint(key, Color.RED);
}
if (showDifference) {
// suppresses compiler warning
assert series != null;
series.setValue(key + " (+100%)", newValue);
}
} else {
double percentChange = (newValue.doubleValue() / oldValue.doubleValue() - 1.0) * 100.0;
double shade = (Math.abs(percentChange) >= percentDiffForMaxScale ? 255 : Math.abs(percentChange) * colorPerPercent);
if (greenForIncrease && newValue.doubleValue() > oldValue.doubleValue() || !greenForIncrease && newValue.doubleValue() < oldValue.doubleValue()) {
plot.setSectionPaint(key, new Color(0, (int) shade, 0));
} else {
plot.setSectionPaint(key, new Color((int) shade, 0, 0));
}
if (showDifference) {
// suppresses compiler warning
assert series != null;
series.setValue(key + " (" + (percentChange >= 0 ? "+" : "") + NumberFormat.getPercentInstance().format(percentChange / 100.0) + ")", newValue);
}
}
}
if (showDifference) {
plot.setDataset(series);
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
if (subTitle) {
TextTitle subtitle = new TextTitle("Bright " + (greenForIncrease ? "red" : "green") + "=change >=-" + percentDiffForMaxScale + "%, Bright " + (!greenForIncrease ? "red" : "green") + "=change >=+" + percentDiffForMaxScale + "%", new Font("SansSerif", Font.PLAIN, 10));
chart.addSubtitle(subtitle);
}
currentTheme.apply(chart);
return chart;
}
use of org.jfree.chart.api.RectangleInsets in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.
the class ChartFactory method createPieChart.
/**
* Creates a pie chart with default settings.
* <P>
* The chart object returned by this method uses a {@link PiePlot} instance
* as the plot.
*
* @param title the chart title ({@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.
* @param tooltips configure chart to generate tool tips?
* @param urls configure chart to generate URLs?
*
* @return A pie chart.
*/
public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls) {
PiePlot plot = new PiePlot(dataset);
plot.setLabelGenerator(new StandardPieSectionLabelGenerator());
plot.setInsets(new RectangleInsets(0.0, 5.0, 5.0, 5.0));
if (tooltips) {
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
}
if (urls) {
plot.setURLGenerator(new StandardPieURLGenerator());
}
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
currentTheme.apply(chart);
return chart;
}
Aggregations