Skip to content

Commit cafb70b

Browse files
committed
Let configure default options via settings
It can be changed via context menu and preserved in browser local storage
1 parent e16f6fd commit cafb70b

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

modules/core.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ settings = {
306306
/** @summary Extra parameters which will be append to the url when item shown in new tab */
307307
NewTabUrlPars: '',
308308
/** @summary Export different settings in output URL */
309-
NewTabUrlExportSettings: false
309+
NewTabUrlExportSettings: false,
310+
/** @summary Custom default draw options for classes like 'TH2:colz;TGraph:al' */
311+
DefaultDrawOptions: ''
310312
},
311313

312314
/** @namespace

modules/draw.mjs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,20 @@ function getDrawSettings(kind, selector) {
315315
setDefaultDrawOpt('TH1', 'text');
316316
setDefaultDrawOpt('TH2', 'col'); */
317317
function setDefaultDrawOpt(classname, opt) {
318-
const handle = getDrawHandle(prROOT + classname, 0);
319-
if (handle)
320-
handle.dflt = opt;
318+
if (!classname)
319+
return;
320+
if ((opt === undefined) && isStr(classname) && (classname.indexOf(':') > 0)) {
321+
// special usage to set list of options like TH2:lego2;TH1:hist
322+
opt.split(';').forEach(part => {
323+
const arr = part.split(':');
324+
if (arr.length >= 1)
325+
setDefaultDrawOpt(arr[0], arr[1] || '');
326+
});
327+
} else {
328+
const handle = getDrawHandle(prROOT + classname, 0);
329+
if (handle)
330+
handle.dflt = opt;
331+
}
321332
}
322333

323334
/** @summary Draw object in specified HTML element with given draw options.

modules/gui/menu.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getColor } from '../base/colors.mjs';
55
import { TAttMarkerHandler } from '../base/TAttMarkerHandler.mjs';
66
import { getSvgLineStyle } from '../base/TAttLineHandler.mjs';
77
import { FontHandler } from '../base/FontHandler.mjs';
8+
import { setDefaultDrawOpt } from '../draw.mjs';
89

910

1011
const kToFront = '__front__', sDfltName = 'root_ctx_menu', sDfltDlg = '_dialog',
@@ -824,6 +825,7 @@ class JSRootMenu {
824825
this.addSelectMenu('Latex', ['Off', 'Symbols', 'Normal', 'MathJax', 'Force MathJax'], settings.Latex, value => { settings.Latex = value; });
825826
this.addSelectMenu('3D rendering', ['Default', 'WebGL', 'Image'], settings.Render3D, value => { settings.Render3D = value; });
826827
this.addSelectMenu('WebGL embeding', ['Default', 'Overlay', 'Embed'], settings.Embed3D, value => { settings.Embed3D = value; });
828+
this.add('Default options', () => this.input('List of options like TH2:lego2;TGraph:l', settings.DefaultDrawOptions).then(v => { settings.DefaultDrawOptions = v; setDefaultDrawOpt(v); }), 'Configure custom default draw options for some classes');
827829
this.endsub();
828830

829831
this.sub('Geometry');

modules/gui/utils.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { select as d3_select, pointer as d3_pointer, drag as d3_drag, color as d
33
import { prSVG, BasePainter } from '../base/BasePainter.mjs';
44
import { resize } from '../base/ObjectPainter.mjs';
55
import { getRootColors } from '../base/colors.mjs';
6+
import { setDefaultDrawOpt } from '../draw.mjs';
7+
68

79
/** @summary Display progress message in the left bottom corner.
810
* @desc Previous message will be overwritten
@@ -470,8 +472,10 @@ function saveSettings(expires = 365, name = 'settings') {
470472
function readSettings(only_check = false, name = 'settings') {
471473
const s = readLocalStorage(name);
472474
if (!s) return false;
473-
if (!only_check)
475+
if (!only_check) {
474476
Object.assign(settings, s);
477+
setDefaultDrawOpt(s.DefaultDrawOptions);
478+
}
475479
return true;
476480
}
477481

0 commit comments

Comments
 (0)