Click a plotted marker to open a style editor (colour, symbol, size, opacity) scoped to the trace or the whole data set, driven by a shared per-window style registry. Panels can overlay several *.dat files from any platform: Plot options > Overlay data sets stores a window-level dataset registry, aligns files by column name, skips missing X columns with a per-panel note, and draws each file in a palette-assigned colour. A palette selector and per-panel axis-title overrides round out the Plot options panel. Electron gets a selectParameterDataFiles IPC channel for the native multi-select dialog; the web uses the browser multi-file picker. Documents the new controls and adds style/overlay/registry tests to the parameter-plot suite.
78 lines
3.4 KiB
JavaScript
78 lines
3.4 KiB
JavaScript
// Copyright (C) 2026 Zaher Salman
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
// Electron-only adapters for the shared parameter-plot renderer. Keeping
|
|
// filesystem, native file-dialog, and bundled-Plotly access here lets
|
|
// muSRFitParameterPlot.js remain platform-neutral.
|
|
//
|
|
// The hardened Electron build runs with contextIsolation:true and
|
|
// nodeIntegration:false, so this script consumes the curated window.electronAPI
|
|
// surface exposed by preload.js. require() is only a last-resort fallback for
|
|
// the vm-based test sandbox.
|
|
(function() {
|
|
var ipcRenderer = (window.electronAPI && window.electronAPI.ipc)
|
|
|| require('electron').ipcRenderer;
|
|
var nodeFs = (window.electronAPI && window.electronAPI.fs)
|
|
|| require('fs');
|
|
var plotlyURL = (window.electronAPI && window.electronAPI.process
|
|
&& window.electronAPI.process.plotlyURL) || "";
|
|
|
|
if (!window.MusrfitParameterPlotPlatform) {
|
|
window.MusrfitParameterPlotPlatform = {};
|
|
}
|
|
var platform = window.MusrfitParameterPlotPlatform;
|
|
|
|
platform.loadPlotly = function() {
|
|
if (window.Plotly) return Promise.resolve(window.Plotly);
|
|
// In the hardened build nodeIntegration is off, so require() is
|
|
// unavailable. Load Plotly from a local file:// URL via a <script> tag,
|
|
// exactly like the web build loads it from a CDN script URL.
|
|
var source = plotlyURL || window.MusrfitPlotlyURL || "";
|
|
if (!source && typeof require === 'function') {
|
|
try {
|
|
window.Plotly = require('plotly.js-dist');
|
|
return Promise.resolve(window.Plotly);
|
|
} catch (error) {
|
|
// Fall through to the script loader / error below.
|
|
}
|
|
}
|
|
if (window.MusrfitPlotlyPromise) return window.MusrfitPlotlyPromise;
|
|
window.MusrfitPlotlyPromise = new Promise(function(resolve, reject) {
|
|
var script = document.createElement('script');
|
|
script.src = source;
|
|
script.async = true;
|
|
script.onload = function() {
|
|
if (window.Plotly) resolve(window.Plotly);
|
|
else reject(new Error('Plotly loaded without exposing window.Plotly'));
|
|
};
|
|
script.onerror = function() {
|
|
reject(new Error('Could not load Plotly from ' + source));
|
|
};
|
|
document.head.appendChild(script);
|
|
});
|
|
return window.MusrfitPlotlyPromise;
|
|
};
|
|
|
|
platform.readDataSource = async function(source) {
|
|
if (source && source.kind === "inline") return String(source.text || "");
|
|
var parameterPath = source && source.path ? source.path : String(source || "");
|
|
if (!parameterPath) throw new Error("No parameter-data path is available");
|
|
return nodeFs.readFileSync(parameterPath, "utf8");
|
|
};
|
|
|
|
platform.chooseDataSource = async function(currentSource) {
|
|
var currentPath = currentSource && currentSource.kind === "path" ? currentSource.path : "";
|
|
var selectedPath = await ipcRenderer.invoke("selectParameterDataFile", currentPath);
|
|
return selectedPath ? { kind: "path", path: selectedPath } : null;
|
|
};
|
|
|
|
platform.chooseDataSources = async function(currentSource) {
|
|
var currentPath = currentSource && currentSource.kind === "path" ? currentSource.path : "";
|
|
var selectedPaths = await ipcRenderer.invoke("selectParameterDataFiles", currentPath);
|
|
if (!Array.isArray(selectedPaths)) return [];
|
|
return selectedPaths.map(function(selectedPath) {
|
|
return { kind: "path", path: selectedPath };
|
|
});
|
|
};
|
|
})();
|