Logo ROOT   6.07/09
Reference Guide
httptextlog.js
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_http
3 ///
4 /// \macro_code
5 ///
6 /// \author
7 
8 (function(){
9 
10  if (typeof JSROOT != "object") {
11  var e1 = new Error("httptextlog.js requires JSROOT to be already loaded");
12  e1.source = "httptextlog.js";
13  throw e1;
14  }
15 
16  function MakeMsgListRequest(hitem, item) {
17  // this function produces url for http request
18  // here one provides id of last string received with previous request
19 
20  var arg = "&max=1000";
21  if ('last-id' in item) arg+= "&id="+item['last-id'];
22  return 'exe.json.gz?method=Select' + arg;
23  }
24 
25  function AfterMsgListRequest(hitem, item, obj) {
26  // after data received, one replaces typename for produced object
27 
28  if (item==null) return;
29 
30  if (obj==null) {
31  delete item['last-id'];
32  return;
33  }
34  // ignore all other classes
35  if (obj['_typename'] != 'TList') return;
36 
37  // change class name - it is only important for drawing
38  obj['_typename'] = "TMsgList";
39 
40  if (obj.arr.length>0) {
41  item['last-id'] = obj.arr[0].fString;
42 
43  // add clear function for item
44  if (!('clear' in item))
45  item['clear'] = function() { delete this['last-id']; }
46  }
47  }
48 
49 
50  function DrawMsgList(divid, lst, opt) {
51 
52  var painter = new JSROOT.TBasePainter();
53  painter.SetDivId(divid);
54 
55  painter.Draw = function(lst) {
56  if (lst == null) return;
57 
58  var frame = d3.select("#" + this.divid);
59 
60  var main = frame.select("div");
61  if (main.empty())
62  main = frame.append("div")
63  .style('max-width','100%')
64  .style('max-height','100%')
65  .style('overflow','auto');
66 
67  var old = main.selectAll("pre");
68  var newsize = old.size() + lst.arr.length - 1;
69 
70  // in the browser keep maximum 1000 entries
71  if (newsize > 1000)
72  old.select(function(d,i) { return i < newsize - 1000 ? this : null; }).remove();
73 
74  for (var i=lst.arr.length-1;i>0;i--)
75  main.append("pre").html(lst.arr[i].fString);
76 
77  // (re) set painter to first child element
78  this.SetDivId(this.divid);
79  }
80 
81  painter.RedrawObject = function(obj) {
82  this.Draw(obj);
83  return true;
84  }
85 
86  painter.Draw(lst);
87  return painter.DrawingReady();
88  }
89 
90  JSROOT.addDrawFunc({name:"TMsgList", icon:"img_text", make_request:MakeMsgListRequest, after_request:AfterMsgListRequest, func:DrawMsgList, opt:"list"});
91 
92 })();
null_t< F > null()
void Error(const char *location, const char *msgfmt,...)
th1 Draw()
double func(double *x, double *p)
Definition: stressTF1.cxx:213
int main(int argc, char **argv)
char name[80]
Definition: TGX11.cxx:109