GSI Object Oriented Online Offline (Go4)  GO4-6.1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
go4canvas.js
Go to the documentation of this file.
1 (function( factory ) {
2 
3  // this is code for web canvas to support Go4 classes like
4  // TGo4Marker or TGo4Condition in the go4 gui
5  // it is slightly different to go4.js which is dedicated with usage of THttpServer
6 
7  if (typeof JSROOT != "object") {
8  var e1 = new Error("go4canvas.js requires JSROOT to be already loaded");
9  e1.source = "go4canvas.js";
10  throw e1;
11  }
12 
13  var myGO4 = { version: "6.1.x", web_canvas: true };
14 
15  factory(JSROOT, (typeof GO4 != 'undefined') ? GO4 : myGO4);
16 
17 } (function(JSROOT, GO4) {
18 
19  "use strict";
20 
21  // adding support of JSROOT v6
22  let ObjectPainter = JSROOT.ObjectPainter || JSROOT.TObjectPainter;
23 
24  let BasePainter = JSROOT.BasePainter || JSROOT.TBasePainter;
25 
26  if (!BasePainter.prototype.get_main_id) {
27  GO4.id_counter = 1;
28  // method removed from JSROOT v6, is not required there, therefore reintroduce it here
29  BasePainter.prototype.get_main_id = function() {
30  var elem = this.selectDom();
31  if (elem.empty()) return "";
32  var id = elem.attr("id");
33  if (!id) {
34  id = "go4_element_" + GO4.id_counter++;
35  elem.attr("id", id);
36  }
37  return id;
38  }
39  }
40 
42 
43  if (!JSROOT._) {
44  BasePainter.prototype.getItemName = BasePainter.prototype.GetItemName;
45  ObjectPainter.prototype.getObject = ObjectPainter.prototype.GetObject;
46  ObjectPainter.prototype.createG = ObjectPainter.prototype.CreateG;
47  ObjectPainter.prototype.axisToSvg = ObjectPainter.prototype.AxisToSvg;
48  ObjectPainter.prototype.svgToAxis = ObjectPainter.prototype.SvgToAxis;
49  ObjectPainter.prototype.getMainPainter = ObjectPainter.prototype.main_painter;
50  JSROOT.create = JSROOT.Create;
51  FFormat = JSROOT.FFormat;
52  findPainter = function(painter, obj, name, typ) {
53  return painter.FindPainterFor(obj, name, typ);
54  }
55  } else {
56  FFormat = JSROOT.Painter.floatToString;
57  findPainter = (painter, obj, name, typ) => {
58  let pp = painter.getPadPainter();
59  return pp ? pp.findPainterFor(obj, name, typ) : null;
60  }
61  }
62 
63  GO4.MarkerPainter = function(divid, marker) {
64  if (JSROOT._) {
65  ObjectPainter.call(this, divid, marker);
66  } else {
67  ObjectPainter.call(this, marker);
68  this.SetDivId(divid); // old
69  }
70  this.pave = null; // drawing of stat
71  }
72 
73  GO4.MarkerPainter.prototype = Object.create(ObjectPainter.prototype);
74 
75  GO4.MarkerPainter.prototype.moveDrag = function(dx,dy) {
76  this.grx += dx;
77  this.gry += dy;
78  this.draw_g.select('path').attr("d",this.markeratt.create(this.grx, this.gry));
79  }
80 
81  GO4.MarkerPainter.prototype.moveEnd = function() {
82  var marker = this.getObject();
83  marker.fX = this.svgToAxis("x", this.grx);
84  marker.fY = this.svgToAxis("y", this.gry);
85  var exec = "SetXY(" + marker.fX + "," + marker.fY + ")";
86  if (JSROOT._)
87  this.submitCanvExec(exec);
88  else
89  this.WebCanvasExec(exec);
90  this.drawLabel();
91  }
92 
93  GO4.MarkerPainter.prototype.drawMarker = function() {
94  let g = this.createG(); // can draw in complete pad
95 
96  var marker = this.getObject();
97 
98  this.createAttMarker({ attr: marker });
99 
100  this.grx = this.axisToSvg("x", marker.fX);
101  this.gry = this.axisToSvg("y", marker.fY);
102 
103  var path = this.markeratt.create(this.grx, this.gry);
104 
105  if (path)
106  g.append("svg:path")
107  .attr("d", path)
108  .call(this.markeratt.func);
109 
110  if (typeof this.AddMove == 'function')
111  this.AddMove();
112  else
113  JSROOT.require(['interactive'])
114  .then(inter => inter.addMoveHandler(this));
115  }
116 
117  GO4.MarkerPainter.prototype.fillLabels = function(marker) {
118  var lbls = [];
119 
120  var main = this.getMainPainter(), hint = null, fx = 0, fy = 0;
121  if (JSROOT._) {
122  let rect = this.getFramePainter().getFrameRect();
123  fx = rect.x;
124  fy = rect.y;
125  if (main && typeof main.processTooltipEvent == 'function')
126  hint = main.processTooltipEvent({ enabled: false, x: this.grx - fx, y: this.gry - fy });
127  } else {
128  fx = this.frame_x();
129  fy = this.frame_y();
130  if (main && typeof main.ProcessTooltip == 'function')
131  hint = main.ProcessTooltip({ enabled: false, x: this.grx - fx, y: this.gry - fy });
132  }
133 
134 
135  lbls.push(marker.fxName + ((hint && hint.name) ? (" : " + hint.name) : ""));
136 
137  if (marker.fbXDraw)
138  lbls.push("X = " + FFormat(marker.fX, "6.4g"));
139 
140  if (marker.fbYDraw)
141  lbls.push("Y = " + FFormat(marker.fY, "6.4g"));
142 
143  if (hint && hint.user_info) {
144  if (marker.fbXbinDraw) {
145  var bin = "<undef>";
146  if (hint.user_info.binx !== undefined) bin = hint.user_info.binx; else
147  if (hint.user_info.bin !== undefined) bin = hint.user_info.bin;
148  lbls.push("Xbin = " + bin);
149  }
150 
151  if (marker.fbYbinDraw) {
152  lbls.push("Ybin = " + ((hint.user_info.biny !== undefined) ? hint.user_info.biny : "<undef>"));
153  }
154 
155  if (marker.fbContDraw)
156  lbls.push("Cont = " + hint.user_info.cont);
157  }
158 
159  return lbls;
160  }
161 
162  GO4.MarkerPainter.prototype.drawLabel = function() {
163 
164  var marker = this.getObject();
165 
166  if (!marker.fbHasLabel) return;
167 
168  var pave_painter = findPainter(this, this.pave);
169 
170  if (!pave_painter) {
171  this.pave = JSROOT.create("TPaveStats");
172  this.pave.fName = "stats_" + marker.fName;
173 
174  var pad_width = 10, pad_height = 10;
175 
176  if (JSROOT._) {
177  let pp = this.getPadPainter();
178  pad_width = pp.getPadWidth();
179  pad_height = pp.getPadHeight();
180  } else {
181  pad_width = this.pad_width();
182  pad_height = this.pad_height();
183  }
184 
185  var px = this.grx / pad_width + 0.02,
186  py = this.gry / pad_height - 0.02;
187  JSROOT.extend(this.pave, { fX1NDC: px, fY1NDC: py - 0.15, fX2NDC: px + 0.2, fY2NDC: py, fBorderSize: 1, fFillColor: 0, fFillStyle: 1001 });
188 
189  var st = JSROOT.gStyle;
190  JSROOT.extend(this.pave, { fFillColor: st.fStatColor, fFillStyle: st.fStatStyle, fTextAngle: 0, fTextSize: st.fStatFontSize,
191  fTextAlign: 12, fTextColor: st.fStatTextColor, fTextFont: st.fStatFont });
192  } else {
193  this.pave.Clear();
194  }
195 
196  var lbls = this.fillLabels(marker);
197  for (var k = 0; k < lbls.length; ++k)
198  this.pave.AddText(lbls[k]);
199 
200  if (JSROOT._) {
201  if (pave_painter)
202  pave_painter.redraw();
203  else
204  JSROOT.draw(this.divid, this.pave, "").then(p => { if (p) p.$secondary = true; });
205  } else {
206  if (pave_painter)
207  pave_painter.redraw();
208  else
209  JSROOT.draw(this.divid, this.pave, "", function(p) {
210  if (p) p.$secondary = true;
211  });
212  }
213  }
214 
215  // should work for both jsroot v5 and v6 up to naming convention
216  if (JSROOT._) {
217  GO4.MarkerPainter.prototype.redrawObject = function(obj) {
218  if (!this.updateObject(obj)) return false;
219  this.redraw(); // no need to redraw complete pad
220  return true;
221  }
222 
223  GO4.MarkerPainter.prototype.cleanup = function(arg) {
224  if (this.pave) {
225  var pp = findPainter(this, this.pave);
226  if (pp) {
227  pp.removeFromPadPrimitives();
228  pp.cleanup();
229  }
230  delete this.pave;
231  }
232 
233  ObjectPainter.prototype.cleanup.call(this, arg);
234  }
235  } else {
236  GO4.MarkerPainter.prototype.RedrawObject = function(obj) {
237  if (!this.UpdateObject(obj)) return false;
238  this.redraw(); // no need to redraw complete pad
239  return true;
240  }
241 
242  GO4.MarkerPainter.prototype.Cleanup = function(arg) {
243  if (this.pave) {
244  var pp = findPainter(this, this.pave);
245  if (pp) pp.DeleteThis();
246  delete this.pave;
247  }
248 
249  ObjectPainter.prototype.Cleanup.call(this, arg);
250  }
251  }
252 
253 
254  GO4.MarkerPainter.prototype.redraw = function() {
255  this.drawMarker();
256  this.drawLabel();
257  }
258 
259 // GO4.MarkerPainter.prototype.fillContextMenu = function(menu) {
260 // var marker = this.getObject();
261 // menu.add("header:"+ marker._typename + "::" + marker.fxName);
262 // function select(name,exec) {
263 // var marker = this.getObject();
264 // marker[name] = !marker[name];
265 // this.submitCanvExec(exec + (marker[name] ? '(true)' : '(false)'));
266 // this.redraw();
267 // }
268 // menu.addchk(marker.fbHasLabel, 'Label', select.bind(this, 'fbHasLabel', 'SetLabelDraw'));
269 // menu.addchk(marker.fbHasConnector, 'Connector', select.bind(this, 'fbHasConnector', 'SetLineDraw'));
270 // menu.addchk(marker.fbXDraw, 'Draw X', select.bind(this, 'fbXDraw', 'SetXDraw'));
271 // menu.addchk(marker.fbYDraw, 'Draw Y', select.bind(this, 'fbYDraw', 'SetYDraw'));
272 // menu.addchk(marker.fbXbinDraw, 'Draw X bin', select.bind(this, 'fbXbinDraw', 'SetXbinDraw'));
273 // menu.addchk(marker.fbYbinDraw, 'Draw Y bin', select.bind(this, 'fbYbinDraw', 'SetYbinDraw'));
274 // menu.addchk(marker.fbContDraw, 'Draw content', select.bind(this, 'fbContDraw', 'SetContDraw'));
275 // return true;
276 // }
277 
278  GO4.MarkerPainter.prototype.processTooltipEvent = function(pnt) {
279  if (!pnt) return null;
280 
281  var marker = this.getObject(), fx = 0, fy = 0, marker_sz = 1;
282  if (JSROOT._) {
283  let rect = this.getFramePainter().getFrameRect();
284  fx = rect.x;
285  fy = rect.y;
286  marker_sz = this.markeratt.getFullSize();
287  } else {
288  fx = this.frame_x();
289  fy = this.frame_y();
290  marker_sz = this.markeratt.GetFullSize();
291  }
292 
293  var hint = { name: marker.fxName,
294  title: marker.fxName,
295  painter: this,
296  menu: true,
297  x: this.grx - fx,
298  y: this.gry - fy,
299  color1: this.markeratt.color };
300 
301  var dist = Math.sqrt(Math.pow(pnt.x - hint.x, 2) + Math.pow(pnt.y - hint.y, 2));
302 
303  hint.menu_dist = dist;
304 
305  if (dist < 2.5 * marker_sz) hint.exact = true;
306 
307  if (hint.exact)
308  hint.lines = this.fillLabels(marker);
309 
310  // res.menu = res.exact; // activate menu only when exactly locate bin
311  // res.menu_dist = 3; // distance always fixed
312 
313  return hint;
314  }
315 
316  if (!JSROOT._) {
317  GO4.MarkerPainter.prototype.Redraw = GO4.MarkerPainter.prototype.redraw;
318  GO4.MarkerPainter.prototype.ProcessTooltip = GO4.MarkerPainter.prototype.processTooltipEvent;
319  }
320 
321  GO4.MarkerPainter.prototype.ShowTooltip = function(hint) {
322  }
323 
324  GO4.drawGo4Marker = function(divid, obj, option) {
325  var painter = new GO4.MarkerPainter(divid, obj);
326  if (JSROOT._) {
327  painter.drawMarker();
328  painter.drawLabel();
329  painter.addToPadPrimitives();
330  return Promise.resolve(painter);
331  }
332  painter.drawMarker();
333  painter.drawLabel();
334  return painter.DrawingReady();
335  }
336 
337  // =========================================================================
338 
339  if (!ObjectPainter.prototype.matchObjectType)
340  ObjectPainter.prototype.matchObjectType = ObjectPainter.prototype.MatchObjectType
341 
342  GO4.ConditionPainter = function(divid, cond) {
343  if (JSROOT._) {
344  ObjectPainter.call(this, divid, cond);
345  } else {
346  ObjectPainter.call(this, cond);
347  this.SetDivId(divid, -1)
348  }
349 
350  this.pave = null; // drawing of stat
351  }
352 
353  GO4.ConditionPainter.prototype = Object.create(ObjectPainter.prototype);
354 
355  GO4.ConditionPainter.prototype.Test = function(x,y) {
356  // JAM: need to put this here, since condition object will lose internal definition after cloning it again!
357  var cond = this.getObject();
358  if (!cond.fbEnabled)
359  return cond.fbResult;
360 
361  if (cond.fxCut)
362  return cond.fxCut.IsInside(x,y) ? cond.fbTrue : cond.fbFalse;
363 
364  if ((x < cond.fLow1) || (x > cond.fUp1)) return cond.fbFalse;
365 
366  if ((cond.fiDim==2) && ((y < cond.fLow2) || (y > cond.fUp2))) return cond.fbFalse;
367 
368  return cond.fbTrue;
369  }
370 
371 
372  GO4.ConditionPainter.prototype.isPolyCond = function() {
373  return this.matchObjectType("TGo4PolyCond") || this.matchObjectType("TGo4ShapedCond");
374  }
375 
376  GO4.ConditionPainter.prototype.isEllipseCond = function() {
377  return this.matchObjectType("TGo4ShapedCond");
378  }
379 
380  GO4.ConditionPainter.prototype.afterCutDraw = function(p) {
381  if (!p || !this.snapid || p._oldexec) return;
382  p.snapid = this.snapid + "#member_fxCut";
383  p._condpainter = this;
384 
385  // catch TCutG exec and mark condition as modified
386  if (JSROOT._) {
387  p._oldexec = p.submitCanvExec;
388  p.submitCanvExec = function(exec, arg) {
389  this._oldexec(exec, arg);
390  p._condpainter.submitCanvExec("SetChanged()");
391  }
392  } else {
393  p._oldexec = p.WebCanvasExec;
394  p.WebCanvasExec = function(exec, arg) {
395  this._oldexec(exec, arg);
396  p._condpainter.WebCanvasExec("SetChanged()");
397  }
398 
399  }
400  }
401 
402  GO4.ConditionPainter.prototype.drawCondition = function(interactive) {
403 
404  var cond = this.getObject();
405 
406  if (!cond || !cond.fbVisible) return;
407 
408  if (this.isPolyCond()) {
409  if (cond.fxCut) {
410  // look here if cut is already drawn in divid:
411  var cutpaint = findPainter(this, null, cond.fName, 'TCutG');
412 
413  if (JSROOT._) {
414  if (cutpaint) {
415  if (cutpaint.updateObject(cond.fxCut)) cutpaint.redraw();
416  this.afterCutDraw(cutpaint);
417  } else {
418  cond.fxCut.fFillStyle = 3006;
419  cond.fxCut.fFillColor = 2;
420  JSROOT.draw(this.divid, cond.fxCut, "LF").then(p => this.afterCutDraw(p));
421  }
422 
423  } else { // old jsroot v5
424  if (cutpaint) {
425  if (cutpaint.UpdateObject(cond.fxCut)) cutpaint.redraw();
426  this.afterCutDraw(cutpaint);
427  } else {
428  cond.fxCut.fFillStyle = 3006;
429  cond.fxCut.fFillColor = 2;
430  JSROOT.draw(this.divid, cond.fxCut, "LF", p => this.afterCutDraw(p));
431  }
432  }
433  }
434  return;
435  }
436 
437 
438  let g = this.createG(true); // drawing performed inside frame
439 
440  if ((cond.fFillStyle==1001) && (cond.fFillColor==19)) {
441  cond.fFillStyle = 3006;
442  cond.fFillColor = 2;
443  }
444 
445  this.createAttFill({attr: cond});
446  this.createAttLine({attr: cond});
447 
448  this.grx1 = this.axisToSvg("x", cond.fLow1);
449  this.grx2 = this.axisToSvg("x", cond.fUp1);
450 
451  if (cond.fiDim == 2) {
452  this.gry1 = this.axisToSvg("y", cond.fUp2);
453  this.gry2 = this.axisToSvg("y", cond.fLow2);
454  this.candy = true;
455  } else {
456  this.gry1 = 0;
457  this.gry2 = JSROOT._ ? this.getFramePainter().getFrameHeight() : this.frame_height();
458  this.candy = false;
459  }
460 
461  g.append("svg:rect")
462  .attr("x", this.grx1)
463  .attr("y", this.gry1)
464  .attr("width", this.grx2 - this.grx1)
465  .attr("height", this.gry2 - this.gry1)
466  .call(this.lineatt.func)
467  .call(this.fillatt.func);
468 
469  if (typeof this.AddMove == 'function')
470  this.AddMove();
471  else
472  JSROOT.require(['interactive'])
473  .then(inter => inter.addMoveHandler(this));
474  }
475 
476  GO4.ConditionPainter.prototype.moveStart = function(x,y) {
477  this.swapx = this.swapy = false;
478  this.dx1 = Math.abs(x-this.grx1) < 5;
479  this.dx2 = Math.abs(x-this.grx2) < 5;
480  this.dy1 = Math.abs(y-this.gry1) < 5;
481  this.dy2 = Math.abs(y-this.gry2) < 5;
482  if (!this.dx1 && !this.dx2 && !this.dy1 && !this.dy2)
483  this.dx1 = this.dx2 = this.dy1 = this.dy2 = true;
484  if (!this.candy) this.dy1 = this.dy2 = false;
485  }
486 
487  GO4.ConditionPainter.prototype.moveDrag = function(dx,dy) {
488  if (this.dx1) this.grx1 += dx;
489  if (this.dx2) this.grx2 += dx;
490  if (this.grx1 > this.grx2) {
491  this.swapx = true;
492  let tempx = this.grx1; this.grx1 = this.grx2; this.grx2 = tempx;
493  tempx = this.dx1; this.dx1 = this.dx2; this.dx2 = tempx;
494  }
495  if (this.dy1) this.gry1 += dy;
496  if (this.dy2) this.gry2 += dy;
497  if (this.gry1 > this.gry2) {
498  this.swapy = true;
499  let tempy = this.gry1; this.gry1 = this.gry2; this.gry2 = tempy;
500  tempy = this.dy1; this.dy1 = this.dy2; this.dy2 = tempy;
501  }
502  this.draw_g.select('rect').attr("x",this.grx1).attr("y", this.gry1)
503  .attr("width", this.grx2 - this.grx1).attr("height", this.gry2 - this.gry1);
504  }
505 
506  GO4.ConditionPainter.prototype.moveEnd = function() {
507  var cond = this.getObject(), exec = "";
508  if (this.dx1 || this.swapx) { cond.fLow1 = this.svgToAxis("x", this.grx1); exec += "SetXLow(" + cond.fLow1 + ");;"; }
509  if (this.dx2 || this.swapx) { cond.fUp1 = this.svgToAxis("x", this.grx2); exec += "SetXUp(" + cond.fUp1 + ");;"; }
510  if (this.dy2 || this.swapy) { cond.fLow2 = this.svgToAxis("y", this.gry2); exec += "SetYLow(" + cond.fLow2 + ");;"; }
511  if (this.dy1 || this.swapy) { cond.fUp2 = this.svgToAxis("y", this.gry1); exec += "SetYUp(" + cond.fUp2 + ");;"; }
512  if (exec) {
513  if (JSROOT._)
514  this.submitCanvExec(exec + "SetChanged()");
515  else
516  this.WebCanvasExec(exec + "SetChanged()");
517  this.drawLabel();
518  }
519  }
520 
521  GO4.ConditionPainter.prototype.drawLabel = function() {
522 
523  var cond = this.getObject(), painter = this, stat = {};
524 
525  if (!cond.fbLabelDraw || !cond.fbVisible) return;
526 
527  var pave_painter = findPainter(this, this.pave);
528 
529  if (!pave_painter) {
530  this.pave = JSROOT.create("TPaveStats");
531  this.pave.fName = "stats_" + cond.fName;
532  JSROOT.extend(this.pave, { fX1NDC: 0.1, fY1NDC: 0.4, fX2NDC: 0.4, fY2NDC: 0.65, fBorderSize: 1, fFillColor: 0, fFillStyle: 1001 });
533 
534  var st = JSROOT.gStyle;
535  JSROOT.extend(this.pave, { fFillColor: st.fStatColor, fFillStyle: st.fStatStyle, fTextAngle: 0, fTextSize: st.fStatFontSize,
536  fTextAlign: 12, fTextColor: st.fStatTextColor, fTextFont: st.fStatFont});
537  } else {
538  this.pave.Clear();
539  }
540 
541  this.pave.AddText(cond.fName);
542 
543  this.pave.AddText("Counts = " + cond.fiCounts);
544 
545  if (cond.fbLimitsDraw)
546  if (this.isPolyCond()) {
547  var res = { xmin: 0, xmax: 0, ymin: 0, ymax: 0 };
548  if (cond.fxCut.fNpoints > 0) {
549  res.xmin = res.xmax = cond.fxCut.fX[0];
550  res.ymin = res.ymax = cond.fxCut.fY[0];
551  for (var i=1; i<cond.fxCut.fNpoints; i++) {
552  res.xmin = Math.min(res.xmin, cond.fxCut.fX[i]);
553  res.xmax = Math.max(res.xmax, cond.fxCut.fX[i]);
554  res.ymin = Math.min(res.ymin, cond.fxCut.fY[i]);
555  res.ymax = Math.max(res.ymax, cond.fxCut.fY[i]);
556  }
557  }
558  this.pave.AddText("Xmin = " + res.xmin);
559  this.pave.AddText("Xmax = " + res.xmax);
560  this.pave.AddText("Ymin = " + res.ymin);
561  this.pave.AddText("Ymax = " + res.ymax);
562  } else {
563  this.pave.AddText("Xmin = " + cond.fLow1);
564  this.pave.AddText("Xmax = " + cond.fUp1);
565  if (cond.fiDim==2) {
566  this.pave.AddText("Ymin = " + cond.fLow2);
567  this.pave.AddText("Ymax = " + cond.fUp2);
568  }
569  }
570 
571  if (JSROOT._) {
572  stat = this.getMainPainter().countStat((x,y) => painter.Test(x,y));
573  } else {
574  stat = this.getMainPainter().CountStat(function(x,y) { return painter.Test(x,y); });
575  }
576 
577  if (cond.fbIntDraw) this.pave.AddText("Integral = " + FFormat(stat.integral, "14.7g"));
578 
579  if (cond.fbXMeanDraw) this.pave.AddText("Mean x = " + FFormat(stat.meanx, "6.4g"));
580 
581  if (cond.fbXRMSDraw) this.pave.AddText("RMS x = " + FFormat(stat.rmsx, "6.4g"));
582 
583  if (cond.fiDim==2) {
584  if (cond.fbYMeanDraw) this.pave.AddText("Mean y = " + FFormat(stat.meany, "6.4g"));
585  if (cond.fbYRMSDraw) this.pave.AddText("RMS y = " + FFormat(stat.rmsy, "6.4g"));
586  }
587 
588  if (cond.fbXMaxDraw) this.pave.AddText("X max = " + FFormat(stat.xmax, "6.4g"));
589 
590  if (cond.fiDim==2)
591  if (cond.fbYMaxDraw) this.pave.AddText("Y max = " + FFormat(stat.ymax, "6.4g"));
592  if (cond.fbCMaxDraw) this.pave.AddText("C max = " + FFormat(stat.wmax, "14.7g"));
593 
594  if (!pave_painter)
595  JSROOT.draw(this.divid, this.pave, "");
596  else if (JSROOT._)
597  pave_painter.redraw();
598  else
599  pave_painter.Redraw(); // old jsroot v5
600  }
601 
602 // GO4.ConditionPainter.prototype.fillContextMenu = function(menu) {
603 // var cond = this.getObject();
604 // menu.add("header:"+ cond._typename + "::" + cond.fName);
605 // function select(name,exec) {
606 // var cond = this.getObject();
607 // cond[name] = !cond[name];
608 // this.submitCanvExec(exec + (cond[name] ? '(true)' : '(false)'));
609 // this.redraw();
610 // }
611 // menu.addchk(cond.fbLabelDraw, 'Label', select.bind(this, 'fbLabelDraw', 'SetLabelDraw'));
612 // menu.addchk(cond.fbLimitsDraw, 'Limits', select.bind(this, 'fbLimitsDraw', 'SetLimitsDraw'));
613 // menu.addchk(cond.fbIntDraw, 'Integral', select.bind(this, 'fbIntDraw', 'SetIntDraw'));
614 // menu.addchk(cond.fbXMeanDraw, 'X mean', select.bind(this, 'fbXMeanDraw', 'SetXMeanDraw'));
615 // menu.addchk(cond.fbXRMSDraw, 'X rms', select.bind(this, 'fbXRMSDraw', 'SetXRMSDraw'));
616 // menu.addchk(cond.fbXMaxDraw, 'X max', select.bind(this, 'fbXMaxDraw', 'SetXMaxDraw'));
617 // menu.addchk(cond.fbYMeanDraw, 'Y mean', select.bind(this, 'fbYMeanDraw', 'SetYMeanDraw'));
618 // menu.addchk(cond.fbYRMSDraw, 'Y rms', select.bind(this, 'fbYRMSDraw', 'SetYRMSDraw'));
619 // menu.addchk(cond.fbYMaxDraw, 'Y max', select.bind(this, 'fbYMaxDraw', 'SetYMaxDraw'));
620 // return true;
621 // }
622 
623  GO4.ConditionPainter.prototype.processTooltipEvent = function(pnt) {
624  if (!pnt) return null;
625 
626  var cond = this.getObject();
627 
628  var hint = { name: cond.fName,
629  title: cond.fTitle,
630  painter: this,
631  menu: true,
632  x: pnt.x,
633  y: pnt.y };
634 
635  if (this.isPolyCond()) {
636 
637  } else {
638 
639  hint.color1 = this.fillatt.color;
640  hint.color2 = this.lineatt.color;
641 
642  hint.menu_dist = Math.sqrt(Math.pow(pnt.x - (this.grx1 + this.grx2)/2, 2) + Math.pow(pnt.y - (this.gry1 + this.gry2)/2, 2));
643  hint.exact = (this.grx1 <= pnt.x) && (pnt.x <= this.grx2) && (this.gry1 <= pnt.y) && (pnt.y <= this.gry2);
644  if (Math.abs(this.grx1 - pnt.x) < 5) hint.sidex = -1;
645  if (Math.abs(this.grx2 - pnt.x) < 5) hint.sidex = 1;
646  if (cond.fiDim == 2) {
647  if (Math.abs(this.gry1 - pnt.y) < 5) hint.sidey = 1;
648  if (Math.abs(this.gry2 - pnt.y) < 5) hint.sidey = -1;
649  }
650  }
651 
652  if (hint.exact)
653  hint.lines = ["condition", cond.fName ];
654 
655  return hint;
656  }
657 
658  if (JSROOT._) {
659  GO4.ConditionPainter.prototype.redrawObject = function(obj) {
660  if (!this.updateObject(obj)) return false;
661  this.redraw(); // no need to redraw complete pad
662  return true;
663  }
664  GO4.ConditionPainter.prototype.cleanup = function(arg) {
665  if (this.pave) {
666  var pp = findPainter(this, this.pave);
667  if (pp) {
668  pp.removeFromPadPrimitives();
669  pp.cleanup();
670  }
671  delete this.pave;
672  }
673 
674  ObjectPainter.prototype.cleanup.call(this, arg);
675  }
676 
677  } else {
678  // support older jsroot v5 interface
679  GO4.ConditionPainter.prototype.RedrawObject = function(obj) {
680  if (!this.UpdateObject(obj)) return false;
681  this.redraw(); // no need to redraw complete pad
682  return true;
683  }
684  GO4.ConditionPainter.prototype.Cleanup = function(arg) {
685  if (this.pave) {
686  var pp = findPainter(this, this.pave);
687  if (pp) pp.DeleteThis();
688  delete this.pave;
689  }
690 
691  ObjectPainter.prototype.Cleanup.call(this, arg);
692  }
693  GO4.ConditionPainter.prototype.ProcessTooltip = GO4.ConditionPainter.prototype.processTooltipEvent;
694  }
695 
696 
697  GO4.ConditionPainter.prototype.redraw = function() {
698  this.drawCondition();
699  this.drawLabel();
700  }
701 
702  // only to support old jsroot v5 interface
703  if (!JSROOT._) GO4.ConditionPainter.prototype.Redraw = GO4.ConditionPainter.prototype.redraw;
704 
705  GO4.drawGo4Cond = function(divid, cond, option) {
706 
707  var condpainter = new GO4.ConditionPainter(divid, cond);
708  let realid = condpainter.get_main_id();
709 
710  if (GO4.web_canvas || (option=='same')) {
711  condpainter.drawCondition();
712  condpainter.drawLabel();
713  if (JSROOT._) {
714  condpainter.addToPadPrimitives();
715  return Promise.resolve(condpainter);
716  }
717  condpainter.SetDivId(divid); // old
718  return condpainter.DrawingReady();
719  }
720 
721  // from here normal code for plain THttpServer
722 
723  if (((cond.fxHistoName=="") || (option=='editor')) && GO4.ConditionEditor) {
724  // $('#'+divid).append("<br/>Histogram name not specified");
725  var h = $("#"+realid).height(), w = $("#"+realid).width();
726  if ((h<10) && (w>10)) $("#"+realid).height(w*0.4);
727  var editor = new GO4.ConditionEditor(realid, cond);
728  if (JSROOT._) return new Promise(resolve => editor.drawEditor(realid, resolve));
729  return editor.drawEditor(realid);
730  }
731 
732  // $('#'+realid).append("<br/>Histogram name is " + cond.fxHistoName);
733 
734  if (!JSROOT.hpainter) {
735  $('#'+realid).append("<br/>Error - did not found hierarchy painter");
736  return;
737  }
738 
739  var histofullpath = null;
740 
741  function TestItem(h) {
742  if ((h._name == cond.fxHistoName) && h._kind && (h._kind.indexOf("ROOT.TH")==0))
743  histofullpath = JSROOT.hpainter.itemFullName(h);
744  }
745 
746  if (JSROOT._)
747  JSROOT.hpainter.forEachItem(TestItem);
748  else
749  JSROOT.hpainter.ForEach(TestItem);
750 
751  if (histofullpath === null) {
752  $('#'+realid).append("<br/>Error - did not found histogram " + cond.fxHistoName);
753 
754  histofullpath = "../../Histograms/" + cond.fxHistoName;
755 
756  let hitem = JSROOT._ ? JSROOT.hpainter.findItem({ name: histofullpath, force: true }) : JSROOT.hpainter.Find({ name: histofullpath, force: true });
757 
758  hitem._kind = "ROOT.TH1I";
759 
760  console.log("Try histogram" + histofullpath);
761  }
762 
763 
764  $('#'+realid).append("<br/>Drawing histogram " + histofullpath);
765  $('#'+realid).empty();
766 
767  function drawCond(hpainter) {
768  if (!hpainter) return console.log("fail to draw histogram " + histofullpath);
769  condpainter.drawCondition();
770  condpainter.drawLabel();
771  if (JSROOT._) {
772  condpainter.addToPadPrimitives();
773  return condpainter;
774  } else {
775  condpainter.SetDivId(divid); // old
776  return condpainter.DrawingReady();
777  }
778  }
779 
780  if (JSROOT._)
781  return JSROOT.hpainter.display(histofullpath, "divid:" + realid).then(hp => drawCond(hp));
782 
783  JSROOT.hpainter.display(histofullpath, "divid:" + realid, drawCond);
784  return condpainter;
785  }
786 
787  GO4.drawCondArray = function(divid, obj, option) {
788  var arr = obj.condarr.arr;
789  var num = obj.fiNumCond;
790  var first;
791  for (var k=0;k<num;++k) {
792  var p = GO4.drawGo4Cond(divid, arr[k], "");
793  if (k == 0) first = p;
794  }
795  return first; // return first condition as result of drawing
796  }
797 
798 
799  // =======================================================================
800 
801  if (GO4.web_canvas) {
802  var jsrp = JSROOT._ ? JSROOT.Painter : JSROOT;
803  jsrp.addDrawFunc({ name: "TGo4Marker", func: GO4.drawGo4Marker });
804  jsrp.addDrawFunc({ name: "TGo4WinCond", func: GO4.drawGo4Cond });
805  jsrp.addDrawFunc({ name: "TGo4PolyCond", func: GO4.drawGo4Cond });
806  jsrp.addDrawFunc({ name: "TGo4ShapedCond", func: GO4.drawGo4Cond });
807  jsrp.addDrawFunc({ name: "TGo4CondArray", func: GO4.drawCondArray });
808  }
809 
810  return GO4;
811 
812 }));
var jsrp
Definition: go4.js:419
function JSROOT
Definition: go4canvas.js:17
let ObjectPainter
Definition: go4canvas.js:22
function factory
Definition: go4canvas.js:1
int main(int argc, char **argv)
let FFormat
Definition: go4canvas.js:41
function GO4
Definition: go4canvas.js:17
function GO4 version
Definition: go4.js:17
let BasePainter
Definition: go4canvas.js:24
GO4 ConditionEditor prototype isPolyCond
Definition: condition.js:29
let findPainter
Definition: go4canvas.js:41
if(!BasePainter.prototype.get_main_id)
Definition: go4canvas.js:26