Plot settings and version
This commit is contained in:
@@ -25,21 +25,89 @@ class CompiledModel:
|
||||
return {"model_name": self.model_name, "executable": self.executable, "working_directory": self.working_directory, "output": self.output, "errors": self.errors}
|
||||
|
||||
|
||||
@dataclass
|
||||
class SimulationTraceSettings:
|
||||
visible: bool = True
|
||||
label: str = ""
|
||||
color: str = ""
|
||||
line_style: str = "-"
|
||||
line_width: float = 1.5
|
||||
marker: str = ""
|
||||
marker_size: float = 6.0
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, data: Mapping[str, Any]) -> SimulationTraceSettings:
|
||||
return cls(visible=bool(data.get("visible", True)), label=str(data.get("label", "")), color=str(data.get("color", "")), line_style=str(data.get("line_style", "-")), line_width=float(data.get("line_width", 1.5)), marker=str(data.get("marker", "")), marker_size=float(data.get("marker_size", 6.0)))
|
||||
|
||||
def to_data(self) -> dict[str, Any]:
|
||||
return {"visible": self.visible, "label": self.label, "color": self.color, "line_style": self.line_style, "line_width": self.line_width, "marker": self.marker, "marker_size": self.marker_size}
|
||||
|
||||
|
||||
@dataclass
|
||||
class SimulationPlotSettings:
|
||||
title: str = ""
|
||||
x_label: str = ""
|
||||
y_label: str = ""
|
||||
x_scale: str = "linear"
|
||||
y_scale: str = "linear"
|
||||
x_auto: bool = True
|
||||
y_auto: bool = True
|
||||
x_min: float = 0.0
|
||||
x_max: float = 1.0
|
||||
y_min: float = 0.0
|
||||
y_max: float = 1.0
|
||||
grid_visible: bool = True
|
||||
grid_axis: str = "both"
|
||||
grid_style: str = "-"
|
||||
grid_alpha: float = 0.5
|
||||
legend_visible: bool = True
|
||||
legend_location: str = "best"
|
||||
traces: dict[str, SimulationTraceSettings] = field(default_factory=dict)
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, data: Mapping[str, Any]) -> SimulationPlotSettings:
|
||||
raw_traces = data.get("traces", {})
|
||||
if not isinstance(raw_traces, Mapping):
|
||||
raise TypeError("plot trace settings must be a mapping")
|
||||
return cls(
|
||||
title=str(data.get("title", "")), x_label=str(data.get("x_label", "")), y_label=str(data.get("y_label", "")),
|
||||
x_scale=str(data.get("x_scale", "linear")), y_scale=str(data.get("y_scale", "linear")),
|
||||
x_auto=bool(data.get("x_auto", True)), y_auto=bool(data.get("y_auto", True)),
|
||||
x_min=float(data.get("x_min", 0.0)), x_max=float(data.get("x_max", 1.0)), y_min=float(data.get("y_min", 0.0)), y_max=float(data.get("y_max", 1.0)),
|
||||
grid_visible=bool(data.get("grid_visible", True)), grid_axis=str(data.get("grid_axis", "both")), grid_style=str(data.get("grid_style", "-")), grid_alpha=float(data.get("grid_alpha", 0.5)),
|
||||
legend_visible=bool(data.get("legend_visible", True)), legend_location=str(data.get("legend_location", "best")),
|
||||
traces={str(signal): SimulationTraceSettings.from_data(trace) for signal, trace in raw_traces.items() if isinstance(trace, Mapping)},
|
||||
)
|
||||
|
||||
def to_data(self) -> dict[str, Any]:
|
||||
return {
|
||||
"title": self.title, "x_label": self.x_label, "y_label": self.y_label, "x_scale": self.x_scale, "y_scale": self.y_scale,
|
||||
"x_auto": self.x_auto, "y_auto": self.y_auto, "x_min": self.x_min, "x_max": self.x_max, "y_min": self.y_min, "y_max": self.y_max,
|
||||
"grid_visible": self.grid_visible, "grid_axis": self.grid_axis, "grid_style": self.grid_style, "grid_alpha": self.grid_alpha,
|
||||
"legend_visible": self.legend_visible, "legend_location": self.legend_location,
|
||||
"traces": {signal: trace.to_data() for signal, trace in self.traces.items()},
|
||||
}
|
||||
|
||||
|
||||
@dataclass
|
||||
class SimulationPlotTab:
|
||||
name: str
|
||||
signals: list[str] = field(default_factory=list)
|
||||
x_axis: str | None = None
|
||||
settings: SimulationPlotSettings = field(default_factory=SimulationPlotSettings)
|
||||
|
||||
@classmethod
|
||||
def from_data(cls, data: Mapping[str, Any]) -> SimulationPlotTab:
|
||||
raw_signals = data.get("signals", [])
|
||||
if not isinstance(raw_signals, list):
|
||||
raise TypeError("plot tab signals must be a list")
|
||||
return cls(name=str(data.get("name", "Plot")), signals=[str(signal) for signal in raw_signals], x_axis=str(data["x_axis"]) if data.get("x_axis") is not None else None)
|
||||
raw_settings = data.get("settings", {})
|
||||
if not isinstance(raw_settings, Mapping):
|
||||
raise TypeError("plot tab settings must be a mapping")
|
||||
return cls(name=str(data.get("name", "Plot")), signals=[str(signal) for signal in raw_signals], x_axis=str(data["x_axis"]) if data.get("x_axis") is not None else None, settings=SimulationPlotSettings.from_data(raw_settings))
|
||||
|
||||
def to_data(self) -> dict[str, Any]:
|
||||
return {"name": self.name, "signals": self.signals, "x_axis": self.x_axis}
|
||||
return {"name": self.name, "signals": self.signals, "x_axis": self.x_axis, "settings": self.settings.to_data()}
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user