00001
00002
00003
00004
00005
00006 function ResetUI() {
00007 if (JSROOT.H('root') != null) {
00008 JSROOT.H('root').clear();
00009 JSROOT.DelHList('root');
00010 }
00011 $('#browser').get(0).innerHTML = '';
00012 }
00013
00014 function guiLayout() {
00015 var res = 'collapsible';
00016 var selects = document.getElementById("layout");
00017 if (selects)
00018 res = selects.options[selects.selectedIndex].text;
00019 return res;
00020 }
00021
00022 function setGuiLayout(value) {
00023 var selects = document.getElementById("layout");
00024 if (!selects) return;
00025
00026 for (var i in selects.options) {
00027 var s = selects.options[i].text;
00028 if (typeof s == 'undefined') continue;
00029 if ((s == value) || (s.replace(/ /g,"") == value)) {
00030 selects.selectedIndex = i;
00031 break;
00032 }
00033 }
00034 }
00035
00036 function BuildNoBrowserGUI(online) {
00037 var itemsarr = [];
00038 var optionsarr = [];
00039 var running_request = {};
00040
00041 var filename = null;
00042 if (!online) {
00043 filename = JSROOT.GetUrlOption("file");
00044 var filesdir = JSROOT.GetUrlOption("path");
00045 if (filesdir!=null) filename = filesdir + filename;
00046 }
00047
00048 var itemname = JSROOT.GetUrlOption("item");
00049 if (itemname) itemsarr.push(itemname);
00050 var opt = JSROOT.GetUrlOption("opt");
00051 if (opt) optionsarr.push(opt);
00052
00053 var items = JSROOT.GetUrlOption("items");
00054 if (items != null) {
00055 items = JSON.parse(items);
00056 for (var i in items) itemsarr.push(items[i]);
00057 }
00058
00059 var opts = JSROOT.GetUrlOption("opts");
00060 if (opts!=null) {
00061 opts = JSON.parse(opts);
00062 for (var i in opts) optionsarr.push(opts[i]);
00063 }
00064
00065
00066 var layout = JSROOT.GetUrlOption("layout");
00067 if (layout=="") layout = null;
00068
00069 var monitor = JSROOT.GetUrlOption("monitoring");
00070 if (monitor == "") monitor = 3000; else
00071 if (monitor != null) monitor = parseInt(monitor);
00072
00073 var divid = online ? "onlineGUI" : "simpleGUI";
00074
00075 $('#'+divid).empty();
00076
00077 $('html').css('height','100%');
00078 $('body').css('min-height','100%').css('margin','0px').css("overflow", "hidden");
00079
00080 $('#'+divid).css("position", "absolute")
00081 .css("left", "1px")
00082 .css("top", "1px")
00083 .css("bottom", "1px")
00084 .css("right", "1px");
00085
00086 var objpainter = null;
00087 var mdi = null;
00088
00089 function file_error(str) {
00090 if ((objpainter == null) && (mdi==null))
00091 $('#'+divid).append("<h4>" + str + "</h4>");
00092 }
00093
00094 if ((filename == null) && !online) {
00095 return file_error('filename not specified');
00096 }
00097
00098 if (itemsarr.length == 0) {
00099 return file_error('itemname not specified');
00100 }
00101
00102 var title = online ? "Online" : ("File: " + filename);
00103 if (itemsarr.length == 1) title += " item: " + itemsarr[0];
00104 else title += " items: " + itemsarr.toString();
00105 document.title = title;
00106
00107 function draw_object(indx, obj) {
00108 document.body.style.cursor = 'wait';
00109 if (obj==null) {
00110 file_error("object " + itemsarr[indx] + " not found");
00111 } else
00112 if (mdi) {
00113 var frame = mdi.FindFrame(itemsarr[indx], true);
00114 mdi.ActivateFrame(frame);
00115 JSROOT.redraw($(frame).attr('id'), obj, optionsarr[indx]);
00116 } else {
00117 objpainter = JSROOT.redraw(divid, obj, optionsarr[indx]);
00118 }
00119 document.body.style.cursor = 'auto';
00120 running_request[indx] = false;
00121 }
00122
00123 function read_object(file, indx) {
00124
00125 if (itemsarr[indx]=="StreamerInfo")
00126 draw_object(indx, file.fStreamerInfos);
00127
00128 file.ReadObject(itemsarr[indx], function(obj) {
00129 draw_object(indx, obj);
00130 });
00131 }
00132
00133 function request_object(indx) {
00134
00135 if (running_request[indx]) return;
00136
00137 running_request[indx] = true;
00138
00139 var url = itemsarr[indx] + "/root.json.gz?compact=3";
00140
00141 var itemreq = JSROOT.NewHttpRequest(url, 'object', function(obj) {
00142 if ((obj != null) && (itemsarr[indx] === "StreamerInfo")
00143 && (obj['_typename'] === 'TList'))
00144 obj['_typename'] = 'TStreamerInfoList';
00145
00146 draw_object(indx, obj);
00147 });
00148
00149 itemreq.send(null);
00150 }
00151
00152 function read_all_objects() {
00153
00154 if (online) {
00155 for (var i in itemsarr)
00156 request_object(i);
00157 return;
00158 }
00159
00160 for (var i in itemsarr)
00161 if (running_request[i]) {
00162 console.log("Request for item " + itemsarr[i] + " still running");
00163 return;
00164 }
00165
00166 new JSROOT.TFile(filename, function(file) {
00167 if (file==null) return file_error("file " + filename + " cannot be opened");
00168
00169 for (var i in itemsarr) {
00170 running_request[i] = true;
00171 read_object(file, i);
00172 }
00173 });
00174 }
00175
00176 if (itemsarr.length > 1) {
00177 if ((layout==null) || (layout=='collapsible') || (layout == "")) {
00178 var divx = 2; divy = 1;
00179 while (divx*divy < itemsarr.length) {
00180 if (divy<divx) divy++; else divx++;
00181 }
00182 layout = 'grid' + divx + 'x' + divy;
00183 }
00184
00185 if (layout=='tabs')
00186 mdi = new JSROOT.TabsDisplay(divid);
00187 else
00188 mdi = new JSROOT.GridDisplay(divid, layout);
00189
00190
00191 for (var i in itemsarr)
00192 mdi.CreateFrame(itemsarr[i]);
00193 }
00194
00195 read_all_objects();
00196
00197 if (monitor>0)
00198 setInterval(read_all_objects, monitor);
00199
00200 JSROOT.RegisterForResize(function() { if (objpainter) objpainter.CheckResize(); if (mdi) mdi.CheckResize(); });
00201 }
00202
00203 function ReadFile(filename, checkitem) {
00204 var navigator_version = navigator.appVersion;
00205 if (typeof ActiveXObject == "function") {
00206
00207 if ((navigator_version.indexOf("MSIE 8") != -1) ||
00208 (navigator_version.indexOf("MSIE 7") != -1)) {
00209 alert("You need at least MS Internet Explorer version 9.0. Note you can also use any other web browser");
00210 return;
00211 }
00212 }
00213 else {
00214
00215 if ((navigator_version.indexOf("Windows NT") == -1) &&
00216 (navigator_version.indexOf("Safari") != -1) &&
00217 (navigator_version.indexOf("Version/5.1.7") != -1)) {
00218 alert("There are know issues with Safari 5.1.7 on MacOS X. It may become unresponsive or even hangs. You can use any other web browser");
00219 return;
00220 }
00221 }
00222
00223 if (filename==null) {
00224 filename = $("#urlToLoad").val();
00225 filename.trim();
00226 } else {
00227 $("#urlToLoad").val(filename);
00228 }
00229 if (filename.length == 0) return;
00230
00231 var layout = null;
00232 var itemsarr = [];
00233 var optionsarr = [];
00234 if (checkitem) {
00235 var itemname = JSROOT.GetUrlOption("item");
00236 if (itemname) itemsarr.push(itemname);
00237 var items = JSROOT.GetUrlOption("items");
00238 if (items!=null) {
00239 items = JSON.parse(items);
00240 for (var i in items) itemsarr.push(items[i]);
00241 }
00242
00243 layout = JSROOT.GetUrlOption("layout");
00244 if (layout=="") layout = null;
00245
00246 var opt = JSROOT.GetUrlOption("opt");
00247 if (opt) optionsarr.push(opt);
00248 var opts = JSROOT.GetUrlOption("opts");
00249 if (opts!=null) {
00250 opts = JSON.parse(opts);
00251 for (var i in opts) optionsarr.push(opts[i]);
00252 }
00253 }
00254
00255 if (layout==null)
00256 layout = guiLayout();
00257 else
00258 setGuiLayout(layout);
00259
00260 var painter = new JSROOT.HierarchyPainter('root', 'browser');
00261
00262 painter.SetDisplay(layout, 'right-div');
00263
00264 painter.OpenRootFile(filename, function() {
00265 painter.displayAll(itemsarr, optionsarr);
00266 });
00267 }
00268
00269 function ProcessResize(direct)
00270 {
00271 if (direct) document.body.style.cursor = 'wait';
00272
00273 JSROOT.H('root').CheckResize();
00274
00275 if (direct) document.body.style.cursor = 'auto';
00276 }
00277
00278 function AddInteractions() {
00279 var drag_sum = 0;
00280
00281 var drag_move = d3.behavior.drag()
00282 .origin(Object)
00283 .on("dragstart", function() {
00284 d3.event.sourceEvent.preventDefault();
00285
00286 drag_sum = 0;
00287 })
00288 .on("drag", function() {
00289 d3.event.sourceEvent.preventDefault();
00290 drag_sum += d3.event.dx;
00291
00292 d3.event.sourceEvent.stopPropagation();
00293 })
00294 .on("dragend", function() {
00295 d3.event.sourceEvent.preventDefault();
00296
00297
00298 var width = d3.select("#left-div").style('width');
00299 width = (parseInt(width.substr(0, width.length - 2)) + Number(drag_sum)).toString() + "px";
00300 d3.select("#left-div").style('width', width);
00301
00302 var left = d3.select("#separator-div").style('left');
00303 left = parseInt(left.substr(0, left.length - 2)) + Number(drag_sum);
00304 d3.select("#separator-div").style('left',left.toString() + "px");
00305 d3.select("#right-div").style('left',(left+6).toString() + "px");
00306
00307 ProcessResize(true);
00308 });
00309
00310 d3.select("#separator-div").call(drag_move);
00311
00312 JSROOT.RegisterForResize(ProcessResize);
00313
00314
00315
00316 document.getElementById("layout").onchange = function() {
00317 if (JSROOT.H('root'))
00318 JSROOT.H('root').SetDisplay(guiLayout(), "right-div");
00319 }
00320 }
00321
00322
00323 function BuildOnlineGUI() {
00324 var myDiv = $('#onlineGUI');
00325 if (!myDiv) {
00326 alert("You have to define a div with id='onlineGUI'!");
00327 return;
00328 }
00329
00330 JSROOT.Painter.readStyleFromURL();
00331
00332 if (JSROOT.GetUrlOption("nobrowser")!=null)
00333 return BuildNoBrowserGUI(true);
00334
00335 var guiCode = "<div id='overlay'><font face='Verdana' size='1px'> JSROOT version " + JSROOT.version + " </font></div>"
00336
00337 guiCode += '<div id="left-div" class="column"><br/>'
00338 + ' <h1><font face="Verdana" size="4">ROOT online server</font></h1>'
00339 + ' Hierarchy in <a href="h.json">json</a> and <a href="h.xml">xml</a> format<br/><br/>'
00340 + ' <input type="checkbox" name="monitoring" id="monitoring"/> Monitoring '
00341 + ' <select style="padding:2px; margin-left:10px; margin-top:5px;" id="layout">'
00342 + ' <option>collapsible</option><option>grid 2x2</option><option>grid 3x3</option><option>grid 4x4</option><option>tabs</option>'
00343 + ' </select>'
00344 + ' <div id="browser"></div>'
00345 + '</div>'
00346 + '<div id="separator-div" class="column"></div>'
00347 + '<div id="right-div" class="column"></div>';
00348
00349 $('#onlineGUI').empty();
00350 $('#onlineGUI').append(guiCode);
00351
00352 var layout = JSROOT.GetUrlOption("layout");
00353 if ((layout=="") || (layout==null))
00354 layout = guiLayout();
00355 else
00356 setGuiLayout(layout);
00357
00358 var monitor = JSROOT.GetUrlOption("monitoring");
00359
00360 var itemsarr = [], optionsarr = [];
00361 var itemname = JSROOT.GetUrlOption("item");
00362 if (itemname) itemsarr.push(itemname);
00363 var items = JSROOT.GetUrlOption("items");
00364 if (items!=null) {
00365 items = JSON.parse(items);
00366 for (var i in items) itemsarr.push(items[i]);
00367 }
00368
00369 var opt = JSROOT.GetUrlOption("opt");
00370 if (opt) optionsarr.push(opt);
00371 var opts = JSROOT.GetUrlOption("opts");
00372 if (opts!=null) {
00373 opts = JSON.parse(opts);
00374 for (var i in opts) optionsarr.push(opts[i]);
00375 }
00376
00377 var h = new JSROOT.HierarchyPainter("root", "browser");
00378
00379 h.SetDisplay(layout, 'right-div');
00380
00381 h.EnableMonitoring(monitor!=null);
00382 $("#monitoring")
00383 .prop('checked', monitor!=null)
00384 .click(function() {
00385 h.EnableMonitoring(this.checked);
00386 if (this.checked) h.updateAll();
00387 });
00388
00389 h.OpenOnline("", function() {
00390 h.displayAll(itemsarr, optionsarr);
00391 });
00392
00393 setInterval(function() { if (h.IsMonitoring()) h.updateAll(); }, h.MonitoringInterval());
00394
00395 AddInteractions();
00396 }
00397
00398 function BuildSimpleGUI() {
00399
00400 if (document.getElementById('onlineGUI')) return BuildOnlineGUI();
00401
00402 var myDiv = $('#simpleGUI');
00403 if (!myDiv) return;
00404
00405 JSROOT.Painter.readStyleFromURL();
00406
00407 if (JSROOT.GetUrlOption("nobrowser")!=null)
00408 return BuildNoBrowserGUI(false);
00409
00410 var files = JSROOT.GetUrlOption("files");
00411 if (files==null) files = myDiv.attr("files");
00412 var filesdir = JSROOT.GetUrlOption("path");
00413 if (filesdir==null) filesdir = myDiv.attr("path");
00414
00415 if (files==null) files = "files/hsimple.root";
00416 if (filesdir==null) filesdir = "";
00417 var arrFiles = files.split(';');
00418
00419 var guiCode = "<div id='overlay'><font face='Verdana' size='1px'> JSROOT version " + JSROOT.version + " </font></div>"
00420
00421 guiCode += "<div id='left-div' class='column'>\n"
00422 +"<h1><font face='Verdana' size='4'>Read a ROOT file with Javascript</font></h1>\n"
00423 +"<p><b>Select a ROOT file to read, or enter a url (*): </b><br/>\n"
00424 +'<small><sub>*: Other URLs might not work because of cross site scripting protection, see e.g. <a href="https://developer.mozilla.org/en/http_access_control">developer.mozilla.org/http_access_control</a> on how to avoid it.</sub></small></p>'
00425 +'<form name="ex">'
00426 +'<div style="margin-left:10px;">'
00427 + '<input type="text" name="state" value="" size="30" id="urlToLoad"/><br/>'
00428 +'<select name="s" size="1" '
00429 +'onchange="document.ex.state.value = document.ex.s.options[document.ex.s.selectedIndex].value;document.ex.s.selectedIndex=0;document.ex.s.value=\'\'">'
00430 +'<option value = " " selected = "selected"> </option>';
00431 for (var i=0; i<arrFiles.length; i++) {
00432 guiCode += '<option value = "' + filesdir + arrFiles[i] + '">' + arrFiles[i] + '</option>';
00433 }
00434 guiCode += '</select>'
00435 +'</div>'
00436 +'<input style="padding:2px; margin-left:10px; margin-top:5px;"'
00437 +' onclick="ReadFile()" type="button" title="Read the Selected File" value="Load"/>'
00438 +'<input style="padding:2px; margin-left:10px;"'
00439 +' onclick="ResetUI()" type="button" title="Clear All" value="Reset"/>'
00440 +'<select style="padding:2px; margin-left:10px; margin-top:5px;" id="layout">'
00441 +' <option>collapsible</option><option>grid 2x2</option><option>grid 3x3</option><option>grid 4x4</option><option>tabs</option>'
00442 +'</select>'
00443 +'</form>'
00444 +'<br/>'
00445 +'<div id="browser"></div>'
00446 +'</div>'
00447 +'<div id="separator-div" class="column"></div>'
00448 +'<div id="right-div" class="column"></div>';
00449
00450 $('#simpleGUI').empty();
00451 $('#simpleGUI').append(guiCode);
00452
00453
00454 AddInteractions();
00455
00456 var filename = JSROOT.GetUrlOption("file");
00457 if ((typeof filename == 'string') && (filename.length>0))
00458 ReadFile(filename, true);
00459 }