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