Search in sources :

Example 16 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class XYBarRendererTest method testSerialization2.

/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization2() {
    XYBarRenderer r1 = new XYBarRenderer();
    r1.setPositiveItemLabelPositionFallback(new ItemLabelPosition());
    XYBarRenderer r2 = TestUtils.serialised(r1);
    assertEquals(r1, r2);
}
Also used : ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Test(org.junit.jupiter.api.Test)

Example 17 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractRendererTest method testEquals_ObjectList4.

@Test
public void testEquals_ObjectList4() {
    BarRenderer r1 = new BarRenderer();
    r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    BarRenderer r2 = new BarRenderer();
    r2.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertEquals(r1, r2);
    r2.setSeriesNegativeItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertNotEquals(r1, r2);
}
Also used : BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Test(org.junit.jupiter.api.Test)

Example 18 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractRendererTest method testEventNotification.

/**
 * Tests each setter method to ensure that it sends an event notification.
 */
@Test
public void testEventNotification() {
    RendererChangeDetector detector = new RendererChangeDetector();
    // have to use a subclass of
    BarRenderer r1 = new BarRenderer();
    // AbstractRenderer
    r1.addChangeListener(detector);
    // PAINT
    detector.setNotified(false);
    r1.setSeriesPaint(0, Color.RED);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultPaint(Color.RED);
    assertTrue(detector.getNotified());
    // OUTLINE PAINT
    detector.setNotified(false);
    r1.setSeriesOutlinePaint(0, Color.RED);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultOutlinePaint(Color.RED);
    assertTrue(detector.getNotified());
    // STROKE
    detector.setNotified(false);
    r1.setSeriesStroke(0, new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultStroke(new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    // OUTLINE STROKE
    detector.setNotified(false);
    r1.setSeriesOutlineStroke(0, new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultOutlineStroke(new BasicStroke(1.0f));
    assertTrue(detector.getNotified());
    // SHAPE
    detector.setNotified(false);
    r1.setSeriesShape(0, new Rectangle2D.Float());
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultShape(new Rectangle2D.Float());
    assertTrue(detector.getNotified());
    // ITEM_LABELS_VISIBLE
    detector.setNotified(false);
    r1.setSeriesItemLabelsVisible(0, Boolean.TRUE);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultItemLabelsVisible(Boolean.TRUE);
    assertTrue(detector.getNotified());
    // ITEM_LABEL_FONT
    detector.setNotified(false);
    r1.setSeriesItemLabelFont(0, new Font("Serif", Font.PLAIN, 12));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultItemLabelFont(new Font("Serif", Font.PLAIN, 12));
    assertTrue(detector.getNotified());
    // ITEM_LABEL_PAINT
    detector.setNotified(false);
    r1.setSeriesItemLabelPaint(0, Color.BLUE);
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultItemLabelPaint(Color.BLUE);
    assertTrue(detector.getNotified());
    // POSITIVE ITEM LABEL POSITION
    detector.setNotified(false);
    r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
    // NEGATIVE ITEM LABEL ANCHOR
    detector.setNotified(false);
    r1.setSeriesNegativeItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
    detector.setNotified(false);
    r1.setDefaultNegativeItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertTrue(detector.getNotified());
}
Also used : BasicStroke(java.awt.BasicStroke) Rectangle2D(java.awt.geom.Rectangle2D) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 19 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class YIntervalRenderer method drawAdditionalItemLabel.

/**
 * Draws an item label.
 *
 * @param g2  the graphics device.
 * @param orientation  the orientation.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param x  the x coordinate (in Java2D space).
 * @param y  the y coordinate (in Java2D space).
 */
private void drawAdditionalItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y) {
    if (this.additionalItemLabelGenerator == null) {
        return;
    }
    Font labelFont = getItemLabelFont(series, item);
    Paint paint = getItemLabelPaint(series, item);
    g2.setFont(labelFont);
    g2.setPaint(paint);
    String label = this.additionalItemLabelGenerator.generateLabel(dataset, series, item);
    ItemLabelPosition position = getNegativeItemLabelPosition(series, item);
    Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation);
    TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor());
}
Also used : Point2D(java.awt.geom.Point2D) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Paint(java.awt.Paint) Font(java.awt.Font)

Example 20 with ItemLabelPosition

use of org.jfree.chart.labels.ItemLabelPosition in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class AbstractRendererTest method testEquals_ObjectList3.

@Test
public void testEquals_ObjectList3() {
    BarRenderer r1 = new BarRenderer();
    r1.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    BarRenderer r2 = new BarRenderer();
    r2.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER));
    assertEquals(r1, r2);
    r2.setSeriesPositiveItemLabelPosition(1, new ItemLabelPosition(ItemLabelAnchor.INSIDE1, TextAnchor.CENTER));
    assertNotEquals(r1, r2);
}
Also used : BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) Test(org.junit.jupiter.api.Test)

Aggregations

ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)72 Font (java.awt.Font)30 Paint (java.awt.Paint)26 Point2D (java.awt.geom.Point2D)22 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)21 NumberAxis (org.jfree.chart.axis.NumberAxis)20 CategoryPlot (org.jfree.chart.plot.CategoryPlot)18 CategoryAxis (org.jfree.chart.axis.CategoryAxis)15 JFreeChart (org.jfree.chart.JFreeChart)13 GradientPaint (java.awt.GradientPaint)11 ValueAxis (org.jfree.chart.axis.ValueAxis)11 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)11 StackedBarRenderer (org.jfree.chart.renderer.category.StackedBarRenderer)11 Color (java.awt.Color)10 Test (org.junit.Test)10 Shape (java.awt.Shape)8 WaterfallBarRenderer (org.jfree.chart.renderer.category.WaterfallBarRenderer)8 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)8 Test (org.junit.jupiter.api.Test)8 BasicStroke (java.awt.BasicStroke)7