From 73214345f663cdb5559fc8034c5e9ccb9bc6be30 Mon Sep 17 00:00:00 2001 From: salman Date: Fri, 20 Nov 2026 08:57:17 +0100 Subject: [PATCH] Fix parameter plot resize and toolbar visibility --- ZGUI.css | 32 +++++++++++++------------------- muSRFitParameterPlot.js | 5 +++++ parameter-plot-window.js | 1 + tests/parameter-plot.test.js | 26 ++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/ZGUI.css b/ZGUI.css index 991400f..69361c2 100644 --- a/ZGUI.css +++ b/ZGUI.css @@ -1684,44 +1684,38 @@ button:not(.tablinks):not(.action-btn):not(.editor-source-tab):not(.status-state } /* Plot tools are hidden until a deliberate tap/click inside this panel. */ -.parameter-plot-window .js-plotly-plot .modebar { +.parameter-plot-window .js-plotly-plot .modebar, +.electron-parameter-plot-page .js-plotly-plot .modebar { opacity: 0 !important; pointer-events: none !important; transition: opacity 120ms ease; } -.parameter-plot-window .js-plotly-plot.modebar-open .modebar { +.parameter-plot-window .js-plotly-plot.modebar-open .modebar, +.electron-parameter-plot-page .js-plotly-plot.modebar-open .modebar { opacity: 1 !important; pointer-events: auto !important; } .parameter-plot-window .js-plotly-plot .modebar-container, -.parameter-plot-window .js-plotly-plot .modebar { +.parameter-plot-window .js-plotly-plot .modebar, +.electron-parameter-plot-page .js-plotly-plot .modebar-container, +.electron-parameter-plot-page .js-plotly-plot .modebar { top: 2px !important; right: 2px !important; } @media (max-width: 700px) { - .parameter-plot-window .js-plotly-plot .modebar-group { + .parameter-plot-window .js-plotly-plot .modebar-group, + .electron-parameter-plot-page .js-plotly-plot .modebar-group { padding: 0 !important; } - .parameter-plot-window .js-plotly-plot .modebar-btn { + .parameter-plot-window .js-plotly-plot .modebar-btn, + .electron-parameter-plot-page .js-plotly-plot .modebar-btn { height: 28px !important; width: 28px !important; padding: 2px !important; } - .parameter-plot-window .js-plotly-plot .modebar-btn svg { - height: 18px !important; - width: 18px !important; - } -} - .parameter-plot-window .js-plotly-plot .modebar-group { - padding: 0 !important; - } - .parameter-plot-window .js-plotly-plot .modebar-btn { - height: 28px !important; - width: 28px !important; - padding: 2px !important; - } - .parameter-plot-window .js-plotly-plot .modebar-btn svg { + .parameter-plot-window .js-plotly-plot .modebar-btn svg, + .electron-parameter-plot-page .js-plotly-plot .modebar-btn svg { height: 18px !important; width: 18px !important; } diff --git a/muSRFitParameterPlot.js b/muSRFitParameterPlot.js index c697721..be8fd6d 100644 --- a/muSRFitParameterPlot.js +++ b/muSRFitParameterPlot.js @@ -2628,6 +2628,11 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa try { var win = shell.root || plotWindow; if (!win || !win.style) return; + if (shell && shell.ownsWindow) { + win.style.height = ""; + win.style.maxHeight = ""; + return; + } var vw = (typeof window !== "undefined" && window.innerWidth) ? window.innerWidth : 1200; var vh = (typeof window !== "undefined" && window.innerHeight) ? window.innerHeight : 800; var statusH = 38; diff --git a/parameter-plot-window.js b/parameter-plot-window.js index 1741e11..1f9e9e1 100644 --- a/parameter-plot-window.js +++ b/parameter-plot-window.js @@ -28,6 +28,7 @@ window.MusrfitParameterPlotPlatform.createPlotWindow = function() { return { root: document.body, content: content, + ownsWindow: true, keyTarget: document, close: function() { window.close(); }, onClose: function(handler) { diff --git a/tests/parameter-plot.test.js b/tests/parameter-plot.test.js index ef7ad14..dec0665 100644 --- a/tests/parameter-plot.test.js +++ b/tests/parameter-plot.test.js @@ -1146,9 +1146,26 @@ function testAxisScaleSurvivesRefresh() { } +function testNativeParameterPlotResize() { + const plot = fs.readFileSync(path.join(repoRoot, "muSRFitParameterPlot.js"), "utf8"); + const windowScript = fs.readFileSync(path.join(repoRoot, "parameter-plot-window.js"), "utf8"); + const css = fs.readFileSync(path.join(repoRoot, "ZGUI.css"), "utf8"); + const start = plot.indexOf("function updateParameterPlotWindowSize"); + const end = plot.indexOf("function applyLayout", start); + assert.ok(start >= 0 && end > start); + const sizing = plot.slice(start, end); + assert.match(sizing, /if \(shell && shell\.ownsWindow\)/); + assert.match(sizing, /win\.style\.height = ""/); + assert.match(sizing, /win\.style\.maxHeight = ""/); + assert.match(windowScript, /ownsWindow: true/); + assert.match(css, /\.electron-parameter-plot-page-root,\s*body\.electron-parameter-plot-page\s*\{\s*height:\s*100%;/s); + assert.match(css, /\.electron-parameter-plot-page \.parameter-plot-content\s*\{\s*height:\s*100%;/s); +} + function testParameterToolbarVisibility() { const plot = fs.readFileSync(path.join(repoRoot, "muSRFitParameterPlot.js"), "utf8"); const css = fs.readFileSync(path.join(repoRoot, "ZGUI.css"), "utf8"); + const html = fs.readFileSync(path.join(repoRoot, "parameter-plot.html"), "utf8"); assert.match(plot, /displayModeBar: true/); assert.match(plot, /addEventListener\("pointerdown"/); assert.match(plot, /addEventListener\("pointerup"/); @@ -1156,8 +1173,12 @@ function testParameterToolbarVisibility() { assert.match(plot, /classList\.add\("modebar-open"\)/); assert.match(plot, /document\.addEventListener\("pointerdown", dismissParameterModeBar, true\)/); assert.match(plot, /document\.removeEventListener\("pointerdown", dismissParameterModeBar, true\)/); - assert.match(css, /\.js-plotly-plot \.modebar\s*\{[^}]*opacity: 0 !important;[^}]*pointer-events: none !important;/s); - assert.match(css, /\.js-plotly-plot\.modebar-open \.modebar\s*\{[^}]*opacity: 1 !important;[^}]*pointer-events: auto !important;/s); + const hiddenModebar = /\.parameter-plot-window \.js-plotly-plot \.modebar,\s*\.electron-parameter-plot-page \.js-plotly-plot \.modebar\s*\{[^}]*opacity: 0 !important;[^}]*pointer-events: none !important;/s; + const openModebar = /\.parameter-plot-window \.js-plotly-plot\.modebar-open \.modebar,\s*\.electron-parameter-plot-page \.js-plotly-plot\.modebar-open \.modebar\s*\{[^}]*opacity: 1 !important;[^}]*pointer-events: auto !important;/s; + assert.match(css, hiddenModebar); + assert.match(css, openModebar); + assert.match(html, //); + assert.strictEqual((css.match(/{/g) || []).length, (css.match(/}/g) || []).length); // Marker styling must remain available after removing the generic click handlers. assert.match(plot, /panel\.chart\.on\("plotly_click"/); } @@ -1174,6 +1195,7 @@ testInlineParameterSource(); testParameterPlotLayoutModes(); testParameterPlotLayoutPersistence(); testDialogAndWindowLayoutPlumbing(); +testNativeParameterPlotResize(); testTraceStyleAndOverlayFoundation(); testParameterStyleEditingFoundation(); testDataSetRegistryFoundation();