Skip to content

Commit

Permalink
[jsroot] dev 30/10/2024
Browse files Browse the repository at this point in the history
1. Fix - handle reordering of fragments in multipart reply root-project/jsroot#319
2. Fix - properly show non-zero entries root-project/jsroot#320
3. Fix - display empty hist bin if fSumw2 not zero
4. Fix - let use batch_mode script injection in interactive session
  • Loading branch information
linev committed Oct 31, 2024
1 parent ace00ec commit df96343
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 29 deletions.
66 changes: 53 additions & 13 deletions js/build/jsroot.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const version_id = 'dev',

/** @summary version date
* @desc Release date in format day/month/year like '14/04/2022' */
version_date = '29/10/2024',
version_date = '30/10/2024',

/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
Expand Down Expand Up @@ -492,7 +492,11 @@ async function injectCode(code) {
// try to detect if code includes import and must be treated as module
const is_v6 = code.indexOf('JSROOT.require') >= 0,
is_mjs = !is_v6 && (code.indexOf('import {') > 0) && (code.indexOf('} from \'') > 0),
promise = is_v6 ? _ensureJSROOT() : Promise.resolve(true);
is_batch = !is_v6 && !is_mjs && (code.indexOf('JSROOT.ObjectPainter') >= 0),
promise = (is_v6 ? _ensureJSROOT() : Promise.resolve(true));

if (is_batch && !globalThis.JSROOT)
globalThis.JSROOT = internals.jsroot;

return promise.then(() => {
const element = document.createElement('script');
Expand Down Expand Up @@ -1916,6 +1920,10 @@ async function _ensureJSROOT() {
}).then(() => globalThis.JSROOT);
}

/** @summary Internal collection of functions potentially used by batch scripts
* @private */
internals.jsroot = { version, source_dir: exports.source_dir, settings, gStyle, parse: parse$2, isBatchMode };

var core = /*#__PURE__*/Object.freeze({
__proto__: null,
BIT: BIT,
Expand Down Expand Up @@ -13894,6 +13902,8 @@ const EAxisBits = {
kOppositeTitle: BIT(32) // artificial bit, not possible to set in ROOT
}, kAxisLabels = 'labels', kAxisNormal = 'normal', kAxisFunc = 'func', kAxisTime = 'time';

Object.assign(internals.jsroot, { ObjectPainter, cleanup, resize });

/**
* @license
* Copyright 2010-2023 Three.js Authors
Expand Down Expand Up @@ -60716,6 +60726,8 @@ function changeObjectMember(painter, member, val, is_color) {
obj[member] = val;
}

Object.assign(internals.jsroot, { addMoveHandler, registerForResize });

const kToFront = '__front__', sDfltName = 'root_ctx_menu', sDfltDlg = '_dialog',
sSub = 'sub:', sEndsub = 'endsub:', sSeparator = 'separator', sHeader = 'header:';

Expand Down Expand Up @@ -62337,6 +62349,8 @@ function assignContextMenu(painter, kind) {
painter.draw_g.on('contextmenu', settings.ContextMenu ? evnt => showPainterMenu(evnt, painter, kind) : null);
}

Object.assign(internals.jsroot, { createMenu, closeMenu, assignContextMenu, kToFront });

/** @summary Return time offset value for given TAxis object
* @private */
function getTimeOffset(axis) {
Expand Down Expand Up @@ -72150,6 +72164,8 @@ async function drawTFrame(dom, obj, opt) {
return ensureTCanvas(fp, false).then(() => fp.redraw());
}

Object.assign(internals.jsroot, { ensureTCanvas, TPadPainter, TCanvasPainter });

var TCanvasPainter$1 = /*#__PURE__*/Object.freeze({
__proto__: null,
TCanvasPainter: TCanvasPainter,
Expand Down Expand Up @@ -77184,7 +77200,7 @@ let TH2Painter$2 = class TH2Painter extends THistPainter {
res.wmax = 0;
res.integral = stat_sum0;

if (histo.fEntries > 1)
if (histo.fEntries > 0)
res.entries = histo.fEntries;

res.eff_entries = stat_sumw2 ? stat_sum0*stat_sum0/stat_sumw2 : Math.abs(stat_sum0);
Expand Down Expand Up @@ -81878,7 +81894,7 @@ let TH1Painter$2 = class TH1Painter extends THistPainter {
else
hsum += histo.getBinContent(0) + histo.getBinContent(this.nbinsx + 1);

this.stat_entries = (histo.fEntries > 1) ? histo.fEntries : hsum;
this.stat_entries = hsum;

this.hmin = hmin;
this.hmax = hmax;
Expand Down Expand Up @@ -81997,7 +82013,8 @@ let TH1Painter$2 = class TH1Painter extends THistPainter {
right = this.getSelectIndex('x', 'right'),
fp = this.getFramePainter(),
res = { name: histo.fName, meanx: 0, meany: 0, rmsx: 0, rmsy: 0, integral: 0,
entries: this.stat_entries, eff_entries: 0, xmax: 0, wmax: 0, skewx: 0, skewd: 0, kurtx: 0, kurtd: 0 },
entries: (histo.fEntries > 0) ? histo.fEntries : this.stat_entries,
eff_entries: 0, xmax: 0, wmax: 0, skewx: 0, skewd: 0, kurtx: 0, kurtd: 0 },
has_counted_stat = !fp.isAxisZoomed('x') && (Math.abs(histo.fTsumw) > 1e-300);
let stat_sumw = 0, stat_sumw2 = 0, stat_sumwx = 0, stat_sumwx2 = 0, stat_sumwy = 0, stat_sumwy2 = 0,
i, xx = 0, w = 0, xmax = null, wmax = null;
Expand Down Expand Up @@ -82345,6 +82362,7 @@ let TH1Painter$2 = class TH1Painter extends THistPainter {
const draw_markers = show_errors || show_markers,
draw_any_but_hist = draw_markers || show_text || show_line || show_curve,
draw_hist = this.options.Hist && (!this.lineatt.empty() || !this.fillatt.empty()),
check_sumw2 = show_errors && histo.fSumw2?.length,
// if there are too many points, exclude many vertical drawings at the same X position
// instead define min and max value and made min-max drawing
use_minmax = draw_any_but_hist || ((right - left) > 3*width);
Expand Down Expand Up @@ -82375,7 +82393,8 @@ let TH1Painter$2 = class TH1Painter extends THistPainter {
// just to get correct values for the specified bin
const extract_bin = bin => {
bincont = histo.getBinContent(bin+1);
if (exclude_zero && (bincont === 0)) return false;
if (exclude_zero && (bincont === 0) && (!check_sumw2 || !histo.fSumw2[bin+1]))
return false;
mx1 = Math.round(funcs.grx(xaxis.GetBinLowEdge(bin+1)));
mx2 = Math.round(funcs.grx(xaxis.GetBinLowEdge(bin+2)));
midx = Math.round((mx1 + mx2) / 2);
Expand Down Expand Up @@ -82854,7 +82873,7 @@ let TH1Painter$2 = class TH1Painter extends THistPainter {
findbin = null;
else if ((pnt_x < grx1 - gapx) || (pnt_x > grx2 + gapx))
findbin = null; // if bars option used check that bar is not match
else if (!this.options.Zero && (histo.getBinContent(findbin+1) === 0))
else if (!this.options.Zero && (histo.getBinContent(findbin+1) === 0) && (histo.getBinError(findbin+1) === 0))
findbin = null; // exclude empty bin if empty bins suppressed
}

Expand Down Expand Up @@ -83561,7 +83580,7 @@ class TH3Painter extends THistPainter {

res.integral = stat_sum0;

if (histo.fEntries > 1)
if (histo.fEntries > 0)
res.entries = histo.fEntries;

res.eff_entries = stat_sumw2 ? stat_sum0*stat_sum0/stat_sumw2 : Math.abs(stat_sum0);
Expand Down Expand Up @@ -100259,7 +100278,7 @@ class TFile {
// multipart messages requires special handling

const indx = hdr.indexOf('boundary=');
let boundary = '', n = first, o = 0;
let boundary = '', n = first, o = 0, normal_order = true;
if (indx > 0) {
boundary = hdr.slice(indx + 9);
if ((boundary[0] === '"') && (boundary[boundary.length - 1] === '"'))
Expand Down Expand Up @@ -100313,12 +100332,34 @@ class TFile {
blobs.push(new DataView(res, o, place[n + 1]));
o += place[n + 1];
n += 2;
} else {
} else if (normal_order) {
const n0 = n;
while ((n < last) && (place[n] >= segm_start) && (place[n] + place[n + 1] - 1 <= segm_last)) {
blobs.push(new DataView(res, o + place[n] - segm_start, place[n + 1]));
n += 2;
}

if (n > n0)
o += (segm_last - segm_start + 1);
else
normal_order = false;
}

if (!normal_order) {
// special situation when server reorder segments in the reply
let isany = false;
for (let n1 = n; n1 < last; n1 += 2) {
if ((place[n1] >= segm_start) && (place[n1] + place[n1 + 1] - 1 <= segm_last)) {
blobs[n1/2] = new DataView(res, o + place[n1] - segm_start, place[n1 + 1]);
isany = true;
}
}
if (!isany)
return rejectFunc(Error(`Provided fragment ${segm_start} - ${segm_last} out of requested multi-range request`));

while (blobs[n/2])
n += 2;

o += (segm_last - segm_start + 1);
}
}
Expand Down Expand Up @@ -142652,6 +142693,8 @@ async function init_v7(arg) {
// to avoid cross-dependency between modules
Object.assign(internals, { addStreamerInfosForPainter, addDrawFunc, setDefaultDrawOpt, makePDF });

Object.assign(internals.jsroot, { draw, redraw, makeSVG, makeImage, addDrawFunc });


/** @summary Draw TRooPlot
* @private */
Expand Down Expand Up @@ -165235,9 +165278,6 @@ class RH3Painter extends RHistPainter {

res.integral = stat_sum0;

if (histo.fEntries > 1)
res.entries = histo.fEntries;

return res;
}

Expand Down
3 changes: 3 additions & 0 deletions js/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
36. Fix - do not force style 8 for hist markers
37. Fix - ensure minimal hist title height
38. Fix - disable Bloom effects on Android TGeo displays
39. Fix - handle reordering of fragments in multipart reply #319
40. Fix - properly show non-zero entries #320
41. Fix - display empty hist bin if fSumw2 not zero


## Changes in 7.7.4
Expand Down
1 change: 1 addition & 0 deletions js/modules/base/ObjectPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,7 @@ const EAxisBits = {
kOppositeTitle: BIT(32) // artificial bit, not possible to set in ROOT
}, kAxisLabels = 'labels', kAxisNormal = 'normal', kAxisFunc = 'func', kAxisTime = 'time';

Object.assign(internals.jsroot, { ObjectPainter, cleanup, resize });

export { getElementCanvPainter, getElementMainPainter, drawingJSON,
selectActivePad, getActivePad, cleanup, resize,
Expand Down
4 changes: 2 additions & 2 deletions js/modules/base/base3d.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ async function importThreeJs(original) {

if (!isNodeJs() || (THREE.REVISION <= 162))
return THREE;
return import('../r162/three.mjs').then(h1 => {
return import('three').then(h1 => {
Object.assign(THREE, h1);
return import('../r162/three_addons.mjs');
return import('three/addons');
}).then(h2 => {
Object.assign(THREE, h2);
return THREE;
Expand Down
12 changes: 10 additions & 2 deletions js/modules/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const version_id = 'dev',

/** @summary version date
* @desc Release date in format day/month/year like '14/04/2022' */
version_date = '29/10/2024',
version_date = '30/10/2024',

/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
Expand Down Expand Up @@ -484,7 +484,11 @@ async function injectCode(code) {
// try to detect if code includes import and must be treated as module
const is_v6 = code.indexOf('JSROOT.require') >= 0,
is_mjs = !is_v6 && (code.indexOf('import {') > 0) && (code.indexOf('} from \'') > 0),
promise = is_v6 ? _ensureJSROOT() : Promise.resolve(true);
is_batch = !is_v6 && !is_mjs && (code.indexOf('JSROOT.ObjectPainter') >= 0),
promise = (is_v6 ? _ensureJSROOT() : Promise.resolve(true));

if (is_batch && !globalThis.JSROOT)
globalThis.JSROOT = internals.jsroot;

return promise.then(() => {
const element = document.createElement('script');
Expand Down Expand Up @@ -1908,6 +1912,10 @@ async function _ensureJSROOT() {
}).then(() => globalThis.JSROOT);
}

/** @summary Internal collection of functions potentially used by batch scripts
* @private */
internals.jsroot = { version, source_dir, settings, gStyle, parse, isBatchMode };

export { version_id, version_date, version, source_dir, isNodeJs, isBatchMode, setBatchMode,
browser, internals, constants, settings, gStyle, atob_func, btoa_func, prROOT,
clTObject, clTNamed, clTString, clTObjString,
Expand Down
2 changes: 2 additions & 0 deletions js/modules/draw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ async function init_v7(arg) {
// to avoid cross-dependency between modules
Object.assign(internals, { addStreamerInfosForPainter, addDrawFunc, setDefaultDrawOpt, makePDF });

Object.assign(internals.jsroot, { draw, redraw, makeSVG, makeImage, addDrawFunc });


/** @summary Draw TRooPlot
* @private */
Expand Down
4 changes: 3 additions & 1 deletion js/modules/gpad/TCanvasPainter.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BIT, settings, browser, create, parse, toJSON, loadScript, isFunc, isStr, clTCanvas } from '../core.mjs';
import { BIT, settings, internals, browser, create, parse, toJSON, loadScript, isFunc, isStr, clTCanvas } from '../core.mjs';
import { select as d3_select } from '../d3.mjs';
import { closeCurrentWindow, showProgress, loadOpenui5, ToolbarIcons, getColorExec } from '../gui/utils.mjs';
import { GridDisplay, getHPainter } from '../gui/display.mjs';
Expand Down Expand Up @@ -978,4 +978,6 @@ async function drawTFrame(dom, obj, opt) {
return ensureTCanvas(fp, false).then(() => fp.redraw());
}

Object.assign(internals.jsroot, { ensureTCanvas, TPadPainter, TCanvasPainter });

export { ensureTCanvas, drawTPadSnapshot, drawTFrame, TPadPainter, TCanvasPainter };
2 changes: 2 additions & 0 deletions js/modules/gui/menu.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1630,4 +1630,6 @@ function assignContextMenu(painter, kind) {
painter.draw_g.on('contextmenu', settings.ContextMenu ? evnt => showPainterMenu(evnt, painter, kind) : null);
}

Object.assign(internals.jsroot, { createMenu, closeMenu, assignContextMenu, kToFront });

export { createMenu, closeMenu, showPainterMenu, assignContextMenu, hasMenu, kToFront };
2 changes: 2 additions & 0 deletions js/modules/gui/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ function changeObjectMember(painter, member, val, is_color) {
obj[member] = val;
}

Object.assign(internals.jsroot, { addMoveHandler, registerForResize });

export { showProgress, closeCurrentWindow, loadOpenui5, ToolbarIcons, registerForResize,
detectRightButton, addMoveHandler, injectStyle,
selectgStyle, setStoragePrefix, saveSettings, readSettings, saveStyle, readStyle,
Expand Down
3 changes: 0 additions & 3 deletions js/modules/hist/RH3Painter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ class RH3Painter extends RHistPainter {

res.integral = stat_sum0;

if (histo.fEntries > 1)
res.entries = histo.fEntries;

return res;
}

Expand Down
2 changes: 1 addition & 1 deletion js/modules/hist/TH3Painter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class TH3Painter extends THistPainter {

res.integral = stat_sum0;

if (histo.fEntries > 1)
if (histo.fEntries > 0)
res.entries = histo.fEntries;

res.eff_entries = stat_sumw2 ? stat_sum0*stat_sum0/stat_sumw2 : Math.abs(stat_sum0);
Expand Down
11 changes: 7 additions & 4 deletions js/modules/hist2d/TH1Painter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TH1Painter extends THistPainter {
else
hsum += histo.getBinContent(0) + histo.getBinContent(this.nbinsx + 1);

this.stat_entries = (histo.fEntries > 1) ? histo.fEntries : hsum;
this.stat_entries = hsum;

this.hmin = hmin;
this.hmax = hmax;
Expand Down Expand Up @@ -235,7 +235,8 @@ class TH1Painter extends THistPainter {
right = this.getSelectIndex('x', 'right'),
fp = this.getFramePainter(),
res = { name: histo.fName, meanx: 0, meany: 0, rmsx: 0, rmsy: 0, integral: 0,
entries: this.stat_entries, eff_entries: 0, xmax: 0, wmax: 0, skewx: 0, skewd: 0, kurtx: 0, kurtd: 0 },
entries: (histo.fEntries > 0) ? histo.fEntries : this.stat_entries,
eff_entries: 0, xmax: 0, wmax: 0, skewx: 0, skewd: 0, kurtx: 0, kurtd: 0 },
has_counted_stat = !fp.isAxisZoomed('x') && (Math.abs(histo.fTsumw) > 1e-300);
let stat_sumw = 0, stat_sumw2 = 0, stat_sumwx = 0, stat_sumwx2 = 0, stat_sumwy = 0, stat_sumwy2 = 0,
i, xx = 0, w = 0, xmax = null, wmax = null;
Expand Down Expand Up @@ -583,6 +584,7 @@ class TH1Painter extends THistPainter {
const draw_markers = show_errors || show_markers,
draw_any_but_hist = draw_markers || show_text || show_line || show_curve,
draw_hist = this.options.Hist && (!this.lineatt.empty() || !this.fillatt.empty()),
check_sumw2 = show_errors && histo.fSumw2?.length,
// if there are too many points, exclude many vertical drawings at the same X position
// instead define min and max value and made min-max drawing
use_minmax = draw_any_but_hist || ((right - left) > 3*width);
Expand Down Expand Up @@ -613,7 +615,8 @@ class TH1Painter extends THistPainter {
// just to get correct values for the specified bin
const extract_bin = bin => {
bincont = histo.getBinContent(bin+1);
if (exclude_zero && (bincont === 0)) return false;
if (exclude_zero && (bincont === 0) && (!check_sumw2 || !histo.fSumw2[bin+1]))
return false;
mx1 = Math.round(funcs.grx(xaxis.GetBinLowEdge(bin+1)));
mx2 = Math.round(funcs.grx(xaxis.GetBinLowEdge(bin+2)));
midx = Math.round((mx1 + mx2) / 2);
Expand Down Expand Up @@ -1092,7 +1095,7 @@ class TH1Painter extends THistPainter {
findbin = null;
else if ((pnt_x < grx1 - gapx) || (pnt_x > grx2 + gapx))
findbin = null; // if bars option used check that bar is not match
else if (!this.options.Zero && (histo.getBinContent(findbin+1) === 0))
else if (!this.options.Zero && (histo.getBinContent(findbin+1) === 0) && (histo.getBinError(findbin+1) === 0))
findbin = null; // exclude empty bin if empty bins suppressed
}

Expand Down
2 changes: 1 addition & 1 deletion js/modules/hist2d/TH2Painter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ class TH2Painter extends THistPainter {
res.wmax = 0;
res.integral = stat_sum0;

if (histo.fEntries > 1)
if (histo.fEntries > 0)
res.entries = histo.fEntries;

res.eff_entries = stat_sumw2 ? stat_sum0*stat_sum0/stat_sumw2 : Math.abs(stat_sum0);
Expand Down
Loading

0 comments on commit df96343

Please sign in to comment.