Search in sources :

Example 16 with RectangleInsets

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

the class CompassPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point ({@code null} permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    int outerRadius, innerRadius;
    int x1, y1, x2, y2;
    double a;
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    // draw the background
    if (this.drawBorder) {
        drawBackground(g2, area);
    }
    int midX = (int) (area.getWidth() / 2);
    int midY = (int) (area.getHeight() / 2);
    int radius = midX;
    if (midY < midX) {
        radius = midY;
    }
    --radius;
    int diameter = 2 * radius;
    midX += (int) area.getMinX();
    midY += (int) area.getMinY();
    this.circle1.setFrame(midX - radius, midY - radius, diameter, diameter);
    this.circle2.setFrame(midX - radius + 15, midY - radius + 15, diameter - 30, diameter - 30);
    g2.setPaint(this.rosePaint);
    this.a1 = new Area(this.circle1);
    this.a2 = new Area(this.circle2);
    this.a1.subtract(this.a2);
    g2.fill(this.a1);
    g2.setPaint(this.roseCenterPaint);
    x1 = diameter - 30;
    g2.fillOval(midX - radius + 15, midY - radius + 15, x1, x1);
    g2.setPaint(this.roseHighlightPaint);
    g2.drawOval(midX - radius, midY - radius, diameter, diameter);
    x1 = diameter - 20;
    g2.drawOval(midX - radius + 10, midY - radius + 10, x1, x1);
    x1 = diameter - 30;
    g2.drawOval(midX - radius + 15, midY - radius + 15, x1, x1);
    x1 = diameter - 80;
    g2.drawOval(midX - radius + 40, midY - radius + 40, x1, x1);
    outerRadius = radius - 20;
    innerRadius = radius - 32;
    for (int w = 0; w < 360; w += 15) {
        a = Math.toRadians(w);
        x1 = midX - ((int) (Math.sin(a) * innerRadius));
        x2 = midX - ((int) (Math.sin(a) * outerRadius));
        y1 = midY - ((int) (Math.cos(a) * innerRadius));
        y2 = midY - ((int) (Math.cos(a) * outerRadius));
        g2.drawLine(x1, y1, x2, y2);
    }
    g2.setPaint(this.roseHighlightPaint);
    innerRadius = radius - 26;
    outerRadius = 7;
    for (int w = 45; w < 360; w += 90) {
        a = Math.toRadians(w);
        x1 = midX - ((int) (Math.sin(a) * innerRadius));
        y1 = midY - ((int) (Math.cos(a) * innerRadius));
        g2.fillOval(x1 - outerRadius, y1 - outerRadius, 2 * outerRadius, 2 * outerRadius);
    }
    // / Squares
    for (int w = 0; w < 360; w += 90) {
        a = Math.toRadians(w);
        x1 = midX - ((int) (Math.sin(a) * innerRadius));
        y1 = midY - ((int) (Math.cos(a) * innerRadius));
        Polygon p = new Polygon();
        p.addPoint(x1 - outerRadius, y1);
        p.addPoint(x1, y1 + outerRadius);
        p.addPoint(x1 + outerRadius, y1);
        p.addPoint(x1, y1 - outerRadius);
        g2.fillPolygon(p);
    }
    // / Draw N, S, E, W
    innerRadius = radius - 42;
    Font f = getCompassFont(radius);
    g2.setFont(f);
    g2.drawString(localizationResources.getString("N"), midX - 5, midY - innerRadius + f.getSize());
    g2.drawString(localizationResources.getString("S"), midX - 5, midY + innerRadius - 5);
    g2.drawString(localizationResources.getString("W"), midX - innerRadius + 5, midY + 5);
    g2.drawString(localizationResources.getString("E"), midX + innerRadius - f.getSize(), midY + 5);
    // plot the data (unless the dataset is null)...
    y1 = radius / 2;
    x1 = radius / 6;
    Rectangle2D needleArea = new Rectangle2D.Double((midX - x1), (midY - y1), (2 * x1), (2 * y1));
    int x = this.seriesNeedle.length;
    int current;
    double value;
    int i = (this.datasets.length - 1);
    for (; i >= 0; --i) {
        ValueDataset data = this.datasets[i];
        if (data != null && data.getValue() != null) {
            value = (data.getValue().doubleValue()) % this.revolutionDistance;
            value = value / this.revolutionDistance * 360;
            current = i % x;
            this.seriesNeedle[current].draw(g2, needleArea, value);
        }
    }
    if (this.drawBorder) {
        drawOutline(g2, area);
    }
}
Also used : Area(java.awt.geom.Area) Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.api.RectangleInsets) ValueDataset(org.jfree.data.general.ValueDataset) DefaultValueDataset(org.jfree.data.general.DefaultValueDataset) Polygon(java.awt.Polygon) Paint(java.awt.Paint) Font(java.awt.Font)

