org.jfree.chart.axis.ValueAxis Java Examples

The following examples show how to use org.jfree.chart.axis.ValueAxis. 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: StackedAreaChartTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
                + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #2
Source File: FastScatterPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown.
 */
@Test
public void testDrawWithNullInfo() {
    try {
        float[][] data = createData();

        ValueAxis domainAxis = new NumberAxis("X");
        ValueAxis rangeAxis = new NumberAxis("Y");
        FastScatterPlot plot = new FastScatterPlot(data, domainAxis,
                rangeAxis);
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200,
                null);
    }
    catch (NullPointerException e) {
        fail("No exception should be thrown.");
    }
}
 
Example #3
Source File: CategoryPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Multiplies the range on the range axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.
 * @param info  the plot rendering info.
 * @param source  the source point.
 * @param useAnchor  a flag that controls whether or not the source point
 *         is used for the zoom anchor.
 *
 * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)
 *
 * @since 1.0.7
 */
@Override
public void zoomRangeAxes(double factor, PlotRenderingInfo info,
                          Point2D source, boolean useAnchor) {

    // perform the zoom on each range axis
    for (ValueAxis rangeAxis : this.rangeAxes.values()) {
        if (rangeAxis == null) {
            continue;
        }
        if (useAnchor) {
            // get the relevant source coordinate given the plot orientation
            double sourceY = source.getY();
            if (this.orientation.isHorizontal()) {
                sourceY = source.getX();
            }
            double anchorY = rangeAxis.java2DToValue(sourceY,
                    info.getDataArea(), getRangeAxisEdge());
            rangeAxis.resizeRange2(factor, anchorY);
        } else {
            rangeAxis.resizeRange(factor);
        }
    }
}
 
Example #4
Source File: Nopol2017_005_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws the range markers (if any) for an axis and layer.  This method is 
 * typically called from within the draw() method.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param index  the renderer index.
 * @param layer  the layer (foreground or background).
 * 
 * @see #drawDomainMarkers(Graphics2D, Rectangle2D, int, Layer)
 */
protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea, 
                                int index, Layer layer) {
                                             
    CategoryItemRenderer r = getRenderer(index);
    if (r == null) {
        return;
    }
    
    Collection markers = getRangeMarkers(index, layer);
    ValueAxis axis = getRangeAxisForDataset(index);
    if (markers != null && axis != null) {
        Iterator iterator = markers.iterator();
        while (iterator.hasNext()) {
            Marker marker = (Marker) iterator.next();
            r.drawRangeMarker(g2, this, axis, marker, dataArea);
        }
    }
    
}
 
Example #5
Source File: AbstractXYItemRenderer.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fills a band between two values on the axis.  This can be used to color
 * bands between the grid lines.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the domain axis.
 * @param dataArea  the data area.
 * @param start  the start value.
 * @param end  the end value.
 */
public void fillDomainGridBand(Graphics2D g2, XYPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double start, double end) {

    double x1 = axis.valueToJava2D(start, dataArea,
            plot.getDomainAxisEdge());
    double x2 = axis.valueToJava2D(end, dataArea,
            plot.getDomainAxisEdge());
    Rectangle2D band;
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        band = new Rectangle2D.Double(Math.min(x1, x2), dataArea.getMinY(),
                Math.abs(x2 - x1), dataArea.getWidth());
    }
    else {
        band = new Rectangle2D.Double(dataArea.getMinX(), Math.min(x1, x2),
                dataArea.getWidth(), Math.abs(x2 - x1));
    }
    Paint paint = plot.getDomainTickBandPaint();

    if (paint != null) {
        g2.setPaint(paint);
        g2.fill(band);
    }

}
 
Example #6
Source File: CategoryPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Multiplies the range on the range axis/axes by the specified factor.
 *
 * @param factor  the zoom factor.
 * @param info  the plot rendering info.
 * @param source  the source point.
 * @param useAnchor  a flag that controls whether or not the source point
 *         is used for the zoom anchor.
 *
 * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean)
 *
 * @since 1.0.7
 */
