diff --git a/muSRFitParameterPlot.js b/muSRFitParameterPlot.js index 3ba5e5e..489b385 100644 --- a/muSRFitParameterPlot.js +++ b/muSRFitParameterPlot.js @@ -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(); + } } } ] diff --git a/tests/parameter-plot.test.js b/tests/parameter-plot.test.js index 5479eb2..ae19445 100644 --- a/tests/parameter-plot.test.js +++ b/tests/parameter-plot.test.js @@ -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");