2/// \ingroup tutorial_http
3/// JavaScript code for drawing TMsgList class from httptextlog.C macro
7/// \author Sergey Linev
9JSROOT.require("painter").then(jsrp => {
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
15 var arg = "&max=1000";
16 if ('last-id' in item) arg+= "&id="+item['last-id'];
17 return 'exe.json.gz?method=Select' + arg;
20 function AfterMsgListRequest(hitem, item, obj) {
21 // after data received, one replaces typename for produced object
23 if (item==null) return;
26 delete item['last-id'];
29 // ignore all other classes
30 if (obj._typename != 'TList') return;
32 // change class name - it is only important for drawing
33 obj._typename = "TMsgList";
35 if (obj.arr.length>0) {
36 item['last-id'] = obj.arr[0].fString;
38 // add clear function for item
39 if (!('clear' in item))
40 item['clear'] = function() { delete this['last-id']; }
45 function DrawMsgList(divid, lst, opt) {
47 let painter = new JSROOT.BasePainter(divid);
49 painter.Draw = function(lst) {
52 let frame = this.selectDom();
54 let main = frame.select("div");
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
64 let old = main.selectAll("pre");
65 let newsize = old.size() + lst.arr.length - 1;
67 // in the browser keep maximum 1000 entries
69 old.select(function(d,i) { return i < newsize - 1000 ? this : null; }).remove();
71 for (let i = lst.arr.length - 1; i > 0; i--)
72 main.append("pre").style('margin','2px').html(lst.arr[i].fString);
75 painter.redrawObject = function(obj) {
81 return Promise.resolve(painter);
84 // register draw function to JSROOT
88 make_request: MakeMsgListRequest,
89 after_request: AfterMsgListRequest,