Merge formatSampleTooltip and formatEventTooltip into a single formatTooltip to ensure consistency in formatting
This commit is contained in:
parent
4b2d4ca837
commit
bc8c0b48be
@ -1,9 +1,11 @@
|
|||||||
package info.openrocket.swing.gui.plot;
|
package info.openrocket.swing.gui.plot;
|
||||||
|
|
||||||
import info.openrocket.core.l10n.Translator;
|
import info.openrocket.core.l10n.Translator;
|
||||||
|
import info.openrocket.core.logging.Warning;
|
||||||
import info.openrocket.core.simulation.DataBranch;
|
import info.openrocket.core.simulation.DataBranch;
|
||||||
import info.openrocket.core.simulation.DataType;
|
import info.openrocket.core.simulation.DataType;
|
||||||
import info.openrocket.core.simulation.FlightDataType;
|
import info.openrocket.core.simulation.FlightDataType;
|
||||||
|
import info.openrocket.core.simulation.FlightEvent;
|
||||||
import info.openrocket.core.startup.Application;
|
import info.openrocket.core.startup.Application;
|
||||||
import info.openrocket.core.unit.Unit;
|
import info.openrocket.core.unit.Unit;
|
||||||
import info.openrocket.core.unit.UnitGroup;
|
import info.openrocket.core.unit.UnitGroup;
|
||||||
@ -53,6 +55,7 @@ import java.text.DecimalFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: It should be possible to simplify this code quite a bit by using a single Renderer instance for
|
* TODO: It should be possible to simplify this code quite a bit by using a single Renderer instance for
|
||||||
@ -227,10 +230,11 @@ public abstract class Plot<T extends DataType, B extends DataBranch<T>, C extend
|
|||||||
double dataY = dataset.getYValue(series, item);
|
double dataY = dataset.getYValue(series, item);
|
||||||
String unitY = ser.getUnit();
|
String unitY = ser.getUnit();
|
||||||
|
|
||||||
return formatSampleTooltip(name,
|
return formatTooltip(name,
|
||||||
nameT, dataT, unitT,
|
nameT, dataT, unitT,
|
||||||
nameX, dataX, unitX,
|
nameX, dataX, unitX,
|
||||||
nameY, dataY, unitY);
|
nameY, dataY, unitY,
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -316,10 +320,11 @@ public abstract class Plot<T extends DataType, B extends DataBranch<T>, C extend
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String formatSampleTooltip(String dataName,
|
protected String formatTooltip(String dataName,
|
||||||
String nameT, double dataT, String unitT,
|
String nameT, double dataT, String unitT,
|
||||||
String nameX, double dataX, String unitX,
|
String nameX, double dataX, String unitX,
|
||||||
String nameY, double dataY, String unitY) {
|
String nameY, double dataY, String unitY,
|
||||||
|
Set<FlightEvent> events) {
|
||||||
|
|
||||||
final String strFormat = "%s: %s %s<br>";
|
final String strFormat = "%s: %s %s<br>";
|
||||||
|
|
||||||
@ -330,7 +335,29 @@ public abstract class Plot<T extends DataType, B extends DataBranch<T>, C extend
|
|||||||
|
|
||||||
sb.append(String.format("<b><i>%s</i></b><br>", dataName));
|
sb.append(String.format("<b><i>%s</i></b><br>", dataName));
|
||||||
|
|
||||||
// If I was given valid Y data, put it in tooltip
|
// Any events?
|
||||||
|
if ((null != events) && (events.size() != 0)) {
|
||||||
|
// Pass through and collect any warnings
|
||||||
|
for (FlightEvent event : events) {
|
||||||
|
if (event.getType() == FlightEvent.Type.SIM_WARN) {
|
||||||
|
sb.append("<b><i>Warning: " + ((Warning) event.getData()).toString() + "</b></i><br>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now pass through and collect the other events
|
||||||
|
String eventStr = "";
|
||||||
|
for (FlightEvent event : events) {
|
||||||
|
if (event.getType() != FlightEvent.Type.SIM_WARN) {
|
||||||
|
if (eventStr != "") {
|
||||||
|
eventStr = eventStr + ", ";
|
||||||
|
}
|
||||||
|
eventStr = eventStr + event.getType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append(eventStr + "<br>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid Y data?
|
||||||
if (!Double.isNaN(dataY)) {
|
if (!Double.isNaN(dataY)) {
|
||||||
DecimalFormat df_y = DecimalFormatter.df(dataY, 2, false);
|
DecimalFormat df_y = DecimalFormatter.df(dataY, 2, false);
|
||||||
sb.append(String.format(strFormat, nameY, df_y.format(dataY), unitY));
|
sb.append(String.format(strFormat, nameY, df_y.format(dataY), unitY));
|
||||||
@ -350,8 +377,8 @@ public abstract class Plot<T extends DataType, B extends DataBranch<T>, C extend
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String formatSampleTooltip(String dataName, String nameX, double dataX, String unitX) {
|
protected String formatTooltip(String dataName, String nameX, double dataX, String unitX) {
|
||||||
return formatSampleTooltip(dataName, "", Double.NaN, "", nameX, dataX, unitX, "", Double.NaN, "");
|
return formatTooltip(dataName, "", Double.NaN, "", nameX, dataX, unitX, "", Double.NaN, "", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class LegendItems implements LegendItemSource {
|
protected static class LegendItems implements LegendItemSource {
|
||||||
|
@ -320,10 +320,11 @@ public class SimulationPlot extends Plot<FlightDataType, FlightDataBranch, Simul
|
|||||||
String unitX = config.getDomainAxisUnit().getUnit();
|
String unitX = config.getDomainAxisUnit().getUnit();
|
||||||
String unitY = series.getUnit();
|
String unitY = series.getUnit();
|
||||||
String unitT = FlightDataType.TYPE_TIME.getUnitGroup().getDefaultUnit().toString();
|
String unitT = FlightDataType.TYPE_TIME.getUnitGroup().getDefaultUnit().toString();
|
||||||
String tooltipText = formatEventTooltip(getNameBasedOnIdxAndSeries(series, sampleIdx), events,
|
String tooltipText = formatTooltip(getNameBasedOnIdxAndSeries(series, sampleIdx),
|
||||||
tName, t, unitT,
|
tName, t, unitT,
|
||||||
xName, xcoord, unitX,
|
xName, xcoord, unitX,
|
||||||
yName, ycoord, unitY);
|
yName, ycoord, unitY,
|
||||||
|
events);
|
||||||
double yloc = slope * ycoord + intercept;
|
double yloc = slope * ycoord + intercept;
|
||||||
|
|
||||||
if (!Double.isNaN(xcoord) && !Double.isNaN(ycoord)) {
|
if (!Double.isNaN(xcoord) && !Double.isNaN(ycoord)) {
|
||||||
@ -338,57 +339,6 @@ public class SimulationPlot extends Plot<FlightDataType, FlightDataBranch, Simul
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String formatEventTooltip(String dataName, Set<FlightEvent> events,
|
|
||||||
String tName, double time, String unitT,
|
|
||||||
String xName, double dataX, String unitX,
|
|
||||||
String yName, double dataY, String unitY) {
|
|
||||||
|
|
||||||
DecimalFormat df_t = DecimalFormatter.df(time, 2, false);
|
|
||||||
DecimalFormat df_y = DecimalFormatter.df(dataY, 2, false);
|
|
||||||
DecimalFormat df_x = DecimalFormatter.df(dataX, 2, false);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
// start tooltip
|
|
||||||
sb.append("<html>");
|
|
||||||
|
|
||||||
// Branchname(s)
|
|
||||||
sb.append(String.format("<b><i>%s</i></b><br>", dataName));
|
|
||||||
|
|
||||||
// Any events?
|
|
||||||
if ((null != events) && (events.size() != 0)) {
|
|
||||||
// Pass through and collect any warnings
|
|
||||||
for (FlightEvent event : events) {
|
|
||||||
if (event.getType() == FlightEvent.Type.SIM_WARN) {
|
|
||||||
sb.append("<b><i>Warning: " + ((Warning) event.getData()).toString() + "</b></i><br>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now pass through and collect the other events
|
|
||||||
String eventStr = "";
|
|
||||||
for (FlightEvent event : events) {
|
|
||||||
if (event.getType() != FlightEvent.Type.SIM_WARN) {
|
|
||||||
if (eventStr != "") {
|
|
||||||
eventStr = eventStr + ", ";
|
|
||||||
}
|
|
||||||
eventStr = eventStr + event.getType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sb.append(eventStr + "<br>");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tName.equals(xName)) {
|
|
||||||
sb.append(String.format("%s: %s %s<br>", tName, df_t.format(time), unitT));
|
|
||||||
}
|
|
||||||
sb.append(String.format("%s: %s %s<br>", xName, df_x.format(dataX), unitX));
|
|
||||||
sb.append(String.format("%s: %s %s<br>", yName, df_y.format(dataY), unitY));
|
|
||||||
|
|
||||||
// End tooltip
|
|
||||||
sb.append("</html>");
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<EventDisplayInfo> buildEventInfo() {
|
private List<EventDisplayInfo> buildEventInfo() {
|
||||||
ArrayList<EventDisplayInfo> eventList = new ArrayList<>();
|
ArrayList<EventDisplayInfo> eventList = new ArrayList<>();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user