Example 17 with RectangleInsets

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

the class RingPlot method drawItem.

/**
 * Draws a single data item.
 *
 * @param g2  the graphics device ({@code null} not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
@Override
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) {
    PieDataset dataset = getDataset();
    Number n = dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    Rotation direction = getDirection();
    if (direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    } else if (direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    } else {
        throw new IllegalStateException("Rotation type not recognised.");
    }
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        Comparable key = getSectionKey(section);
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(key) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.OPEN);
        // create the bounds for the inner arc
        double depth = this.sectionDepth / 2.0;
        RectangleInsets s = new RectangleInsets(UnitType.RELATIVE, depth, depth, depth, depth);
        Rectangle2D innerArcBounds = new Rectangle2D.Double();
        innerArcBounds.setRect(arcBounds);
        s.trim(innerArcBounds);
        // calculate inner arc in reverse direction, for later
        // GeneralPath construction
        Arc2D.Double arc2 = new Arc2D.Double(innerArcBounds, angle1 + angle, -angle, Arc2D.OPEN);
        GeneralPath path = new GeneralPath();
        path.moveTo((float) arc.getStartPoint().getX(), (float) arc.getStartPoint().getY());
        path.append(arc.getPathIterator(null), false);
        path.append(arc2.getPathIterator(null), true);
        path.closePath();
        Line2D separator = new Line2D.Double(arc2.getEndPoint(), arc.getStartPoint());
        if (currentPass == 0) {
            Paint shadowPaint = getShadowPaint();
            double shadowXOffset = getShadowXOffset();
            double shadowYOffset = getShadowYOffset();
            if (shadowPaint != null && getShadowGenerator() == null) {
                Shape shadowArc = ShapeUtils.createTranslatedShape(path, (float) shadowXOffset, (float) shadowYOffset);
                g2.setPaint(shadowPaint);
                g2.fill(shadowArc);
            }
        } else if (currentPass == 1) {
            Paint paint = lookupSectionPaint(key);
            g2.setPaint(paint);
            g2.fill(path);
            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (getSectionOutlinesVisible() && outlinePaint != null && outlineStroke != null) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(path);
            }
            if (section == 0) {
                String nstr = null;
                if (this.centerTextMode.equals(CenterTextMode.VALUE)) {
                    nstr = this.centerTextFormatter.format(n);
                } else if (this.centerTextMode.equals(CenterTextMode.FIXED)) {
                    nstr = this.centerText;
                }
                if (nstr != null) {
                    g2.setFont(this.centerTextFont);
                    g2.setPaint(this.centerTextColor);
                    TextUtils.drawAlignedString(nstr, g2, (float) dataArea.getCenterX(), (float) dataArea.getCenterY(), TextAnchor.CENTER);
                }
            }
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    PieToolTipGenerator toolTipGenerator = getToolTipGenerator();
                    if (toolTipGenerator != null) {
                        tip = toolTipGenerator.generateToolTip(dataset, key);
                    }
                    String url = null;
                    PieURLGenerator urlGenerator = getURLGenerator();
                    if (urlGenerator != null) {
                        url = urlGenerator.generateURL(dataset, key, getPieIndex());
                    }
                    PieSectionEntity entity = new PieSectionEntity(path, dataset, getPieIndex(), section, key, tip, url);
                    entities.add(entity);
                }
            }
        } else if (currentPass == 2) {
            if (this.separatorsVisible) {
                Line2D extendedSeparator = LineUtils.extendLine(separator, this.innerSeparatorExtension, this.outerSeparatorExtension);
                g2.setStroke(this.separatorStroke);
                g2.setPaint(this.separatorPaint);
                g2.draw(extendedSeparator);
            }
        }
    }
    state.setLatestAngle(angle2);
}
Also used : PieURLGenerator(org.jfree.chart.urls.PieURLGenerator) GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) Rotation(org.jfree.chart.api.Rotation) Arc2D(java.awt.geom.Arc2D) Line2D(java.awt.geom.Line2D) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) PieDataset(org.jfree.data.general.PieDataset) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleInsets(org.jfree.chart.api.RectangleInsets) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 18 with RectangleInsets

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

the class SpiderWebPlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point ({@code null} permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    if (info != null) {
        info.setPlotArea(area);
        info.setDataArea(area);
    }
    drawBackground(g2, area);
    drawOutline(g2, area);
    Shape savedClip = g2.getClip();
    g2.clip(area);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    if (!DatasetUtils.isEmptyOrNull(this.dataset)) {
        int seriesCount, catCount;
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            seriesCount = this.dataset.getRowCount();
            catCount = this.dataset.getColumnCount();
        } else {
            seriesCount = this.dataset.getColumnCount();
            catCount = this.dataset.getRowCount();
        }
        // ensure we have a maximum value to use on the axes
        if (this.maxValue == DEFAULT_MAX_VALUE) {
            calculateMaxValue(seriesCount, catCount);
        }
        // Next, setup the plot area
        // adjust the plot area by the interior spacing value
        double gapHorizontal = area.getWidth() * getInteriorGap();
        double gapVertical = area.getHeight() * getInteriorGap();
        double X = area.getX() + gapHorizontal / 2;
        double Y = area.getY() + gapVertical / 2;
        double W = area.getWidth() - gapHorizontal;
        double H = area.getHeight() - gapVertical;
        double headW = area.getWidth() * this.headPercent;
        double headH = area.getHeight() * this.headPercent;
        // make the chart area a square
        double min = Math.min(W, H) / 2;
        X = (X + X + W) / 2 - min;
        Y = (Y + Y + H) / 2 - min;
        W = 2 * min;
        H = 2 * min;
        Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2);
        Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H);
        // draw the axis and category label
        for (int cat = 0; cat < catCount; cat++) {
            double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount);
            Point2D endPoint = getWebPoint(radarArea, angle, 1);
            // 1 = end of axis
            Line2D line = new Line2D.Double(centre, endPoint);
            g2.setPaint(this.axisLinePaint);
            g2.setStroke(this.axisLineStroke);
            g2.draw(line);
            drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / catCount);
        }
        // Now actually plot each of the series polygons..
        for (int series = 0; series < seriesCount; series++) {
            drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW);
        }
    } else {
        drawNoDataMessage(g2, area);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, area);
}
Also used : RectangleInsets(org.jfree.chart.api.RectangleInsets)

Example 19 with RectangleInsets

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

the class PeriodAxisLabelInfoTest method testEquals.

/**
 * Confirm that the equals method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    PeriodAxisLabelInfo info1 = new PeriodAxisLabelInfo(Day.class, new SimpleDateFormat("d"));
    PeriodAxisLabelInfo info2 = new PeriodAxisLabelInfo(Day.class, new SimpleDateFormat("d"));
    assertEquals(info1, info2);
    assertEquals(info2, info1);
    Class c1 = Day.class;
    Class c2 = Month.class;
    DateFormat df1 = new SimpleDateFormat("d");
    DateFormat df2 = new SimpleDateFormat("MMM");
    RectangleInsets sp1 = new RectangleInsets(1, 1, 1, 1);
    RectangleInsets sp2 = new RectangleInsets(2, 2, 2, 2);
    Font lf1 = new Font("SansSerif", Font.PLAIN, 10);
    Font lf2 = new Font("SansSerif", Font.BOLD, 9);
    Paint lp1 = Color.BLACK;
    Paint lp2 = Color.BLUE;
    boolean b1 = true;
    boolean b2 = false;
    Stroke s1 = new BasicStroke(0.5f);
    Stroke s2 = new BasicStroke(0.25f);
    Paint dp1 = Color.RED;
    Paint dp2 = Color.GREEN;
    info1 = new PeriodAxisLabelInfo(c2, df1, sp1, lf1, lp1, b1, s1, dp1);
    info2 = new PeriodAxisLabelInfo(c1, df1, sp1, lf1, lp1, b1, s1, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df1, sp1, lf1, lp1, b1, s1, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp1, lf1, lp1, b1, s1, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp1, lf1, lp1, b1, s1, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp2, lf1, lp1, b1, s1, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp2, lf1, lp1, b1, s1, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp1, b1, s1, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp1, b1, s1, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b1, s1, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b1, s1, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b2, s1, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b2, s1, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b2, s2, dp1);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b2, s2, dp1);
    assertEquals(info1, info2);
    info1 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b2, s2, dp2);
    assertNotEquals(info1, info2);
    info2 = new PeriodAxisLabelInfo(c2, df2, sp2, lf2, lp2, b2, s2, dp2);
    assertEquals(info1, info2);
}
Also used : BasicStroke(java.awt.BasicStroke) Month(org.jfree.data.time.Month) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RectangleInsets(org.jfree.chart.api.RectangleInsets) Paint(java.awt.Paint) SimpleDateFormat(java.text.SimpleDateFormat) Day(org.jfree.data.time.Day) Font(java.awt.Font) Test(org.junit.jupiter.api.Test)

Example 20 with RectangleInsets

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

the class AbstractBlockTest method testEquals.

/**
 * Confirm that the equals() method can distinguish all the required fields.
 */
