Search in sources :

Example 16 with DefaultXYDataset

use of org.jfree.data.xy.DefaultXYDataset in project qpid-broker-j by apache.

the class XYDataSetBasedChartBuilder method newDatasetHolder.

@Override
protected DatasetHolder newDatasetHolder() {
    return new DatasetHolder() {

        private final DefaultXYDataset _dataset = new DefaultXYDataset();

        private List<Double[]> _xyPairs = null;

        @Override
        public void beginSeries(SeriesDefinition seriesDefinition) {
            _xyPairs = new ArrayList<Double[]>();
        }

        @Override
        public void addDataPointToSeries(SeriesDefinition seriesDefinition, SeriesRow row) {
            double x = row.dimensionAsDouble(0);
            double y = row.dimensionAsDouble(1);
            _xyPairs.add(new Double[] { x, y });
        }

        @Override
        public void endSeries(SeriesDefinition seriesDefinition) {
            double[][] seriesData = listToSeriesDataArray();
            _dataset.addSeries(seriesDefinition.getSeriesLegend(), seriesData);
        }

        @Override
        public int getNumberOfDimensions() {
            return 2;
        }

        private double[][] listToSeriesDataArray() {
            double[][] seriesData = new double[2][_xyPairs.size()];
            int i = 0;
            for (Iterator<Double[]> iterator = _xyPairs.iterator(); iterator.hasNext(); ) {
                Double[] xyPair = iterator.next();
                seriesData[0][i] = xyPair[0];
                seriesData[1][i] = xyPair[1];
                i++;
            }
            return seriesData;
        }

        @Override
        public Dataset getPopulatedDataset() {
            return _dataset;
        }
    };
}
Also used : SeriesDefinition(org.apache.qpid.disttest.charting.definition.SeriesDefinition) DatasetHolder(org.apache.qpid.disttest.charting.seriesbuilder.DatasetHolder) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) ArrayList(java.util.ArrayList) List(java.util.List) SeriesRow(org.apache.qpid.disttest.charting.seriesbuilder.SeriesRow)

Example 17 with DefaultXYDataset

use of org.jfree.data.xy.DefaultXYDataset in project vcell by virtualcell.

the class LinePlot method run.

@Override
public void run() {
    try {
        // Find the port that a separately running VCell client is listening on
        System.out.println("vcell service port=" + vcellHelper.findVCellApiServerPort());
    } catch (Exception e) {
        uiService.showDialog("Activate VCell client ImageJ service\nTools->'Start Fiji (ImageJ) service'\n" + e.getMessage(), "Couldn't contact VCell client", MessageType.ERROR_MESSAGE);
        return;
    }
    String theCacheKey = null;
    VCellHelper.VCellModelSearch vcms = new VCellHelper.VCellModelSearch(VCellHelper.ModelType.valueOf(modelType), vCellUser, vCellModel, application, simulation, null, null);
    try {
        ArrayList<VCellModelSearchResults> vcmsr = vcellHelper.getSearchedModelSimCacheKey(false, vcms, null);
        if (vcmsr.size() == 0) {
            throw new Exception("No Results for search found");
        }
        theCacheKey = vcmsr.get(0).getCacheKey();
        System.out.println("theCacheKey=" + theCacheKey);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", null, null\n" + e.getMessage(), "Search failed", MessageType.ERROR_MESSAGE);
        return;
    }
    IJDataList timePointData = null;
    // there is 1 timePoint
    int[] timePointIndexes = new int[1];
    int theTimePointIndex = 0;
    timePointIndexes[theTimePointIndex] = timePoint;
    try {
        timePointData = vcellHelper.getTimePointData(theCacheKey, variable, VARTYPE_POSTPROC.NotPostProcess, timePointIndexes, 0);
    } catch (Exception e) {
        uiService.showDialog(modelType + ", " + vCellUser + ", " + vCellModel + ", " + application + ", " + simulation + ", " + variable + ", " + timePoint + "\n" + e.getMessage(), "Get Data failed", MessageType.ERROR_MESSAGE);
        return;
    }
    double[] theTimePointData = timePointData.ijData[theTimePointIndex].getDoubleData();
    Range xAxisRange = null;
    int[] dataIndexes = new int[endIndex - startIndex + 1];
    // This is just for JFreeChart
    double[] dataIndexesDouble = new double[dataIndexes.length];
    for (int i = startIndex; i <= endIndex; i++) {
        dataIndexes[i - startIndex] = i;
        dataIndexesDouble[i - startIndex] = i;
        xAxisRange = Range.expandToInclude(xAxisRange, dataIndexesDouble[i - startIndex]);
    }
    Range yAxisRange = null;
    double[] chartTheseDataPoints = new double[dataIndexes.length];
    for (int i = 0; i < dataIndexes.length; i++) {
        chartTheseDataPoints[i] = theTimePointData[dataIndexes[i]];
        yAxisRange = Range.expandToInclude(yAxisRange, chartTheseDataPoints[i]);
    // ijTimeSeriesJobResults.data[0/*index of "r"*/][i+1/*data, skip 0 because it holds copy of times*/][0/*0 always because we had only 1 timePoint=22.0*/]
    }
    try {
        // LINE plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { dataIndexesDouble, chartTheseDataPoints };
        String title = "LINE Plot at time=" + timePoint;
        String xAxisLabel = "distance";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // Y
        chart.getXYPlot().getDomainAxis().setRange(xAxisRange);
        // X
        chart.getXYPlot().getRangeAxis().setRange(yAxisRange);
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("LINE PlotGet Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    IJTimeSeriesJobResults timeSeries = null;
    try {
        IJVarInfos simulationInfo = vcellHelper.getSimulationInfo(theCacheKey);
        double[] times = simulationInfo.getTimes();
        timeSeries = vcellHelper.getTimeSeries(new String[] { variable }, new int[] { dataIndexes[0] }, times[0], 1, times[times.length - 1], false, false, 0, Integer.parseInt(theCacheKey));
    } catch (Exception e) {
        uiService.showDialog("TIME Plot Get Data failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
    try {
        // TIME plot of data at 1 timePoint along defined indexes
        // Create JFreechart x,y axis arrays for plotting x=data indexes, y=dataPoint values
        double[][] data = new double[][] { timeSeries.data[0][0], timeSeries.data[0][1] };
        String title = "TIME Plot at dataIndex=" + dataIndexes[0];
        String xAxisLabel = "time";
        String yAxisLabel = "val";
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("data1", data);
        JFreeChart chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, xyDataset, PlotOrientation.VERTICAL, false, false, false);
        // chart.getXYPlot().getDomainAxis().setRange(yAxisRange);//Y
        // chart.getXYPlot().getRangeAxis().setRange(xAxisRange);//X
        ChartPanel chartPanel = new ChartPanel(chart);
        JFrame frame = new JFrame("Chart");
        // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(chartPanel);
        // Display the window.
        frame.pack();
        frame.setVisible(true);
    } catch (Exception e) {
        uiService.showDialog("TIME Plot show chart failed\n" + e.getMessage(), MessageType.ERROR_MESSAGE);
        return;
    }
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) IJVarInfos(org.vcell.imagej.helper.VCellHelper.IJVarInfos) DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) VCellModelSearchResults(org.vcell.imagej.helper.VCellHelper.VCellModelSearchResults) Range(org.jfree.data.Range) VCellHelper(org.vcell.imagej.helper.VCellHelper) JFreeChart(org.jfree.chart.JFreeChart) JFrame(javax.swing.JFrame) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) IJTimeSeriesJobResults(org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)