@Override
public void zoomRangeAxes(double factor, PlotRenderingInfo info,
                          Point2D source, boolean useAnchor) {

    // perform the zoom on each range axis
    for (ValueAxis rangeAxis : this.rangeAxes.values()) {
        if (rangeAxis == null) {
            continue;
        }
        if (useAnchor) {
            // get the relevant source coordinate given the plot orientation
            double sourceY = source.getY();
            if (this.orientation.isHorizontal()) {
                sourceY = source.getX();
            }
            double anchorY = rangeAxis.java2DToValue(sourceY,
                    info.getDataArea(), getRangeAxisEdge());
            rangeAxis.resizeRange2(factor, anchorY);
        } else {
            rangeAxis.resizeRange(factor);
        }
    }
}
 
Example #7
Source File: XYPlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param index  the axis index.
 * @param axis  the axis.
 * @param notify  notify listeners?
 *
 * @see #getDomainAxis(int)
 */
public void setDomainAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = getDomainAxis(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.domainAxes.put(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #8
Source File: Cardumen_0075_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws all the annotations for the specified layer.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param layer  the layer.
 * @param info  the plot rendering info.
 *
 * @since 1.2.0
 */
public void drawAnnotations(Graphics2D g2, Rectangle2D dataArea,
        CategoryAxis domainAxis, ValueAxis rangeAxis, Layer layer,
        PlotRenderingInfo info) {

    Iterator iterator = null;
    if (layer.equals(Layer.FOREGROUND)) {
        iterator = this.foregroundAnnotations.iterator();
    }
    else if (layer.equals(Layer.BACKGROUND)) {
        iterator = this.backgroundAnnotations.iterator();
    }
    else {
        // should not get here
        throw new RuntimeException("Unknown layer.");
    }
    while (iterator.hasNext()) {
        CategoryAnnotation annotation = (CategoryAnnotation) iterator.next();
        annotation.draw(g2, this.plot, dataArea, domainAxis, rangeAxis,
                0, info);
    }

}
 
Example #9
Source File: XYPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Utility method for drawing a vertical line on the data area of the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param value  the coordinate, where to draw the line.
 * @param stroke  the stroke to use.
 * @param paint  the paint to use.
 */
protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea,
                                double value, Stroke stroke, Paint paint) {

    ValueAxis axis = getDomainAxis();
    if (getOrientation() == PlotOrientation.HORIZONTAL) {
        axis = getRangeAxis();
    }
    if (axis.getRange().contains(value)) {
        double xx = axis.valueToJava2D(value, dataArea,
                RectangleEdge.BOTTOM);
        Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(line);
    }

}
 
Example #10
Source File: ScatterPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #11
Source File: Chart_14_XYPlot_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the range axis for a dataset.
 *
 * @param index  the dataset index.
 *
 * @return The axis.
 */
public ValueAxis getRangeAxisForDataset(int index) {

    if (index < 0 || index >= getDatasetCount()) {
        throw new IllegalArgumentException("Index " + index 
                + " out of bounds.");
    }

    ValueAxis valueAxis = null;
    Integer axisIndex
        = (Integer) this.datasetToRangeAxisMap.get(new Integer(index));
    if (axisIndex != null) {
        valueAxis = getRangeAxis(axisIndex.intValue());
    }
    else {
        valueAxis = getRangeAxis(0);
    }
    return valueAxis;

}
 
Example #12
Source File: patch1-Chart-26-jMutRepair_patch1-Chart-26-jMutRepair_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws the gridlines for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param ticks  the ticks.
 * 
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D)
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, 
                                  List ticks) {
    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            ValueAxis axis = getRangeAxis();
            if (axis != null) {
                Iterator iterator = ticks.iterator();
                while (iterator.hasNext()) {
                    ValueTick tick = (ValueTick) iterator.next();
                    CategoryItemRenderer renderer1 = getRenderer();
                    if (renderer1 != null) {
                        renderer1.drawRangeGridline(g2, this, 
                                getRangeAxis(), dataArea, tick.getValue());
                    }
                }
            }
        }
    }
}
 
