00001
00002
00003
00004
00005
00006 (function( factory ) {
00007 if ( typeof define === "function" && define.amd ) {
00008
00009 define( ['jquery', 'jquery-ui', 'd3', 'JSRootPainter'], factory );
00010 } else {
00011
00012 if (typeof jQuery == 'undefined')
00013 throw new Error('jQuery not defined', 'JSRootPainter.jquery.js');
00014
00015 if (typeof jQuery.ui == 'undefined')
00016 throw new Error('jQuery-ui not defined', 'JSRootPainter.jquery.js');
00017
00018 if (typeof d3 != 'object')
00019 throw new Error('This extension requires d3.v3.js', 'JSRootPainter.jquery.js');
00020
00021 if (typeof JSROOT == 'undefined')
00022 throw new Error('JSROOT is not defined', 'JSRootPainter.jquery.js');
00023
00024 if (typeof JSROOT.Painter != 'object')
00025 throw new Error('JSROOT.Painter not defined', 'JSRootPainter.jquery.js');
00026
00027
00028 factory(jQuery, jQuery.ui, d3, JSROOT);
00029 }
00030 } (function($, myui, d3, JSROOT) {
00031
00032 var hpainter = null;
00033
00034 if ( typeof define === "function" && define.amd )
00035 JSROOT.loadScript('$$$style/JSRootInterface.css');
00036
00037 ResetUI = function() {
00038 if (hpainter) hpainter.clear(true);
00039 }
00040
00041 guiLayout = function() {
00042 var res = 'collapsible';
00043 var selects = document.getElementById("layout");
00044 if (selects)
00045 res = selects.options[selects.selectedIndex].text;
00046 return res;
00047 }
00048
00049 setGuiLayout = function(value) {
00050 var selects = document.getElementById("layout");
00051 if (!selects) return;
00052
00053 for (var i in selects.options) {
00054 var s = selects.options[i].text;
00055 if (typeof s == 'undefined') continue;
00056 if ((s == value) || (s.replace(/ /g,"") == value)) {
00057 selects.selectedIndex = i;
00058 break;
00059 }
00060 }
00061 }
00062
00063 ReadFile = function() {
00064 var filename = $("#urlToLoad").val();
00065 filename.trim();
00066 if (filename.length == 0) return;
00067
00068 if (hpainter==null) alert("Hierarchy painter not initialized");
00069 if ((filename.lastIndexOf(".json") == filename.length-5) ||
00070 (filename.lastIndexOf(".JSON") == filename.length-5))
00071 hpainter.OpenJsonFile(filename);
00072 else
00073 hpainter.OpenRootFile(filename);
00074 }
00075
00076 BuildSimpleGUI = function() {
00077
00078 if (JSROOT.GetUrlOption("nobrowser")!=null)
00079 return JSROOT.BuildNobrowserGUI();
00080
00081 var myDiv = $('#simpleGUI');
00082 var online = false;
00083
00084 if (myDiv.length==0) {
00085 myDiv = $('#onlineGUI');
00086 if (myDiv.length==0) return alert('no div for simple gui found');
00087 online = true;
00088 }
00089
00090 JSROOT.Painter.readStyleFromURL();
00091
00092 var guiCode = "<div id='left-div' class='column' style='top:1px; bottom:1px'>";
00093
00094 if (online) {
00095 guiCode += '<h1><font face="Verdana" size="4"><div id="toptitle">ROOT online server</div></font></h1>'
00096 + "<p><font face='Verdana' size='1px'><a href='https://github.com/linev/jsroot'>JSROOT</a> version <span style='color:green'><b>" + JSROOT.version + "</b></span></font></p>"
00097 + '<p> Hierarchy in <a href="h.json">json</a> and <a href="h.xml">xml</a> format</p>'
00098 + ' <input type="checkbox" name="monitoring" id="monitoring"/> Monitoring '
00099 + ' <select style="padding:2px; margin-left:10px; margin-top:5px;" id="layout">'
00100 +' <option>simple</option><option>collapsible</option><option>flex</option><option>tabs</option><option>grid 1x2</option><option>grid 2x2</option><option>grid 1x3</option><option>grid 2x3</option><option>grid 3x3</option><option>grid 4x4</option>'
00101 + ' </select>';
00102 } else {
00103
00104 var files = myDiv.attr("files");
00105 var path = JSROOT.GetUrlOption("path");
00106 if (path==null) path = myDiv.attr("path");
00107 if (path==null) path = "";
00108
00109 if (files==null) files = "../files/hsimple.root";
00110 var arrFiles = files.split(';');
00111
00112 guiCode += "<h1><font face='Verdana' size='4'>Read a ROOT file</font></h1>"
00113 + "<p><font face='Verdana' size='1px'><a href='https://root.cern.ch/js/'>JSROOT</a> version <span style='color:green'><b>" + JSROOT.version + "</b></span></font></p>";
00114
00115 if (JSROOT.GetUrlOption("noselect")==null) {
00116 guiCode += '<form name="ex">'
00117 +'<input type="text" name="state" value="" style="width:95%; margin-top:5px;" id="urlToLoad"/>'
00118 +'<select name="s" style="width:65%; margin-top:5px;" '
00119 +'onchange="document.ex.state.value = document.ex.s.options[document.ex.s.selectedIndex].value;document.ex.s.selectedIndex=0;document.ex.s.value=\'\'">'
00120 +'<option value=" " selected="selected"> </option>';
00121 for (var i in arrFiles)
00122 guiCode += '<option value = "' + path + arrFiles[i] + '">' + arrFiles[i] + '</option>';
00123 guiCode += '</select><br/>'
00124 +'<p><small><a href="https://github.com/linev/jsroot/blob/master/docs/JSROOT.md#reading-root-files-from-other-servers">Read docu</a>'
00125 +' how to open files from other servers.</small></p>'
00126 +'<input style="padding:2px; margin-top:5px;"'
00127 +' onclick="ReadFile()" type="button" title="Read the Selected File" value="Load"/>'
00128 +'<input style="padding:2px; margin-left:10px;"'
00129 +' onclick="ResetUI()" type="button" title="Clear All" value="Reset"/>'
00130 +'<select style="padding:2px; margin-left:10px; margin-top:5px;" title="layout kind" id="layout">'
00131 +' <option>simple</option><option>collapsible</option><option>flex</option><option>tabs</option><option>grid 1x2</option><option>grid 2x2</option><option>grid 1x3</option><option>grid 2x3</option><option>grid 3x3</option><option>grid 4x4</option>'
00132 +'</select><br/>'
00133 +'</form>';
00134 }
00135 }
00136
00137 guiCode += '<div id="browser"></div>'
00138 +'</div>'
00139 +'<div id="separator-div" style="top:1px; bottom:1px"></div>'
00140 +'<div id="right-div" class="column" style="top:1px; bottom:1px"></div>';
00141
00142 var drawDivId = 'right-div';
00143
00144 myDiv.empty().append(guiCode);
00145
00146 var h0 = null;
00147
00148 if (online) {
00149 if (typeof GetCachedHierarchy == 'function') h0 = GetCachedHierarchy();
00150 if (typeof h0 != 'object') h0 = "";
00151 }
00152
00153 hpainter = new JSROOT.HierarchyPainter('root', 'browser');
00154
00155 hpainter.SetDisplay(null, drawDivId);
00156
00157 JSROOT.Painter.ConfigureVSeparator(hpainter);
00158
00159
00160
00161 hpainter.StartGUI(h0, function() {
00162
00163 setGuiLayout(hpainter.GetLayout());
00164
00165
00166
00167 $("#layout").change(function() {
00168 if (hpainter) hpainter.SetDisplay(guiLayout(), drawDivId);
00169 });
00170
00171 if (online) {
00172 if ((hpainter.h!=null) && ('_toptitle' in hpainter.h))
00173 $("#toptitle").html(hpainter.h._toptitle);
00174 $("#monitoring")
00175 .prop('checked', hpainter.IsMonitoring())
00176 .click(function() {
00177 hpainter.EnableMonitoring(this.checked);
00178 hpainter.updateAll(!this.checked);
00179 });
00180 } else {
00181 var fname = "";
00182 hpainter.ForEachRootFile(function(item) { if (fname=="") fname = item._fullurl; });
00183 $("#urlToLoad").val(fname);
00184 }
00185 });
00186 }
00187
00188 return JSROOT;
00189
00190 }));
00191