Add smart legend labels and preserve user-renamed legend entries

Overlaid data sets show which physical state each scan represents
instead of just a file name: the legend tag is derived from the data
set's own scan variable, tagging an energy scan with its constant
temperature, a temperature scan with its constant energy (LE-µSR) or
field (bulk µSR), and a field scan with its temperature. Legend
entries renamed directly in the plot are remembered and survive Refresh
instead of being rebuilt from the smart defaults.

The Histograms field on the Runs tab gains a hover note documenting the
forward/backward pair syntax and the slash-separated multi-group
asymmetry option.
This commit is contained in:
salman committed 2026-09-22 18:12:06 +02:00
1 parent 23c2ed233f
commit 5ec64db2b8
8 files changed
+213 -5

No files matched your search

+6
View File
@@ -41,6 +41,12 @@ release path documented in [`TODO.md`](TODO.md).
can be compared across the whole window without repeating the overlay step
per panel. Overlaying no longer rewrites the panel's Y-axis label: it stays
on the active panel's parameter instead of reverting to "Fit parameter".
- Overlaid curves get smart legend labels derived from each data set's scan
variable: an energy scan is tagged with its constant temperature, a
temperature scan with its energy for LE-µSR or its field for bulk µSR, and a
field scan with its temperature. Legend entries renamed directly in the plot
are remembered, so Refresh keeps the user's labels instead of rebuilding the
defaults.
- Remembered parameter-plot configurations are no longer restored silently.
The **Choose X axis** dialog now always appears, and a **Configuration**
dropdown lists saved configurations whose parameter set matches the current
+11
View File
@@ -88,6 +88,17 @@ layout choice. Panels share the chosen X axis. The toolbar holds:
Adding files this way is the same overlay mechanism as **Overlay data
sets** in *Plot options*; the toolbar shortcut just applies the additions
to all panels instead of the active one.
Overlaid curves get a *smart legend* label that says which physical state
each scan represents instead of only a file name. The label is derived from
the data set's own scan variable and its constant coordinate: an energy scan
(``dataE`` varying) is tagged with its fixed temperature (``(T = 300 K)``), a
temperature scan with its fixed energy for LE-µSR (``(E = 12 keV)``) or with
its field for bulk µSR (``(B = 100 G)``), and a field scan with its fixed
temperature. When no fixed coordinate is present the plain file label is used.
You can also rename a legend entry directly in the plot; a Refresh then keeps
your name instead of rebuilding the default.
* **Plot options** -- expand the layout, X, parameter, style, and displayed
series controls for the active panel.
+11
View File
@@ -182,6 +182,17 @@ the active panel’s parameter rather than reverting to a generic label.
Adding files this way is the same overlay mechanism as <strong>Overlay data
sets</strong> in <em>Plot options</em>; the toolbar shortcut just applies the additions
to all panels instead of the active one.</p></li>
</ul>
<p>Overlaid curves get a <em>smart legend</em> label that says which physical state
each scan represents instead of only a file name. The label is derived from
the data set’s own scan variable and its constant coordinate: an energy scan
(<code class="docutils literal notranslate"><span class="pre">dataE</span></code> varying) is tagged with its fixed temperature (<code class="docutils literal notranslate"><span class="pre">(T</span> <span class="pre">=</span> <span class="pre">300</span> <span class="pre">K)</span></code>), a
temperature scan with its fixed energy for LE-µSR (<code class="docutils literal notranslate"><span class="pre">(E</span> <span class="pre">=</span> <span class="pre">12</span> <span class="pre">keV)</span></code>) or with
its field for bulk µSR (<code class="docutils literal notranslate"><span class="pre">(B</span> <span class="pre">=</span> <span class="pre">100</span> <span class="pre">G)</span></code>), and a field scan with its fixed
temperature. When no fixed coordinate is present the plain file label is used.
You can also rename a legend entry directly in the plot; a Refresh then keeps
your name instead of rebuilding the default.</p>
<ul class="simple">
<li><p><strong>Plot options</strong> – expand the layout, X, parameter, style, and displayed
series controls for the active panel.</p></li>
</ul>
+1 -1
View File
@@ -1 +1 @@
Search.setIndex({"alltitles":{"A first fit":[[7,"a-first-fit"]],"Command log":[[11,"command-log"]],"Configuration sharing":[[0,null]],"Constraints":[[1,null],[1,"id1"]],"Contents":[[4,null]],"Custom parameters":[[1,"custom-parameters"]],"Desktop installation":[[2,"desktop-installation"]],"Editing trace styles":[[8,"editing-trace-styles"]],"Example: couple the magnetic field to the Larmor frequency":[[1,"example-couple-the-magnetic-field-to-the-larmor-frequency"]],"Execution details":[[11,"execution-details"]],"File handling":[[6,"file-handling"]],"Fit and Plot":[[12,"fit-and-plot"]],"Fit model":[[12,"fit-model"]],"Fit options":[[12,"fit-options"]],"Fit or plot will not start":[[14,"fit-or-plot-will-not-start"]],"Fit range":[[12,"fit-range"]],"Fitted parameters look wrong or unchanged":[[14,"fitted-parameters-look-wrong-or-unchanged"]],"General notes":[[5,"general-notes"]],"Getting started":[[2,null]],"Glossary":[[3,null]],"Keyboard shortcuts":[[5,null],[8,"keyboard-shortcuts"]],"MSR editor":[[5,"msr-editor"],[6,null]],"Multi-group asymmetry fits":[[13,"multi-group-asymmetry-fits"]],"Notes":[[0,"notes"]],"On the desktop":[[0,"on-the-desktop"]],"On the web":[[0,"on-the-web"]],"Opening the web edition":[[2,"opening-the-web-edition"]],"Outcome dialog":[[11,"outcome-dialog"]],"Overlay data sets (multiple files in one panel)":[[8,"overlay-data-sets-multiple-files-in-one-panel"]],"Overview":[[7,null]],"Ownership: GUI or editor":[[6,"ownership-gui-or-editor"]],"Parameter plot hangs on \u201cPreparing plot files\u201d":[[14,"parameter-plot-hangs-on-preparing-plot-files"]],"Parameter plot is empty or missing data":[[14,"parameter-plot-is-empty-or-missing-data"]],"Parameter selection (Parameters tab)":[[5,"parameter-selection-parameters-tab"]],"Parameter-plot window":[[5,"parameter-plot-window"]],"Parameters and parameter plots":[[8,null]],"Per-run statistics":[[12,"per-run-statistics"]],"Plot options":[[8,"plot-options"]],"Preferences":[[10,null]],"Prerequisites":[[2,"prerequisites"]],"Preview":[[1,"preview"]],"Remembered plot configurations":[[8,"remembered-plot-configurations"]],"Reporting problems":[[14,"reporting-problems"]],"Restored configuration differs from the original machine":[[14,"restored-configuration-differs-from-the-original-machine"]],"Result files":[[11,"result-files"]],"Results and diagnostics":[[11,null]],"Run log window":[[11,"run-log-window"]],"Run selection":[[12,"run-selection"]],"Running the desktop app":[[2,"running-the-desktop-app"]],"Runs and fitting":[[12,null]],"Selecting parameters for plotting":[[8,"selecting-parameters-for-plotting"]],"Series fit actions":[[12,"series-fit-actions"]],"Some links start with a different prefix":[[14,"some-links-start-with-a-different-prefix"]],"Support":[[2,"support"]],"Template and series presets":[[8,"template-and-series-presets"]],"The Choose X axis dialog":[[8,"the-choose-x-axis-dialog"]],"The Quick Start guide":[[2,"the-quick-start-guide"]],"The Shared column":[[8,"the-shared-column"]],"The parameter table":[[8,"the-parameter-table"]],"The parameter-plot window":[[8,"the-parameter-plot-window"]],"The status bar":[[11,"the-status-bar"]],"Troubleshooting":[[14,null]],"Two editions":[[7,"two-editions"]],"Under the hood":[[7,"under-the-hood"]],"View settings":[[12,"view-settings"]],"Web and desktop editions":[[9,null]],"Web page cannot load data":[[14,"web-page-cannot-load-data"]],"What is shared":[[0,"what-is-shared"]],"What you get":[[7,"what-you-get"]],"Workflow":[[6,"workflow"]],"muSRFlow User Manual":[[4,null]],"t0 / background":[[13,null]],"\u201cNothing to fit\u201d":[[14,"nothing-to-fit"]]},"docnames":["configuration-sharing","constraints","getting-started","glossary","index","keyboard-shortcuts","msr-editor","overview","parameters-plots","platforms","preferences","results-diagnostics","runs-fitting","t0-background","troubleshooting"],"envversion":{"sphinx":65,"sphinx.domains.c":3,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":9,"sphinx.domains.index":1,"sphinx.domains.javascript":3,"sphinx.domains.math":2,"sphinx.domains.python":4,"sphinx.domains.rst":2,"sphinx.domains.std":2},"filenames":["configuration-sharing.rst","constraints.rst","getting-started.rst","glossary.rst","index.rst","keyboard-shortcuts.rst","msr-editor.rst","overview.rst","parameters-plots.rst","platforms.rst","preferences.rst","results-diagnostics.rst","runs-fitting.rst","t0-background.rst","troubleshooting.rst"],"indexentries":{},"objects":{},"objnames":{},"objtypes":{},"terms":{"":[0,3,5,6,8,10,12,13,14],"0":12,"01":12,"012":11,"1":[8,11,12,13],"100":12,"101":13,"103":13,"12":12,"16":12,"1998":12,"2":[8,12,13],"21":12,"24":12,"25":12,"3":[8,12,13],"4":[12,13],"5":12,"514":[3,12],"515":[3,12],"516":12,"520":12,"525":12,"540":12,"7":12,"8":12,"A":[0,1,3,4,8,10,11,12,13,14],"For":[2,6,8,11,12,13],"If":[0,4,8,11,12,14],"In":[5,7,8,14],"It":[0,1,4,6,7,11],"Its":[5,7],"On":[2,3,4,6,7,9,11,12,14],"One":[3,12],"The":[0,1,3,4,5,6,7,9,10,12,13,14],"ThenLine truncated
Search.setIndex({"alltitles":{"A first fit":[[7,"a-first-fit"]],"Command log":[[11,"command-log"]],"Configuration sharing":[[0,null]],"Constraints":[[1,null],[1,"id1"]],"Contents":[[4,null]],"Custom parameters":[[1,"custom-parameters"]],"Desktop installation":[[2,"desktop-installation"]],"Editing trace styles":[[8,"editing-trace-styles"]],"Example: couple the magnetic field to the Larmor frequency":[[1,"example-couple-the-magnetic-field-to-the-larmor-frequency"]],"Execution details":[[11,"execution-details"]],"File handling":[[6,"file-handling"]],"Fit and Plot":[[12,"fit-and-plot"]],"Fit model":[[12,"fit-model"]],"Fit options":[[12,"fit-options"]],"Fit or plot will not start":[[14,"fit-or-plot-will-not-start"]],"Fit range":[[12,"fit-range"]],"Fitted parameters look wrong or unchanged":[[14,"fitted-parameters-look-wrong-or-unchanged"]],"General notes":[[5,"general-notes"]],"Getting started":[[2,null]],"Glossary":[[3,null]],"Keyboard shortcuts":[[5,null],[8,"keyboard-shortcuts"]],"MSR editor":[[5,"msr-editor"],[6,null]],"Multi-group asymmetry fits":[[13,"multi-group-asymmetry-fits"]],"Notes":[[0,"notes"]],"On the desktop":[[0,"on-the-desktop"]],"On the web":[[0,"on-the-web"]],"Opening the web edition":[[2,"opening-the-web-edition"]],"Outcome dialog":[[11,"outcome-dialog"]],"Overlay data sets (multiple files in one panel)":[[8,"overlay-data-sets-multiple-files-in-one-panel"]],"Overview":[[7,null]],"Ownership: GUI or editor":[[6,"ownership-gui-or-editor"]],"Parameter plot hangs on \u201cPreparing plot files\u201d":[[14,"parameter-plot-hangs-on-preparing-plot-files"]],"Parameter plot is empty or missing data":[[14,"parameter-plot-is-empty-or-missing-data"]],"Parameter selection (Parameters tab)":[[5,"parameter-selection-parameters-tab"]],"Parameter-plot window":[[5,"parameter-plot-window"]],"Parameters and parameter plots":[[8,null]],"Per-run statistics":[[12,"per-run-statistics"]],"Plot options":[[8,"plot-options"]],"Preferences":[[10,null]],"Prerequisites":[[2,"prerequisites"]],"Preview":[[1,"preview"]],"Remembered plot configurations":[[8,"remembered-plot-configurations"]],"Reporting problems":[[14,"reporting-problems"]],"Restored configuration differs from the original machine":[[14,"restored-configuration-differs-from-the-original-machine"]],"Result files":[[11,"result-files"]],"Results and diagnostics":[[11,null]],"Run log window":[[11,"run-log-window"]],"Run selection":[[12,"run-selection"]],"Running the desktop app":[[2,"running-the-desktop-app"]],"Runs and fitting":[[12,null]],"Selecting parameters for plotting":[[8,"selecting-parameters-for-plotting"]],"Series fit actions":[[12,"series-fit-actions"]],"Some links start with a different prefix":[[14,"some-links-start-with-a-different-prefix"]],"Support":[[2,"support"]],"Template and series presets":[[8,"template-and-series-presets"]],"The Choose X axis dialog":[[8,"the-choose-x-axis-dialog"]],"The Quick Start guide":[[2,"the-quick-start-guide"]],"The Shared column":[[8,"the-shared-column"]],"The parameter table":[[8,"the-parameter-table"]],"The parameter-plot window":[[8,"the-parameter-plot-window"]],"The status bar":[[11,"the-status-bar"]],"Troubleshooting":[[14,null]],"Two editions":[[7,"two-editions"]],"Under the hood":[[7,"under-the-hood"]],"View settings":[[12,"view-settings"]],"Web and desktop editions":[[9,null]],"Web page cannot load data":[[14,"web-page-cannot-load-data"]],"What is shared":[[0,"what-is-shared"]],"What you get":[[7,"what-you-get"]],"Workflow":[[6,"workflow"]],"muSRFlow User Manual":[[4,null]],"t0 / background":[[13,null]],"\u201cNothing to fit\u201d":[[14,"nothing-to-fit"]]},"docnames":["configuration-sharing","constraints","getting-started","glossary","index","keyboard-shortcuts","msr-editor","overview","parameters-plots","platforms","preferences","results-diagnostics","runs-fitting","t0-background","troubleshooting"],"envversion":{"sphinx":65,"sphinx.domains.c":3,"sphinx.domains.changeset":1,"sphinx.domains.citation":1,"sphinx.domains.cpp":9,"sphinx.domains.index":1,"sphinx.domains.javascript":3,"sphinx.domains.math":2,"sphinx.domains.python":4,"sphinx.domains.rst":2,"sphinx.domains.std":2},"filenames":["configuration-sharing.rst","constraints.rst","getting-started.rst","glossary.rst","index.rst","keyboard-shortcuts.rst","msr-editor.rst","overview.rst","parameters-plots.rst","platforms.rst","preferences.rst","results-diagnostics.rst","runs-fitting.rst","t0-background.rst","troubleshooting.rst"],"indexentries":{},"objects":{},"objnames":{},"objtypes":{},"terms":{"":[0,3,5,6,8,10,12,13,14],"0":12,"01":12,"012":11,"1":[8,11,12,13],"100":[8,12],"101":13,"103":13,"12":[8,12],"16":12,"1998":12,"2":[8,12,13],"21":12,"24":12,"25":12,"3":[8,12,13],"300":8,"4":[12,13],"5":12,"514":[3,12],"515":[3,12],"516":12,"520":12,"525":12,"540":12,"7":12,"8":12,"A":[0,1,3,4,8,10,11,12,13,14],"For":[2,6,8,11,12,13],"If":[0,4,8,11,12,14],"In":[5,7,8,14],"It":[0,1,4,6,7,11],"Its":[5,7],"On":[2,3,4,6,7,9,11,12,14],"One":[3,12],"The":[0,1,3,4,5,6,7,9,10Line truncated
+11
View File
@@ -88,6 +88,17 @@ layout choice. Panels share the chosen X axis. The toolbar holds:
Adding files this way is the same overlay mechanism as **Overlay data
sets** in *Plot options*; the toolbar shortcut just applies the additions
to all panels instead of the active one.
Overlaid curves get a *smart legend* label that says which physical state
each scan represents instead of only a file name. The label is derived from
the data set's own scan variable and its constant coordinate: an energy scan
(``dataE`` varying) is tagged with its fixed temperature (``(T = 300 K)``), a
temperature scan with its fixed energy for LE-µSR (``(E = 12 keV)``) or with
its field for bulk µSR (``(B = 100 G)``), and a field scan with its fixed
temperature. When no fixed coordinate is present the plain file label is used.
You can also rename a legend entry directly in the plot; a Refresh then keeps
your name instead of rebuilding the default.
* **Plot options** -- expand the layout, X, parameter, style, and displayed
series controls for the active panel.
+8 -1
View File
@@ -142,7 +142,14 @@
</label>
<label class="fit-model-field fit-model-histograms" for="LRBF">
<span>Histograms</span>
<input type="text" id="LRBF" onchange="clearTabs();">
<input type="text" id="LRBF" onchange="clearTabs();"
title="Histograms that form the asymmetry signal, e.g. 21 25 (forward,backward).
Single hist fits take one histogram number.
Multiple groups of one run can be fit simultaneously with slash-separated pairs:
1,2/3,4 two groups (detectors 1+2 yield the first, 3+4 the second),
each with its own alpha/phase and a ratio scaling a shared amplitude.
Multi-group fits are not available for multi-component models or per-run
pairs of a multi-run (global) fit.">
</label>
<div class="fit-model-components" id="compRows" aria-label="Fit model components"></div>
<button class="fit-model-add" type="button" onclick="addFitComponent();" title="Add fit component" aria-label="Add fit component">+</button>
+104 -3
View File
@@ -211,6 +211,56 @@ function detectMusrfitScanVariable(dataset) {
};
}
// A compact "fixed-coordinate" legend tag for an overlaid scan, derived from
// the data set's own scan variable: an energy scan is tagged with its constant
// temperature, a temperature scan with its constant energy (LE-µSR) or field
// (bulk µSR), a field scan with its constant temperature or energy. This makes
// the legend say which physical state each curve represents instead of just a
// file name. Returns "" when no unambiguous fixed coordinate is present.
function musrfitParameterFixedCoordinateLegend(dataset) {
if (!dataset || !dataset.columns || !dataset.rows || !dataset.rows.length) return "";
let scanName = detectMusrfitScanVariable(dataset).name;
let priorities = [];
if (scanName === "dataE") {
priorities = ["dataT", "dataB"];
} else if (scanName === "dataT") {
priorities = ["dataE", "dataB"];
} else if (scanName === "dataB") {
priorities = ["dataT", "dataE"];
} else {
priorities = ["dataT", "dataB", "dataE"];
}
let shortNames = { dataT: "T", dataB: "B", dataE: "E", dataSpinRot: "SR" };
let units = { dataT: "K", dataB: "G", dataE: "keV", dataSpinRot: "\u00b0" };
for (let name of priorities) {
let column = musrfitParameterColumnIndex(dataset, name);
if (column < 0) continue;
let distinct = new Set(musrfitParameterColumnValues(dataset, column)
.filter(function(value) { return Number.isFinite(value); }));
if (distinct.size !== 1) continue;
let value = distinct.values().next().value;
let base = shortNames[name] || name;
let magnitude = Math.abs(value);
let digits = magnitude >= 100 ? 0 : (magnitude >= 10 ? 1 : (magnitude >= 1 ? 2 : 4));
let number = Number(value.toFixed(digits));
return base + " = " + number + (units[name] ? " " + units[name] : "");
}
return "";
}
// The default legend prefix for one data set in overlay mode: the data set's
// plain file label plus the fixed-coordinate tag when available (so curves are
// told apart by their physical state too), for example "514_par.dat (T = 4 K)".
function musrfitParameterOverlayPrefix(entry, dataset) {
let label = (entry && entry.label) ? entry.label : "data set";
let fixed = musrfitParameterFixedCoordinateLegend(dataset);
return fixed ? label + " (" + fixed + ")" : label;
}
function musrfitParameterLegendOverrideKey(dataSetKey, yName) {
return dataSetKey + "\u0000" + (yName || "");
}
// Built-in parameter-plot templates are declarative data: a stable identifier,
// a human name, the compatible X-variable names, the panel layout, shared-X
// behavior, and per-panel semantic parameter roles. Templates are applied by
@@ -609,6 +659,7 @@ function validateParameterPlotState(snapshot) {
if (typeof snapshot.mainSourceKey !== "string" || !snapshot.mainSourceKey) return false;
if (!Array.isArray(snapshot.panelStates) || !Array.isArray(snapshot.registeredDataSets)) return false;
if (!isPlainObjectValue(snapshot.styleRegistry)) return false;
if (snapshot.legendNameOverrides !== undefined && !isPlainObjectValue(snapshot.legendNameOverrides)) return false;
for (let style of Object.keys(snapshot.styleRegistry)) {
if (typeof style !== "string" || !isPlainObjectValue(snapshot.styleRegistry[style])) return false;
}
@@ -1036,6 +1087,7 @@ function parameterOverlayEntries(panel, registry) {
function buildMusrfitParameterOverlayTraces(dataSets, xName, yNames, mode, options) {
options = options || {};
let traces = [];
let traceMeta = [];
let skipped = [];
let paletteId = options.paletteId || "default";
// In overlay mode every trace of a data set shares the data set's color so
@@ -1056,6 +1108,7 @@ function buildMusrfitParameterOverlayTraces(dataSets, xName, yNames, mode, optio
}
let entryColorIndex = Number.isFinite(entry.colorIndex) ? entry.colorIndex : i;
let dataSetKey = entry.dataSetKey || entry.key || "";
let defaultPrefix = musrfitParameterOverlayPrefix(entry, dataset);
let nameOffset = 0;
for (let name of yNames) {
let yIndex = musrfitParameterColumnIndex(dataset, name);
@@ -1068,12 +1121,22 @@ function buildMusrfitParameterOverlayTraces(dataSets, xName, yNames, mode, optio
options.styleRegistry, options.styleKeyOf && options.styleKeyOf(dataSetKey, name) || "", dataSetKey, style);
}
let trace = buildMusrfitParameterTrace(dataset, xIndex, yIndex, mode, style);
if (overlayMode) trace.name = (entry.label ? entry.label + ": " : "") + trace.name;
if (overlayMode) {
let defaultName = defaultPrefix + ": " + trace.name;
let override = options.legendNameOf && typeof options.legendNameOf === "function"
? options.legendNameOf(dataSetKey, name) : "";
trace.name = override ? override : defaultName;
}
traces.push(trace);
traceMeta.push({
dataSetKey: dataSetKey,
name: name,
defaultName: trace.name
});
nameOffset++;
}
}
return { traces: traces, skipped: skipped };
return { traces: traces, skipped: skipped, traceMeta: traceMeta };
}
function musrfitParameterYCandidates(dataset, xIndex) {
@@ -1598,6 +1661,10 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
// parameterDataSetStyleKey / parameterTraceStyleKey; values are plain
// {color, symbol, size, opacity} objects edited from the marker picker.
let styleRegistry = {};
// User-renamed legend entries, keyed by musrfitParameterLegendOverrideKey.
// They override the smart default (file prefix or fixed-coordinate tag) so a
// Refresh does not throw away legend labels the user edited.
let legendNameOverrides = {};
let panelSequence = 0;
let windowPaletteId = "default";
let stylePicker = null;
@@ -1663,6 +1730,7 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
registeredDataSets: registeredDataSets.map(function(entry) {
return { key: entry.key, source: portableParameterSource(entry.source), label: entry.label, colorIndex: entry.colorIndex };
}),
legendNameOverrides: JSON.parse(JSON.stringify(legendNameOverrides)),
styleRegistry: typeof styleRegistry === "object" && styleRegistry ? JSON.parse(JSON.stringify(styleRegistry)) : {}
};
}
@@ -1689,6 +1757,8 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
// Style registry comes in as plain JSON; no need for a structured clone.
styleRegistry = snapshot.styleRegistry || {};
legendNameOverrides = snapshot.legendNameOverrides
&& typeof snapshot.legendNameOverrides === "object" ? snapshot.legendNameOverrides : {};
// Rebuild every panel in the saved order. StableIds are read from the
// snapshot so style registry keys stay aligned across sessions.
@@ -1995,9 +2065,13 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
styleRegistry: styleRegistry,
styleKeyOf: function(key, name) {
return parameterTraceStyleKey(key, panel.stableId, name);
},
legendNameOf: function(dataSetKey, name) {
return legendNameOverrides[musrfitParameterLegendOverrideKey(dataSetKey, name)] || "";
}
});
let traces = overlayResult.traces;
panel.traceMeta = overlayResult.traceMeta || [];
if (panel.note) {
panel.note.textContent = overlayResult.skipped.map(function(skipped) {
return skipped.label + ": " + skipped.reason;
@@ -2041,7 +2115,7 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
plotly.react(panel.chart, traces, layout, {
responsive: true,
editable: true,
edits: { titleText: false },
edits: { titleText: false, legendText: true },
displaylogo: false,
modeBarButtonsToAdd: [
@@ -2091,6 +2165,33 @@ function showMusrfitParameterPlotWindow(parameterPath, jobName = "", preferredPa
if (!yName) return;
openParameterStylePicker(panel, yName, clicked.event);
});
// Capture legend-entry renames (Plotly allows editing legend text while
// the plot is editable) so a Refresh keeps the user's labels instead of
// rebuilding the smart defaults. The rename arrives as a plotly_restyle
// whose data carries the new name; we only record names that actually
// differ from the values we just rendered.
panel.chart.on("plotly_restyle", function(restyleEvent) {
let changes = restyleEvent && restyleEvent.data;
if (!changes || !Array.isArray(changes) || !panel.traceMeta) return;
let indices = restyleEvent.traceIndices;
for (let c = 0; c < changes.length; c++) {
let names = changes[c] && changes[c].name;
if (names === undefined || names === null) continue;
let updated = Array.isArray(names) ? names : [names];
let traceIndex = indices && Array.isArray(indices) ? indices[c] : c;
if (typeof traceIndex !== "number" || traceIndex < 0) continue;
let meta = panel.traceMeta[traceIndex];
if (!meta || !meta.dataSetKey) continue;
let newName = panel.chart.data[traceIndex] && panel.chart.data[traceIndex].name;
if (typeof newName !== "string" || !newName.trim()) continue;
if (meta.defaultName === newName) continue;
let key = musrfitParameterLegendOverrideKey(meta.dataSetKey, meta.name);
if (legendNameOverrides[key] === newName) continue;
legendNameOverrides[key] = newName;
meta.defaultName = newName;
scheduleParameterPlotStateSave();
}
});
}
}
+61
View File
@@ -671,6 +671,67 @@ function testTraceStyleAndOverlayFoundation() {
assert.deepStrictEqual(Array.from(leanOverlay.traces, function(t) { return t.name; }),
["Scan A: α", "Scan A: λ (μs⁻¹)", "Lean: λ (μs⁻¹)"]);
assert.strictEqual(leanOverlay.skipped.length, 0);
// Smart legend prefixes: an energy scan is tagged with its constant
// temperature, a temperature scan with its constant energy (LE) or field
// (bulk), and a user rename override replaces the default entirely.
const energyScan = lib.parseMusrfitParameterData([
"% RUN dataE dataT Alpha dAlpha",
"514 5.0 300 0.30 0.01",
"515 7.5 300 0.29 0.01"
].join("\n"));
const temperatureScan = lib.parseMusrfitParameterData([
"% RUN dataT dataE Alpha dAlpha",
"516 10 12.0 0.24 0.01",
"517 20 12.0 0.22 0.01"
].join("\n"));
const bulkScan = lib.parseMusrfitParameterData([
"% RUN dataT dataB Alpha dAlpha",
"518 10 100 0.24 0.01",
"519 20 100 0.22 0.01"
].join("\n"));
// A scan with no fixed coordinate (cold field scan, everything varies).
const fullyVarying = lib.parseMusrfitParameterData([
"% RUN dataT dataB dataE Alpha dAlpha",
"520 10 100 5.0 0.30 0.01",
"521 20 200 7.5 0.29 0.01"
].join("\n"));
assert.strictEqual(lib.musrfitParameterOverlayPrefix(
{ label: "E scan" }, energyScan), "E scan (T = 300 K)");
assert.strictEqual(lib.musrfitParameterOverlayPrefix(
{ label: "T scan" }, temperatureScan), "T scan (E = 12 keV)");
assert.strictEqual(lib.musrfitParameterOverlayPrefix(
{ label: "Bulk" }, bulkScan), "Bulk (B = 100 G)");
assert.strictEqual(lib.musrfitParameterOverlayPrefix(
{ label: "Cold" }, fullyVarying), "Cold");
const keyD = "path:energy";
const keyE = "path:temp";
const smartOverlay = lib.buildMusrfitParameterOverlayTraces(
[{ dataSetKey: keyD, label: "E scan", dataset: energyScan },
{ dataSetKey: keyE, label: "T scan", dataset: temperatureScan }],
"dataT", ["Alpha"], "markers", { paletteId: "default" });
assert.deepStrictEqual(Array.from(smartOverlay.traces, function(t) { return t.name; }),
["E scan (T = 300 K): α", "T scan (E = 12 keV): α"]);
assert.strictEqual(smartOverlay.traceMeta.length, 2);
assert.strictEqual(smartOverlay.traceMeta[0].name, "Alpha");
assert.strictEqual(smartOverlay.traceMeta[0].defaultName, "E scan (T = 300 K): α");
// A user-renamed legend entry (persisted override) beats the smart default.
const overrides = {};
overrides[lib.musrfitParameterLegendOverrideKey(keyE, "Alpha")] = "My temp scan";
const renamed = lib.buildMusrfitParameterOverlayTraces(
[{ dataSetKey: keyD, label: "E scan", dataset: energyScan },
{ dataSetKey: keyE, label: "T scan", dataset: temperatureScan }],
"dataT", ["Alpha"], "markers", {
paletteId: "default",
legendNameOf: function(dataSetKey, name) {
return overrides[lib.musrfitParameterLegendOverrideKey(dataSetKey, name)] || "";
}
});
assert.deepStrictEqual(Array.from(renamed.traces, function(t) { return t.name; }),
["E scan (T = 300 K): α", "My temp scan"]);
}
function testParameterStyleEditingFoundation() {