Example #13
Source File: CategoryPlot.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws the range markers (if any) for an axis and layer.  This method is
 * typically called from within the draw() method.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param index  the renderer index.
 * @param layer  the layer (foreground or background).
 *
 * @see #drawDomainMarkers(Graphics2D, Rectangle2D, int, Layer)
 */
protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea,
                                int index, Layer layer) {

    CategoryItemRenderer r = getRenderer(index);
    if (r == null) {
        return;
    }

    Collection markers = getRangeMarkers(index, layer);
    ValueAxis axis = getRangeAxisForDataset(index);
    if (markers != null && axis != null) {
        Iterator iterator = markers.iterator();
        while (iterator.hasNext()) {
            Marker marker = (Marker) iterator.next();
            r.drawRangeMarker(g2, this, axis, marker, dataArea);
        }
    }

}
 
Example #14
Source File: TimeSeriesChartTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    XYSeries series1 = new XYSeries("Series 1");
    series1.add(10.0, 10.0);
    series1.add(20.0, 20.0);
    series1.add(30.0, 30.0);
    XYDataset dataset = new XYSeriesCollection(series1);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    XYPlot plot = (XYPlot) this.chart.getPlot();
    plot.setDataset(dataset);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around 10: "
               + range.getLowerBound(), range.getLowerBound() <= 10);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #15
Source File: XYPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Utility method for drawing a vertical line on the data area of the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the data area.
 * @param value  the coordinate, where to draw the line.
 * @param stroke  the stroke to use.
 * @param paint  the paint to use.
 */
protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea,
                                double value, Stroke stroke, Paint paint) {

    ValueAxis axis = getDomainAxis();
    if (getOrientation() == PlotOrientation.HORIZONTAL) {
        axis = getRangeAxis();
    }
    if (axis.getRange().contains(value)) {
        double xx = axis.valueToJava2D(value, dataArea,
                RectangleEdge.BOTTOM);
        Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                dataArea.getMaxY());
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(line);
    }

}
 
Example #16
Source File: Cardumen_0082_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a domain crosshair.
 *
 * @param g2  the graphics target.
 * @param dataArea  the data area.
 * @param orientation  the plot orientation.
 * @param value  the crosshair value.
 * @param axis  the axis against which the value is measured.
 * @param stroke  the stroke used to draw the crosshair line.
 * @param paint  the paint used to draw the crosshair line.
 *
 * @since 1.0.4
 */
protected void drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea,
        PlotOrientation orientation, double value, ValueAxis axis,
        Stroke stroke, Paint paint) {

    if (axis.getRange().contains(value)) {
        Line2D line = null;
        if (orientation == PlotOrientation.VERTICAL) {
            double xx = axis.valueToJava2D(value, dataArea,
                    RectangleEdge.BOTTOM);
            line = new Line2D.Double(xx, dataArea.getMinY(), xx,
                    dataArea.getMaxY());
        }
        else {
            double yy = axis.valueToJava2D(value, dataArea,
                    RectangleEdge.LEFT);
            line = new Line2D.Double(dataArea.getMinX(), yy,
                    dataArea.getMaxX(), yy);
        }
        g2.setStroke(stroke);
        g2.setPaint(paint);
        g2.draw(line);
    }

}
 
Example #17
Source File: CategoryPlot.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Receives notification of a change to the plot's dataset.
 * <P>
 * The range axis bounds will be recalculated if necessary.
 *
 * @param event  information about the event (not used here).
 */
