From 627abcd87e82049ec0d7a638e08b8e62d3bc1100 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Tue, 20 Aug 2024 18:17:41 +0200 Subject: [PATCH] Move Chart creation inside Plot --- .../info/openrocket/swing/gui/plot/Plot.java | 22 ++++++++++++--- .../swing/gui/plot/SimulationPlot.java | 28 +++---------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/swing/src/main/java/info/openrocket/swing/gui/plot/Plot.java b/swing/src/main/java/info/openrocket/swing/gui/plot/Plot.java index b553dcef5..948433eba 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/plot/Plot.java +++ b/swing/src/main/java/info/openrocket/swing/gui/plot/Plot.java @@ -8,6 +8,7 @@ import info.openrocket.core.unit.Unit; import info.openrocket.core.unit.UnitGroup; import info.openrocket.swing.gui.util.SwingPreferences; import info.openrocket.swing.utils.DecimalFormatter; +import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemCollection; @@ -53,6 +54,11 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +/* + * TODO: It should be possible to simplify this code quite a bit by using a single Renderer instance for + * both datasets and the legend. But for now, the renderers are queried for the line color information + * and this is held in the Legend. + */ public abstract class Plot, C extends PlotConfiguration> { protected static final Translator trans = Application.getTranslator(); protected static final SwingPreferences preferences = (SwingPreferences) Application.getPreferences(); @@ -64,15 +70,23 @@ public abstract class Plot, C extend protected final LegendItems legendItems; protected final XYSeriesCollection[] data; protected final C filledConfig; // Configuration after using 'fillAutoAxes' - private final List allBranches; protected final JFreeChart chart; - protected Plot(JFreeChart chart, B mainBranch, C config, List allBranches, boolean initialShowPoints) { - this.chart = chart; - this.allBranches = allBranches; + protected Plot(String plotName, B mainBranch, C config, List allBranches, boolean initialShowPoints) { this.branchCount = allBranches.size(); + this.chart = ChartFactory.createXYLineChart( + //// Simulated flight + /*title*/plotName, + /*xAxisLabel*/null, + /*yAxisLabel*/null, + /*dataset*/null, + /*orientation*/PlotOrientation.VERTICAL, + /*legend*/false, + /*tooltips*/true, + /*urls*/false + ); this.chart.addSubtitle(new TextTitle(config.getName())); this.chart.getTitle().setFont(new Font("Dialog", Font.BOLD, 23)); this.chart.setBackgroundPaint(new Color(240, 240, 240)); diff --git a/swing/src/main/java/info/openrocket/swing/gui/plot/SimulationPlot.java b/swing/src/main/java/info/openrocket/swing/gui/plot/SimulationPlot.java index 7fa36a3be..c493ea4de 100644 --- a/swing/src/main/java/info/openrocket/swing/gui/plot/SimulationPlot.java +++ b/swing/src/main/java/info/openrocket/swing/gui/plot/SimulationPlot.java @@ -19,12 +19,9 @@ import info.openrocket.core.simulation.FlightEvent; import info.openrocket.core.preferences.ApplicationPreferences; import info.openrocket.core.util.LinearInterpolator; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.JFreeChart; import org.jfree.chart.annotations.XYImageAnnotation; import org.jfree.chart.annotations.XYTitleAnnotation; import org.jfree.chart.block.BlockBorder; -import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.ValueMarker; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; @@ -36,11 +33,6 @@ import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; -/* - * TODO: It should be possible to simplify this code quite a bit by using a single Renderer instance for - * both datasets and the legend. But for now, the renderers are queried for the line color information - * and this is held in the Legend. - */ @SuppressWarnings("serial") public class SimulationPlot extends Plot { private final SimulationPlotConfiguration config; @@ -50,8 +42,8 @@ public class SimulationPlot extends Plot allBranches) { - super(chart, mainBranch, config, allBranches, initialShowPoints); + FlightDataBranch mainBranch, List allBranches) { + super(simulation.getName(), mainBranch, config, allBranches, initialShowPoints); this.simulation = simulation; this.config = config; @@ -67,21 +59,9 @@ public class SimulationPlot extends Plot