org.jfree.chart.axis.NumberTick Java Examples

The following examples show how to use org.jfree.chart.axis.NumberTick. 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: PolarPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 * 
 * @return A list of {@link NumberTick} instances.
 * 
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0; 
            currentTickVal += this.angleTickUnit.getSize()) {
        NumberTick tick = new NumberTick(Double.valueOf(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #2
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {

        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #3
Source File: DefaultPolarItemRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param radialAxis  the radial axis (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
        ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {

    ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double centerValue;
    if (radialAxis.isInverted()) {
        centerValue = radialAxis.getUpperBound();
    } else {
        centerValue = radialAxis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double angleDegrees = plot.isCounterClockwise() 
                ? plot.getAngleOffset() : -plot.getAngleOffset();
        Point p = plot.translateToJava2D(angleDegrees,
                tick.getNumber().doubleValue(), radialAxis, dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #4
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {

        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #5
Source File: DefaultPolarItemRenderer.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param radialAxis  the radial axis (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
        ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {

    ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double centerValue;
    if (radialAxis.isInverted()) {
        centerValue = radialAxis.getUpperBound();
    } else {
        centerValue = radialAxis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double angleDegrees = plot.isCounterClockwise() 
                ? plot.getAngleOffset() : -plot.getAngleOffset();
        Point p = plot.translateToJava2D(angleDegrees,
                tick.getNumber().doubleValue(), radialAxis, dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #6
Source File: CustomLogarithmicAxisTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testRefreshTicksVerticalAxisOrientation() throws Exception {
    CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis");
    testAxis.setRange(-300, -3);
    List ticks = testAxis.refreshTicks(RectangleEdge.LEFT, CustomLogarithmicAxis.VERTICAL);
    assertNotNull(ticks);
    assertEquals(19, ticks.size());
    assertEquals("", ((NumberTick) ticks.get(0)).getText());
    assertEquals("", ((NumberTick) ticks.get(1)).getText());
    assertEquals("-10", ((NumberTick) ticks.get(7)).getText());
    assertEquals("", ((NumberTick) ticks.get(9)).getText());
    assertEquals("-100", ((NumberTick) ticks.get(16)).getText());
    assertEquals("", ((NumberTick) ticks.get(18)).getText());
}
 
Example #7
Source File: CustomLogarithmicAxisTest.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testRefreshTicksForNegativeAxisRange() throws Exception {
    CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis");
    testAxis.setRange(-300, -3);
    List ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL);
    assertNotNull(ticks);
    assertEquals(19, ticks.size());
    // we expect labels at the power of 10 values only
    assertEquals("", ((NumberTick) ticks.get(0)).getText());
    assertEquals("", ((NumberTick) ticks.get(1)).getText());
    assertEquals("-10", ((NumberTick) ticks.get(7)).getText());
    assertEquals("", ((NumberTick) ticks.get(9)).getText());
    assertEquals("-100", ((NumberTick) ticks.get(16)).getText());
    assertEquals("", ((NumberTick) ticks.get(18)).getText());
}
 
Example #8
Source File: CustomLogarithmicAxis.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void addVerticalTicks(RectangleEdge edge, List ticks, double lowerBoundVal, String tickLabel, double tickVal) {
    if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
        //tick value not below lowest data value
        TextAnchor anchor;
        TextAnchor rotationAnchor;
        double angle = 0.0;
        if (isVerticalTickLabels()) {
            if (edge == RectangleEdge.LEFT) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                angle = -Math.PI / 2.0;
            } else {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
                angle = Math.PI / 2.0;
            }
        } else {
            if (edge == RectangleEdge.LEFT) {
                anchor = TextAnchor.CENTER_RIGHT;
                rotationAnchor = TextAnchor.CENTER_RIGHT;
            } else {
                anchor = TextAnchor.CENTER_LEFT;
                rotationAnchor = TextAnchor.CENTER_LEFT;
            }
        }
        //create tick object and add to list:
        ticks.add(new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle));
    }
}
 
Example #9
Source File: CustomLogarithmicAxis.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void addHorizontalTicks(RectangleEdge edge, List ticks, double lowerBoundVal, String tickLabel, double tickVal) {
    if (tickVal >= lowerBoundVal - SMALL_LOG_VALUE) {
        //tick value not below lowest data value
        TextAnchor anchor;
        TextAnchor rotationAnchor;
        double angle = 0.0;
        if (isVerticalTickLabels()) {
            anchor = TextAnchor.CENTER_RIGHT;
            rotationAnchor = TextAnchor.CENTER_RIGHT;
            if (edge == RectangleEdge.TOP) {
                angle = Math.PI / 2.0;
            } else {
                angle = -Math.PI / 2.0;
            }
        } else {
            if (edge == RectangleEdge.TOP) {
                anchor = TextAnchor.BOTTOM_CENTER;
                rotationAnchor = TextAnchor.BOTTOM_CENTER;
            } else {
                anchor = TextAnchor.TOP_CENTER;
                rotationAnchor = TextAnchor.TOP_CENTER;
            }
        }

        ticks.add(new NumberTick(new Double(tickVal), tickLabel, anchor, rotationAnchor, angle));
    }
}
 
Example #10
Source File: DefaultPolarItemRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 * 
 * @param g2  the drawing surface.
 * @param plot  the plot.
 * @param radialAxis  the radial axis.
 * @param ticks  the ticks.
 * @param dataArea  the data area.
 */
public void drawRadialGridLines(Graphics2D g2, 
                                PolarPlot plot,
                                ValueAxis radialAxis,
                                List ticks,
                                Rectangle2D dataArea) {
    
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double axisMin = radialAxis.getLowerBound();
    Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin,
            dataArea);
    
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        Point p = plot.translateValueThetaRadiusToJava2D(90.0, 
                tick.getNumber().doubleValue(), dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #11
Source File: DefaultPolarItemRenderer.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param radialAxis  the radial axis (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
        ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {

    ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double centerValue;
    if (radialAxis.isInverted()) {
        centerValue = radialAxis.getUpperBound();
    } else {
        centerValue = radialAxis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double angleDegrees = plot.isCounterClockwise() 
                ? plot.getAngleOffset() : -plot.getAngleOffset();
        Point p = plot.translateToJava2D(angleDegrees,
                tick.getNumber().doubleValue(), radialAxis, dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #12
Source File: DefaultPolarItemRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 * 
 * @param g2  the drawing surface.
 * @param plot  the plot.
 * @param radialAxis  the radial axis.
 * @param ticks  the ticks.
 * @param dataArea  the data area.
 */
public void drawRadialGridLines(Graphics2D g2, 
                                PolarPlot plot,
                                ValueAxis radialAxis,
                                List ticks,
                                Rectangle2D dataArea) {
    
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double axisMin = radialAxis.getLowerBound();
    Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin,
            dataArea);
    
    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        Point p = plot.translateValueThetaRadiusToJava2D(90.0, 
                tick.getNumber().doubleValue(), dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #13
Source File: PolarPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #14
Source File: DefaultPolarItemRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface.
 * @param plot  the plot.
 * @param radialAxis  the radial axis.
 * @param ticks  the ticks.
 * @param dataArea  the data area.
 */
public void drawRadialGridLines(Graphics2D g2,
                                PolarPlot plot,
                                ValueAxis radialAxis,
                                List ticks,
                                Rectangle2D dataArea) {

    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double axisMin = radialAxis.getLowerBound();
    Point center = plot.translateValueThetaRadiusToJava2D(axisMin, axisMin,
            dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        Point p = plot.translateValueThetaRadiusToJava2D(90.0,
                tick.getNumber().doubleValue(), dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #15
Source File: PolarPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {

        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #16
Source File: DefaultPolarItemRenderer.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param radialAxis  the radial axis (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
        ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {

    ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double centerValue;
    if (radialAxis.isInverted()) {
        centerValue = radialAxis.getUpperBound();
    } else {
        centerValue = radialAxis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double angleDegrees = plot.isCounterClockwise() 
                ? plot.getAngleOffset() : -plot.getAngleOffset();
        Point p = plot.translateToJava2D(angleDegrees,
                tick.getNumber().doubleValue(), radialAxis, dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #17
Source File: PolarPlot.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {

        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #18
Source File: DefaultPolarItemRenderer.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param radialAxis  the radial axis (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
        ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {

    ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double centerValue;
    if (radialAxis.isInverted()) {
        centerValue = radialAxis.getUpperBound();
    } else {
        centerValue = radialAxis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double angleDegrees = plot.isCounterClockwise() 
                ? plot.getAngleOffset() : -plot.getAngleOffset();
        Point p = plot.translateToJava2D(angleDegrees,
                tick.getNumber().doubleValue(), radialAxis, dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #19
Source File: PolarPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {

        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #20
Source File: DefaultPolarItemRenderer.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw the radial gridlines - the rings.
 *
 * @param g2  the drawing surface (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param radialAxis  the radial axis (<code>null</code> not permitted).
 * @param ticks  the ticks (<code>null</code> not permitted).
 * @param dataArea  the data area.
 */
@Override
public void drawRadialGridLines(Graphics2D g2, PolarPlot plot, 
        ValueAxis radialAxis, List ticks, Rectangle2D dataArea) {

    ParamChecks.nullNotPermitted(radialAxis, "radialAxis");
    g2.setFont(radialAxis.getTickLabelFont());
    g2.setPaint(plot.getRadiusGridlinePaint());
    g2.setStroke(plot.getRadiusGridlineStroke());

    double centerValue;
    if (radialAxis.isInverted()) {
        centerValue = radialAxis.getUpperBound();
    } else {
        centerValue = radialAxis.getLowerBound();
    }
    Point center = plot.translateToJava2D(0, centerValue, radialAxis, dataArea);

    Iterator iterator = ticks.iterator();
    while (iterator.hasNext()) {
        NumberTick tick = (NumberTick) iterator.next();
        double angleDegrees = plot.isCounterClockwise() 
                ? plot.getAngleOffset() : -plot.getAngleOffset();
        Point p = plot.translateToJava2D(angleDegrees,
                tick.getNumber().doubleValue(), radialAxis, dataArea);
        int r = p.x - center.x;
        int upperLeftX = center.x - r;
        int upperLeftY = center.y - r;
        int d = 2 * r;
        Ellipse2D ring = new Ellipse2D.Double(upperLeftX, upperLeftY, d, d);
        g2.setPaint(plot.getRadiusGridlinePaint());
        g2.draw(ring);
    }
}
 
Example #21
Source File: PolarPlot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a list of tick values for the angular tick marks.
 *
 * @return A list of {@link NumberTick} instances.
 *
 * @since 1.0.10
 */
protected List refreshAngleTicks() {
    List ticks = new ArrayList();
    for (double currentTickVal = 0.0; currentTickVal < 360.0;
            currentTickVal += this.angleTickUnit.getSize()) {

        TextAnchor ta = calculateTextAnchor(currentTickVal);
        NumberTick tick = new NumberTick(new Double(currentTickVal),
            this.angleTickUnit.valueToString(currentTickVal),
            ta, TextAnchor.CENTER, 0.0);
        ticks.add(tick);
    }
    return ticks;
}
 
Example #22
Source File: PolarPlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new plot.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param radiusAxis  the radius axis (<code>null</code> permitted).
 * @param renderer  the renderer (<code>null</code> permitted).
 */
public PolarPlot(XYDataset dataset, 
                 ValueAxis radiusAxis,
                 PolarItemRenderer renderer) {
  
    super();
        
    this.dataset = dataset;
    if (this.dataset != null) {
        this.dataset.addChangeListener(this);
    }
  
    this.angleTicks = new java.util.ArrayList();
    this.angleTicks.add(new NumberTick(new Double(0.0), "0", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(45.0), "45", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(90.0), "90", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(135.0), "135", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(180.0), "180", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(225.0), "225", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(270.0), "270", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    this.angleTicks.add(new NumberTick(new Double(315.0), "315", 
            TextAnchor.CENTER, TextAnchor.CENTER, 0.0));
    
    this.axis = radiusAxis;
    if (this.axis != null) {
        this.axis.setPlot(this);
        this.axis.addChangeListener(this);
    }
  
    this.renderer = renderer;
    if (this.renderer != null) {
        this.renderer.setPlot(this);
        this.renderer.addChangeListener(this);
    }
  
    this.angleGridlinesVisible = true;
    this.angleGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.angleGridlinePaint = DEFAULT_GRIDLINE_PAINT;
  
    this.radiusGridlinesVisible = true;
    this.radiusGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.radiusGridlinePaint = DEFAULT_GRIDLINE_PAINT;      
}
 
Example #23
Source File: CustomLogarithmicAxisTest.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Test
    public void testRefreshTicks() throws Exception {
        CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis");

        // axis range includes 3 power of 10 values: 1, 10, 100
        testAxis.setRange(0.3, 300.0);
        List ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL);
        assertNotNull(ticks);
        assertEquals(28, ticks.size());
        // we expect labels at the power of 10 values only
        assertEquals("", ((NumberTick) ticks.get(0)).getText());
        assertEquals("", ((NumberTick) ticks.get(1)).getText());
        assertEquals("1", ((NumberTick) ticks.get(7)).getText());
        assertEquals("", ((NumberTick) ticks.get(9)).getText());
        assertEquals("10", ((NumberTick) ticks.get(16)).getText());
        assertEquals("", ((NumberTick) ticks.get(18)).getText());
        assertEquals("100", ((NumberTick) ticks.get(25)).getText());
        assertEquals("", ((NumberTick) ticks.get(26)).getText());

        // axis range includes 2 power of 10 values: 1, 10
        testAxis.setRange(0.3, 30.0);
        ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL);
        assertNotNull(ticks);
        assertEquals(19, ticks.size());
        // we expect labels at the power of 10 values only
        assertEquals("", ((NumberTick) ticks.get(0)).getText());
        assertEquals("", ((NumberTick) ticks.get(1)).getText());
        assertEquals("1", ((NumberTick) ticks.get(7)).getText());
        assertEquals("", ((NumberTick) ticks.get(9)).getText());
        assertEquals("10", ((NumberTick) ticks.get(16)).getText());
        assertEquals("", ((NumberTick) ticks.get(18)).getText());

        // axis range includes 1 power of 10 values: 1
        testAxis.setRange(0.3, 3.0);
        ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL);
        assertNotNull(ticks);
        assertEquals(10, ticks.size());
        // we expect labels at every tick!
        // todo: clarify why these tests work locally, but not on buildserver (who expects "0.3", "0.4", ...)
//        assertEquals("0,3", ((NumberTick) ticks.get(0)).getText());
//        assertEquals("0,4", ((NumberTick) ticks.get(1)).getText());
//        assertEquals("0,5", ((NumberTick) ticks.get(2)).getText());
//        assertEquals("0,6", ((NumberTick) ticks.get(3)).getText());
//        assertEquals("0,7", ((NumberTick) ticks.get(4)).getText());
//        assertEquals("0,8", ((NumberTick) ticks.get(5)).getText());
//        assertEquals("0,9", ((NumberTick) ticks.get(6)).getText());
        assertEquals(0.3, ((NumberTick) ticks.get(0)).getValue(), 1.E-6);
        assertEquals(0.4, ((NumberTick) ticks.get(1)).getValue(), 1.E-6);
        assertEquals(0.5, ((NumberTick) ticks.get(2)).getValue(), 1.E-6);
        assertEquals(0.6, ((NumberTick) ticks.get(3)).getValue(), 1.E-6);
        assertEquals(0.7, ((NumberTick) ticks.get(4)).getValue(), 1.E-6);
        assertEquals(0.8, ((NumberTick) ticks.get(5)).getValue(), 1.E-6);
        assertEquals(0.9, ((NumberTick) ticks.get(6)).getValue(), 1.E-6);
        assertEquals("1", ((NumberTick) ticks.get(7)).getText());
        assertEquals("2", ((NumberTick) ticks.get(8)).getText());
        assertEquals("3", ((NumberTick) ticks.get(9)).getText());

        // axis range includes no power of 10 values
        testAxis.setRange(0.3, 0.8);
        ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL);
        assertNotNull(ticks);
        assertEquals(6, ticks.size());
        // we expect labels at every tick!
        // todo: clarify why these tests work locally, but not on buildserver (who expects "0.3", "0.4", ...)
//        assertEquals("0,3", ((NumberTick) ticks.get(0)).getText());
//        assertEquals("0,4", ((NumberTick) ticks.get(1)).getText());
//        assertEquals("0,5", ((NumberTick) ticks.get(2)).getText());
//        assertEquals("0,6", ((NumberTick) ticks.get(3)).getText());
//        assertEquals("0,7", ((NumberTick) ticks.get(4)).getText());
//        assertEquals("0,8", ((NumberTick) ticks.get(5)).getText());
        assertEquals(0.3, ((NumberTick) ticks.get(0)).getValue(), 1.E-6);
        assertEquals(0.4, ((NumberTick) ticks.get(1)).getValue(), 1.E-6);
        assertEquals(0.5, ((NumberTick) ticks.get(2)).getValue(), 1.E-6);
        assertEquals(0.6, ((NumberTick) ticks.get(3)).getValue(), 1.E-6);
        assertEquals(0.7, ((NumberTick) ticks.get(4)).getValue(), 1.E-6);
        assertEquals(0.8, ((NumberTick) ticks.get(5)).getValue(), 1.E-6);
    }