Example usage for org.jfree.chart.plot.dial DialScale valueToAngle

List of usage examples for org.jfree.chart.plot.dial DialScale valueToAngle

Introduction

In this page you can find the example usage for org.jfree.chart.plot.dial DialScale valueToAngle.

Prototype

public double valueToAngle(double value);

Source Link

Document

Converts a data value to an angle (in degrees, using the same specification as Java's Arc2D class).

Usage

From source file:com.bdb.weather.display.current.WindDirPointer.java

/**
 * Draws the pointer./* w  ww.  j av  a 2  s.  c om*/
 * 
 * @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));
    DialScale scale = plot.getScaleForDataset(getDatasetIndex());
    double value = plot.getValue(getDatasetIndex());
    double angle = scale.valueToAngle(value % 360.0);

    Rectangle2D outerRect = DialPlot.rectangleByRadius(frame, outerRadius, outerRadius);
    Rectangle2D innerRect = DialPlot.rectangleByRadius(frame, outerRadius - innerOffset,
            outerRadius - innerOffset);

    g2.setPaint(getOutlinePaint());
    Arc2D arc1 = new Arc2D.Double(outerRect, angle - (ARC_LENGTH / 2), ARC_LENGTH, Arc2D.OPEN);
    g2.draw(arc1);
    Arc2D arc2 = new Arc2D.Double(innerRect, angle, 0.0, Arc2D.OPEN);
    GeneralPath gp = new GeneralPath();
    gp.moveTo(arc1.getStartPoint().getX(), arc1.getStartPoint().getY());
    gp.lineTo(arc2.getStartPoint().getX(), arc2.getStartPoint().getY());
    gp.lineTo(arc1.getEndPoint().getX(), arc1.getEndPoint().getY());
    g2.draw(gp);
    if (fill) {
        g2.setPaint(getFillPaint());
        g2.fill(gp);
    }
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range./*from w w w .j  a v  a  2 s  . co  m*/
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range./* ww  w  . j  a v  a  2 s.  c  om*/
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer.//from  w  w w  .ja v  a  2  s .  co m
 *
 * @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.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    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.getOutlinePaint());
    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);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer.//from  ww w . j a va  2  s. c  om
 *
 * @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.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    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.getOutlinePaint());
    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);
}