Keep parameter-plot log scale across Refresh
redrawPanel rebuilt the layout with a fresh xaxis/yaxis and plotly.react reset any log-scale choice back to linear. The axis scale is now stored per panel, carried in the saved-state descriptor, reapplied to the layout on every redraw, and written back by the Toggle X/Y linear/log buttons.
This commit is contained in:
1 parent
cd0b1587bd
commit
f2033e50d1
2 files changed
+55
-3
No files matched your search
+26
-3
@@ -1697,7 +1697,9 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
|
||||
overlays: (panel.overlays || []).slice(),
|
||||
paletteId: panel.paletteId,
|
||||
xTitle: panel.xTitle || "",
|
||||
yTitle: panel.yTitle || ""
|
||||
yTitle: panel.yTitle || "",
|
||||
xScale: panel.xScale || "linear",
|
||||
yScale: panel.yScale || "linear"
|
||||
};
|
||||
}),
|
||||
registeredDataSets: registeredDataSets.map(function(entry) {
|
||||
@@ -1748,6 +1750,8 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
|
||||
panel.paletteId = savedPanel.paletteId || windowPaletteId;
|
||||
panel.xTitle = savedPanel.xTitle || "";
|
||||
panel.yTitle = savedPanel.yTitle || "";
|
||||
panel.xScale = savedPanel.xScale === "log" ? "log" : "linear";
|
||||
panel.yScale = savedPanel.yScale === "log" ? "log" : "linear";
|
||||
panel.dataSetKey = panel.source ? parameterDataSetKey(panel.source) : savedPanel.dataSetKey || "";
|
||||
panelStates.push(panel);
|
||||
}
|
||||
@@ -1801,6 +1805,10 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
|
||||
paletteId: windowPaletteId,
|
||||
xTitle: "",
|
||||
yTitle: "",
|
||||
// Axis scale survives a Refresh: redrawPanel applies it to layout and
|
||||
// the Plotly toggle buttons write it back here.
|
||||
xScale: "linear",
|
||||
yScale: "linear",
|
||||
wrapper: null,
|
||||
chart: null,
|
||||
emptyMessage: null,
|
||||
@@ -2073,6 +2081,11 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
|
||||
tickfont: { size: compact ? 11 : 14 }, showline: true, mirror: true, automargin: true
|
||||
}
|
||||
};
|
||||
// plotly.react with a fresh layout resets xaxis.type/yaxis.type to the
|
||||
// default linear. Reapply the panel's persisted scale so a Refresh does
|
||||
// not silently switch a log axis back to linear.
|
||||
if (panel.xScale === "log") layout.xaxis.type = "log";
|
||||
if (panel.yScale === "log") layout.yaxis.type = "log";
|
||||
plotly.react(panel.chart, traces, layout, {
|
||||
responsive: true,
|
||||
editable: true,
|
||||
@@ -2085,9 +2098,14 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
|
||||
icon: plotly.Icons.pencil,
|
||||
click: function(gd) {
|
||||
let current = gd.layout.xaxis.type || "linear";
|
||||
let next = current === "log" ? "linear" : "log";
|
||||
plotly.relayout(gd, {
|
||||
"xaxis.type": current === "log" ? "linear" : "log"
|
||||
"xaxis.type": next
|
||||
});
|
||||
if (panel.xScale !== next) {
|
||||
panel.xScale = next;
|
||||
scheduleParameterPlotStateSave();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -2095,9 +2113,14 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
|
||||
icon: plotly.Icons.pencil,
|
||||
click: function(gd) {
|
||||
let current = gd.layout.yaxis.type || "linear";
|
||||
let next = current === "log" ? "linear" : "log";
|
||||
plotly.relayout(gd, {
|
||||
"yaxis.type": current === "log" ? "linear" : "log"
|
||||
"yaxis.type": next
|
||||
});
|
||||
if (panel.yScale !== next) {
|
||||
panel.yScale = next;
|
||||
scheduleParameterPlotStateSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1056,6 +1056,34 @@ function testRememberedPlotConfigurations() {
|
||||
assert.ok(sourcesKept.size <= 8, "Global source cap should apply, got " + sourcesKept.size);
|
||||
}
|
||||
|
||||
function testAxisScaleSurvivesRefresh() {
|
||||
const plot = fs.readFileSync(path.join(repoRoot, "muSRFitParameterPlot.js"), "utf8");
|
||||
|
||||
// A log-scale choice must survive a Refresh. redrawPanel reapplies the
|
||||
// persisted scale to the fresh layout (plotly.react would otherwise reset
|
||||
// the axis to linear), the toggle buttons write the choice back to the
|
||||
// panel and save it, and the saved descriptor carries it.
|
||||
assert.match(plot, /if \(panel\.xScale === "log"\) layout\.xaxis\.type = "log";/);
|
||||
assert.match(plot, /if \(panel\.yScale === "log"\) layout\.yaxis\.type = "log";/);
|
||||
assert.match(plot, /panel\.xScale = next;\s*scheduleParameterPlotStateSave\(\);/);
|
||||
assert.match(plot, /panel\.yScale = next;\s*scheduleParameterPlotStateSave\(\);/);
|
||||
assert.match(plot, /xScale: panel\.xScale \|\| "linear"/);
|
||||
assert.match(plot, /yScale: panel\.yScale \|\| "linear"/);
|
||||
assert.match(plot, /panel\.xScale = savedPanel\.xScale === "log" \? "log" : "linear";/);
|
||||
assert.match(plot, /panel\.yScale = savedPanel\.yScale === "log" \? "log" : "linear";/);
|
||||
|
||||
// Snapshots carrying the new per-panel scale fields still validate, so a
|
||||
// window/plot saved with a log axis restores cleanly.
|
||||
const lib = loadParameterPlotLibrary();
|
||||
assert.strictEqual(lib.validateParameterPlotState({
|
||||
v: 1,
|
||||
mainSourceKey: "path:/work/514_par.dat",
|
||||
panelStates: [{ stableId: "pp1", xScale: "log", yScale: "linear" }],
|
||||
registeredDataSets: [],
|
||||
styleRegistry: {}
|
||||
}), true);
|
||||
}
|
||||
|
||||
testParserAndSmartDefaults();
|
||||
testScanVariableDetection();
|
||||
testTfTemplateApplication();
|
||||
@@ -1071,4 +1099,5 @@ testParameterStyleEditingFoundation();
|
||||
testDataSetRegistryFoundation();
|
||||
testParameterPlotStatePersistence();
|
||||
testRememberedPlotConfigurations();
|
||||
testAxisScaleSurvivesRefresh();
|
||||
console.log("Parameter plot tests passed");
|
||||
Reference in new issue
Block a user