Search in sources :

Example 76 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CombinedDomainXYPlotTest method createPlot.

/**
 * Creates a sample plot.
 *
 * @return A sample plot.
 */
private CombinedDomainXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);
    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
    // parent plot...
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);
    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
Also used : XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) NumberAxis(org.jfree.chart.axis.NumberAxis) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYDataset(org.jfree.data.xy.XYDataset) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) Font(java.awt.Font)

Example 77 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CombinedRangeXYPlotTest method testNotification.

/**
 * Check that only one chart change event is generated by a change to a
 * subplot.
 */
@Test
public void testNotification() {
    CombinedRangeXYPlot plot = createPlot();
    JFreeChart chart = new JFreeChart(plot);
    chart.addChangeListener(this);
    XYPlot subplot1 = (XYPlot) plot.getSubplots().get(0);
    NumberAxis xAxis = (NumberAxis) subplot1.getDomainAxis();
    xAxis.setAutoRangeIncludesZero(!xAxis.getAutoRangeIncludesZero());
    assertEquals(1, this.events.size());
    // a redraw should NOT trigger another change event
    BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    this.events.clear();
    chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));
    assertTrue(this.events.isEmpty());
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle2D(java.awt.geom.Rectangle2D) JFreeChart(org.jfree.chart.JFreeChart) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) Test(org.junit.Test)

Example 78 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class CategoryPlotTest method testDomainMarkerIndices.

@Test
public void testDomainMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    // add a second dataset, plotted against a second x axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    CategoryMarker xMarker1 = new CategoryMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(xMarker1));
}
Also used : LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) DefaultCategoryItemRenderer(org.jfree.chart.renderer.category.DefaultCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryDataset(org.jfree.data.category.CategoryDataset) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) Test(org.junit.Test)

Example 79 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class ContourPlot method contourRenderer.

/**
 * Fills the plot.
 *
 * @param g2  the graphics device.
 * @param dataArea  the area within which the data is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param horizontalAxis  the domain (horizontal) axis.
 * @param verticalAxis  the range (vertical) axis.
 * @param colorBar  the color bar axis.
 * @param data  the dataset.
 * @param crosshairState  information about crosshairs on a plot.
 */
