8 if ( typeof define ===
"function" && define.amd ) {
10 var jsroot = factory({});
12 var dir = jsroot.source_dir +
"scripts/", ext = jsroot.source_min ?
".min" :
"";
15 'd3' : dir+
'd3.v3.min',
16 'jquery' : dir+
'jquery.min',
17 'jquery-ui' : dir+
'jquery-ui.min',
18 'jqueryui-mousewheel' : dir+
'jquery.mousewheel'+ext,
19 'jqueryui-touch-punch' : dir+
'touch-punch.min',
20 'rawinflate' : dir+
'rawinflate'+ext,
21 'MathJax' :
'https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG&delayStartupUntil=configured',
22 'saveSvgAsPng' : dir+
'saveSvgAsPng'+ext,
23 'threejs' : dir+
'three'+ext,
24 'threejs_all' : dir+
'three.extra'+ext,
26 'JSRootMath' : dir+
'JSRootMath'+ext,
27 'JSRootInterface' : dir+
'JSRootInterface'+ext,
28 'JSRootIOEvolution' : dir+
'JSRootIOEvolution'+ext,
29 'JSRootPainter' : dir+
'JSRootPainter'+ext,
30 'JSRootPainter.more' : dir+
'JSRootPainter.more'+ext,
31 'JSRootPainter.jquery' : dir+
'JSRootPainter.jquery'+ext,
32 'JSRoot3DPainter' : dir+
'JSRoot3DPainter'+ext,
33 'ThreeCSG' : dir+
'ThreeCSG'+ext,
34 'JSRootGeoPainter' : dir+
'JSRootGeoPainter'+ext
38 if ((requirejs.s!==undefined) && (requirejs.s.contexts !== undefined) && ((requirejs.s.contexts._!==undefined) &&
39 requirejs.s.contexts._.config!==undefined)) cfg_paths = requirejs.s.contexts._.config.paths;
40 else console.warn(
"Require.js paths changed - please contact JSROOT developers");
43 for (var module in paths)
44 if (requirejs.defined(module) || (cfg_paths && (module in cfg_paths)))
51 'jqueryui-mousewheel': { deps: [
'jquery-ui'] },
52 'jqueryui-touch-punch': { deps: [
'jquery-ui'] },
53 'threejs_all': { deps: [
'threejs'] },
57 MathJax.Hub.Config({ TeX: { extensions: [
"color.js"] }});
58 MathJax.Hub.Register.StartupHook(
"SVG Jax Ready",
function () {
59 var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;
60 VARIANT[
"normal"].fonts.unshift(
"MathJax_SansSerif");
61 VARIANT[
"bold"].fonts.unshift(
"MathJax_SansSerif-bold");
62 VARIANT[
"italic"].fonts.unshift(
"MathJax_SansSerif");
63 VARIANT[
"-tex-mathit"].fonts.unshift(
"MathJax_SansSerif");
65 MathJax.Hub.Startup.onload();
75 if (!require.specified(
"JSRootCore"))
76 define(
'JSRootCore', [], jsroot);
78 if (!require.specified(
"jsroot"))
79 define(
'jsroot', [], jsroot);
83 if (typeof JSROOT !=
'undefined')
84 throw new Error(
"JSROOT is already defined",
"JSRootCore.js");
92 JSROOT.version =
"4.5.0 25/04/2016";
94 JSROOT.source_dir =
"";
95 JSROOT.source_min =
false;
96 JSROOT.source_fullpath =
"";
97 JSROOT.bower_dir =
"";
99 JSROOT.id_counter = 0;
101 JSROOT.touches =
false;
102 JSROOT.browser = { isOpera:
false, isFirefox:
true, isSafari:
false, isChrome:
false, isIE:
false };
104 if ((typeof document !==
"undefined") && (typeof window !==
"undefined")) {
105 var scripts = document.getElementsByTagName(
'script');
106 for (var n = 0; n < scripts.length; ++n) {
107 var src = scripts[n].src;
108 if ((src===undefined) || (typeof src !==
'string'))
continue;
110 var pos = src.indexOf(
"scripts/JSRootCore.");
113 JSROOT.source_dir = src.substr(0, pos);
114 JSROOT.source_min = src.indexOf(
"scripts/JSRootCore.min.js") >= 0;
116 JSROOT.source_fullpath = src;
118 if ((console!==undefined) && (typeof console.log ==
'function'))
119 console.log(
"Set JSROOT.source_dir to " + JSROOT.source_dir +
", " + JSROOT.version);
123 JSROOT.touches = (
'ontouchend' in document);
124 JSROOT.browser.isOpera = !!window.opera || navigator.userAgent.indexOf(
' OPR/') >= 0;
125 JSROOT.browser.isFirefox = typeof InstallTrigger !==
'undefined';
126 JSROOT.browser.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf(
'Constructor') > 0;
127 JSROOT.browser.isChrome = !!window.chrome && !JSROOT.browser.isOpera;
128 JSROOT.browser.isIE =
false || !!document.documentMode;
131 JSROOT.browser.isWebKit = JSROOT.browser.isChrome || JSROOT.browser.isSafari;
145 FrameNDC : { fX1NDC: 0.07, fY1NDC: 0.12, fX2NDC: 0.95, fY2NDC: 0.88 },
146 StatNDC : { fX1NDC: 0.78, fY1NDC: 0.75, fX2NDC: 0.98, fY2NDC: 0.91 },
147 StatText : { fTextAngle: 0, fTextSize: 9, fTextAlign: 12, fTextColor: 1, fTextFont: 42 },
148 StatFill : { fFillColor: 0, fFillStyle: 1001 },
149 TimeOffset : 788918400000,
160 JSROOT.BIT =
function(n) {
return 1 << (n); }
163 JSROOT.TH1StatusBits = {
164 kNoStats : JSROOT.BIT(9),
165 kUserContour : JSROOT.BIT(10),
166 kCanRebin : JSROOT.BIT(11),
167 kLogX : JSROOT.BIT(15),
168 kIsZoomed : JSROOT.BIT(16),
169 kNoTitle : JSROOT.BIT(17),
170 kIsAverage : JSROOT.BIT(18)
174 kTickPlus : JSROOT.BIT(9),
175 kTickMinus : JSROOT.BIT(10),
176 kAxisRange : JSROOT.BIT(11),
177 kCenterTitle : JSROOT.BIT(12),
178 kCenterLabels : JSROOT.BIT(14),
179 kRotateTitle : JSROOT.BIT(15),
180 kPalette : JSROOT.BIT(16),
181 kNoExponent : JSROOT.BIT(17),
182 kLabelsHori : JSROOT.BIT(18),
183 kLabelsVert : JSROOT.BIT(19),
184 kLabelsDown : JSROOT.BIT(20),
185 kLabelsUp : JSROOT.BIT(21),
186 kIsInteger : JSROOT.BIT(22),
187 kMoreLogLabels : JSROOT.BIT(23),
188 kDecimals : JSROOT.BIT(11)
193 JSROOT.console =
function(value, divid) {
194 if ((divid!=null) && (typeof divid==
'string') && ((typeof document.getElementById(divid))!=
'undefined'))
195 document.getElementById(divid).innerHTML = value;
197 if ((typeof console !=
'undefined') && (typeof console.log ==
'function'))
205 JSROOT.JSONR_unref =
function(value, dy) {
209 switch (typeof value) {
211 if ((value.length > 5) && (value.substr(0, 5) ==
"$ref:")) {
212 c = parseInt(value.substr(5));
213 if (!isNaN(c) && (c < dy.length)) {
220 if (value !== null) {
222 if (Object.prototype.toString.apply(value) ===
'[object Array]') {
223 for (i = 0; i < value.length; ++i) {
224 value[i] = this.JSONR_unref(value[i], dy);
229 if (dy.indexOf(value) === -1) {
234 if (
'_typename' in value) this.addMethods(value);
236 ks = Object.keys(value);
237 for (i = 0; i < ks.length; ++i) {
239 value[k] = this.JSONR_unref(value[k], dy);
253 JSROOT.extend =
function(tgt, src, map, deep_copy) {
254 if ((src === null) || (typeof src !==
'object'))
return src;
255 if ((tgt === null) || (typeof tgt !==
'object')) tgt = {};
264 JSROOT.clone =
function(src, map) {
265 if (src === null)
return null;
268 map = { obj:[], clones:[] };
270 var i = map.obj.indexOf(src);
271 if (i>=0)
return map.clones[i];
274 var proto = Object.prototype.toString.apply(src);
277 if (proto ===
'[object Array]') {
280 map.clones.push(tgt);
281 for (var i = 0; i < src.length; ++i)
282 tgt.push(JSROOT.clone(src[i], map));
288 if ((proto.indexOf(
'[object ') == 0) && (proto.indexOf(
'Array]') == proto.length-6)) {
291 map.clones.push(tgt);
292 for (var i = 0; i < src.length; ++i)
300 map.clones.push(tgt);
303 if (typeof src[k] ===
'object')
304 tgt[k] = JSROOT.clone(src[k], map);
314 JSROOT.clear_func =
function(src, map) {
315 if (src === null)
return;
317 var proto = Object.prototype.toString.apply(src);
319 if (proto ===
'[object Array]') {
320 for (var n=0;n<src.length;n++)
321 if (typeof src[n] ===
'object')
322 JSROOT.clear_func(src[n], map);
326 if ((proto.indexOf(
'[object ') == 0) && (proto.indexOf(
'Array]') == proto.length-6))
return;
329 var nomap = (map.length == 0);
330 if (
'__clean_func__' in src)
return;
333 src[
'__clean_func__'] =
true;
336 if (typeof src[k] ===
'object')
337 JSROOT.clear_func(src[k], map);
339 if (typeof src[k] ===
'function')
delete src[k];
343 for (var n=0;n<map.length;++n)
344 delete map[n][
'__clean_func__'];
348 JSROOT.parse =
function(arg) {
349 if ((arg==null) || (arg==
""))
return null;
350 var obj = JSON.parse(arg);
351 if (obj!=null) obj = this.JSONR_unref(obj);
355 JSROOT.GetUrlOption =
function(opt, url, dflt) {
361 if (arguments.length < 3) dflt = null;
362 if ((opt==null) || (typeof opt !=
'string') || (opt.length==0))
return dflt;
365 if (typeof document ===
'undefined')
return dflt;
369 var pos = url.indexOf(
"?");
370 if (pos<0)
return dflt;
371 url = url.slice(pos+1);
373 while (url.length>0) {
375 if (url==opt)
return "";
377 pos = url.indexOf(
"&");
378 if (pos < 0) pos = url.length;
380 if (url.indexOf(opt) == 0) {
381 if (url.charAt(opt.length)==
"&")
return "";
384 if (url.charAt(opt.length)==
"=")
385 return url.slice(opt.length+1, pos).replace(/%27/g,
"'").replace(/%22/g,
'"').replace(/%20/g,
' ').replace(/%3C/g,
'<').replace(/%3E/g,
'>').replace(/%5B/g,
'[').replace(/%5D/g,
']');
388 url = url.slice(pos+1);
393 JSROOT.ParseAsArray =
function(val) {
400 if (typeof val !=
'string')
return res;
403 if (val==
"")
return res;
406 if ((val.length<2) || (val[0]!=
'[') || (val[val.length-1]!=
']')) {
407 res.push(val);
return res;
411 var arr = val.substr(1, val.length-2).split(
",");
413 for (var i = 0; i < arr.length; ++i) {
414 var sub = arr[i].trim();
415 if ((sub.length>1) && (sub[0]==sub[sub.length-1]) && ((sub[0]==
'"') || (sub[0]==
"'")))
416 sub = sub.substr(1, sub.length-2);
422 JSROOT.GetUrlOptionAsArray =
function(opt, url) {
432 while (opt.length>0) {
433 var separ = opt.indexOf(
";");
434 var part = separ>0 ? opt.substr(0, separ) : opt;
435 if (separ>0) opt = opt.substr(separ+1);
else opt =
"";
437 var val = this.GetUrlOption(part, url, null);
438 res = res.concat(JSROOT.ParseAsArray(val));
443 JSROOT.findFunction =
function(name) {
444 if (typeof name ===
'function')
return name;
445 var func = window[name];
446 if (typeof func ==
'function')
return func;
447 var separ = name.lastIndexOf(
".");
448 if (separ<0)
return null;
449 var
namespace = name.slice(0, separ);
450 name = name.slice(separ+1);
451 if (
namespace==
"JSROOT") func =
this[name];
else
452 if (
namespace==
"JSROOT.Painter") {
if (
'Painter' in
this) func =
this[
'Painter'][name]; }
else
453 if (window[
namespace]) func = window[
namespace][name];
454 return (typeof func ==
'function') ? func : null;
457 JSROOT.CallBack =
function(func, arg1, arg2) {
463 if (typeof func ==
'string') func = JSROOT.findFunction(func);
465 if (func == null)
return;
467 if (typeof func ==
'function')
return func(arg1,arg2);
469 if (typeof func !=
'object')
return;
471 if ((
'obj' in func) && (
'func' in func) &&
472 (typeof func.obj ==
'object') && (typeof func.func ==
'string') &&
473 (typeof func.obj[func.func] ==
'function')) {
474 alert(
'Old-style call-back, change code for ' + func.func);
475 return func.obj[func.func](arg1, arg2);
479 JSROOT.NewHttpRequest =
function(url, kind, user_call_back) {
493 var xhr =
new XMLHttpRequest();
495 function callback(res) {
497 if (typeof user_call_back ==
'function') user_call_back.call(xhr, res);
502 if (window.ActiveXObject) {
504 xhr.onreadystatechange =
function() {
505 if (xhr.readyState != 4)
return;
507 if (xhr.status != 200 && xhr.status != 206) {
509 return callback(null);
512 if (kind ==
"xml")
return callback(xhr.responseXML);
513 if (kind ==
"text")
return callback(xhr.responseText);
514 if (kind ==
"object")
return callback(pthis.parse(xhr.responseText));
515 if (kind ==
"head")
return callback(xhr);
517 if ((kind ==
"buf") && (
'responseType' in xhr) &&
518 (xhr.responseType ==
'arraybuffer') && (
'response' in xhr))
519 return callback(xhr.response);
521 var filecontent =
new String(
"");
522 var array =
new VBArray(xhr.responseBody).toArray();
523 for (var i = 0; i < array.length; ++i)
524 filecontent = filecontent + String.fromCharCode(array[i]);
526 callback(filecontent);
529 xhr.open(kind ==
'head' ?
'HEAD' :
'GET', url,
true);
532 if ((
'Uint8Array' in window) && (
'responseType' in xhr))
533 xhr.responseType =
'arraybuffer';
538 xhr.onreadystatechange =
function() {
539 if (xhr.readyState != 4)
return;
541 if (xhr.status != 200 && xhr.status != 206) {
542 return callback(null);
545 if (kind ==
"xml")
return callback(xhr.responseXML);
546 if (kind ==
"text")
return callback(xhr.responseText);
547 if (kind ==
"object")
return callback(pthis.parse(xhr.responseText));
548 if (kind ==
"head")
return callback(xhr);
551 if (! (
'responseType' in xhr))
552 return callback(xhr.responseText);
554 if ((kind==
"bin") && (
'Uint8Array' in window) && (
'byteLength' in xhr.response)) {
556 var filecontent =
"";
557 var u8Arr =
new Uint8Array(xhr.response, 0, xhr.response.byteLength);
558 for (var i = 0; i < u8Arr.length; ++i)
559 filecontent = filecontent + String.fromCharCode(u8Arr[i]);
562 return callback(filecontent);
565 callback(xhr.response);
568 xhr.open(kind ==
'head' ?
'HEAD' :
'GET', url,
true);
570 if ((kind ==
"bin") || (kind ==
"buf")) {
571 if ((
'Uint8Array' in window) && (
'responseType' in xhr)) {
572 xhr.responseType =
'arraybuffer';
575 xhr.overrideMimeType(
"text/plain; charset=x-user-defined");
583 JSROOT.loadScript =
function(urllist, callback, debugout) {
592 function completeLoad() {
594 document.getElementById(debugout).innerHTML =
"";
598 if ((urllist!=null) && (urllist.length>0))
599 return JSROOT.loadScript(urllist, callback, debugout);
601 JSROOT.CallBack(callback);
604 if ((urllist==null) || (urllist.length==0))
605 return completeLoad();
607 var filename = urllist;
608 var separ = filename.indexOf(
";");
610 filename = filename.substr(0, separ);
611 urllist = urllist.slice(separ+1);
616 var isrootjs =
false, isbower =
false;
617 if (filename.indexOf(
"$$$")===0) {
619 filename = filename.slice(3);
620 if ((filename.indexOf(
"style/")==0) && JSROOT.source_min &&
621 (filename.lastIndexOf(
'.css')==filename.length-3) &&
622 (filename.indexOf(
'.min.css')<0))
623 filename = filename.slice(0, filename.length-4) +
'.min.css';
625 if (filename.indexOf(
"###")===0) {
627 filename = filename.slice(3);
629 var isstyle = filename.indexOf(
'.css') > 0;
632 var styles = document.getElementsByTagName(
'link');
633 for (var n = 0; n < styles.length; ++n) {
634 if ((styles[n].type !=
'text/css') || (styles[n].rel !==
'stylesheet'))
continue;
636 var href = styles[n].href;
637 if ((href == null) || (href.length == 0))
continue;
639 if (href.indexOf(filename)>=0)
return completeLoad();
643 var scripts = document.getElementsByTagName(
'script');
645 for (var n = 0; n < scripts.length; ++n) {
648 var src = scripts[n].src;
649 if ((src == null) || (src.length == 0))
continue;
651 if ((src.indexOf(filename)>=0) && (src.indexOf(
"load=")<0)) {
653 return completeLoad();
658 if (isrootjs && (JSROOT.source_dir!=null)) filename = JSROOT.source_dir + filename;
else
659 if (isbower && (JSROOT.bower_dir.length>0)) filename = JSROOT.bower_dir + filename;
664 document.getElementById(debugout).innerHTML =
"loading " + filename +
" ...";
666 JSROOT.progress(
"loading " + filename +
" ...");
669 element = document.createElement(
"link");
670 element.setAttribute(
"rel",
"stylesheet");
671 element.setAttribute(
"type",
"text/css");
672 element.setAttribute(
"href", filename);
674 element = document.createElement(
"script");
675 element.setAttribute(
'type',
"text/javascript");
676 element.setAttribute(
'src', filename);
679 if (element.readyState) {
680 element.onreadystatechange =
function() {
681 if (element.readyState ==
"loaded" || element.readyState ==
"complete") {
682 element.onreadystatechange = null;
687 element.onload =
function() {
688 element.onload = null;
693 document.getElementsByTagName(
"head")[0].appendChild(element);
696 JSROOT.AssertPrerequisites =
function(kind, callback, debugout) {
708 if (!(
'doing_assert' in jsroot)) jsroot.doing_assert = [];
710 if ((typeof kind !==
'string') || (kind ==
''))
711 return jsroot.CallBack(callback);
713 if (kind==
'__next__') {
714 if (jsroot.doing_assert.length==0)
return;
715 var req = jsroot.doing_assert[0];
716 if (
'running' in req)
return;
718 callback = req._callback;
719 debugout = req._debug;
721 jsroot.doing_assert.push({_kind:kind, _callback:callback, _debug: debugout});
722 if (jsroot.doing_assert.length > 1)
return;
725 jsroot.doing_assert[0][
'running'] =
true;
727 if (kind.charAt(kind.length-1)!=
";") kind+=
";";
729 var ext = jsroot.source_min ?
".min" :
"";
731 var need_jquery =
false, use_bower = (JSROOT.bower_dir.length>0);
734 var mainfiles =
"", extrafiles =
"";
737 if (kind.indexOf(
'io;')>=0) {
738 mainfiles +=
"$$$scripts/rawinflate" + ext +
".js;" +
739 "$$$scripts/JSRootIOEvolution" + ext +
".js;";
740 modules.push(
'JSRootIOEvolution');
743 if (kind.indexOf(
'2d;')>=0) {
744 if (!(
'_test_d3_' in jsroot)) {
745 if (typeof d3 !=
'undefined') {
746 jsroot.console(
'Reuse existing d3.js ' + d3.version +
", required 3.4.10", debugout);
747 jsroot[
'_test_d3_'] = 1;
749 mainfiles += use_bower ?
'###d3/d3.min.js;' :
'$$$scripts/d3.v3.min.js;';
750 jsroot[
'_test_d3_'] = 2;
753 modules.push(
'JSRootPainter');
754 mainfiles +=
'$$$scripts/JSRootPainter' + ext +
".js;";
755 extrafiles +=
'$$$style/JSRootPainter' + ext +
'.css;';
758 if (kind.indexOf(
'savepng;')>=0) {
759 modules.push(
'saveSvgAsPng');
760 mainfiles +=
'$$$scripts/saveSvgAsPng' + ext +
".js;";
763 if (kind.indexOf(
'jq;')>=0) need_jquery =
true;
765 if (kind.indexOf(
'math;')>=0) {
766 mainfiles +=
'$$$scripts/JSRootMath' + ext +
".js;";
767 modules.push(
'JSRootMath');
770 if (kind.indexOf(
'more2d;')>=0) {
771 mainfiles +=
'$$$scripts/JSRootPainter.more' + ext +
".js;";
772 modules.push(
'JSRootPainter.more');
775 if (kind.indexOf(
'jq2d;')>=0) {
776 mainfiles +=
'$$$scripts/JSRootPainter.jquery' + ext +
".js;";
777 modules.push(
'JSRootPainter.jquery');
781 if ((kind.indexOf(
"3d;")>=0) || (kind.indexOf(
"geom;")>=0)) {
783 mainfiles +=
"###threejs/build/three.min.js;" +
784 "###threejs/examples/js/utils/FontUtils.js;" +
785 "###threejs/examples/js/renderers/Projector.js;" +
786 "###threejs/examples/js/renderers/CanvasRenderer.js;" +
787 "###threejs/examples/js/geometries/TextGeometry.js;" +
788 "###threejs/examples/js/controls/OrbitControls.js;" +
789 "###threejs/examples/js/controls/TransformControls.js;" +
790 "###threejs/examples/fonts/helvetiker_regular.typeface.js";
792 mainfiles +=
"$$$scripts/three" + ext +
".js;" +
793 "$$$scripts/three.extra" + ext +
".js;";
794 modules.push(
"threejs_all");
795 mainfiles +=
"$$$scripts/JSRoot3DPainter" + ext +
".js;";
796 modules.push(
'JSRoot3DPainter');
799 if (kind.indexOf(
"geom;")>=0) {
800 mainfiles +=
"$$$scripts/ThreeCSG" + ext +
".js;" +
801 "$$$scripts/JSRootGeoPainter" + ext +
".js;";
802 extrafiles +=
"$$$style/JSRootGeoPainter" + ext +
".css;";
803 modules.push(
'ThreeCSG',
'JSRootGeoPainter');
806 if (kind.indexOf(
"mathjax;")>=0) {
807 if (typeof MathJax ==
'undefined') {
808 mainfiles += (use_bower ?
"###MathJax/MathJax.js" :
"https://cdn.mathjax.org/mathjax/latest/MathJax.js") +
809 "?config=TeX-AMS-MML_SVG," + jsroot.source_dir +
"scripts/mathjax_config.js;";
811 if (JSROOT.gStyle.MathJax == 0) JSROOT.gStyle.MathJax = 1;
812 modules.push(
'MathJax');
815 if (kind.indexOf(
"simple;")>=0) {
817 mainfiles +=
'$$$scripts/JSRootInterface' + ext +
".js;";
818 extrafiles +=
'$$$style/JSRootInterface' + ext +
'.css;';
819 modules.push(
'JSRootInterface');
822 if (need_jquery && (JSROOT.load_jquery==null)) {
823 var has_jq = (typeof jQuery !=
'undefined'), lst_jq =
"";
826 jsroot.console(
'Reuse existing jQuery ' + jQuery.fn.jquery +
", required 2.1.4", debugout);
828 lst_jq += (use_bower ?
"###jquery/dist" :
"$$$scripts") +
"/jquery.min.js;";
829 if (has_jq && typeof $.ui !=
'undefined')
830 jsroot.console(
'Reuse existing jQuery-ui ' + $.ui.version +
", required 1.11.4", debugout);
832 lst_jq += (use_bower ?
"###jquery-ui" :
"$$$scripts") +
'/jquery-ui.min.js;';
833 extrafiles +=
'$$$style/jquery-ui' + ext +
'.css;';
836 if (JSROOT.touches) {
837 lst_jq += use_bower ?
'###jqueryui-touch-punch/jquery.ui.touch-punch.min.js;' :
'$$$scripts/touch-punch.min.js;';
838 modules.push(
'jqueryui-touch-punch');
841 modules.splice(0,0,
'jquery',
'jquery-ui',
'jqueryui-mousewheel');
842 mainfiles = lst_jq + mainfiles;
844 jsroot.load_jquery =
true;
847 var pos = kind.indexOf(
"user:");
848 if (pos<0) pos = kind.indexOf(
"load:");
849 if (pos>=0) extrafiles += kind.slice(pos+5);
851 function load_callback() {
852 var req = jsroot.doing_assert.shift();
853 jsroot.CallBack(req._callback);
854 jsroot.AssertPrerequisites(
'__next__');
857 if ((typeof define ===
"function") && define.amd && (modules.length>0)) {
858 jsroot.console(
"loading " + JSON.stringify(modules) +
" with require.js", debugout);
859 require(modules,
function() {
860 jsroot.loadScript(extrafiles, load_callback, debugout);
863 jsroot.loadScript(mainfiles + extrafiles, load_callback, debugout);
868 JSROOT.OpenFile =
function(filename, callback) {
869 JSROOT.AssertPrerequisites(
"io",
function() {
870 new JSROOT.TFile(filename, callback);
877 JSROOT.draw =
function(divid, obj, opt) {
878 JSROOT.AssertPrerequisites(
"2d",
function() {
879 JSROOT.draw(divid, obj, opt);
883 JSROOT.redraw =
function(divid, obj, opt) {
884 JSROOT.AssertPrerequisites(
"2d",
function() {
885 JSROOT.redraw(divid, obj, opt);
889 JSROOT.BuildSimpleGUI =
function(user_scripts, andThen) {
890 if (typeof user_scripts ==
'function') {
891 andThen = user_scripts;
896 var nobrowser = JSROOT.GetUrlOption(
'nobrowser')!=null;
897 var requirements =
"io;2d;";
899 if (document.getElementById(
'simpleGUI')) {
900 debugout =
'simpleGUI';
901 if ((JSROOT.GetUrlOption(
'json')!=null) &&
902 (JSROOT.GetUrlOption(
'file')==null) &&
903 (JSROOT.GetUrlOption(
'files')==null)) requirements =
"2d;";
905 if (document.getElementById(
'onlineGUI')) { debugout =
'onlineGUI'; requirements =
"2d;"; }
else
906 if (document.getElementById(
'drawGUI')) { debugout =
'drawGUI'; requirements =
"2d;"; nobrowser =
true; }
908 if (user_scripts ==
'check_existing_elements') {
910 if (debugout == null)
return;
913 if (!nobrowser) requirements +=
'jq2d;simple;';
915 if (user_scripts == null) user_scripts = JSROOT.GetUrlOption(
"autoload");
916 if (user_scripts == null) user_scripts = JSROOT.GetUrlOption(
"load");
918 if (user_scripts != null)
919 requirements +=
"load:" + user_scripts +
";";
921 JSROOT.AssertPrerequisites(requirements,
function() {
922 JSROOT.CallBack(JSROOT.findFunction(nobrowser ?
'JSROOT.BuildNobrowserGUI' :
'BuildSimpleGUI'));
923 JSROOT.CallBack(andThen);
927 JSROOT.Create =
function(
typename, target) {
929 if (obj == null) obj = { _typename:
typename };
933 JSROOT.extend(obj, { fUniqueID: 0, fBits: 0x3000008 });
936 JSROOT.extend(obj, { fUniqueID: 0, fBits: 0x3000008, fName:
"", fTitle:
"" });
940 JSROOT.extend(obj, { name:
typename, arr : [], opt : [] });
943 JSROOT.extend(obj, { fNdivisions: 510, fAxisColor: 1,
944 fLabelColor: 1, fLabelFont: 42, fLabelOffset: 0.005, fLabelSize: 0.035, fTickLength: 0.03,
945 fTitleOffset: 1, fTitleSize: 0.035, fTitleColor: 1, fTitleFont : 42 });
948 JSROOT.Create(
"TNamed", obj);
949 JSROOT.Create(
"TAttAxis", obj);
950 JSROOT.extend(obj, { fNbins: 0, fXmin: 0, fXmax: 0, fXbins : [], fFirst: 0, fLast: 0,
951 fBits2: 0, fTimeDisplay:
false, fTimeFormat:
"", fLabels: null });
954 JSROOT.extend(obj, { fLineColor: 1, fLineStyle : 1, fLineWidth : 1 });
957 JSROOT.extend(obj, { fFillColor: 0, fFillStyle : 0 } );
960 JSROOT.extend(obj, { fMarkerColor: 1, fMarkerStyle : 1, fMarkerSize : 1. });
963 JSROOT.Create(
"TObject", obj);
964 JSROOT.Create(
"TAttLine", obj);
965 JSROOT.extend(obj, { fX1: 0, fX2: 1, fY1: 0, fY2: 1 });
968 JSROOT.Create(
"TObject", obj);
969 JSROOT.Create(
"TAttLine", obj);
970 JSROOT.Create(
"TAttFill", obj);
971 JSROOT.extend(obj, { fX1: 0, fX2: 1, fY1: 0, fY2: 1 });
974 JSROOT.Create(
"TBox", obj);
975 JSROOT.extend(obj, { fX1NDC : 0., fY1NDC: 0, fX2NDC: 1, fY2NDC: 1,
976 fBorderSize: 0, fInit: 1, fShadowColor: 1,
977 fCornerRadius: 0, fOption:
"blNDC", fName:
"title" });
980 JSROOT.extend(obj, { fTextAngle: 0, fTextSize: 0, fTextAlign: 22, fTextColor: 1, fTextFont: 42});
983 JSROOT.Create(
"TPave", obj);
984 JSROOT.Create(
"TAttText", obj);
985 JSROOT.extend(obj, { fLabel:
"", fLongest: 27, fMargin: 0.05, fLines: JSROOT.Create(
"TList") });
988 JSROOT.Create(
"TPaveText", obj);
989 JSROOT.extend(obj, { fOptFit: 0, fOptStat: 0, fFitFormat:
"", fStatFormat:
"", fParent: null });
992 JSROOT.Create(
"TObject", obj);
993 JSROOT.extend(obj, { fString:
"" });
996 JSROOT.Create(
"TNamed", obj);
997 JSROOT.Create(
"TAttLine", obj);
998 JSROOT.Create(
"TAttFill", obj);
999 JSROOT.Create(
"TAttMarker", obj);
1001 JSROOT.extend(obj, {
1003 fXaxis: JSROOT.Create(
"TAxis"),
1004 fYaxis: JSROOT.Create(
"TAxis"),
1005 fZaxis: JSROOT.Create(
"TAxis"),
1006 fBarOffset: 0, fBarWidth: 1000, fEntries: 0.,
1007 fTsumw: 0., fTsumw2: 0., fTsumwx: 0., fTsumwx2: 0.,
1008 fMaximum: -1111., fMinimum: -1111, fNormFactor: 0., fContour: [],
1009 fSumw2: [], fOption:
"",
1010 fFunctions: JSROOT.Create(
"TList"),
1011 fBufferSize: 0, fBuffer: [], fBinStatErrOpt: 0 });
1018 JSROOT.Create(
"TH1", obj);
1022 JSROOT.Create(
"TH1", obj);
1023 JSROOT.extend(obj, { fScalefactor: 1., fTsumwy: 0., fTsumwy2: 0, fTsumwxy : 0});
1030 JSROOT.Create(
"TH2", obj);
1034 JSROOT.Create(
"TNamed", obj);
1035 JSROOT.Create(
"TAttLine", obj);
1036 JSROOT.Create(
"TAttFill", obj);
1037 JSROOT.Create(
"TAttMarker", obj);
1038 JSROOT.extend(obj, { fFunctions: JSROOT.Create(
"TList"), fHistogram: null,
1039 fMaxSize: 0, fMaximum:-1111, fMinimum:-1111, fNpoints: 0, fX: [], fY: [] });
1042 JSROOT.Create(
"TNamed", obj);
1043 JSROOT.extend(obj, { fFunctions: JSROOT.Create(
"TList"), fGraphs: JSROOT.Create(
"TList"),
1044 fHistogram: null, fMaximum: -1111, fMinimum: -1111 });
1047 JSROOT.Create(
"TLine", obj);
1048 JSROOT.Create(
"TAttText", obj);
1049 JSROOT.extend(obj, { _fChopt:
"", fFunctionName:
"", fGridLength: 0,
1050 fLabelColor: 1, fLabelFont: 42, fLabelOffset: 0.005, fLabelSize: 0.035,
1051 fName:
"", fNdiv: 12, fTickSize: 0.02, fTimeFormat:
"",
1052 fTitle:
"", fTitleOffset: 1, fTitleSize: 0.035,
1053 fWmax: 100, fWmin: 0 });
1058 obj._typename =
typename;
1059 this.addMethods(obj);
1064 JSROOT.CreateTList =
function() {
return JSROOT.Create(
"TList"); }
1065 JSROOT.CreateTAxis =
function() {
return JSROOT.Create(
"TAxis"); }
1067 JSROOT.CreateTH1 =
function(nbinsx) {
1069 var histo = JSROOT.extend(JSROOT.Create(
"TH1I"),
1070 { fName:
"dummy_histo_" + this.id_counter++, fTitle:
"dummytitle" });
1072 if (nbinsx!==undefined) {
1073 histo.fNcells = nbinsx+2;
1074 for (var i=0;i<histo.fNcells;++i) histo.fArray.push(0);
1075 JSROOT.extend(histo.fXaxis, { fNbins: nbinsx, fXmin: 0, fXmax: nbinsx });
1080 JSROOT.CreateTH2 =
function(nbinsx, nbinsy) {
1082 var histo = JSROOT.extend(JSROOT.Create(
"TH2I"),
1083 { fName:
"dummy_histo_" + this.id_counter++, fTitle:
"dummytitle" });
1085 if ((nbinsx!==undefined) && (nbinsy!==undefined)) {
1086 histo.fNcells = (nbinsx+2) * (nbinsy+2);
1087 for (var i=0;i<histo.fNcells;++i) histo.fArray.push(0);
1088 JSROOT.extend(histo.fXaxis, { fNbins: nbinsx, fXmin: 0, fXmax: nbinsx });
1089 JSROOT.extend(histo.fYaxis, { fNbins: nbinsy, fXmin: 0, fXmax: nbinsy });
1094 JSROOT.CreateTGraph =
function(npoints, xpts, ypts) {
1095 var graph = JSROOT.extend(JSROOT.Create(
"TGraph"),
1096 { fBits: 0x3000408, fName:
"dummy_graph_" + this.id_counter++, fTitle:
"dummytitle" });
1099 graph.fMaxSize = graph.fNpoints = npoints;
1101 var usex = (typeof xpts ==
'object') && (xpts.length === npoints);
1102 var usey = (typeof ypts ==
'object') && (ypts.length === npoints);
1104 for (var i=0;i<npoints;++i) {
1105 graph.fX.push(usex ? xpts[i] : i/npoints);
1106 graph.fY.push(usey ? ypts[i] : i/npoints);
1113 JSROOT.CreateTMultiGraph =
function() {
1114 var mgraph = JSROOT.Create(
"TMultiGraph");
1115 for(var i=0; i<arguments.length; ++i)
1116 mgraph.fGraphs.Add(arguments[i],
"");
1120 JSROOT.methodsCache = {};
1122 JSROOT.getMethods =
function(
typename, obj) {
1123 var m = JSROOT.methodsCache[
typename];
1125 if (m !== undefined)
return m;
1129 if ((
typename==
"TObject") || (
typename==
"TNamed") || ((obj!==undefined) && (
'fBits' in obj))) {
1130 m.TestBit =
function (f) {
return (this.fBits & f) != 0; };
1131 m.InvertBit =
function (f) { this.fBits = this.fBits ^ (f & 0xffffff); };
1134 if ((
typename ===
'TList') || (
typename ===
'THashList')) {
1135 m.Clear =
function() {
1139 m.Add =
function(obj,opt) {
1141 this.opt.push((opt && typeof opt==
'string') ? opt :
"");
1143 m.AddFirst =
function(obj,opt) {
1144 this.arr.unshift(obj);
1145 this.opt.unshift((opt && typeof opt==
'string') ? opt :
"");
1147 m.RemoveAt =
function(indx) {
1148 this.arr.splice(indx, 1);
1149 this.opt.splice(indx, 1);
1153 if ((
typename ===
"TPaveText") || (
typename ===
"TPaveStats")) {
1154 m.AddText =
function(txt) {
1155 this.fLines.Add({ fTitle: txt, fTextColor: 1 });
1157 m.Clear =
function() {
1158 this.fLines.Clear();
1162 if (
typename.indexOf(
"TF1") == 0) {
1163 m.addFormula =
function(obj) {
1164 if (obj==null)
return;
1165 if (!(
'formulas' in
this)) this.formulas = [];
1166 this.formulas.push(obj);
1169 m.evalPar =
function(x) {
1170 if (! (
'_func' in
this) || (this._title !== this.fTitle)) {
1172 var _func = this.fTitle;
1174 if (
'formulas' in
this)
1175 for (var i=0;i<this.formulas.length;++i)
1176 while (_func.indexOf(
this.formulas[i].fName) >= 0)
1177 _func = _func.replace(
this.formulas[i].fName,
this.formulas[i].fTitle);
1178 _func = _func.replace(/\b(abs)\b/g,
'TMath::Abs');
1179 _func = _func.replace(
'TMath::Exp(',
'Math.exp(');
1180 _func = _func.replace(
'TMath::Abs(',
'Math.abs(');
1181 if (typeof JSROOT.Math ==
'object') {
1182 this._math = JSROOT.Math;
1183 _func = _func.replace(
'TMath::Prob(',
'this._math.Prob(');
1184 _func = _func.replace(
'gaus(',
'this._math.gaus(this, x, ');
1185 _func = _func.replace(
'gausn(',
'this._math.gausn(this, x, ');
1186 _func = _func.replace(
'expo(',
'this._math.expo(this, x, ');
1187 _func = _func.replace(
'landau(',
'this._math.landau(this, x, ');
1188 _func = _func.replace(
'landaun(',
'this._math.landaun(this, x, ');
1190 _func = _func.replace(
'pi',
'Math.PI');
1191 for (var i=0;i<this.fNpar;++i)
1192 while(_func.indexOf(
'['+i+
']') != -1)
1193 _func = _func.replace(
'['+i+
']',
this.GetParValue(i));
1194 _func = _func.replace(/\b(sin)\b/gi,
'Math.sin');
1195 _func = _func.replace(/\b(cos)\b/gi,
'Math.cos');
1196 _func = _func.replace(/\b(tan)\b/gi,
'Math.tan');
1197 _func = _func.replace(/\b(exp)\b/gi,
'Math.exp');
1199 this._func =
new Function(
"x",
"return " + _func).bind(
this);
1200 this._title = this.fTitle;
1203 return this._func(x);
1205 m.GetParName =
function(n) {
1206 if ((
'fFormula' in
this) && (
'fParams' in this.fFormula))
return this.fFormula.fParams[n].first;
1207 if (
'fNames' in
this)
return this.fNames[n];
1210 m.GetParValue =
function(n) {
1211 if ((
'fFormula' in
this) && (
'fClingParameters' in this.fFormula))
return this.fFormula.fClingParameters[n];
1212 if ((
'fParams' in
this) && (this.fParams!=null))
return this.fParams[n];
1217 if ((
typename.indexOf(
"TGraph") == 0) || (
typename ==
"TCutG")) {
1219 m.IsInside =
function(xp,yp) {
1220 var j = this.fNpoints - 1, x = this.fX, y = this.fY;
1221 var oddNodes =
false;
1223 for (var i=0; i<this.fNpoints; ++i) {
1224 if ((y[i]<yp && y[j]>=yp) || (y[j]<yp && y[i]>=yp)) {
1225 if (x[i]+(yp-y[i])/(y[j]-y[i])*(x[j]-x[i])<xp) {
1226 oddNodes = !oddNodes;
1236 if (
typename.indexOf(
"TH1") == 0 ||
1237 typename.indexOf(
"TH2") == 0 ||
1238 typename.indexOf(
"TH3") == 0) {
1239 m.getBinError =
function(bin) {
1244 if (bin >= this.fNcells) bin = this.fNcells - 1;
1245 if (bin < 0) bin = 0;
1246 if (bin < this.fSumw2.length)
1247 return Math.sqrt(this.fSumw2[bin]);
1248 return Math.sqrt(Math.abs(
this.fArray[bin]));
1250 m.setBinContent =
function(bin, content) {
1254 if ((bin>=0) && (bin<this.fArray.length))
1255 this.fArray[bin] = content;
1259 if (
typename.indexOf(
"TH1") == 0) {
1260 m.getBin =
function(x) {
return x; }
1261 m.getBinContent =
function(bin) {
return this.fArray[bin]; }
1264 if (
typename.indexOf(
"TH2") == 0) {
1265 m.getBin =
function(x, y) {
return (x + (this.fXaxis.fNbins+2) * y); }
1266 m.getBinContent =
function(x, y) {
return this.fArray[this.getBin(x, y)]; }
1269 if (
typename.indexOf(
"TH3") == 0) {
1270 m.getBin =
function(x, y, z) {
return (x + (this.fXaxis.fNbins+2) * (y + (this.fYaxis.fNbins+2) * z)); }
1271 m.getBinContent =
function(x, y, z) {
return this.fArray[this.getBin(x, y, z)]; };
1274 if (
typename.indexOf(
"TProfile") == 0) {
1275 m.getBin =
function(x) {
return x; }
1276 m.getBinContent =
function(bin) {
1277 if (bin < 0 || bin >= this.fNcells)
return 0;
1278 if (this.fBinEntries[bin] < 1e-300)
return 0;
1279 if (!this.fArray)
return 0;
1280 return this.fArray[bin]/this.fBinEntries[bin];
1282 m.getBinEffectiveEntries =
function(bin) {
1283 if (bin < 0 || bin >= this.fNcells)
return 0;
1284 var sumOfWeights = this.fBinEntries[bin];
1285 if ( this.fBinSumw2 == null || this.fBinSumw2.length !=
this.fNcells) {
1287 return sumOfWeights;
1289 var sumOfWeightsSquare = this.fSumw2[bin];
1290 return ( sumOfWeightsSquare > 0 ? sumOfWeights * sumOfWeights / sumOfWeightsSquare : 0 );
1292 m.getBinError =
function(bin) {
1293 if (bin < 0 || bin >= this.fNcells)
return 0;
1294 var cont = this.fArray[bin],
1295 sum = this.fBinEntries[bin],
1296 err2 = this.fSumw2[bin],
1297 neff = this.getBinEffectiveEntries(bin);
1298 if (sum < 1e-300)
return 0;
1299 var EErrorType = { kERRORMEAN : 0, kERRORSPREAD : 1, kERRORSPREADI : 2, kERRORSPREADG : 3 };
1301 if (this.fErrorMode === EErrorType.kERRORSPREADG)
1302 return 1.0/Math.sqrt(sum);
1304 var contsum = cont/sum;
1305 var eprim2 = Math.abs(err2/sum - contsum*contsum);
1306 var eprim = Math.sqrt(eprim2);
1307 if (this.fErrorMode === EErrorType.kERRORSPREADI) {
1308 if (eprim != 0)
return eprim/Math.sqrt(neff);
1311 return 1.0/Math.sqrt(12*neff);
1316 if (this.fErrorMode === EErrorType.kERRORSPREAD)
return eprim;
1319 return (eprim/Math.sqrt(neff));
1323 JSROOT.methodsCache[
typename] = m;
1327 JSROOT.addMethods =
function(obj) {
1328 this.extend(obj, JSROOT.getMethods(obj._typename, obj));
1331 JSROOT.lastFFormat =
"";
1333 JSROOT.FFormat =
function(value, fmt) {
1337 if (!fmt) fmt =
"6.4g";
1339 JSROOT.lastFFormat =
"";
1342 var len = fmt.length;
1343 if (len<2)
return value.toFixed(4);
1344 var last = fmt.charAt(len-1);
1345 fmt = fmt.slice(0,len-1);
1347 var prec = fmt.indexOf(
".");
1348 if (prec<0) prec = 4;
else prec = Number(fmt.slice(prec+1));
1349 if (isNaN(prec) || (prec<0) || (prec==null)) prec = 4;
1351 var significance =
false;
1352 if ((last==
'e') || (last==
'E')) { isexp =
true; }
else
1353 if (last==
'Q') { isexp =
true; significance =
true; }
else
1354 if ((last==
'f') || (last==
'F')) { isexp =
false; }
else
1355 if (last==
'W') { isexp =
false; significance =
true; }
else
1356 if ((last==
'g') || (last==
'G')) {
1357 var se = JSROOT.FFormat(value, fmt+
'Q');
1358 var _fmt = JSROOT.lastFFormat;
1359 var sg = JSROOT.FFormat(value, fmt+
'W');
1361 if (se.length < sg.length) {
1362 JSROOT.lastFFormat = _fmt;
1373 if (significance) prec--;
1374 if (prec<0) prec = 0;
1376 JSROOT.lastFFormat =
'5.'+prec+
'e';
1378 return value.toExponential(prec);
1381 var sg = value.toFixed(prec);
1386 if ((value!=0) && (Number(sg)==0.) && (prec>0)) {
1387 prec = 20; sg = value.toFixed(prec);
1391 while ((l<sg.length) && (sg.charAt(l) ==
'0' || sg.charAt(l) ==
'-' || sg.charAt(l) ==
'.')) l++;
1393 var diff = sg.length - l - prec;
1394 if (sg.indexOf(
".")>l) diff--;
1398 if (prec<0) prec = 0;
else if (prec>20) prec = 20;
1399 sg = value.toFixed(prec);
1403 JSROOT.lastFFormat =
'5.'+prec+
'f';
1408 JSROOT.log10 =
function(n) {
1409 return Math.log(n) / Math.log(10);
1413 JSROOT.progress =
function(msg) {
1414 if ((msg !== undefined) && (typeof msg==
"string")) JSROOT.console(msg);
1417 JSROOT.Initialize =
function() {
1419 if (JSROOT.source_fullpath.length === 0)
return this;
1421 function window_on_load(func) {
1423 if (document.attachEvent ? document.readyState ===
'complete' : document.readyState !==
'loading')
1426 window.onload = func;
1431 var src = JSROOT.source_fullpath;
1433 if (JSROOT.GetUrlOption(
'gui', src) !== null)
1434 return window_on_load(
function() { JSROOT.BuildSimpleGUI(); } );
1436 if ( typeof define ===
"function" && define.amd )
1437 return window_on_load(
function() { JSROOT.BuildSimpleGUI(
'check_existing_elements'); } );
1440 if (JSROOT.GetUrlOption(
'io', src)!=null) prereq +=
"io;";
1441 if (JSROOT.GetUrlOption(
'2d', src)!=null) prereq +=
"2d;";
1442 if (JSROOT.GetUrlOption(
'jq2d', src)!=null) prereq +=
"jq2d;";
1443 if (JSROOT.GetUrlOption(
'more2d', src)!=null) prereq +=
"more2d;";
1444 if (JSROOT.GetUrlOption(
'geo', src)!=null) prereq +=
"geo;";
1445 if (JSROOT.GetUrlOption(
'3d', src)!=null) prereq +=
"3d;";
1446 if (JSROOT.GetUrlOption(
'math', src)!=null) prereq +=
"math;";
1447 if (JSROOT.GetUrlOption(
'mathjax', src)!=null) prereq +=
"mathjax;";
1448 var user = JSROOT.GetUrlOption(
'load', src);
1449 if ((user!=null) && (user.length>0)) prereq +=
"load:" + user;
1450 var onload = JSROOT.GetUrlOption(
'onload', src);
1451 var bower = JSROOT.GetUrlOption(
'bower', src);
1453 if (bower.length>0) JSROOT.bower_dir = bower;
else
1454 if (JSROOT.source_dir.indexOf(
"jsroot/") == JSROOT.source_dir.length - 7)
1455 JSROOT.bower_dir = JSROOT.source_dir.substr(0, JSROOT.source_dir.length - 7);
1456 if (JSROOT.bower_dir.length > 0) console.log(
"Set JSROOT.bower_dir to " + JSROOT.bower_dir);
1459 if ((prereq.length>0) || (onload!=null))
1460 window_on_load(
function() {
1461 if (prereq.length>0) JSROOT.AssertPrerequisites(prereq, onload);
else
1463 onload = JSROOT.findFunction(onload);
1464 if (typeof onload ==
'function') onload();
1471 return JSROOT.Initialize();