Search in sources :

Example 1 with SubPlotOptions

use of com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions in project j6dof-flight-sim by chris-ali.

the class SimulationPlot method createPlots.

/**
 * Populates the {@link plotLists} List with {@link XYPlot} objects created from the logsOut ArrayList
 * argument. It first creates {@link XYSeries} objects with data from logsOut, adds those to
 * {@link XYSeriesCollection}, adds those series collections to {@link XYPlot} objects, and finally
 * puts the XYPlot objects into {@link plotList}. The types of {@link XYPlot} objects generated
 * comes from settings in {@link SubPlotBundle}
 *
 * @param logsOut
 * @param bundle
 */
private void createPlots(List<Map<SimOuts, Double>> logsOut, SubPlotBundle bundle) {
    for (SubPlotOptions option : bundle.getSubPlots()) {
        XYSeriesCollection collection = new XYSeriesCollection();
        for (SimOuts simout : option.getyData()) {
            XYSeries series = new XYSeries(simout.toString());
            xySeriesData.put(simout, series);
            collection.addSeries(series);
        }
        domainAxis = new NumberAxis(option.getxAxisName());
        rangeAxes.put(option.getTitle(), new NumberAxis(option.getyAxisName()));
        xyCollections.put(option.getTitle(), collection);
    }
    combinedDomPlot = new CombinedDomainXYPlot(domainAxis);
    updateXYSeriesData(logsOut, bundle);
    for (Map.Entry<String, XYSeriesCollection> entry : xyCollections.entrySet()) {
        logger.debug("Creating a subplot called: " + entry.getKey() + "...");
        XYPlot subPlot = new XYPlot(entry.getValue(), domainAxis, rangeAxes.get(entry.getKey()), new StandardXYItemRenderer());
        plotList.add(subPlot);
    }
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) CombinedDomainXYPlot(org.jfree.chart.plot.CombinedDomainXYPlot) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SubPlotOptions(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)

Example 2 with SubPlotOptions

use of com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions in project j6dof-flight-sim by chris-ali.

the class ReadWriteJsonTest method WriteThenReadPlotConfigurationTest.

@Test
public void WriteThenReadPlotConfigurationTest() {
    PlotConfiguration plots = FileUtilities.readPlotConfiguration();
    String assertion = "Deserialized property should not be null";
    assertNotNull(assertion, plots);
    assertNotNull(assertion, plots.getSubPlotBundles());
    assertTrue("There should be at least one bundle in configuration", plots.getSubPlotBundles().size() > 0);
    for (Map.Entry<String, SubPlotBundle> entry : plots.getSubPlotBundles().entrySet()) {
        SubPlotBundle bundle = entry.getValue();
        assertNotNull(assertion, bundle);
        assertNotNull(assertion, bundle.getSizeXPixels());
        assertNotNull(assertion, bundle.getSizeYPixels());
        assertNotNull(assertion, bundle.getTitle());
        assertNotNull(assertion, bundle.getSubPlots());
        assertTrue("There should be at least one subplot in this bundle", bundle.getSubPlots().size() > 0);
        for (SubPlotOptions subplot : bundle.getSubPlots()) {
            assertNotNull(assertion, subplot);
            assertNotNull(assertion, subplot.getTitle());
            assertNotNull(assertion, subplot.getxAxisName());
            assertNotNull(assertion, subplot.getyAxisName());
            assertNotNull(assertion, subplot.getxData());
            assertNotNull(assertion, subplot.getyData());
            assertTrue("There should be at least one y data in this bundle", subplot.getyData().size() > 0);
            for (SimOuts simout : subplot.getyData()) {
                assertNotNull(assertion, simout);
            }
        }
    }
    plots.save();
    PlotConfiguration readPlots = FileUtilities.readPlotConfiguration();
    assertion = "Deserialized property should not be null";
    assertNotNull(assertion, readPlots);
    assertNotNull(assertion, readPlots.getSubPlotBundles());
    assertTrue("There should be at least one bundle in configuration", readPlots.getSubPlotBundles().size() > 0);
    for (Map.Entry<String, SubPlotBundle> entry : readPlots.getSubPlotBundles().entrySet()) {
        SubPlotBundle bundle = entry.getValue();
        assertNotNull(assertion, bundle);
        assertNotNull(assertion, bundle.getSizeXPixels());
        assertNotNull(assertion, bundle.getSizeYPixels());
        assertNotNull(assertion, bundle.getTitle());
        assertNotNull(assertion, bundle.getSubPlots());
        assertTrue("There should be at least one subplot in this bundle", bundle.getSubPlots().size() > 0);
        for (SubPlotOptions subplot : bundle.getSubPlots()) {
            assertNotNull(assertion, subplot);
            assertNotNull(assertion, subplot.getTitle());
            assertNotNull(assertion, subplot.getxAxisName());
            assertNotNull(assertion, subplot.getyAxisName());
            assertNotNull(assertion, subplot.getxData());
            assertNotNull(assertion, subplot.getyData());
            assertTrue("There should be at least one y data in this bundle", subplot.getyData().size() > 0);
            for (SimOuts simout : subplot.getyData()) {
                assertNotNull(assertion, simout);
            }
        }
    }
}
Also used : SubPlotBundle(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotBundle) PlotConfiguration(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration) SimOuts(com.chrisali.javaflightsim.simulation.integration.SimOuts) Map(java.util.Map) SubPlotOptions(com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions) Test(org.junit.Test)

Aggregations

SimOuts (com.chrisali.javaflightsim.simulation.integration.SimOuts)2 SubPlotOptions (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotOptions)2 Map (java.util.Map)2 PlotConfiguration (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration)1 SubPlotBundle (com.chrisali.javaflightsim.swing.plotting.PlotConfiguration.SubPlotBundle)1 LinkedHashMap (java.util.LinkedHashMap)1 NumberAxis (org.jfree.chart.axis.NumberAxis)1 CombinedDomainXYPlot (org.jfree.chart.plot.CombinedDomainXYPlot)1 XYPlot (org.jfree.chart.plot.XYPlot)1 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)1 XYSeries (org.jfree.data.xy.XYSeries)1 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)1 Test (org.junit.Test)1