Search in sources :

Example 16 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class ThermometerPlot 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</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    RoundRectangle2D outerStem = new RoundRectangle2D.Double();
    RoundRectangle2D innerStem = new RoundRectangle2D.Double();
    RoundRectangle2D mercuryStem = new RoundRectangle2D.Double();
    Ellipse2D outerBulb = new Ellipse2D.Double();
    Ellipse2D innerBulb = new Ellipse2D.Double();
    String temp = null;
    FontMetrics metrics = null;
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    drawBackground(g2, area);
    // adjust for padding...
    Rectangle2D interior = (Rectangle2D) area.clone();
    this.padding.trim(interior);
    int midX = (int) (interior.getX() + (interior.getWidth() / 2));
    int midY = (int) (interior.getY() + (interior.getHeight() / 2));
    int stemTop = (int) (interior.getMinY() + getBulbRadius());
    int stemBottom = (int) (interior.getMaxY() - getBulbDiameter());
    Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop);
    outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter());
    outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter());
    Area outerThermometer = new Area(outerBulb);
    Area tempArea = new Area(outerStem);
    outerThermometer.add(tempArea);
    innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2);
    innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2);
    Area innerThermometer = new Area(innerBulb);
    tempArea = new Area(innerStem);
    innerThermometer.add(tempArea);
    if ((this.dataset != null) && (this.dataset.getValue() != null)) {
        double current = this.dataset.getValue().doubleValue();
        double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT);
        // already calculated
        int i = getColumnDiameter() - getGap() * 2;
        // already calculated
        int j = getColumnRadius() - getGap();
        int l = (i / 2);
        int k = (int) Math.round(ds);
        if (k < (getGap() + interior.getMinY())) {
            k = (int) (getGap() + interior.getMinY());
            l = getBulbRadius();
        }
        Area mercury = new Area(innerBulb);
        if (k < (stemBottom + getBulbRadius())) {
            mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l);
            tempArea = new Area(mercuryStem);
            mercury.add(tempArea);
        }
        g2.setPaint(getCurrentPaint());
        g2.fill(mercury);
        // draw range indicators...
        if (this.subrangeIndicatorsVisible) {
            g2.setStroke(this.subrangeIndicatorStroke);
            Range range = this.rangeAxis.getRange();
            // draw start of normal range
            double value = this.subrangeInfo[NORMAL][RANGE_LOW];
            if (range.contains(value)) {
                double x = midX + getColumnRadius() + 2;
                double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
                Line2D line = new Line2D.Double(x, y, x + 10, y);
                g2.setPaint(this.subrangePaint[NORMAL]);
                g2.draw(line);
            }
            // draw start of warning range
            value = this.subrangeInfo[WARNING][RANGE_LOW];
            if (range.contains(value)) {
                double x = midX + getColumnRadius() + 2;
                double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
                Line2D line = new Line2D.Double(x, y, x + 10, y);
                g2.setPaint(this.subrangePaint[WARNING]);
                g2.draw(line);
            }
            // draw start of critical range
            value = this.subrangeInfo[CRITICAL][RANGE_LOW];
            if (range.contains(value)) {
                double x = midX + getColumnRadius() + 2;
                double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT);
                Line2D line = new Line2D.Double(x, y, x + 10, y);
                g2.setPaint(this.subrangePaint[CRITICAL]);
                g2.draw(line);
            }
        }
        // draw the axis...
        if ((this.rangeAxis != null) && (this.axisLocation != NONE)) {
            int drawWidth = AXIS_GAP;
            Rectangle2D drawArea;
            double cursor = 0;
            switch(this.axisLocation) {
                case RIGHT:
                    cursor = midX + getColumnRadius();
                    drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1));
                    this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null);
                    break;
                case LEFT:
                default:
                    // cursor = midX - COLUMN_RADIUS - AXIS_GAP;
                    cursor = midX - getColumnRadius();
                    drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1));
                    this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null);
                    break;
            }
        }
        // draw text value on screen
        g2.setFont(this.valueFont);
        g2.setPaint(this.valuePaint);
        metrics = g2.getFontMetrics();
        switch(this.valueLocation) {
            case RIGHT:
                g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY);
                break;
            case LEFT:
                String valueString = this.valueFormat.format(current);
                int stringWidth = metrics.stringWidth(valueString);
                g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY);
                break;
            case BULB:
                temp = this.valueFormat.format(current);
                i = metrics.stringWidth(temp) / 2;
                g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap());
                break;
            default:
        }
    /**
     */
    }
    g2.setPaint(this.thermometerPaint);
    g2.setFont(this.valueFont);
    // draw units indicator
    metrics = g2.getFontMetrics();
    int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]);
    if (tickX1 > area.getMinX()) {
        g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20));
    }
    // draw thermometer outline
    g2.setStroke(this.thermometerStroke);
    g2.draw(outerThermometer);
    g2.draw(innerThermometer);
    drawOutline(g2, area);
}
Also used : RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Range(org.jfree.data.Range) Line2D(java.awt.geom.Line2D) Ellipse2D(java.awt.geom.Ellipse2D) Paint(java.awt.Paint) Area(java.awt.geom.Area) FontMetrics(java.awt.FontMetrics) RectangleInsets(org.jfree.chart.util.RectangleInsets)

