Java Code Examples for java.awt.geom.Arc2D#getEndPoint()

The following examples show how to use java.awt.geom.Arc2D#getEndPoint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example 2
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are 
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded, 
                                   Rectangle2D exploded,
                                   double angle, double extent, 
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    else {
        Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2, 
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2, 
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * explodePercent;
        double deltaY = (point1.getY() - point2.getY()) * explodePercent;
        return new Rectangle2D.Double(unexploded.getX() - deltaX, 
                unexploded.getY() - deltaY, unexploded.getWidth(), 
                unexploded.getHeight());
    }
}
 
Example 3
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example 4
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are 
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded, 
                                   Rectangle2D exploded,
                                   double angle, double extent, 
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    else {
        Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2, 
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2, 
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * explodePercent;
        double deltaY = (point1.getY() - point2.getY()) * explodePercent;
        return new Rectangle2D.Double(unexploded.getX() - deltaX, 
                unexploded.getY() - deltaY, unexploded.getWidth(), 
                unexploded.getHeight());
    }
}
 
Example 5
Source File: DialPointer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the pointer.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(), 
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 6
Source File: DialPointer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 7
Source File: DialPointer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 8
Source File: DialPointer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 9
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example 10
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a rectangle that can be used to create a pie section (taking
 * into account the amount by which the pie section is 'exploded').
 *
 * @param unexploded  the area inside which the unexploded pie sections are
 *                    drawn.
 * @param exploded  the area inside which the exploded pie sections are
 *                  drawn.
 * @param angle  the start angle.
 * @param extent  the extent of the arc.
 * @param explodePercent  the amount by which the pie section is exploded.
 *
 * @return A rectangle that can be used to create a pie section.
 */
protected Rectangle2D getArcBounds(Rectangle2D unexploded,
                                   Rectangle2D exploded,
                                   double angle, double extent,
                                   double explodePercent) {

    if (explodePercent == 0.0) {
        return unexploded;
    }
    Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();
    Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2,
            Arc2D.OPEN);
    Point2D point2 = arc2.getEndPoint();
    double deltaX = (point1.getX() - point2.getX()) * explodePercent;
    double deltaY = (point1.getY() - point2.getY()) * explodePercent;
    return new Rectangle2D.Double(unexploded.getX() - deltaX,
            unexploded.getY() - deltaY, unexploded.getWidth(),
            unexploded.getHeight());
}
 
Example 11
Source File: DialPointer.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
    Rectangle2D view) {

    g2.setPaint(this.paint);
    g2.setStroke(this.stroke);
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);

    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc = new Arc2D.Double(arcRect, angle, 0, Arc2D.OPEN);
    Point2D pt = arc.getEndPoint();

    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt.getX(), pt.getY());
    g2.draw(line);
}
 
Example 12
Source File: SpiderWebPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the location for a label
 *
 * @param labelBounds the label bounds.
 * @param ascent the ascent (height of font).
 * @param plotArea the plot area
 * @param startAngle the start angle for the pie series.
 *
 * @return The location for a label.
 */
protected Point2D calculateLabelLocation(Rectangle2D labelBounds,
                                         double ascent,
                                         Rectangle2D plotArea,
                                         double startAngle)
{
    Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();

    double deltaX = -(point1.getX() - plotArea.getCenterX())
                    * this.axisLabelGap;
    double deltaY = -(point1.getY() - plotArea.getCenterY())
                    * this.axisLabelGap;

    double labelX = point1.getX() - deltaX;
    double labelY = point1.getY() - deltaY;

    if (labelX < plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth();
    }

    if (labelX == plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth() / 2;
    }

    if (labelY > plotArea.getCenterY()) {
        labelY += ascent;
    }

    return new Point2D.Double(labelX, labelY);
}
 
Example 13
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the location for a label
 * 
 * @param labelBounds the label bounds.
 * @param ascent the ascent (height of font).
 * @param plotArea the plot area
 * @param startAngle the start angle for the pie series.
 * 
 * @return The location for a label.
 */
protected Point2D calculateLabelLocation(Rectangle2D labelBounds, 
                                         double ascent,
                                         Rectangle2D plotArea, 
                                         double startAngle)
{
    Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();

    double deltaX = -(point1.getX() - plotArea.getCenterX()) 
                    * this.axisLabelGap;
    double deltaY = -(point1.getY() - plotArea.getCenterY()) 
                    * this.axisLabelGap;

    double labelX = point1.getX() - deltaX;
    double labelY = point1.getY() - deltaY;

    if (labelX < plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth();
    }

    if (labelX == plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth() / 2;
    }

    if (labelY > plotArea.getCenterY()) {
        labelY += ascent;
    }

    return new Point2D.Double(labelX, labelY);
}
 
Example 14
Source File: SpiderWebPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the location for a label
 *
 * @param labelBounds the label bounds.
 * @param ascent the ascent (height of font).
 * @param plotArea the plot area
 * @param startAngle the start angle for the pie series.
 *
 * @return The location for a label.
 */