@Test
public void testEquals() {
    EmptyBlock b1 = new EmptyBlock(1.0, 2.0);
    EmptyBlock b2 = new EmptyBlock(1.0, 2.0);
    assertEquals(b1, b2);
    assertEquals(b2, b2);
    b1.setID("Test");
    assertNotEquals(b1, b2);
    b2.setID("Test");
    assertEquals(b1, b2);
    b1.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertNotEquals(b1, b2);
    b2.setMargin(new RectangleInsets(1.0, 2.0, 3.0, 4.0));
    assertEquals(b1, b2);
    b1.setFrame(new BlockBorder(Color.RED));
    assertNotEquals(b1, b2);
    b2.setFrame(new BlockBorder(Color.RED));
    assertEquals(b1, b2);
    b1.setPadding(new RectangleInsets(2.0, 4.0, 6.0, 8.0));
    assertNotEquals(b1, b2);
    b2.setPadding(new RectangleInsets(2.0, 4.0, 6.0, 8.0));
    assertEquals(b1, b2);
    b1.setWidth(1.23);
    assertNotEquals(b1, b2);
    b2.setWidth(1.23);
    assertEquals(b1, b2);
    b1.setHeight(4.56);
    assertNotEquals(b1, b2);
    b2.setHeight(4.56);
    assertEquals(b1, b2);
    b1.setBounds(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertNotEquals(b1, b2);
    b2.setBounds(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(b1, b2);
    b1 = new EmptyBlock(1.1, 2.0);
    assertNotEquals(b1, b2);
    b2 = new EmptyBlock(1.1, 2.0);
    assertEquals(b1, b2);
    b1 = new EmptyBlock(1.1, 2.2);
    assertNotEquals(b1, b2);
    b2 = new EmptyBlock(1.1, 2.2);
    assertEquals(b1, b2);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) RectangleInsets(org.jfree.chart.api.RectangleInsets) Test(org.junit.jupiter.api.Test)

Aggregations

RectangleInsets (org.jfree.chart.api.RectangleInsets)58 Rectangle2D (java.awt.geom.Rectangle2D)19 Test (org.junit.jupiter.api.Test)17 Font (java.awt.Font)16 BasicStroke (java.awt.BasicStroke)14 GradientPaint (java.awt.GradientPaint)13 Paint (java.awt.Paint)9 Shape (java.awt.Shape)9 AxisState (org.jfree.chart.axis.AxisState)7 FontMetrics (java.awt.FontMetrics)6 Stroke (java.awt.Stroke)6 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 RectangleEdge (org.jfree.chart.api.RectangleEdge)6 AxisSpace (org.jfree.chart.axis.AxisSpace)6 ValueAxis (org.jfree.chart.axis.ValueAxis)6 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)6 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)6 AlphaComposite (java.awt.AlphaComposite)5 Composite (java.awt.Composite)5