public void datasetChanged(DatasetChangeEvent event) {

    int count = this.rangeAxes.size();
    for (int axisIndex = 0; axisIndex < count; axisIndex++) {
        ValueAxis yAxis = getRangeAxis(axisIndex);
        if (yAxis != null) {
            yAxis.configure();
        }
    }
    if (getParent() != null) {
        getParent().datasetChanged(event);
    }
    else {
        PlotChangeEvent e = new PlotChangeEvent(this);
        e.setType(ChartChangeEventType.DATASET_UPDATED);
        notifyListeners(e);
    }

}
 
Example #18
Source File: 1_AbstractCategoryItemRenderer.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example #19
Source File: Chart_14_XYPlot_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Returns the domain axis for a dataset.
 *
 * @param index  the dataset index.
 *
 * @return The axis.
 */
public ValueAxis getDomainAxisForDataset(int index) {

    if (index < 0 || index >= getDatasetCount()) {
        throw new IllegalArgumentException("Index " + index 
                + " out of bounds.");
    }

    ValueAxis valueAxis = null;
    Integer axisIndex = (Integer) this.datasetToDomainAxisMap.get(
            new Integer(index));
    if (axisIndex != null) {
        valueAxis = getDomainAxis(axisIndex.intValue());
    }
    else {
        valueAxis = getDomainAxis(0);
    }
    return valueAxis;

}
 
Example #20
Source File: StackedBarChartTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Replaces the dataset and checks that it has changed as expected.
 */
@Test
public void testReplaceDataset() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-30), new Integer(-20)},
         {new Integer(-10), new Integer(10)},
         {new Integer(20), new Integer(30)}};

    CategoryDataset newData = DatasetUtilities.createCategoryDataset("S",
            "C", data);

    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(newData);
    assertEquals(true, l.flag);
    ValueAxis axis = plot.getRangeAxis();
    Range range = axis.getRange();
    assertTrue("Expecting the lower bound of the range to be around -30: "
                + range.getLowerBound(), range.getLowerBound() <= -30);
    assertTrue("Expecting the upper bound of the range to be around 30: "
               + range.getUpperBound(), range.getUpperBound() >= 30);

}
 
Example #21
Source File: FastScatterPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown.
 */
@Test
public void testDrawWithNullInfo() {
    try {
        float[][] data = createData();

        ValueAxis domainAxis = new NumberAxis("X");
        ValueAxis rangeAxis = new NumberAxis("Y");
        FastScatterPlot plot = new FastScatterPlot(data, domainAxis,
                rangeAxis);
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200,
                null);
    }
    catch (NullPointerException e) {
        fail("No exception should be thrown.");
    }
}
 
Example #22
Source File: jMutRepair_0030_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws the gridlines for the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area inside the axes.
 * @param ticks  the ticks.
 * 
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D)
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, 
                                  List ticks) {
    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible()) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            ValueAxis axis = getRangeAxis();
            if (axis != null) {
                Iterator iterator = ticks.iterator();
                while (iterator.hasNext()) {
                    ValueTick tick = (ValueTick) iterator.next();
                    CategoryItemRenderer renderer1 = getRenderer();
                    if (renderer1 != null) {
                        renderer1.drawRangeGridline(g2, this, 
                                getRangeAxis(), dataArea, tick.getValue());
                    }
                }
            }
        }
    }
}
 
Example #23
Source File: Cardumen_009_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Pans the range axes by the specified percentage.
 *
 * @param percent  the distance to pan (as a percentage of the axis length).
 * @param info the plot info
 * @param source the source point where the pan action started.
 *
 * @since 1.0.13
 */
public void panRangeAxes(double percent, PlotRenderingInfo info,
        Point2D source) {
    if (!isRangePannable()) {
        return;
    }
    int rangeAxisCount = getRangeAxisCount();
    for (int i = 0; i < rangeAxisCount; i++) {
        ValueAxis axis = getRangeAxis(i);
        if (axis == null) {
            continue;
        }
        if (axis.isInverted()) {
            percent = -percent;
        }
        axis.pan(percent);
    }
}
 
