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