Example 18 with DefaultXYDataset

use of org.jfree.data.xy.DefaultXYDataset in project SIMVA-SoS by SESoS.

the class ChartPanelTest method test2502355_restoreAutoDomainBounds.

/**
 * Checks that a call to the restoreAutoDomainBounds() method, for a plot
 * with more than one range axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_restoreAutoDomainBounds() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainAxis(1, new NumberAxis("X2"));
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.restoreAutoDomainBounds();
    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)

Example 19 with DefaultXYDataset

use of org.jfree.data.xy.DefaultXYDataset in project SIMVA-SoS by SESoS.

the class ChartPanelTest method test2502355_restoreAutoRangeBounds.

/**
 * Checks that a call to the restoreAutoRangeBounds() method, for a plot
 * with more than one range axis, generates just one ChartChangeEvent.
 */
@Test
public void test2502355_restoreAutoRangeBounds() {
    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.restoreAutoRangeBounds();
    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)

Example 20 with DefaultXYDataset

use of org.jfree.data.xy.DefaultXYDataset in project SIMVA-SoS by SESoS.

the class ChartPanelTest method testSetMouseWheelEnabled.

/**
 * In version 1.0.13 there is a bug where enabling the mouse wheel handler
 * twice would in fact disable it.
 */
@Test
public void testSetMouseWheelEnabled() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset, PlotOrientation.VERTICAL, false, false, false);
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    assertTrue(panel.isMouseWheelEnabled());
    panel.setMouseWheelEnabled(true);
    assertTrue(panel.isMouseWheelEnabled());
    panel.setMouseWheelEnabled(false);
    assertFalse(panel.isMouseWheelEnabled());
}
Also used : DefaultXYDataset(org.jfree.data.xy.DefaultXYDataset) Test(org.junit.Test)

Aggregations

DefaultXYDataset (org.jfree.data.xy.DefaultXYDataset)28 Test (org.junit.Test)24 JFreeChart (org.jfree.chart.JFreeChart)8 NumberAxis (org.jfree.chart.axis.NumberAxis)7 XYPlot (org.jfree.chart.plot.XYPlot)7 Rectangle2D (java.awt.geom.Rectangle2D)4 BufferedImage (java.awt.image.BufferedImage)4 Graphics2D (java.awt.Graphics2D)3 Range (org.jfree.data.Range)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 List (java.util.List)2 JFrame (javax.swing.JFrame)2 ChartPanel (org.jfree.chart.ChartPanel)2 XYSplineRenderer (org.jfree.chart.renderer.xy.XYSplineRenderer)2 VCellHelper (org.vcell.imagej.helper.VCellHelper)2 IJDataList (org.vcell.imagej.helper.VCellHelper.IJDataList)2 IJTimeSeriesJobResults (org.vcell.imagej.helper.VCellHelper.IJTimeSeriesJobResults)2 IJVarInfos (org.vcell.imagej.helper.VCellHelper.IJVarInfos)2