Example #24
Source File: ContourPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the range axis for the plot.
 * <P>
 * An exception is thrown if the new axis and the plot are not mutually
 * compatible.
 *
 * @param axis The new axis (null permitted).
 */
public void setRangeAxis(ValueAxis axis) {

    if (axis != null) {
        axis.setPlot(this);
        axis.addChangeListener(this);
    }

    // plot is likely registered as a listener with the existing axis...
    if (this.rangeAxis != null) {
        this.rangeAxis.removeChangeListener(this);
    }

    this.rangeAxis = axis;
    fireChangeEvent();

}
 
Example #25
Source File: Chart_14_XYPlot_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param index  the axis index.
 * @param axis  the axis.
 * @param notify  notify listeners?
 * 
 * @see #getDomainAxis(int)
 */
public void setDomainAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = getDomainAxis(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.domainAxes.set(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #26
Source File: CombinedRangeCategoryPlot.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds a subplot and sends a {@link PlotChangeEvent} to all registered
 * listeners.
 * <br><br>
 * You must ensure that the subplot has a non-null domain axis.  The range
 * axis for the subplot will be set to <code>null</code>.
 *
 * @param subplot  the subplot (<code>null</code> not permitted).
 * @param weight  the weight (must be &gt;= 1).
 */
public void add(CategoryPlot subplot, int weight) {
    ParamChecks.nullNotPermitted(subplot, "subplot");
    if (weight <= 0) {
        throw new IllegalArgumentException("Require weight >= 1.");
    }
    // store the plot and its weight
    subplot.setParent(this);
    subplot.setWeight(weight);
    subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    subplot.setRangeAxis(null);
    subplot.setOrientation(getOrientation());
    subplot.addChangeListener(this);
    this.subplots.add(subplot);
    // configure the range axis...
    ValueAxis axis = getRangeAxis();
    if (axis != null) {
        axis.configure();
    }
    fireChangeEvent();
}
 
Example #27
Source File: 1_CategoryPlot.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to 
 * all registered listeners.
 *
 * @param index  the axis index.
 * @param axis  the axis.
 * @param notify  notify listeners?
 */
public void setRangeAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = (ValueAxis) this.rangeAxes.get(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.rangeAxes.set(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #28
Source File: Cardumen_0075_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * Draws a line perpendicular to the range axis.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param axis  the value axis.
 * @param dataArea  the area for plotting data (not yet adjusted for any 3D
 *                  effect).
 * @param value  the value at which the grid line should be drawn.
 * @param paint  the paint (<code>null</code> not permitted).
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #drawRangeGridline
 *
 * @since 1.0.13
 */
public void drawRangeLine(Graphics2D g2, CategoryPlot plot, ValueAxis axis,
        Rectangle2D dataArea, double value, Paint paint, Stroke stroke) {

    Range range = axis.getRange();
    if (!range.contains(value)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    Line2D line = null;
    double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge());
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(v, dataArea.getMinY(), v,
                dataArea.getMaxY());
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(dataArea.getMinX(), v,
                dataArea.getMaxX(), v);
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(line);

}
 
Example #29
Source File: XYPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param index  the axis index.
 * @param axis  the axis (<code>null</code> permitted).
 * @param notify  notify listeners?
 *
 * @see #getRangeAxis(int)
 */
public void setRangeAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = getRangeAxis(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.rangeAxes.put(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        fireChangeEvent();
    }
}
 
Example #30
Source File: XYPlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to
 * all registered listeners.
 *
 * @param index  the axis index.
 * @param axis  the axis.
 * @param notify  notify listeners?
 *
 * @see #getDomainAxis(int)
 */
public void setDomainAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = getDomainAxis(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.domainAxes.put(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        fireChangeEvent();
    }
}