Search in sources :

Example 11 with Path2D

use of java.awt.geom.Path2D in project intellij-community by JetBrains.

the class DiffDrawUtil method drawCurveTrapezium.

public static void drawCurveTrapezium(@NotNull Graphics2D g, int x1, int x2, int start1, int end1, int start2, int end2, @Nullable Color fillColor, @Nullable Color borderColor) {
    Shape upperCurve = makeCurve(x1, x2, start1, start2, true);
    Shape lowerCurve = makeCurve(x1, x2, end1 + 1, end2 + 1, false);
    Shape lowerCurveBorder = makeCurve(x1, x2, end1, end2, false);
    if (fillColor != null) {
        Path2D path = new Path2D.Double();
        path.append(upperCurve, true);
        path.append(lowerCurve, true);
        g.setColor(fillColor);
        g.fill(path);
    }
    if (borderColor != null) {
        g.setColor(borderColor);
        g.draw(upperCurve);
        g.draw(lowerCurveBorder);
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 12 with Path2D

use of java.awt.geom.Path2D in project intellij-community by JetBrains.

the class DividerPolygon method paint.

private void paint(Graphics2D g, int width) {
    GraphicsUtil.setupAntialiasing(g);
    if (!myApplied) {
        Shape upperCurve = makeCurve(width, myStart1, myStart2, true);
        Shape lowerCurve = makeCurve(width, myEnd1, myEnd2, false);
        Path2D path = new Path2D.Double();
        path.append(upperCurve, true);
        path.append(lowerCurve, true);
        g.setColor(myColor);
        g.fill(path);
        g.setColor(DiffUtil.getFramingColor(myColor));
        g.draw(upperCurve);
        g.draw(lowerCurve);
    } else {
        g.setColor(myColor);
        g.draw(makeCurve(width, myStart1 + 1, myStart2 + 1, true));
        g.draw(makeCurve(width, myStart1 + 2, myStart2 + 2, true));
        g.draw(makeCurve(width, myEnd1 + 1, myEnd2 + 1, false));
        g.draw(makeCurve(width, myEnd1 + 2, myEnd2 + 2, false));
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Example 13 with Path2D

use of java.awt.geom.Path2D in project android by JetBrains.

the class LineChart method postAnimate.

@Override
public void postAnimate() {
    long duration = System.nanoTime();
    int p = 0;
    // Store the Y coordinates of the last stacked series to use them to increment the Y values
    // of the current stacked series.
    TDoubleArrayList lastStackedSeriesY = null;
    Deque<Path2D> orderedPaths = new ArrayDeque<>(myLinesConfig.size());
    Deque<LineConfig> orderedConfigs = new ArrayDeque<>(myLinesConfig.size());
    for (Map.Entry<RangedContinuousSeries, LineConfig> lineConfig : myLinesConfig.entrySet()) {
        final RangedContinuousSeries ranged = lineConfig.getKey();
        final LineConfig config = lineConfig.getValue();
        // Stores the y coordinates of the current series in case it's used as a stacked series
        final TDoubleArrayList currentSeriesY = new TDoubleArrayList();
        Path2D path = new Path2D.Float();
        double xMin = ranged.getXRange().getMin();
        double xMax = ranged.getXRange().getMax();
        double yMin = ranged.getYRange().getMin();
        double yMax = ranged.getYRange().getMax();
        // X coordinate of the first point
        double firstXd = 0f;
        List<SeriesData<Long>> seriesList = ranged.getSeries();
        for (int i = 0; i < seriesList.size(); i++) {
            // TODO: refactor to allow different types (e.g. double)
            SeriesData<Long> seriesData = seriesList.get(i);
            long currX = seriesData.x;
            long currY = seriesData.value;
            double xd = (currX - xMin) / (xMax - xMin);
            double yd = (currY - yMin) / (yMax - yMin);
            // prior iteration). In this case, yd of the current series shouldn't change.
            if (config.isStacked() && lastStackedSeriesY != null && i < lastStackedSeriesY.size()) {
                yd += lastStackedSeriesY.get(i);
            }
            currentSeriesY.add(yd);
            // Swing's (0, 0) coordinate is in top-left. As we use bottom-left (0, 0), we need to adjust the y coordinate.
            float adjustedYd = 1 - (float) yd;
            if (i == 0) {
                path.moveTo(xd, adjustedYd);
                firstXd = xd;
            } else {
                // drawing a line to the destination point itself (e.g. (x1, y1)).
                if (config.isStepped()) {
                    float y = (float) path.getCurrentPoint().getY();
                    path.lineTo(xd, y);
                }
                path.lineTo(xd, adjustedYd);
            }
        }
        if (config.isFilled() && path.getCurrentPoint() != null) {
            // If the chart is filled, but not stacked, draw a line from the last point to X
            // axis and another one from this new point to the first destination point.
            path.lineTo(path.getCurrentPoint().getX(), 1f);
            path.lineTo(firstXd, 1f);
        }
        if (config.isStacked()) {
            lastStackedSeriesY = currentSeriesY;
        }
        if (config.isFilled()) {
            // Draw the filled lines first, otherwise other lines won't be visible.
            // Also, to draw stacked and filled lines correctly, they need to be drawn in reverse order to their adding order.
            orderedPaths.addFirst(path);
            orderedConfigs.addFirst(config);
        } else {
            orderedPaths.addLast(path);
            orderedConfigs.addLast(config);
        }
        addDebugInfo("Range[%d] Max: %.2f", p, xMax);
        p++;
    }
    myLinePaths.clear();
    myLinePaths.addAll(orderedPaths);
    myLinePathConfigs.clear();
    myLinePathConfigs.addAll(orderedConfigs);
    addDebugInfo("postAnimate time: %d ms", TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - duration));
}
Also used : Path2D(java.awt.geom.Path2D) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) SeriesData(com.android.tools.adtui.model.SeriesData) TDoubleArrayList(gnu.trove.TDoubleArrayList)

Example 14 with Path2D

use of java.awt.geom.Path2D in project android by JetBrains.

the class TimelineComponent method fillTriangle.

private void fillTriangle(Point p1, Point p2, Point p3, Color color, Graphics2D g2d) {
    g2d.setColor(color);
    Path2D path = new Path2D.Float();
    path.moveTo(p1.getX(), p1.getY());
    path.lineTo(p2.getX(), p2.getY());
    path.lineTo(p3.getX(), p3.getY());
    path.lineTo(p1.getX(), p1.getY());
    g2d.fill(path);
}
Also used : Path2D(java.awt.geom.Path2D)

Example 15 with Path2D

use of java.awt.geom.Path2D in project android by JetBrains.

the class LineChart method drawLines.

public static void drawLines(Graphics2D g2d, List<Path2D> transformedPaths, List<LineConfig> configs, boolean grayScale) {
    assert transformedPaths.size() == configs.size();
    for (int i = 0; i < transformedPaths.size(); ++i) {
        Path2D path = transformedPaths.get(i);
        LineConfig config = configs.get(i);
        Color lineColor = config.getColor();
        if (grayScale) {
            int gray = (lineColor.getBlue() + lineColor.getRed() + lineColor.getGreen()) / 3;
            g2d.setColor(new Color(gray, gray, gray));
        } else {
            g2d.setColor(lineColor);
        }
        g2d.setStroke(config.getStroke());
        if (config.isFilled()) {
            g2d.fill(path);
        } else {
            g2d.draw(path);
        }
    }
}
Also used : Path2D(java.awt.geom.Path2D)

Aggregations

Path2D (java.awt.geom.Path2D)24 Graphics2D (java.awt.Graphics2D)4 BasicStroke (java.awt.BasicStroke)3 PathIterator (java.awt.geom.PathIterator)3 Rectangle2D (java.awt.geom.Rectangle2D)3 TDoubleArrayList (gnu.trove.TDoubleArrayList)2 Color (java.awt.Color)2 Font (java.awt.Font)2 AffineTransform (java.awt.geom.AffineTransform)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 Point2D (aima.core.util.math.geom.shapes.Point2D)1 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)1 SeriesData (com.android.tools.adtui.model.SeriesData)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Insets (java.awt.Insets)1 Paint (java.awt.Paint)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1