Example 17 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class WaferMapPlot method draw.

/**
 * Draws the wafermap view.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param state  the plot state.
 * @param info  the plot rendering info.
 */
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState state, PlotRenderingInfo info) {
    // if the plot area is too small, just return...
    boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
    boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
    if (b1 || b2) {
        return;
    }
    // record the plot area...
    if (info != null) {
        info.setPlotArea(area);
    }
    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    drawChipGrid(g2, area);
    drawWaferEdge(g2, area);
}
Also used : RectangleInsets(org.jfree.chart.util.RectangleInsets)

Example 18 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class RingPlot method drawItem.

/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> 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.
 */
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) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(path, (float) shadowXOffset, (float) shadowYOffset);
                g2.setPaint(shadowPaint);
                g2.fill(shadowArc);
            }
        } else if (currentPass == 1) {
            Paint paint = lookupSectionPaint(key, false);
            g2.setPaint(paint);
            g2.fill(path);
            Paint outlinePaint = lookupSectionOutlinePaint(key, false);
            Stroke outlineStroke = lookupSectionOutlineStroke(key, false);
            if (outlinePaint != null && outlineStroke != null) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(path);
            }
            // 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 = 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) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Rotation(org.jfree.chart.util.Rotation) Arc2D(java.awt.geom.Arc2D) Line2D(java.awt.geom.Line2D) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) PieDataset(org.jfree.data.pie.PieDataset) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleInsets(org.jfree.chart.util.RectangleInsets) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Example 19 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class DateAxis method estimateMaximumTickLabelHeight.

/**
 * Estimates the maximum width of the tick labels, assuming the specified
 * tick unit is used.
 * <P>
 * Rather than computing the string bounds of every tick on the axis, we
 * just look at two values: the lower bound and the upper bound for the
 * axis.  These two values will usually be representative.
 *
 * @param g2  the graphics device.
 * @param unit  the tick unit to use for calculation.
 *
 * @return The estimated maximum width of the tick labels.
 */
private double estimateMaximumTickLabelHeight(Graphics2D g2, DateTickUnit unit) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    LineMetrics lm = tickLabelFont.getLineMetrics("ABCxyz", frc);
    if (!isVerticalTickLabels()) {
        // all tick labels have the same width (equal to the height of
        // the font)...
        result += lm.getHeight();
    } else {
        // look at lower and upper bounds...
        DateRange range = (DateRange) getRange();
        Date lower = range.getLowerDate();
        Date upper = range.getUpperDate();
        String lowerStr = null;
        String upperStr = null;
        DateFormat formatter = getDateFormatOverride();
        if (formatter != null) {
            lowerStr = formatter.format(lower);
            upperStr = formatter.format(upper);
        } else {
            lowerStr = unit.dateToString(lower);
            upperStr = unit.dateToString(upper);
        }
        FontMetrics fm = g2.getFontMetrics(tickLabelFont);
        double w1 = fm.stringWidth(lowerStr);
        double w2 = fm.stringWidth(upperStr);
        result += Math.max(w1, w2);
    }
    return result;
}
Also used : DateRange(org.jfree.data.time.DateRange) FontMetrics(java.awt.FontMetrics) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RectangleInsets(org.jfree.chart.util.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) LineMetrics(java.awt.font.LineMetrics) Font(java.awt.Font) Date(java.util.Date)

Example 20 with RectangleInsets

use of org.jfree.chart.util.RectangleInsets in project graphcode2vec by graphcode2vec.

the class LogAxis method estimateMaximumTickLabelHeight.

/**
 * Estimates the maximum tick label height.
 *
 * @param g2  the graphics device.
 *
 * @return The maximum height.
 *
 * @since 1.0.7
 */
protected double estimateMaximumTickLabelHeight(Graphics2D g2) {
    RectangleInsets tickLabelInsets = getTickLabelInsets();
    double result = tickLabelInsets.getTop() + tickLabelInsets.getBottom();
    Font tickLabelFont = getTickLabelFont();
    FontRenderContext frc = g2.getFontRenderContext();
    result += tickLabelFont.getLineMetrics("123", frc).getHeight();
    return result;
}
Also used : RectangleInsets(org.jfree.chart.util.RectangleInsets) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font)

Aggregations

RectangleInsets (org.jfree.chart.util.RectangleInsets)44 Rectangle2D (java.awt.geom.Rectangle2D)21 Shape (java.awt.Shape)13 Font (java.awt.Font)11 FontMetrics (java.awt.FontMetrics)10 AlphaComposite (java.awt.AlphaComposite)8 Composite (java.awt.Composite)8 Paint (java.awt.Paint)8 AxisState (org.jfree.chart.axis.AxisState)8 AxisSpace (org.jfree.chart.axis.AxisSpace)7 ValueAxis (org.jfree.chart.axis.ValueAxis)7 FontRenderContext (java.awt.font.FontRenderContext)6 LineMetrics (java.awt.font.LineMetrics)6 Iterator (java.util.Iterator)6 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)6 RectangleEdge (org.jfree.chart.util.RectangleEdge)6 BasicStroke (java.awt.BasicStroke)4 Rectangle (java.awt.Rectangle)4 Stroke (java.awt.Stroke)4 Point2D (java.awt.geom.Point2D)4