public void contourRenderer(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, ContourPlot plot, ValueAxis horizontalAxis, ValueAxis verticalAxis, ColorBar colorBar, ContourDataset data, CrosshairState crosshairState) {
    // setup for collecting optional entity info...
    Rectangle2D.Double entityArea;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    Rectangle2D.Double rect;
    rect = new Rectangle2D.Double();
    // turn off anti-aliasing when filling rectangles
    Object antiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    // get the data points
    Number[] xNumber = data.getXValues();
    Number[] yNumber = data.getYValues();
    Number[] zNumber = data.getZValues();
    double[] x = new double[xNumber.length];
    double[] y = new double[yNumber.length];
    for (int i = 0; i < x.length; i++) {
        x[i] = xNumber[i].doubleValue();
        y[i] = yNumber[i].doubleValue();
    }
    int[] xIndex = data.indexX();
    int[] indexX = data.getXIndices();
    boolean vertInverted = ((NumberAxis) verticalAxis).isInverted();
    boolean horizInverted = false;
    if (horizontalAxis instanceof NumberAxis) {
        horizInverted = ((NumberAxis) horizontalAxis).isInverted();
    }
    double transX = 0.0;
    double transXm1;
    double transXp1;
    double transDXm1;
    double transDXp1 = 0.0;
    double transDX = 0.0;
    double transY;
    double transYm1;
    double transYp1;
    double transDYm1;
    double transDYp1 = 0.0;
    double transDY;
    int iMax = xIndex[xIndex.length - 1];
    for (int k = 0; k < x.length; k++) {
        int i = xIndex[k];
        if (indexX[i] == k) {
            // this is a new column
            if (i == 0) {
                transX = horizontalAxis.valueToJava2D(x[k], dataArea, RectangleEdge.BOTTOM);
                transXm1 = transX;
                transXp1 = horizontalAxis.valueToJava2D(x[indexX[i + 1]], dataArea, RectangleEdge.BOTTOM);
                transDXm1 = Math.abs(0.5 * (transX - transXm1));
                transDXp1 = Math.abs(0.5 * (transX - transXp1));
            } else if (i == iMax) {
                transX = horizontalAxis.valueToJava2D(x[k], dataArea, RectangleEdge.BOTTOM);
                transXm1 = horizontalAxis.valueToJava2D(x[indexX[i - 1]], dataArea, RectangleEdge.BOTTOM);
                transXp1 = transX;
                transDXm1 = Math.abs(0.5 * (transX - transXm1));
                transDXp1 = Math.abs(0.5 * (transX - transXp1));
            } else {
                transX = horizontalAxis.valueToJava2D(x[k], dataArea, RectangleEdge.BOTTOM);
                transXp1 = horizontalAxis.valueToJava2D(x[indexX[i + 1]], dataArea, RectangleEdge.BOTTOM);
                transDXm1 = transDXp1;
                transDXp1 = Math.abs(0.5 * (transX - transXp1));
            }
            if (horizInverted) {
                transX -= transDXp1;
            } else {
                transX -= transDXm1;
            }
            transDX = transDXm1 + transDXp1;
            transY = verticalAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT);
            transYm1 = transY;
            if (k + 1 == y.length) {
                continue;
            }
            transYp1 = verticalAxis.valueToJava2D(y[k + 1], dataArea, RectangleEdge.LEFT);
            transDYm1 = Math.abs(0.5 * (transY - transYm1));
            transDYp1 = Math.abs(0.5 * (transY - transYp1));
        } else if ((i < indexX.length - 1 && indexX[i + 1] - 1 == k) || k == x.length - 1) {
            // end of column
            transY = verticalAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT);
            transYm1 = verticalAxis.valueToJava2D(y[k - 1], dataArea, RectangleEdge.LEFT);
            transYp1 = transY;
            transDYm1 = Math.abs(0.5 * (transY - transYm1));
            transDYp1 = Math.abs(0.5 * (transY - transYp1));
        } else {
            transY = verticalAxis.valueToJava2D(y[k], dataArea, RectangleEdge.LEFT);
            transYp1 = verticalAxis.valueToJava2D(y[k + 1], dataArea, RectangleEdge.LEFT);
            transDYm1 = transDYp1;
            transDYp1 = Math.abs(0.5 * (transY - transYp1));
        }
        if (vertInverted) {
            transY -= transDYm1;
        } else {
            transY -= transDYp1;
        }
        transDY = transDYm1 + transDYp1;
        rect.setRect(transX, transY, transDX, transDY);
        if (zNumber[k] != null) {
            g2.setPaint(colorBar.getPaint(zNumber[k].doubleValue()));
            g2.fill(rect);
        } else if (this.missingPaint != null) {
            g2.setPaint(this.missingPaint);
            g2.fill(rect);
        }
        entityArea = rect;
        // add an entity for the item...
        if (entities != null) {
            String tip = "";
            if (getToolTipGenerator() != null) {
                tip = this.toolTipGenerator.generateToolTip(data, k);
            }
            // Shape s = g2.getClip();
            // if (s.contains(rect) || s.intersects(rect)) {
            String url = null;
            // if (getURLGenerator() != null) {    //dmo: look at this later
            // url = getURLGenerator().generateURL(data, series, item);
            // }
            // Unlike XYItemRenderer, we need to clone entityArea since it
            // reused.
            ContourEntity entity = new ContourEntity((Rectangle2D.Double) entityArea.clone(), tip, url);
            entity.setIndex(k);
            entities.add(entity);
        // }
        }
        // do we need to update the crosshair values?
        if (plot.isDomainCrosshairLockedOnData()) {
            if (plot.isRangeCrosshairLockedOnData()) {
                // both axes
                crosshairState.updateCrosshairPoint(x[k], y[k], transX, transY, PlotOrientation.VERTICAL);
            } else {
                // just the horizontal axis...
                crosshairState.updateCrosshairX(transX);
            }
        } else {
            if (plot.isRangeCrosshairLockedOnData()) {
                // just the vertical axis...
                crosshairState.updateCrosshairY(transY);
            }
        }
    }
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias);
}
Also used : ContourEntity(org.jfree.chart.entity.ContourEntity) NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) EntityCollection(org.jfree.chart.entity.EntityCollection)

Example 80 with NumberAxis

use of org.jfree.chart.axis.NumberAxis in project SIMVA-SoS by SESoS.

the class ChartPanelTest method test2502355_zoomInRange.

/**
 * Checks that a call to the zoomInRange() method, for a plot with more
 * than one range axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_zoomInRange() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRangeAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoomInRange(1.0, 2.0);
    assertEquals(1, this.chartChangeEvents.size());
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) Test(org.junit.Test)

Aggregations

NumberAxis (org.jfree.chart.axis.NumberAxis)259 JFreeChart (org.jfree.chart.JFreeChart)146 Test (org.junit.Test)118 XYPlot (org.jfree.chart.plot.XYPlot)98 CategoryAxis (org.jfree.chart.axis.CategoryAxis)95 CategoryPlot (org.jfree.chart.plot.CategoryPlot)80 ValueAxis (org.jfree.chart.axis.ValueAxis)45 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)40 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)39 XYSeries (org.jfree.data.xy.XYSeries)38 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)37 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)30 XYDataset (org.jfree.data.xy.XYDataset)30 Color (java.awt.Color)28 DateAxis (org.jfree.chart.axis.DateAxis)27 StandardXYToolTipGenerator (org.jfree.chart.labels.StandardXYToolTipGenerator)27 BasicStroke (java.awt.BasicStroke)25 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)24 CategoryDataset (org.jfree.data.category.CategoryDataset)21