protected Point2D calculateLabelLocation(Rectangle2D labelBounds,
                                         double ascent,
                                         Rectangle2D plotArea,
                                         double startAngle)
{
    Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN);
    Point2D point1 = arc1.getEndPoint();

    double deltaX = -(point1.getX() - plotArea.getCenterX())
                    * this.axisLabelGap;
    double deltaY = -(point1.getY() - plotArea.getCenterY())
                    * this.axisLabelGap;

    double labelX = point1.getX() - deltaX;
    double labelY = point1.getY() - deltaY;

    if (labelX < plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth();
    }

    if (labelX == plotArea.getCenterX()) {
        labelX -= labelBounds.getWidth() / 2;
    }

    if (labelY > plotArea.getCenterY()) {
        labelY += ascent;
    }

    return new Point2D.Double(labelX, labelY);
}
 
Example 15
Source File: DialPointer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the pointer.
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    g2.setPaint(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame,
            this.radius, this.radius);
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame,
            this.widthRadius, this.widthRadius);
    double value = plot.getValue(this.datasetIndex);
    DialScale scale = plot.getScaleForDataset(this.datasetIndex);
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0,
            Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0,
            Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.outlinePaint);
    Line2D line = new Line2D.Double(frame.getCenterX(),
            frame.getCenterY(), pt1.getX(), pt1.getY());
    g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}
 
Example 16
Source File: StandardDialScale.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not
 *     permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.majorTickLength,
            this.tickRadius - this.majorTickLength);
    Rectangle2D arcRectMinor = arcRect;
    if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame,
                this.tickRadius - this.minorTickLength,
                this.tickRadius - this.minorTickLength);
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.tickLabelOffset,
            this.tickRadius - this.tickLabelOffset);

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound;
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                g2.setPaint(this.tickLabelPaint);
                TextUtilities.drawAlignedString(
                        this.tickLabelFormatter.format(v), g2,
                        (float) pt2.getX(), (float) pt2.getY(),
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
            double minorTickIncrement = this.majorTickIncrement
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.minorTickStroke);
                g2.setPaint(this.minorTickPaint);
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}
 
Example 17
Source File: StandardDialScale.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not
 *     permitted).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.majorTickLength,
            this.tickRadius - this.majorTickLength);
    Rectangle2D arcRectMinor = arcRect;
    if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame,
                this.tickRadius - this.minorTickLength,
                this.tickRadius - this.minorTickLength);
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.tickLabelOffset,
            this.tickRadius - this.tickLabelOffset);

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound;
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                g2.setPaint(this.tickLabelPaint);
                TextUtilities.drawAlignedString(
                        this.tickLabelFormatter.format(v), g2,
                        (float) pt2.getX(), (float) pt2.getY(),
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
            double minorTickIncrement = this.majorTickIncrement
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.minorTickStroke);
                g2.setPaint(this.minorTickPaint);
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}
 
Example 18
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 19
Source File: StandardDialScale.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame, 
            this.tickRadius - this.majorTickLength, 
            this.tickRadius - this.majorTickLength);
    Rectangle2D arcRectMinor = arcRect;
    if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame, 
                this.tickRadius - this.minorTickLength, 
                this.tickRadius - this.minorTickLength);
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, 
            this.tickRadius - this.tickLabelOffset, 
            this.tickRadius - this.tickLabelOffset);
    
    boolean firstLabel = true;
    
    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound; 
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v) 
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v) 
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v) 
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();
        
        if (this.tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                TextUtilities.drawAlignedString(
                        this.tickLabelFormatter.format(v), g2, 
                        (float) pt2.getX(), (float) pt2.getY(), 
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;
        
        // now do the minor tick marks
        if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
            double minorTickIncrement = this.majorTickIncrement 
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);
               
                arc.setArc(arcRect, this.startAngle, angle 
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.startAngle, angle 
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.minorTickStroke);
                g2.setPaint(this.minorTickPaint);
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }
        
    }
}
 
Example 20
Source File: StandardDialScale.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not
 *     permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame,
        Rectangle2D view) {

    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame,
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.majorTickLength,
            this.tickRadius - this.majorTickLength);
    Rectangle2D arcRectMinor = arcRect;
    if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
        arcRectMinor = DialPlot.rectangleByRadius(frame,
                this.tickRadius - this.minorTickLength,
                this.tickRadius - this.minorTickLength);
    }
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame,
            this.tickRadius - this.tickLabelOffset,
            this.tickRadius - this.tickLabelOffset);

    boolean firstLabel = true;

    Arc2D arc = new Arc2D.Double();
    Line2D workingLine = new Line2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound;
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectMajor, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        workingLine.setLine(pt0, pt1);
        g2.draw(workingLine);
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v)
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();

        if (this.tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                g2.setPaint(this.tickLabelPaint);
                TextUtilities.drawAlignedString(
                        this.tickLabelFormatter.format(v), g2,
                        (float) pt2.getX(), (float) pt2.getY(),
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;

        // now do the minor tick marks
        if (this.minorTickCount > 0 && this.minorTickLength > 0.0) {
            double minorTickIncrement = this.majorTickIncrement
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);

                arc.setArc(arcRect, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectMinor, this.startAngle, angle
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(this.minorTickStroke);
                g2.setPaint(this.minorTickPaint);
                workingLine.setLine(pt0, pt3);
                g2.draw(workingLine);
            }
        }

    }
}