jsrootdi
Version:
JavaScript ROOT
1,164 lines (1,082 loc) • 833 kB
JavaScript
// https://root.cern/js/ v7.6.101
/** @summary version id
* @desc For the JSROOT release the string in format 'major.minor.patch' like '7.0.0' */
const version_id = 'dev',
/** @summary version date
* @desc Release date in format day/month/year like '14/04/2022' */
version_date = '8/05/2024',
/** @summary version id and date
* @desc Produced by concatenation of {@link version_id} and {@link version_date}
* Like '7.0.0 14/04/2022' */
version = version_id + ' ' + version_date,
/** @summary Is node.js flag
* @private */
nodejs = !!((typeof process === 'object') && isObject(process.versions) && process.versions.node && process.versions.v8),
/** @summary internal data
* @private */
internals = {
/** @summary unique id counter, starts from 1 */
id_counter: 1
},
_src = (typeof document === 'undefined' && typeof location === 'undefined' ? undefined : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('jsroot.js', document.baseURI).href));
/** @summary Location of JSROOT modules
* @desc Automatically detected and used to dynamically load other modules
* @private */
let source_dir = '';
if (_src && isStr(_src)) {
const pos = _src.indexOf('modules/core.mjs');
if (pos >= 0) {
source_dir = _src.slice(0, pos);
if (!nodejs)
console.log(`Set jsroot source_dir to ${source_dir}, ${version}`);
} else {
if (!nodejs)
console.log(`jsroot bundle, ${version}`);
internals.ignore_v6 = true;
}
}
/** @summary Indicates if running inside Node.js */
function isNodeJs() { return nodejs; }
/** @summary atob function in all environments
* @private */
const atob_func = isNodeJs() ? str => Buffer.from(str, 'base64').toString('latin1') : globalThis?.atob,
/** @summary btoa function in all environments
* @private */
btoa_func = isNodeJs() ? str => Buffer.from(str, 'latin1').toString('base64') : globalThis?.btoa,
/** @summary browser detection flags
* @private */
browser = { isFirefox: true, isSafari: false, isChrome: false, isWin: false, touches: false, screenWidth: 1200 };
if ((typeof document !== 'undefined') && (typeof window !== 'undefined') && (typeof navigator !== 'undefined')) {
navigator.userAgentData?.brands?.forEach(item => {
if (item.brand === 'HeadlessChrome') {
browser.isChromeHeadless = true;
browser.chromeVersion = parseInt(item.version);
} else if (item.brand === 'Chromium') {
browser.isChrome = true;
browser.chromeVersion = parseInt(item.version);
}
});
if (browser.chromeVersion) {
browser.isFirefox = false;
browser.isWin = navigator.userAgentData.platform === 'Windows';
} else {
browser.isFirefox = navigator.userAgent.indexOf('Firefox') >= 0;
browser.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
browser.isChrome = !!window.chrome;
browser.isChromeHeadless = navigator.userAgent.indexOf('HeadlessChrome') >= 0;
browser.chromeVersion = (browser.isChrome || browser.isChromeHeadless) ? parseInt(navigator.userAgent.match(/Chrom(?:e|ium)\/([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/)[1]) : 0;
browser.isWin = navigator.userAgent.indexOf('Windows') >= 0;
}
browser.touches = ('ontouchend' in document); // identify if touch events are supported
browser.screenWidth = window.screen?.width ?? 1200;
}
/** @summary Check if prototype string match to array (typed on untyped)
* @return {Number} 0 - not array, 1 - regular array, 2 - typed array
* @private */
function isArrayProto(proto) {
if ((proto.length < 14) || (proto.indexOf('[object ') !== 0)) return 0;
const p = proto.indexOf('Array]');
if ((p < 0) || (p !== proto.length - 6)) return 0;
// plain array has only '[object Array]', typed array type name inside
return proto.length === 14 ? 1 : 2;
}
/** @desc Specialized JSROOT constants, used in {@link settings}
* @namespace */
const constants = {
/** @summary Kind of 3D rendering, used for {@link settings.Render3D}
* @namespace */
Render3D: {
/** @summary Default 3D rendering, normally WebGL, if not supported - SVG */
Default: 0,
/** @summary Use normal WebGL rendering and place as interactive Canvas element on HTML page */
WebGL: 1,
/** @summary Use WebGL rendering, but convert into svg image, not interactive */
WebGLImage: 2,
/** @summary Use SVG rendering, slow, inprecise and not interactive, nor recommendet */
SVG: 3,
fromString(s) {
if ((s === 'webgl') || (s === 'gl')) return this.WebGL;
if (s === 'img') return this.WebGLImage;
if (s === 'svg') return this.SVG;
return this.Default;
}
},
/** @summary Way to embed 3D into SVG, used for {@link settings.Embed3D}
* @namespace */
Embed3D: {
/** @summary Do not embed 3D drawing, use complete space */
NoEmbed: -1,
/** @summary Default embeding mode - on Firefox and latest Chrome is real ```Embed```, on all other ```Overlay``` */
Default: 0,
/** @summary WebGL canvas not inserted into SVG, but just overlayed The only way how earlier Chrome browser can be used */
Overlay: 1,
/** @summary Really embed WebGL Canvas into SVG */
Embed: 2,
/** @summary Embeding, but when SVG rendering or SVG image converion is used */
EmbedSVG: 3,
/** @summary Convert string values into number */
fromString(s) {
if (s === 'embed') return this.Embed;
if (s === 'overlay') return this.Overlay;
return this.Default;
}
},
/** @summary How to use latex in text drawing, used for {@link settings.Latex}
* @namespace */
Latex: {
/** @summary do not use Latex at all for text drawing */
Off: 0,
/** @summary convert only known latex symbols */
Symbols: 1,
/** @summary normal latex processing with svg */
Normal: 2,
/** @summary use MathJax for complex cases, otherwise simple SVG text */
MathJax: 3,
/** @summary always use MathJax for text rendering */
AlwaysMathJax: 4,
/** @summary Convert string values into number */
fromString(s) {
if (!s || !isStr(s))
return this.Normal;
switch (s) {
case 'off': return this.Off;
case 'symbols': return this.Symbols;
case 'normal':
case 'latex':
case 'exp':
case 'experimental': return this.Normal;
case 'MathJax':
case 'mathjax':
case 'math': return this.MathJax;
case 'AlwaysMathJax':
case 'alwaysmath':
case 'alwaysmathjax': return this.AlwaysMathJax;
}
const code = parseInt(s);
return (Number.isInteger(code) && (code >= this.Off) && (code <= this.AlwaysMathJax)) ? code : this.Normal;
}
}
},
/** @desc Global JSROOT settings
* @namespace */
settings = {
/** @summary Render of 3D drawing methods, see {@link constants.Render3D} for possible values */
Render3D: constants.Render3D.Default,
/** @summary 3D drawing methods in batch mode, see {@link constants.Render3D} for possible values */
Render3DBatch: constants.Render3D.Default,
/** @summary Way to embed 3D drawing in SVG, see {@link constants.Embed3D} for possible values */
Embed3D: constants.Embed3D.Default,
/** @summary Enable or disable tooltips, default on */
Tooltip: !nodejs,
/** @summary Time in msec for appearance of tooltips, 0 - no animation */
TooltipAnimation: 500,
/** @summary Enables context menu usage */
ContextMenu: !nodejs,
/** @summary Global zooming flag, enable/disable any kind of interactive zooming */
Zooming: !nodejs,
/** @summary Zooming with the mouse events */
ZoomMouse: !nodejs,
/** @summary Zooming with mouse wheel */
ZoomWheel: !nodejs,
/** @summary Zooming on touch devices */
ZoomTouch: !nodejs,
/** @summary Enables move and resize of elements like statbox, title, pave, colz */
MoveResize: !browser.touches && !nodejs,
/** @summary Configures keybord key press handling
* @desc Can be disabled to prevent keys heandling in complex HTML layouts
* @default true */
HandleKeys: !nodejs,
/** @summary enables drag and drop functionality */
DragAndDrop: !nodejs,
/** @summary Interactive dragging of TGraph points */
DragGraphs: true,
/** @summary Show progress box, can be false, true or 'modal' */
ProgressBox: !nodejs,
/** @summary Show additional tool buttons on the canvas, false - disabled, true - enabled, 'popup' - only toggle button */
ToolBar: nodejs ? false : 'popup',
/** @summary Position of toolbar 'left' left-bottom corner on canvas, 'right' - right-bottom corner on canvas, opposite on sub-pads */
ToolBarSide: 'left',
/** @summary display tool bar vertical (default false) */
ToolBarVert: false,
/** @summary if drawing inside particular div can be enlarged on full window */
CanEnlarge: true,
/** @summary if frame position can be adjusted to let show axis or colz labels */
CanAdjustFrame: false,
/** @summary calculation of text size consumes time and can be skipped to improve performance (but with side effects on text adjustments) */
ApproxTextSize: false,
/** @summary Histogram drawing optimization: 0 - disabled, 1 - only for large (>5000 1d bins, >50 2d bins) histograms, 2 - always */
OptimizeDraw: 1,
/** @summary Automatically create stats box, default on */
AutoStat: true,
/** @summary Default frame position in NFC
* @deprecated Use gStyle.fPad[Left/Right/Top/Bottom]Margin values instead */
FrameNDC: {},
/** @summary size of pad, where many features will be deactivated like text draw or zooming */
SmallPad: { width: 150, height: 100 },
/** @summary Default color palette id */
Palette: 57,
/** @summary Configures Latex usage, see {@link constants.Latex} for possible values */
Latex: constants.Latex.Normal,
/** @summary Grads per segment in TGeo spherical shapes like tube */
GeoGradPerSegm: 6,
/** @summary Enables faces compression after creation of composite shape */
GeoCompressComp: true,
/** @summary if true, ignore all kind of URL options in the browser URL */
IgnoreUrlOptions: false,
/** @summary how many items shown on one level of hierarchy */
HierarchyLimit: 250,
/** @summary default display kind for the hierarchy painter */
DislpayKind: 'simple',
/** @summary default left area width in browser layout */
BrowserWidth: 250,
/** @summary custom format for all X values, when not specified {@link gStyle.fStatFormat} is used */
XValuesFormat: undefined,
/** @summary custom format for all Y values, when not specified {@link gStyle.fStatFormat} is used */
YValuesFormat: undefined,
/** @summary custom format for all Z values, when not specified {@link gStyle.fStatFormat} is used */
ZValuesFormat: undefined,
/** @summary Let detect and solve problem when browser returns wrong content-length parameter
* @desc See [jsroot#189]{@link https://github.com/root-project/jsroot/issues/189} for more info
* Can be enabled by adding 'wrong_http_response' parameter to URL when using JSROOT UI
* @default false */
HandleWrongHttpResponse: false,
/** @summary Tweak browser caching with stamp URL parameter
* @desc When specified, extra URL parameter like ```?stamp=unique_value``` append to each files loaded
* In such case browser will be forced to load file content disregards of server cache settings
* Can be disabled by providing &usestamp=false in URL or via Settings/Files sub-menu
* @default true */
UseStamp: true,
/** @summary Maximal number of bytes ranges in http 'Range' header
* @desc Some http server has limitations for number of bytes rannges therefore let change maximal number via setting
* @default 200 */
MaxRanges: 200,
/** @summary Configure xhr.withCredentials = true when submitting http requests from JSROOT */
WithCredentials: false,
/** @summary Skip streamer infos from the GUI */
SkipStreamerInfos: false,
/** @summary Show only last cycle for objects in TFile */
OnlyLastCycle: false,
/** @summary Configures dark mode for the GUI */
DarkMode: false,
/** @summary Prefer to use saved points in TF1/TF2, avoids eval() and Function() when possible */
PreferSavedPoints: false,
/** @summary Angle in degree for axis labels tilt when available space is not enough */
AxisTiltAngle: 25,
/** @summary Strip axis labels trailing 0 or replace 10^0 by 1 */
StripAxisLabels: true,
/** @summary Draw TF1 by default as curve or line */
FuncAsCurve: false,
/** @summary Time zone used for date/time display of file time */
TimeZone: '',
/** @summary Page URL which will be used to show item in new tab, jsroot main dir used by default */
NewTabUrl: '',
/** @summary Extra parameters which will be append to the url when item shown in new tab */
NewTabUrlPars: '',
/** @summary Export different settings in output URL */
NewTabUrlExportSettings: false
},
/** @namespace
* @summary Insiance of TStyle object like in ROOT
* @desc Includes default draw styles, can be changed after loading of JSRoot.core.js
* or can be load from the file providing style=itemname in the URL
* See [TStyle docu]{@link https://root.cern/doc/master/classTStyle.html} 'Private attributes' section for more detailed info about each value */
gStyle = {
fName: 'Modern',
/** @summary Default log x scale */
fOptLogx: 0,
/** @summary Default log y scale */
fOptLogy: 0,
/** @summary Default log z scale */
fOptLogz: 0,
fOptDate: 0,
fOptFile: 0,
fDateX: 0.01,
fDateY: 0.01,
/** @summary Draw histogram title */
fOptTitle: 1,
/** @summary Canvas fill color */
fCanvasColor: 0,
/** @summary Pad fill color */
fPadColor: 0,
fPadBottomMargin: 0.1,
fPadTopMargin: 0.1,
fPadLeftMargin: 0.1,
fPadRightMargin: 0.1,
/** @summary TPad.fGridx default value */
fPadGridX: false,
/** @summary TPad.fGridy default value */
fPadGridY: false,
fPadTickX: 0,
fPadTickY: 0,
fPadBorderSize: 2,
fPadBorderMode: 0,
fCanvasBorderSize: 2,
fCanvasBorderMode: 0,
/** @summary fill color for stat box */
fStatColor: 0,
/** @summary fill style for stat box */
fStatStyle: 1000,
/** @summary text color in stat box */
fStatTextColor: 1,
/** @summary text size in stat box */
fStatFontSize: 0,
/** @summary stat text font */
fStatFont: 42,
/** @summary Stat border size */
fStatBorderSize: 1,
/** @summary Printing format for stats */
fStatFormat: '6.4g',
fStatX: 0.98,
fStatY: 0.935,
fStatW: 0.2,
fStatH: 0.16,
fTitleAlign: 23,
fTitleColor: 0,
fTitleTextColor: 1,
fTitleBorderSize: 0,
fTitleFont: 42,
fTitleFontSize: 0.05,
fTitleStyle: 0,
/** @summary X position of top left corner of title box */
fTitleX: 0.5,
/** @summary Y position of top left corner of title box */
fTitleY: 0.995,
/** @summary Width of title box */
fTitleW: 0,
/** @summary Height of title box */
fTitleH: 0,
/** @summary Printing format for fit parameters */
fFitFormat: '5.4g',
fOptStat: 1111,
fOptFit: 0,
fNumberContours: 20,
fGridColor: 0,
fGridStyle: 3,
fGridWidth: 1,
fFrameFillColor: 0,
fFrameFillStyle: 1001,
fFrameLineColor: 1,
fFrameLineWidth: 1,
fFrameLineStyle: 1,
fFrameBorderSize: 1,
fFrameBorderMode: 0,
/** @summary size in pixels of end error for E1 draw options */
fEndErrorSize: 2,
/** @summary X size of the error marks for the histogram drawings */
fErrorX: 0.5,
/** @summary when true, BAR and LEGO drawing using base = 0 */
fHistMinimumZero: false,
/** @summary Margin between histogram's top and pad's top */
fHistTopMargin: 0.05,
fHistFillColor: 0,
fHistFillStyle: 1001,
fHistLineColor: 602,
fHistLineStyle: 1,
fHistLineWidth: 1,
/** @summary format for bin content */
fPaintTextFormat: 'g',
/** @summary default time offset, UTC time at 01/01/95 */
fTimeOffset: 788918400,
fLegendBorderSize: 1,
fLegendFont: 42,
fLegendTextSize: 0,
fLegendFillColor: 0,
fHatchesLineWidth: 1,
fHatchesSpacing: 1,
fCandleWhiskerRange: 1.0,
fCandleBoxRange: 0.5,
fCandleScaled: false,
fViolinScaled: true,
fOrthoCamera: false,
fXAxisExpXOffset: 0,
fXAxisExpYOffset: 0,
fYAxisExpXOffset: 0,
fYAxisExpYOffset: 0,
fAxisMaxDigits: 5,
fStripDecimals: true,
fBarWidth: 1
};
/** @summary Method returns current document in use
* @private */
function getDocument() {
if (nodejs)
return internals.nodejs_document;
if (typeof document !== 'undefined')
return document;
if (typeof window === 'object')
return window.document;
return undefined;
}
/** @summary Generate mask for given bit
* @param {number} n bit number
* @return {Number} produced mask
* @private */
function BIT(n) { return 1 << n; }
// used very often - keep shortcut
const extend$1 = Object.assign;
/** @summary Adds specific methods to the object.
* @desc JSROOT implements some basic methods for different ROOT classes.
* @param {object} obj - object where methods are assigned
* @param {string} [typename] - optional typename, if not specified, obj._typename will be used
* @private */
function addMethods(obj, typename) {
extend$1(obj, getMethods(typename || obj._typename, obj));
}
/** @summary Should be used to parse JSON string produced with TBufferJSON class
* @desc Replace all references inside object like { "$ref": "1" }
* @param {object|string} json object where references will be replaced
* @return {object} parsed object */
function parse(json) {
if (!json) return null;
const obj = isStr(json) ? JSON.parse(json) : json, map = [];
let newfmt;
const unref_value = value => {
if ((value === null) || (value === undefined)) return;
if (isStr(value)) {
if (newfmt || (value.length < 6) || (value.indexOf('$ref:') !== 0)) return;
const ref = parseInt(value.slice(5));
if (!Number.isInteger(ref) || (ref < 0) || (ref >= map.length)) return;
newfmt = false;
return map[ref];
}
if (typeof value !== 'object') return;
const proto = Object.prototype.toString.apply(value);
// scan array - it can contain other objects
if (isArrayProto(proto) > 0) {
for (let i = 0; i < value.length; ++i) {
const res = unref_value(value[i]);
if (res !== undefined) value[i] = res;
}
return;
}
const ks = Object.keys(value), len = ks.length;
if ((newfmt !== false) && (len === 1) && (ks[0] === '$ref')) {
const ref = parseInt(value.$ref);
if (!Number.isInteger(ref) || (ref < 0) || (ref >= map.length)) return;
newfmt = true;
return map[ref];
}
if ((newfmt !== false) && (len > 1) && (ks[0] === '$arr') && (ks[1] === 'len')) {
// this is ROOT-coded array
let arr;
switch (value.$arr) {
case 'Int8': arr = new Int8Array(value.len); break;
case 'Uint8': arr = new Uint8Array(value.len); break;
case 'Int16': arr = new Int16Array(value.len); break;
case 'Uint16': arr = new Uint16Array(value.len); break;
case 'Int32': arr = new Int32Array(value.len); break;
case 'Uint32': arr = new Uint32Array(value.len); break;
case 'Float32': arr = new Float32Array(value.len); break;
case 'Int64':
case 'Uint64':
case 'Float64': arr = new Float64Array(value.len); break;
default: arr = new Array(value.len);
}
arr.fill((value.$arr === 'Bool') ? false : 0);
if (value.b !== undefined) {
// base64 coding
const buf = atob_func(value.b);
if (arr.buffer) {
const dv = new DataView(arr.buffer, value.o || 0),
len = Math.min(buf.length, dv.byteLength);
for (let k = 0; k < len; ++k)
dv.setUint8(k, buf.charCodeAt(k));
} else
throw new Error('base64 coding supported only for native arrays with binary data');
} else {
// compressed coding
let nkey = 2, p = 0;
while (nkey < len) {
if (ks[nkey][0] === 'p') p = value[ks[nkey++]]; // position
if (ks[nkey][0] !== 'v') throw new Error(`Unexpected member ${ks[nkey]} in array decoding`);
const v = value[ks[nkey++]]; // value
if (typeof v === 'object') {
for (let k = 0; k < v.length; ++k)
arr[p++] = v[k];
} else {
arr[p++] = v;
if ((nkey < len) && (ks[nkey][0] === 'n')) {
let cnt = value[ks[nkey++]]; // counter
while (--cnt) arr[p++] = v;
}
}
}
}
return arr;
}
if ((newfmt !== false) && (len === 3) && (ks[0] === '$pair') && (ks[1] === 'first') && (ks[2] === 'second')) {
newfmt = true;
const f1 = unref_value(value.first),
s1 = unref_value(value.second);
if (f1 !== undefined) value.first = f1;
if (s1 !== undefined) value.second = s1;
value._typename = value.$pair;
delete value.$pair;
return; // pair object is not counted in the objects map
}
// prevent endless loop
if (map.indexOf(value) >= 0) return;
// add object to object map
map.push(value);
// add methods to all objects, where _typename is specified
if (value._typename) addMethods(value);
for (let k = 0; k < len; ++k) {
const i = ks[k], res = unref_value(value[i]);
if (res !== undefined) value[i] = res;
}
};
unref_value(obj);
return obj;
}
/** @summary Parse response from multi.json request
* @desc Method should be used to parse JSON code, produced by multi.json request of THttpServer
* @param {string} json string to parse
* @return {Array} array of parsed elements */
function parseMulti(json) {
if (!json) return null;
const arr = JSON.parse(json);
if (arr?.length) {
for (let i = 0; i < arr.length; ++i)
arr[i] = parse(arr[i]);
}
return arr;
}
/** @summary Method to create http request, without promise can be used only in browser environment
* @private */
function createHttpRequest(url, kind, user_accept_callback, user_reject_callback, use_promise) {
function configureXhr(xhr) {
xhr.http_callback = isFunc(user_accept_callback) ? user_accept_callback.bind(xhr) : () => {};
xhr.error_callback = isFunc(user_reject_callback) ? user_reject_callback.bind(xhr) : function(err) { console.warn(err.message); this.http_callback(null); }.bind(xhr);
if (!kind) kind = 'buf';
let method = 'GET', is_async = true;
const p = kind.indexOf(';sync');
if (p > 0) { kind = kind.slice(0, p); is_async = false; }
switch (kind) {
case 'head': method = 'HEAD'; break;
case 'posttext': method = 'POST'; kind = 'text'; break;
case 'postbuf': method = 'POST'; kind = 'buf'; break;
case 'post':
case 'multi': method = 'POST'; break;
}
xhr.kind = kind;
if (settings.WithCredentials)
xhr.withCredentials = true;
if (settings.HandleWrongHttpResponse && (method === 'GET') && isFunc(xhr.addEventListener)) {
xhr.addEventListener('progress', function(oEvent) {
if (oEvent.lengthComputable && this.expected_size && (oEvent.loaded > this.expected_size)) {
this.did_abort = true;
this.abort();
this.error_callback(Error(`Server sends more bytes ${oEvent.loaded} than expected ${this.expected_size}. Abort I/O operation`), 598);
}
}.bind(xhr));
}
xhr.onreadystatechange = function() {
if (this.did_abort) return;
if ((this.readyState === 2) && this.expected_size) {
const len = parseInt(this.getResponseHeader('Content-Length'));
if (Number.isInteger(len) && (len > this.expected_size) && !settings.HandleWrongHttpResponse) {
this.did_abort = true;
this.abort();
return this.error_callback(Error(`Server response size ${len} larger than expected ${this.expected_size}. Abort I/O operation`), 599);
}
}
if (this.readyState !== 4) return;
if ((this.status !== 200) && (this.status !== 206) && !browser.qt5 &&
// in these special cases browsers not always set status
!((this.status === 0) && ((url.indexOf('file://') === 0) || (url.indexOf('blob:') === 0))))
return this.error_callback(Error(`Fail to load url ${url}`), this.status);
if (this.nodejs_checkzip && (this.getResponseHeader('content-encoding') === 'gzip')) {
// special handling of gzipped JSON objects in Node.js
return Promise.resolve().then(function () { return _rollup_plugin_ignore_empty_module_placeholder$1; }).then(handle => {
const res = handle.unzipSync(Buffer.from(this.response)),
obj = JSON.parse(res); // zlib returns Buffer, use JSON to parse it
return this.http_callback(parse(obj));
});
}
switch (this.kind) {
case 'xml': return this.http_callback(this.responseXML);
case 'text': return this.http_callback(this.responseText);
case 'object': return this.http_callback(parse(this.responseText));
case 'multi': return this.http_callback(parseMulti(this.responseText));
case 'head': return this.http_callback(this);
}
// if no response type is supported, return as text (most probably, will fail)
if (this.responseType === undefined)
return this.http_callback(this.responseText);
if ((this.kind === 'bin') && ('byteLength' in this.response)) {
// if string representation in requested - provide it
const u8Arr = new Uint8Array(this.response);
let filecontent = '';
for (let i = 0; i < u8Arr.length; ++i)
filecontent += String.fromCharCode(u8Arr[i]);
return this.http_callback(filecontent);
}
this.http_callback(this.response);
};
xhr.open(method, url, is_async);
if ((kind === 'bin') || (kind === 'buf'))
xhr.responseType = 'arraybuffer';
if (nodejs && (method === 'GET') && (kind === 'object') && (url.indexOf('.json.gz') > 0)) {
xhr.nodejs_checkzip = true;
xhr.responseType = 'arraybuffer';
}
return xhr;
}
if (isNodeJs()) {
if (!use_promise)
throw Error('Not allowed to create http requests in node.js without promise');
// eslint-disable-next-line new-cap
return Promise.resolve().then(function () { return _rollup_plugin_ignore_empty_module_placeholder$1; }).then(h => configureXhr(new h.default()));
}
const xhr = configureXhr(new XMLHttpRequest());
return use_promise ? Promise.resolve(xhr) : xhr;
}
const clTObject = 'TObject', clTNamed = 'TNamed', clTString = 'TString', clTObjString = 'TObjString',
clTKey = 'TKey', clTFile = 'TFile',
clTList = 'TList', clTHashList = 'THashList', clTMap = 'TMap', clTObjArray = 'TObjArray', clTClonesArray = 'TClonesArray',
clTAttLine = 'TAttLine', clTAttFill = 'TAttFill', clTAttMarker = 'TAttMarker', clTAttText = 'TAttText',
clTHStack = 'THStack', clTGraph = 'TGraph', clTMultiGraph = 'TMultiGraph', clTCutG = 'TCutG',
clTGraphPolargram = 'TGraphPolargram', clTGraphTime = 'TGraphTime',
clTPave = 'TPave', clTPaveText = 'TPaveText', clTPaveStats = 'TPaveStats', clTLegend = 'TLegend', clTLegendEntry = 'TLegendEntry',
clTPaletteAxis = 'TPaletteAxis', clTImagePalette = 'TImagePalette',
clTText = 'TText', clTLatex = 'TLatex', clTLine = 'TLine', clTBox = 'TBox', clTPolyLine = 'TPolyLine',
clTPolyLine3D = 'TPolyLine3D', clTPolyMarker3D = 'TPolyMarker3D',
clTAttPad = 'TAttPad', clTPad = 'TPad', clTCanvas = 'TCanvas', clTAttCanvas = 'TAttCanvas',
clTGaxis = 'TGaxis', clTAttAxis = 'TAttAxis', clTAxis = 'TAxis', clTStyle = 'TStyle',
clTH1 = 'TH1', clTH1I = 'TH1I', clTH1D = 'TH1D', clTH2 = 'TH2', clTH2I = 'TH2I', clTH2F = 'TH2F', clTH3 = 'TH3',
clTF1 = 'TF1', clTF2 = 'TF2', clTProfile = 'TProfile', clTProfile2D = 'TProfile2D', clTProfile3D = 'TProfile3D',
clTGeoVolume = 'TGeoVolume', clTGeoNode = 'TGeoNode', clTGeoNodeMatrix = 'TGeoNodeMatrix',
nsREX = 'ROOT::Experimental::',
kNoZoom = -1111, kInspect = 'inspect';
/** @summary Create some ROOT classes
* @desc Supported classes: `TObject`, `TNamed`, `TList`, `TAxis`, `TLine`, `TText`, `TLatex`, `TPad`, `TCanvas`
* @param {string} typename - ROOT class name
* @example
* import { create } from 'https://root.cern/js/latest/modules/core.mjs';
* let obj = create('TNamed');
* obj.fName = 'name';
* obj.fTitle = 'title'; */
function create$1(typename, target) {
const obj = target || {};
switch (typename) {
case clTObject:
extend$1(obj, { fUniqueID: 0, fBits: 0 });
break;
case clTNamed:
extend$1(obj, { fUniqueID: 0, fBits: 0, fName: '', fTitle: '' });
break;
case clTList:
case clTHashList:
extend$1(obj, { name: typename, arr: [], opt: [] });
break;
case clTAttAxis:
extend$1(obj, { fNdivisions: 510, fAxisColor: 1,
fLabelColor: 1, fLabelFont: 42, fLabelOffset: 0.005, fLabelSize: 0.035, fTickLength: 0.03,
fTitleOffset: 1, fTitleSize: 0.035, fTitleColor: 1, fTitleFont: 42 });
break;
case clTAxis:
create$1(clTNamed, obj);
create$1(clTAttAxis, obj);
extend$1(obj, { fNbins: 1, fXmin: 0, fXmax: 1, fXbins: [], fFirst: 0, fLast: 0,
fBits2: 0, fTimeDisplay: false, fTimeFormat: '', fLabels: null, fModLabs: null });
break;
case clTAttLine:
extend$1(obj, { fLineColor: 1, fLineStyle: 1, fLineWidth: 1 });
break;
case clTAttFill:
extend$1(obj, { fFillColor: 0, fFillStyle: 0 });
break;
case clTAttMarker:
extend$1(obj, { fMarkerColor: 1, fMarkerStyle: 1, fMarkerSize: 1 });
break;
case clTLine:
create$1(clTObject, obj);
create$1(clTAttLine, obj);
extend$1(obj, { fX1: 0, fX2: 1, fY1: 0, fY2: 1 });
break;
case clTBox:
create$1(clTObject, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
extend$1(obj, { fX1: 0, fX2: 1, fY1: 0, fY2: 1 });
break;
case clTPave:
create$1(clTBox, obj);
extend$1(obj, { fX1NDC: 0, fY1NDC: 0, fX2NDC: 1, fY2NDC: 1,
fBorderSize: 0, fInit: 1, fShadowColor: 1,
fCornerRadius: 0, fOption: 'brNDC', fName: '' });
break;
case clTAttText:
extend$1(obj, { fTextAngle: 0, fTextSize: 0, fTextAlign: 22, fTextColor: 1, fTextFont: 42 });
break;
case clTPaveText:
create$1(clTPave, obj);
create$1(clTAttText, obj);
extend$1(obj, { fLabel: '', fLongest: 27, fMargin: 0.05, fLines: create$1(clTList) });
break;
case clTPaveStats:
create$1(clTPaveText, obj);
extend$1(obj, { fFillColor: gStyle.fStatColor, fFillStyle: gStyle.fStatStyle,
fTextFont: gStyle.fStatFont, fTextSize: gStyle.fStatFontSize, fTextColor: gStyle.fStatTextColor,
fBorderSize: gStyle.fStatBorderSize,
fOptFit: 0, fOptStat: 0, fFitFormat: '', fStatFormat: '', fParent: null });
break;
case clTLegend:
create$1(clTPave, obj);
create$1(clTAttText, obj);
extend$1(obj, { fColumnSeparation: 0, fEntrySeparation: 0.1, fMargin: 0.25, fNColumns: 1, fPrimitives: create$1(clTList), fName: clTPave,
fBorderSize: gStyle.fLegendBorderSize, fTextFont: gStyle.fLegendFont, fTextSize: gStyle.fLegendTextSize, fFillColor: gStyle.fLegendFillColor });
break;
case clTPaletteAxis:
create$1(clTPave, obj);
extend$1(obj, { fAxis: create$1(clTGaxis), fH: null, fName: clTPave });
break;
case clTLegendEntry:
create$1(clTObject, obj);
create$1(clTAttText, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
create$1(clTAttMarker, obj);
extend$1(obj, { fLabel: '', fObject: null, fOption: '', fTextAlign: 0, fTextColor: 0, fTextFont: 0 });
break;
case clTText:
create$1(clTNamed, obj);
create$1(clTAttText, obj);
extend$1(obj, { fLimitFactorSize: 3, fOriginSize: 0.04 });
break;
case clTLatex:
create$1(clTText, obj);
create$1(clTAttLine, obj);
extend$1(obj, { fX: 0, fY: 0 });
break;
case clTObjString:
create$1(clTObject, obj);
extend$1(obj, { fString: '' });
break;
case clTH1:
create$1(clTNamed, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
create$1(clTAttMarker, obj);
extend$1(obj, { fBits: 8, fNcells: 0,
fXaxis: create$1(clTAxis), fYaxis: create$1(clTAxis), fZaxis: create$1(clTAxis),
fFillColor: gStyle.fHistFillColor, fFillStyle: gStyle.fHistFillStyle,
fLineColor: gStyle.fHistLineColor, fLineStyle: gStyle.fHistLineStyle, fLineWidth: gStyle.fHistLineWidth,
fBarOffset: 0, fBarWidth: 1000, fEntries: 0,
fTsumw: 0, fTsumw2: 0, fTsumwx: 0, fTsumwx2: 0,
fMaximum: kNoZoom, fMinimum: kNoZoom, fNormFactor: 0, fContour: [],
fSumw2: [], fOption: '', fFunctions: create$1(clTList),
fBufferSize: 0, fBuffer: [], fBinStatErrOpt: 0, fStatOverflows: 2 });
break;
case clTH1I:
case clTH1D:
case 'TH1L64':
case 'TH1F':
case 'TH1S':
case 'TH1C':
create$1(clTH1, obj);
obj.fArray = [];
break;
case clTH2:
create$1(clTH1, obj);
extend$1(obj, { fScalefactor: 1, fTsumwy: 0, fTsumwy2: 0, fTsumwxy: 0 });
break;
case clTH2I:
case 'TH2L64':
case clTH2F:
case 'TH2D':
case 'TH2S':
case 'TH2C':
create$1(clTH2, obj);
obj.fArray = [];
break;
case clTH3:
create$1(clTH1, obj);
extend$1(obj, { fTsumwy: 0, fTsumwy2: 0, fTsumwz: 0, fTsumwz2: 0, fTsumwxy: 0, fTsumwxz: 0, fTsumwyz: 0 });
break;
case 'TH3I':
case 'TH3L64':
case 'TH3F':
case 'TH3D':
case 'TH3S':
case 'TH3C':
create$1(clTH3, obj);
obj.fArray = [];
break;
case clTHStack:
create$1(clTNamed, obj);
extend$1(obj, { fHists: create$1(clTList), fHistogram: null, fMaximum: kNoZoom, fMinimum: kNoZoom });
break;
case clTGraph:
create$1(clTNamed, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
create$1(clTAttMarker, obj);
extend$1(obj, { fFunctions: create$1(clTList), fHistogram: null,
fMaxSize: 0, fMaximum: kNoZoom, fMinimum: kNoZoom, fNpoints: 0, fX: [], fY: [] });
break;
case 'TGraphAsymmErrors':
create$1(clTGraph, obj);
extend$1(obj, { fEXlow: [], fEXhigh: [], fEYlow: [], fEYhigh: [] });
break;
case clTMultiGraph:
create$1(clTNamed, obj);
extend$1(obj, { fFunctions: create$1(clTList), fGraphs: create$1(clTList),
fHistogram: null, fMaximum: kNoZoom, fMinimum: kNoZoom });
break;
case clTGraphPolargram:
create$1(clTNamed, obj);
create$1(clTAttText, obj);
create$1(clTAttLine, obj);
extend$1(obj, { fRadian: true, fDegree: false, fGrad: false, fPolarLabelColor: 1, fRadialLabelColor: 1,
fAxisAngle: 0, fPolarOffset: 0.04, fPolarTextSize: 0.04, fRadialOffset: 0.025, fRadialTextSize: 0.035,
fRwrmin: 0, fRwrmax: 1, fRwtmin: 0, fRwtmax: 2*Math.PI, fTickpolarSize: 0.02,
fPolarLabelFont: 62, fRadialLabelFont: 62, fCutRadial: 0, fNdivRad: 508, fNdivPol: 508 });
break;
case clTPolyLine:
create$1(clTObject, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
extend$1(obj, { fLastPoint: -1, fN: 0, fOption: '', fX: null, fY: null });
break;
case clTGaxis:
create$1(clTLine, obj);
create$1(clTAttText, obj);
extend$1(obj, { fChopt: '', fFunctionName: '', fGridLength: 0,
fLabelColor: 1, fLabelFont: 42, fLabelOffset: 0.005, fLabelSize: 0.035,
fName: '', fNdiv: 12, fTickSize: 0.02, fTimeFormat: '',
fTitle: '', fTitleOffset: 1, fTitleSize: 0.035,
fWmax: 100, fWmin: 0 });
break;
case clTAttPad:
extend$1(obj, { fLeftMargin: gStyle.fPadLeftMargin,
fRightMargin: gStyle.fPadRightMargin,
fBottomMargin: gStyle.fPadBottomMargin,
fTopMargin: gStyle.fPadTopMargin,
fXfile: 2, fYfile: 2, fAfile: 1, fXstat: 0.99, fYstat: 0.99, fAstat: 2,
fFrameFillColor: gStyle.fFrameFillColor,
fFrameFillStyle: gStyle.fFrameFillStyle,
fFrameLineColor: gStyle.fFrameLineColor,
fFrameLineWidth: gStyle.fFrameLineWidth,
fFrameLineStyle: gStyle.fFrameLineStyle,
fFrameBorderSize: gStyle.fFrameBorderSize,
fFrameBorderMode: gStyle.fFrameBorderMode });
break;
case clTPad:
create$1(clTObject, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
create$1(clTAttPad, obj);
extend$1(obj, { fFillColor: gStyle.fPadColor, fFillStyle: 1001,
fX1: 0, fY1: 0, fX2: 1, fY2: 1, fXtoAbsPixelk: 1, fXtoPixelk: 1,
fXtoPixel: 1, fYtoAbsPixelk: 1, fYtoPixelk: 1, fYtoPixel: 1,
fUtoAbsPixelk: 1, fUtoPixelk: 1, fUtoPixel: 1, fVtoAbsPixelk: 1,
fVtoPixelk: 1, fVtoPixel: 1, fAbsPixeltoXk: 1, fPixeltoXk: 1,
fPixeltoX: 1, fAbsPixeltoYk: 1, fPixeltoYk: 1, fPixeltoY: 1,
fXlowNDC: 0, fYlowNDC: 0, fXUpNDC: 0, fYUpNDC: 0, fWNDC: 1, fHNDC: 1,
fAbsXlowNDC: 0, fAbsYlowNDC: 0, fAbsWNDC: 1, fAbsHNDC: 1,
fUxmin: 0, fUymin: 0, fUxmax: 0, fUymax: 0, fTheta: 30, fPhi: 30, fAspectRatio: 0,
fNumber: 0, fLogx: gStyle.fOptLogx, fLogy: gStyle.fOptLogy, fLogz: gStyle.fOptLogz,
fTickx: gStyle.fPadTickX, fTicky: gStyle.fPadTickY,
fPadPaint: 0, fCrosshair: 0, fCrosshairPos: 0, fBorderSize: gStyle.fPadBorderSize,
fBorderMode: gStyle.fPadBorderMode, fModified: false,
fGridx: gStyle.fPadGridX, fGridy: gStyle.fPadGridY,
fAbsCoord: false, fEditable: true, fFixedAspectRatio: false,
fPrimitives: create$1(clTList), fExecs: null,
fName: 'pad', fTitle: 'canvas' });
break;
case clTAttCanvas:
extend$1(obj, { fXBetween: 2, fYBetween: 2, fTitleFromTop: 1.2,
fXdate: 0.2, fYdate: 0.3, fAdate: 1 });
break;
case clTCanvas:
create$1(clTPad, obj);
extend$1(obj, { fFillColor: gStyle.fCanvasColor, fFillStyle: 1001,
fNumPaletteColor: 0, fNextPaletteColor: 0, fDISPLAY: '$DISPLAY',
fDoubleBuffer: 0, fRetained: true, fXsizeUser: 0,
fYsizeUser: 0, fXsizeReal: 20, fYsizeReal: 10,
fWindowTopX: 0, fWindowTopY: 0, fWindowWidth: 0, fWindowHeight: 0,
fBorderSize: gStyle.fCanvasBorderSize, fBorderMode: gStyle.fCanvasBorderMode,
fCw: 500, fCh: 300, fCatt: create$1(clTAttCanvas),
kMoveOpaque: true, kResizeOpaque: true, fHighLightColor: 5,
fBatch: true, kShowEventStatus: false, kAutoExec: true, kMenuBar: true });
break;
case clTGeoVolume:
create$1(clTNamed, obj);
create$1(clTAttLine, obj);
create$1(clTAttFill, obj);
extend$1(obj, { fGeoAtt: 0, fFinder: null, fMedium: null, fNodes: null, fNtotal: 0, fNumber: 0, fRefCount: 0, fShape: null, fVoxels: null });
break;
case clTGeoNode:
create$1(clTNamed, obj);
extend$1(obj, { fGeoAtt: 0, fMother: null, fNovlp: 0, fNumber: 0, fOverlaps: null, fVolume: null });
break;
case clTGeoNodeMatrix:
create$1(clTGeoNode, obj);
extend$1(obj, { fMatrix: null });
break;
case 'TGeoTrack':
create$1(clTObject, obj);
create$1(clTAttLine, obj);
create$1(clTAttMarker, obj);
extend$1(obj, { fGeoAtt: 0, fNpoints: 0, fPoints: [] });
break;
case clTPolyLine3D:
create$1(clTObject, obj);
create$1(clTAttLine, obj);
extend$1(obj, { fLastPoint: -1, fN: 0, fOption: '', fP: [] });
break;
case clTPolyMarker3D:
create$1(clTObject, obj);
create$1(clTAttMarker, obj);
extend$1(obj, { fLastPoint: -1, fN: 0, fName: '', fOption: '', fP: [] });
break;
}
obj._typename = typename;
addMethods(obj, typename);
return obj;
}
/** @summary variable used to keep methods for known classes
* @private */
const methodsCache = {};
/** @summary Returns methods for given typename
* @private */
function getMethods(typename, obj) {
let m = methodsCache[typename];
const has_methods = (m !== undefined);
if (!has_methods) m = {};
// Due to binary I/O such TObject methods may not be set for derived classes
// Therefore when methods requested for given object, check also that basic methods are there
if ((typename === clTObject) || (typename === clTNamed) || (obj?.fBits !== undefined)) {
if (typeof m.TestBit === 'undefined') {
m.TestBit = function(f) { return (this.fBits & f) !== 0; };
m.InvertBit = function(f) { this.fBits = this.fBits ^ (f & 0xffffff); };
}
}
if (has_methods) return m;
if ((typename === clTList) || (typename === clTHashList)) {
m.Clear = function() {
this.arr = [];
this.opt = [];
};
m.Add = function(obj, opt) {
this.arr.push(obj);
this.opt.push(isStr(opt) ? opt : '');
};
m.AddFirst = function(obj, opt) {
this.arr.unshift(obj);
this.opt.unshift(isStr(opt) ? opt : '');
};
m.RemoveAt = function(indx) {
this.arr.splice(indx, 1);
this.opt.splice(indx, 1);
};
}
if ((typename === clTPaveText) || (typename === clTPaveStats)) {
m.AddText = function(txt) {
const line = create$1(clTLatex);
line.fTitle = txt;
line.fTextAlign = 0;
line.fTextColor = 0;
line.fTextFont = 0;
line.fTextSize = 0;
this.fLines.Add(line);
};
m.Clear = function() {
this.fLines.Clear();
};
}
if ((typename.indexOf(clTF1) === 0) || (typename === clTF2)) {
m.addFormula = function(obj) {
if (!obj) return;
if (this.formulas === undefined) this.formulas = [];
this.formulas.push(obj);
};
m.GetParName = function(n) {
if (this.fParams?.fParNames)
return this.fParams.fParNames[n];
if (this.fFormula?.fParams) {
for (let k = 0, arr = this.fFormula.fParams; k < arr.length; ++k) {
if (arr[k].second === n)
return arr[k].first;
}
}
return (this.fNames && this.fNames[n]) ? this.fNames[n] : `p${n}`;
};
m.GetParValue = function(n) {
if (this.fParams?.fParameters) return this.fParams.fParameters[n];
if (this.fFormula?.fClingParameters) return this.fFormula.fClingParameters[n];
if (this.fParams) return this.fParams[n];
return undefined;
};
m.GetParError = function(n) {
return this.fParErrors ? this.fParErrors[n] : undefined;
};
m.GetNumPars = function() {
return this.fNpar;
};
}
if (((typename.indexOf(clTGraph) === 0) || (typename === clTCutG)) && (typename !== clTGraphPolargram) && (typename !== clTGraphTime)) {
// check if point inside figure specified by the TGraph
m.IsInside = function(xp, yp) {
const x = this.fX, y = this.fY;
let i = 0, j = this.fNpoints - 1, oddNodes = false;
for (; i < this.fNpoints; ++i) {
if ((y[i] < yp && y[j] >= yp) || (y[j] < yp && y[i] >= yp)) {
if (x[i] + (yp - y[i])/(y[j] - y[i])*(x[j] - x[i]) < xp)
oddNodes = !oddNodes;
}
j = i;
}
return oddNodes;
};
}
if (typename.indexOf(clTH1) === 0 || typename.indexOf(clTH2) === 0 || typename.indexOf(clTH3) === 0) {
m.getBinError = function(bin) {
// -*-*-*-*-*Return value of error associated to bin number bin*-*-*-*-*
// if the sum of squares of weights has been defined (via Sumw2),
// this function returns the sqrt(sum of w2).
// otherwise it returns the sqrt(contents) for this bin.
if (bin >= this.fNcells) bin = this.fNcells - 1;
if (bin < 0) bin = 0;
if (bin < this.fSumw2.length)
return Math.sqrt(this.fSumw2[bin]);
return Math.sqrt(Math.abs(this.fArray[bin]));
};
m.setBinContent = function(bin, content) {
// Set bin content - only trivial case, without expansion
this.fEntries++;
this.fTsumw = 0;
if ((bin >= 0) && (bin < this.fArray.length))
this.fArray[bin] = content;
};
}
if (typename.indexOf(clTH1) === 0) {
m.getBin = function(x) { return x; };
m.getBinContent = function(bin) { return this.fArray[bin]; };
m.Fill = function(x, weight) {
const a = this.fXaxis,
bin = Math.max(0, 1 + Math.min(a.fNbins, Math.floor((x - a.fXmin) / (a.fXmax - a.fXmin) * a.fNbins)));
this.fArray[bin] += weight ?? 1;
this.fEntries++;
};
}
if (typename.indexOf(clTH2) === 0) {
m.getBin = function(x, y) { return (x + (this.fXaxis.fNbins+2) * y); };
m.getBinContent = function(x, y) { return this.fArray[this.getBin(x, y)]; };
m.Fill = function(x, y, weight) {
const a1 = this.fXaxis, a2 = this.fYaxis,
bin1 = Math.max(0, 1 + Math.min(a1.fNbins, Math.floor((x - a1.fXmin) / (a1.fXmax - a1.fXmin) * a1.fNbins))),
bin2 = Math.max(0, 1 + Math.min(a2.fNbins, Math.floor((y - a2.fXmin) / (a2.fXmax - a2.fXmin) * a2.fNbins)));
this.fArray[bin1 + (a1.fNbins + 2)*bin2] += weight ?? 1;
this.fEntries++;
};
}
if (typename.indexOf(clTH3) === 0) {
m.getBin = function(x, y, z) { return (x + (this.fXaxis.fNbins+2) * (y + (this.fYaxis.fNbins+2) * z)); };
m.getBinContent = function(x, y, z) { return this.fArray[this.getBin(x, y, z)]; };
m.Fill = function(x, y, z, weight) {
const a1 = this.fXaxis, a2 = this.fYaxis, a3 = this.fZaxis,
bin1 = Math.max(0, 1 + Math.min(a1.fNbins, Math.floor((x - a1.fXmin) / (a1.fXmax - a1.fXmin) * a1.fNbins))),
bin2 = Math.max(0, 1 + Math.min(a2.fNbins, Math.floor((y - a2.fXmin) / (a2.fXmax - a2.fXmin) * a2.fNbins))),
bin3 = Math.max(0, 1 + Math.min(a3.fNbins, Math.floor((z - a3.fXmin) / (a3.fXmax - a3.fXmin) * a3