otsdaq_utilities  v2_05_02_indev
JSRootInterface.js
1 // JSRootInterface.js
2 //
3 // default user interface for JavaScript ROOT Web Page.
4 //
5 
6 (function( factory ) {
7  if ( typeof define === "function" && define.amd ) {
8  // AMD. Register as an anonymous module.
9  define( ['jquery', 'jquery-ui', 'd3', 'JSRootPainter'], factory );
10  } else {
11 
12  if (typeof jQuery == 'undefined')
13  throw new Error('jQuery not defined', 'JSRootPainter.jquery.js');
14 
15  if (typeof jQuery.ui == 'undefined')
16  throw new Error('jQuery-ui not defined', 'JSRootPainter.jquery.js');
17 
18  if (typeof d3 != 'object')
19  throw new Error('This extension requires d3.v3.js', 'JSRootPainter.jquery.js');
20 
21  if (typeof JSROOT == 'undefined')
22  throw new Error('JSROOT is not defined', 'JSRootPainter.jquery.js');
23 
24  if (typeof JSROOT.Painter != 'object')
25  throw new Error('JSROOT.Painter not defined', 'JSRootPainter.jquery.js');
26 
27  // Browser globals
28  factory(jQuery, jQuery.ui, d3, JSROOT);
29  }
30 } (function($, myui, d3, JSROOT) {
31 
32  var hpainter = null;
33 
34  if ( typeof define === "function" && define.amd )
35  JSROOT.loadScript('$$$style/JSRootInterface.css');
36 
37  ResetUI = function() {
38  if (hpainter) hpainter.clear(true);
39  }
40 
41  guiLayout = function() {
42  var res = 'collapsible';
43  var selects = document.getElementById("layout");
44  if (selects)
45  res = selects.options[selects.selectedIndex].text;
46  return res;
47  }
48 
49  setGuiLayout = function(value) {
50  var selects = document.getElementById("layout");
51  if (!selects) return;
52 
53  for (var i in selects.options) {
54  var s = selects.options[i].text;
55  if (typeof s == 'undefined') continue;
56  if ((s == value) || (s.replace(/ /g,"") == value)) {
57  selects.selectedIndex = i;
58  break;
59  }
60  }
61  }
62 
63  ReadFile = function() {
64  var filename = $("#urlToLoad").val();
65  filename.trim();
66  if (filename.length == 0) return;
67 
68  if (hpainter==null) alert("Hierarchy painter not initialized");
69  if ((filename.lastIndexOf(".json") == filename.length-5) ||
70  (filename.lastIndexOf(".JSON") == filename.length-5))
71  hpainter.OpenJsonFile(filename);
72  else
73  hpainter.OpenRootFile(filename);
74  }
75 
76  BuildSimpleGUI = function() {
77 
78  if (JSROOT.GetUrlOption("nobrowser")!=null)
79  return JSROOT.BuildNobrowserGUI();
80 
81  var myDiv = $('#simpleGUI');
82  var online = false;
83 
84  if (myDiv.length==0) {
85  myDiv = $('#onlineGUI');
86  if (myDiv.length==0) return alert('no div for simple gui found');
87  online = true;
88  }
89 
90  JSROOT.Painter.readStyleFromURL();
91 
92  var guiCode = "<div id='left-div' class='column' style='top:1px; bottom:1px'>";
93 
94  if (online) {
95  guiCode += '<h1><font face="Verdana" size="4"><div id="toptitle">ROOT online server</div></font></h1>'
96  + "<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>"
97  + '<p> Hierarchy in <a href="h.json">json</a> and <a href="h.xml">xml</a> format</p>'
98  + ' <input type="checkbox" name="monitoring" id="monitoring"/> Monitoring '
99  + ' <select style="padding:2px; margin-left:10px; margin-top:5px;" id="layout">'
100  +' <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>'
101  + ' </select>';
102  } else {
103 
104  var files = myDiv.attr("files");
105  var path = JSROOT.GetUrlOption("path");
106  if (path==null) path = myDiv.attr("path");
107  if (path==null) path = "";
108 
109  if (files==null) files = "../files/hsimple.root";
110  var arrFiles = files.split(';');
111 
112  guiCode += "<h1><font face='Verdana' size='4'>Read a ROOT file</font></h1>"
113  + "<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>";
114 
115  if (JSROOT.GetUrlOption("noselect")==null) {
116  guiCode += '<form name="ex">'
117  +'<input type="text" name="state" value="" style="width:95%; margin-top:5px;" id="urlToLoad"/>'
118  +'<select name="s" style="width:65%; margin-top:5px;" '
119  +'onchange="document.ex.state.value = document.ex.s.options[document.ex.s.selectedIndex].value;document.ex.s.selectedIndex=0;document.ex.s.value=\'\'">'
120  +'<option value=" " selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
121  for (var i in arrFiles)
122  guiCode += '<option value = "' + path + arrFiles[i] + '">' + arrFiles[i] + '</option>';
123  guiCode += '</select><br/>'
124  +'<p><small><a href="https://github.com/linev/jsroot/blob/master/docs/JSROOT.md#reading-root-files-from-other-servers">Read docu</a>'
125  +' how to open files from other servers.</small></p>'
126  +'<input style="padding:2px; margin-top:5px;"'
127  +' onclick="ReadFile()" type="button" title="Read the Selected File" value="Load"/>'
128  +'<input style="padding:2px; margin-left:10px;"'
129  +' onclick="ResetUI()" type="button" title="Clear All" value="Reset"/>'
130  +'<select style="padding:2px; margin-left:10px; margin-top:5px;" title="layout kind" id="layout">'
131  +' <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>'
132  +'</select><br/>'
133  +'</form>';
134  }
135  }
136 
137  guiCode += '<div id="browser"></div>'
138  +'</div>'
139  +'<div id="separator-div" style="top:1px; bottom:1px"></div>'
140  +'<div id="right-div" class="column" style="top:1px; bottom:1px"></div>';
141 
142  var drawDivId = 'right-div';
143 
144  myDiv.empty().append(guiCode);
145 
146  var h0 = null;
147 
148  if (online) {
149  if (typeof GetCachedHierarchy == 'function') h0 = GetCachedHierarchy();
150  if (typeof h0 != 'object') h0 = "";
151  }
152 
153  hpainter = new JSROOT.HierarchyPainter('root', 'browser');
154 
155  hpainter.SetDisplay(null, drawDivId);
156 
157  JSROOT.Painter.ConfigureVSeparator(hpainter);
158 
159  // JSROOT.Painter.ConfigureHSeparator(28, true);
160 
161  hpainter.StartGUI(h0, function() {
162 
163  setGuiLayout(hpainter.GetLayout());
164 
165  // specify display kind every time selection done
166  // will be actually used only for first drawing or after reset
167  $("#layout").change(function() {
168  if (hpainter) hpainter.SetDisplay(guiLayout(), drawDivId);
169  });
170 
171  if (online) {
172  if ((hpainter.h!=null) && ('_toptitle' in hpainter.h))
173  $("#toptitle").html(hpainter.h._toptitle);
174  $("#monitoring")
175  .prop('checked', hpainter.IsMonitoring())
176  .click(function() {
177  hpainter.EnableMonitoring(this.checked);
178  hpainter.updateAll(!this.checked);
179  });
180  } else {
181  var fname = "";
182  hpainter.ForEachRootFile(function(item) { if (fname=="") fname = item._fullurl; });
183  $("#urlToLoad").val(fname);
184  }
185  });
186  }
187 
188  return JSROOT;
189 
190 }));
191