Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TWebCanvas.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, GSI 7/12/2016
2
3/*************************************************************************
4 * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#include "TWebCanvas.h"
12
13#include "TWebSnapshot.h"
14#include "TWebPadPainter.h"
15#include "TWebPS.h"
16#include "TWebMenuItem.h"
17
18#include "TSystem.h"
19#include "TStyle.h"
20#include "TCanvas.h"
21#include "TButton.h"
22#include "TFrame.h"
23#include "TPaveText.h"
24#include "TPaveStats.h"
25#include "TText.h"
26#include "TROOT.h"
27#include "TClass.h"
28#include "TColor.h"
29#include "TObjArray.h"
30#include "TArrayI.h"
31#include "TList.h"
32#include "TF1.h"
33#include "TF2.h"
34#include "TH1.h"
35#include "TH2.h"
36#include "TH1K.h"
37#include "THStack.h"
38#include "TMultiGraph.h"
39#include "TEnv.h"
40#include "TError.h"
41#include "TGraph.h"
42#include "TGraph2D.h"
43#include "TGaxis.h"
44#include "TScatter.h"
45#include "TCutG.h"
46#include "TBufferJSON.h"
47#include "TBase64.h"
48#include "TAtt3D.h"
49#include "TView.h"
50#include "TExec.h"
51#include "TVirtualX.h"
52#include "TMath.h"
53#include "TTimer.h"
54#include "TThread.h"
55
56#include <cstdio>
57#include <cstring>
58#include <fstream>
59#include <iostream>
60#include <memory>
61#include <sstream>
62#include <vector>
63
64
65class TWebCanvasTimer : public TTimer {
70public:
72
73 Bool_t IsSlow() const { return fSlow; }
74 void SetSlow(Bool_t slow = kTRUE)
75 {
76 fSlow = slow;
77 fSlowCnt = 0;
78 SetTime(slow ? 1000 : 10);
79 }
80
81 /// used to send control messages to clients
82 void Timeout() override
83 {
84 if (fProcessing || fCanv.fProcessingData) return;
88 if (res) {
89 fSlowCnt = 0;
90 } else if (++fSlowCnt > 10 && !IsSlow()) {
92 }
93 }
94};
95
96
97/** \class TWebCanvas
98\ingroup webgui6
99
100Basic TCanvasImp ABI implementation for Web-based Graphics
101Provides painting of main ROOT classes in web browsers using [JSROOT](https://root.cern/js/)
102
103Following settings parameters can be useful for TWebCanvas:
104
105 WebGui.FullCanvas: 1 read-only mode (0), full-functional canvas (1) (default - 1)
106 WebGui.StyleDelivery: 1 provide gStyle object to JSROOT client (default - 1)
107 WebGui.PaletteDelivery: 1 provide color palette to JSROOT client (default - 1)
108 WebGui.TF1UseSave: 1 used saved values for function drawing: 0 - off, 1 - if client fail to evaluate function, 2 - always (default - 1)
109
110TWebCanvas is used by default in interactive ROOT session. To use web-based canvas in batch mode for image
111generation, one should explicitly specify `--web` option when starting ROOT:
112
113 [shell] root -b --web tutorials/hsimple.root -e 'hpxpy->Draw("colz"); c1->SaveAs("image.png");'
114
115If for any reasons TWebCanvas does not provide required functionality, one always can disable it.
116Either by specifying `root --web=off` when starting ROOT or by setting `Canvas.Name: TRootCanvas` in rootrc file.
117
118*/
119
120using namespace std::string_literals;
121
122static const std::string sid_pad_histogram = "__pad_histogram__";
123
124
125struct WebFont_t {
130 WebFont_t() = default;
131 WebFont_t(Int_t indx, const TString &name, const TString &fmt, const TString &data) : fIndx(indx), fName(name), fFormat(fmt), fData(data) {}
132};
133
134static std::vector<WebFont_t> gWebFonts;
135
136////////////////////////////////////////////////////////////////////////////////
137/// Constructor
138
140 : TCanvasImp(c, name, x, y, width, height)
141{
142 // Workaround for multi-threaded environment
143 // Ensure main thread id picked when canvas implementation is created -
144 // otherwise it may be assigned in other thread and screw-up gPad access.
145 // Workaround may not work if main thread id was wrongly initialized before
146 // This resolves issue https://github.com/root-project/root/issues/15498
148
149 fTimer = new TWebCanvasTimer(*this);
150
151 fReadOnly = readonly;
152 fStyleDelivery = gEnv->GetValue("WebGui.StyleDelivery", 1);
153 fPaletteDelivery = gEnv->GetValue("WebGui.PaletteDelivery", 1);
154 fPrimitivesMerge = gEnv->GetValue("WebGui.PrimitivesMerge", 100);
155 fTF1UseSave = gEnv->GetValue("WebGui.TF1UseSave", (Int_t) 1);
157
158 fWebConn.emplace_back(0); // add special connection which only used to perform updates
159
160 fTimer->TurnOn();
161
162 // fAsyncMode = kTRUE;
163}
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// Destructor
168
170{
171 delete fTimer;
172}
173
174
175//////////////////////////////////////////////////////////////////////////////////////////////////
176/// Add font to static list of fonts upported by the canvas
177/// Name specifies name of the font, second is font file with .ttf or .woff2 extension
178/// Only True Type Fonts (ttf) are supported by PDF
179/// Returns font index which can be used in
180/// auto font_indx = TWebCanvas::AddFont("test", "test.ttf", 2);
181/// gStyle->SetStatFont(font_indx);
182
183Font_t TWebCanvas::AddFont(const char *name, const char *fontfile, Int_t precision)
184{
185 Font_t maxindx = 22;
186 for (auto &entry : gWebFonts) {
187 if (entry.fName == name)
188 return precision > 0 ? entry.fIndx*10 + precision : entry.fIndx;
189 if (entry.fIndx > maxindx)
190 maxindx = entry.fIndx;
191 }
192
193 TString fullname = fontfile, fmt = "ttf";
194 auto pos = fullname.Last('.');
195 if (pos != kNPOS) {
196 fmt = fullname(pos+1, fullname.Length() - pos);
197 fmt.ToLower();
198 if ((fmt != "ttf") && (fmt != "woff2")) {
199 ::Error("TWebCanvas::AddFont", "Unsupported font file extension %s", fmt.Data());
200 return (Font_t) -1;
201 }
202 }
203
204 gSystem->ExpandPathName(fullname);
205
206 if (gSystem->AccessPathName(fullname.Data(), kReadPermission)) {
207 ::Error("TWebCanvas::AddFont", "Not possible to read font file %s", fullname.Data());
208 return (Font_t) -1;
209 }
210
211 std::ifstream is(fullname.Data(), std::ios::in | std::ios::binary);
212 std::string res;
213 if (is) {
214 is.seekg(0, std::ios::end);
215 res.resize(is.tellg());
216 is.seekg(0, std::ios::beg);
217 is.read((char *)res.data(), res.length());
218 if (!is)
219 res.clear();
220 }
221
222 if (res.empty()) {
223 ::Error("TWebCanvas::AddFont", "Fail to read font file %s", fullname.Data());
224 return (Font_t) -1;
225 }
226
227 TString base64 = TBase64::Encode(res.c_str(), res.length());
228
229 maxindx++;
230
231 gWebFonts.emplace_back(maxindx, name, fmt, base64);
232
233 return precision > 0 ? maxindx*10 + precision : maxindx;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Initialize window for the web canvas
238/// At this place canvas is not yet register to the list of canvases - one cannot call RWebWindow::Show()
239
241{
242 return 111222333; // should not be used at all
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Creates web-based pad painter
247
249{
250 return new TWebPadPainter();
251}
252
253////////////////////////////////////////////////////////////////////////////////
254/// Returns kTRUE when object is fully supported on JSROOT side
255/// In ROOT7 Paint function will just return appropriate flag that object can be displayed on JSROOT side
256
258{
259 if (!obj)
260 return kTRUE;
261
262 static const struct {
263 const char *name{nullptr};
264 bool with_derived{false};
265 bool reduse_by_many{false};
266 } supported_classes[] = {{"TH1", true},
267 {"TF1", true},
268 {"TGraph", true},
269 {"TScatter"},
270 {"TFrame"},
271 {"THStack"},
272 {"TMultiGraph"},
273 {"TGraphPolargram", true},
274 {"TPave", true},
275 {"TGaxis"},
276 {"TPave", true},
277 {"TArrow"},
278 {"TBox", false, true}, // can be handled via TWebPainter, disable for large number of primitives (like in greyscale.C)
279 {"TWbox"}, // some extra calls which cannot be handled via TWebPainter
280 {"TLine", false, true}, // can be handler via TWebPainter, disable for large number of primitives (like in greyscale.C)
281 {"TEllipse", true, true}, // can be handled via TWebPainter, disable for large number of primitives (like in greyscale.C)
282 {"TText"},
283 {"TLatex"},
284 {"TAnnotation"},
285 {"TMathText"},
286 {"TMarker"},
287 {"TPolyMarker"},
288 {"TPolyLine", true, true}, // can be handled via TWebPainter, simplify colors handling
289 {"TPolyMarker3D"},
290 {"TPolyLine3D"},
291 {"TGraphTime"},
292 {"TGraph2D"},
293 {"TGraph2DErrors"},
294 {"TGraphTime"},
295 {"TASImage"},
296 {"TRatioPlot"},
297 {"TSpline"},
298 {"TSpline3"},
299 {"TSpline5"},
300 {"TGeoManager"},
301 {"TGeoVolume"},
302 {}};
303
304 // fast check of class name
305 for (int i = 0; supported_classes[i].name != nullptr; ++i)
306 if ((!many_primitives || !supported_classes[i].reduse_by_many) && (strcmp(supported_classes[i].name, obj->ClassName()) == 0))
307 return kTRUE;
308
309 // now check inheritance only for configured classes
310 for (int i = 0; supported_classes[i].name != nullptr; ++i)
311 if (supported_classes[i].with_derived && (!many_primitives || !supported_classes[i].reduse_by_many))
312 if (obj->InheritsFrom(supported_classes[i].name))
313 return kTRUE;
314
315 return IsCustomClass(obj->IsA());
316}
317
318//////////////////////////////////////////////////////////////////////////////////////////////////
319/// Configures custom script for canvas.
320/// If started from "load:" or "assert:" prefix will be loaded with JSROOT.AssertPrerequisites function
321/// Script should implement custom user classes, which transferred as is to client
322/// In the script draw handler for appropriate classes would be assigned
323
324void TWebCanvas::SetCustomScripts(const std::string &src)
325{
327}
328
329//////////////////////////////////////////////////////////////////////////////////////////////////
330/// Assign custom class
331
332void TWebCanvas::AddCustomClass(const std::string &clname, bool with_derived)
333{
334 if (with_derived)
335 fCustomClasses.emplace_back("+"s + clname);
336 else
337 fCustomClasses.emplace_back(clname);
338}
339
340//////////////////////////////////////////////////////////////////////////////////////////////////
341/// Checks if class belongs to custom
342
344{
345 for (auto &name : fCustomClasses) {
346 if (name[0] == '+') {
347 if (cl->InheritsFrom(name.substr(1).c_str()))
348 return true;
349 } else if (name.compare(cl->GetName()) == 0) {
350 return true;
351 }
352 }
353 return false;
354}
355
356//////////////////////////////////////////////////////////////////////////////////////////////////
357/// Creates representation of the object for painting in web browser
358
359void TWebCanvas::CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps)
360{
361 if (IsJSSupportedClass(obj, masterps != nullptr)) {
362 master.NewPrimitive(obj, opt).SetSnapshot(TWebSnapshot::kObject, obj);
363 return;
364 }
365
366 // painter is not necessary for batch canvas, but keep configuring it for a while
367 auto *painter = dynamic_cast<TWebPadPainter *>(Canvas()->GetCanvasPainter());
368
369 TView *view = nullptr;
370
372
373 gPad = pad;
374
375 if (obj->InheritsFrom(TAtt3D::Class()) && !pad->GetView()) {
376 pad->GetViewer3D("pad");
377 view = TView::CreateView(1, 0, 0); // Cartesian view by default
378 pad->SetView(view);
379
380 // Set view to perform first auto-range (scaling) pass
381 view->SetAutoRange(kTRUE);
382 }
383
384 TVirtualPS *saveps = gVirtualPS;
385
386 TWebPS ps;
387 gVirtualPS = masterps ? masterps : &ps;
388 if (painter)
389 painter->SetPainting(ps.GetPainting());
390
391 // calling Paint function for the object
392 obj->Paint(opt);
393
394 if (view) {
395 view->SetAutoRange(kFALSE);
396 // call 3D paint once again to make real drawing
397 obj->Paint(opt);
398 pad->SetView(nullptr);
399 }
400
401 if (painter)
402 painter->SetPainting(nullptr);
403
404 gVirtualPS = saveps;
405
406 fPadsStatus[pad]._has_specials = true;
407
408 // if there are master PS, do not create separate entries
409 if (!masterps && !ps.IsEmptyPainting())
411}
412
413//////////////////////////////////////////////////////////////////////////////////////////////////
414/// Calculate hash function for all colors and palette
415
417{
418 UInt_t hash = 0;
419
420 TObjArray *colors = (TObjArray *)gROOT->GetListOfColors();
421
422 if (colors) {
423 for (Int_t n = 0; n <= colors->GetLast(); ++n)
424 if (colors->At(n))
425 hash += TString::Hash(colors->At(n), TColor::Class()->Size());
426 }
427
429
430 hash += TString::Hash(pal.GetArray(), pal.GetSize() * sizeof(Int_t));
431
432 return hash;
433}
434
435
436//////////////////////////////////////////////////////////////////////////////////////////////////
437/// Add special canvas objects with list of colors and color palette
438
440{
441 TObjArray *colors = (TObjArray *)gROOT->GetListOfColors();
442
443 if (!colors)
444 return;
445
446 //Int_t cnt = 0;
447 //for (Int_t n = 0; n <= colors->GetLast(); ++n)
448 // if (colors->At(n))
449 // cnt++;
450 //if (cnt <= 598)
451 // return; // normally there are 598 colors defined
452
454
455 auto listofcols = new TWebPainting;
456 for (Int_t n = 0; n <= colors->GetLast(); ++n)
457 listofcols->AddColor(n, (TColor *)colors->At(n));
458
459 // store palette in the buffer
460 auto *tgt = listofcols->Reserve(pal.GetSize());
461 for (Int_t i = 0; i < pal.GetSize(); i++)
462 tgt[i] = pal[i];
463 listofcols->FixSize();
464
465 master.NewSpecials().SetSnapshot(TWebSnapshot::kColors, listofcols, kTRUE);
466}
467
468//////////////////////////////////////////////////////////////////////////////////////////////////
469/// Add special canvas objects with custom fonts
470
472{
473 for (auto &entry : gWebFonts) {
474 TString code = TString::Format("%d:%s:%s:%s", entry.fIndx, entry.fName.Data(), entry.fFormat.Data(), entry.fData.Data());
475 auto custom_font = new TWebPainting;
476 custom_font->AddOper(code.Data());
477 master.NewSpecials().SetSnapshot(TWebSnapshot::kFont, custom_font, kTRUE);
478 }
479}
480
481//////////////////////////////////////////////////////////////////////////////////////////////////
482/// Create snapshot for pad and all primitives
483/// Callback function is used to create JSON in the middle of data processing -
484/// when all misc objects removed from canvas list of primitives or histogram list of functions
485/// After that objects are moved back to their places
486
488{
489 auto &pad_status = fPadsStatus[pad];
490
491 // send primitives if version 0 or actual pad version grater than already send version
492 bool process_primitives = (version == 0) || (pad_status.fVersion > version);
493
494 if (paddata.IsSetObjectIds()) {
495 paddata.SetActive(pad == gPad);
496 paddata.SetObjectIDAsPtr(pad);
497 }
498 paddata.SetSnapshot(TWebSnapshot::kSubPad, pad); // add ref to the pad
499 paddata.SetWithoutPrimitives(!process_primitives);
500 paddata.SetHasExecs(pad->GetListOfExecs()); // if pad execs are there provide more events from client
501
502 // check style changes every time when creating canvas snapshot
503 if (resfunc && (GetStyleDelivery() > 0)) {
504
506 auto hash = TString::Hash(gStyle, TStyle::Class()->Size());
507 if ((hash != fStyleHash) || (fStyleVersion == 0)) {
508 fStyleHash = hash;
510 }
511 }
512
513 if (fStyleVersion > version)
515 }
516
517 // for the first time add custom fonts to the canvas snapshot
518 if (resfunc && (version == 0))
519 AddCustomFonts(paddata);
520
521 fAllPads.emplace_back(pad);
522
523 TList *primitives = pad->GetListOfPrimitives();
524
525 TWebPS masterps;
526 bool usemaster = primitives ? (primitives->GetSize() > fPrimitivesMerge) : false;
527
528 TIter iter(primitives);
529 TObject *obj = nullptr;
530 TFrame *frame = nullptr;
531 TPaveText *title = nullptr;
532 bool need_frame = false, has_histo = false, need_palette = false;
533 std::string need_title;
534
535 auto checkNeedPalette = [](TH1* hist, const TString &opt) {
536 auto check = [&opt](const TString &arg) {
537 return opt.Contains(arg + "Z") || opt.Contains(arg + "HZ");
538 };
539
540 return ((hist->GetDimension() == 2) && (check("COL") || check("LEGO") || check("LEGO4") || check("SURF2"))) ||
541 ((hist->GetDimension() == 3) && (check("BOX2") || check("BOX3")));
542 };
543
544 while (process_primitives && ((obj = iter()) != nullptr)) {
545 TString opt = iter.GetOption();
546 opt.ToUpper();
547
548 if (obj->InheritsFrom(THStack::Class())) {
549 // workaround for THStack, create extra components before sending to client
550 auto hs = static_cast<THStack *>(obj);
551 if (strlen(obj->GetTitle()) > 0)
552 need_title = obj->GetTitle();
553 TVirtualPad::TContext ctxt(pad, kFALSE);
554 hs->BuildPrimitives(iter.GetOption());
555 has_histo = true;
556 need_frame = true;
557 } else if (obj->InheritsFrom(TMultiGraph::Class())) {
558 // workaround for TMultiGraph
559 if (opt.Contains("A")) {
560 auto mg = static_cast<TMultiGraph *>(obj);
562 mg->GetHistogram(); // force creation of histogram without any drawings
563 has_histo = true;
564 if (strlen(obj->GetTitle()) > 0)
565 need_title = obj->GetTitle();
566 need_frame = true;
567 }
568 } else if (obj->InheritsFrom(TFrame::Class())) {
569 if (!frame)
570 frame = static_cast<TFrame *>(obj);
571 } else if (obj->InheritsFrom(TH1::Class())) {
572 need_frame = true;
573 has_histo = true;
574 if (!obj->TestBit(TH1::kNoTitle) && !opt.Contains("SAME") && !opt.Contains("AXIS") && !opt.Contains("AXIG") && (strlen(obj->GetTitle()) > 0))
575 need_title = obj->GetTitle();
576 if (checkNeedPalette(static_cast<TH1*>(obj), opt))
577 need_palette = true;
578 } else if (obj->InheritsFrom(TGraph::Class())) {
579 if (opt.Contains("A")) {
580 need_frame = true;
581 if (!has_histo && (strlen(obj->GetTitle()) > 0))
582 need_title = obj->GetTitle();
583 }
584 } else if (obj->InheritsFrom(TGraph2D::Class())) {
585 if (!has_histo && (strlen(obj->GetTitle()) > 0))
586 need_title = obj->GetTitle();
587 } else if (obj->InheritsFrom(TScatter::Class())) {
588 need_frame = need_palette = true;
589 if (strlen(obj->GetTitle()) > 0)
590 need_title = obj->GetTitle();
591 } else if (obj->InheritsFrom(TF1::Class())) {
592 need_frame = !obj->InheritsFrom(TF2::Class());
593 if (!has_histo && (strlen(obj->GetTitle()) > 0))
594 need_title = obj->GetTitle();
595 } else if (obj->InheritsFrom(TPaveText::Class())) {
596 if (strcmp(obj->GetName(), "title") == 0)
597 title = static_cast<TPaveText *>(obj);
598 }
599 }
600
601 if (need_frame && !frame && primitives && CanCreateObject("TFrame")) {
602 if (!IsReadOnly() && need_palette && (pad->GetRightMargin() < 0.12) && (pad->GetRightMargin() == gStyle->GetPadRightMargin()))
603 pad->SetRightMargin(0.12);
604
605 frame = pad->GetFrame();
606 if(frame)
607 primitives->AddFirst(frame);
608 }
609
610 if (!need_title.empty() && gStyle->GetOptTitle()) {
611 if (title) {
612 auto line0 = title->GetLine(0);
613 if (line0 && !IsReadOnly()) line0->SetTitle(need_title.c_str());
614 } else if (primitives && CanCreateObject("TPaveText")) {
615 title = new TPaveText(0, 0, 0, 0, "blNDC");
618 title->SetName("title");
621 title->SetTextFont(gStyle->GetTitleFont(""));
622 if (gStyle->GetTitleFont("") % 10 > 2)
624 title->AddText(need_title.c_str());
625 title->SetBit(kCanDelete);
626 primitives->Add(title);
627 }
628 }
629
630 auto flush_master = [&]() {
631 if (!usemaster || masterps.IsEmptyPainting()) return;
632
634 masterps.CreatePainting(); // create for next operations
635 };
636
637 auto check_cutg_in_options = [&](const TString &opt) {
638 auto p1 = opt.Index("["), p2 = opt.Index("]");
639 if ((p1 != kNPOS) && (p2 != kNPOS) && p2 > p1 + 1) {
640 TString cutname = opt(p1 + 1, p2 - p1 - 1);
641 TObject *cutg = primitives->FindObject(cutname.Data());
642 if (!cutg || (cutg->IsA() != TCutG::Class())) {
643 cutg = gROOT->GetListOfSpecials()->FindObject(cutname.Data());
644 if (cutg && cutg->IsA() == TCutG::Class())
645 paddata.NewPrimitive(cutg, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, cutg);
646 }
647 }
648 };
649
650 auto check_save_tf1 = [&](TObject *fobj, bool ignore_nodraw = false) {
651 if (!paddata.IsBatchMode() && (fTF1UseSave <= 0))
652 return;
653 if (!ignore_nodraw && fobj->TestBit(TF1::kNotDraw))
654 return;
655
656 auto f1 = static_cast<TF1 *>(fobj);
657 if (!f1->IsValid())
658 return;
659
660 if (fTF1UseSave == 1) {
661 // check if save buffer empty, workaround for yet missing TF1::IsSaveBuffer()
662 Bool_t is_empty = kTRUE;
663 static auto offset = TF1::Class()->GetDataMemberOffset("fSave");
664 if (offset > 0)
665 is_empty = ((std::vector<Double_t> *) ((char *) f1 + offset))->empty();
666 if (!is_empty)
667 return;
668 }
669
670 f1->Save(0, 0, 0, 0, 0, 0);
671 };
672
673 auto create_stats = [&]() {
674 TPaveStats *stats = nullptr;
675 if ((gStyle->GetOptStat() > 0) && CanCreateObject("TPaveStats")) {
676 stats = new TPaveStats(
679 gStyle->GetStatX(),
680 gStyle->GetStatY(), "brNDC");
681
682 // do not set optfit and optstat, they calling pad->Update,
683 // values correctly set already in TPaveStats constructor
684 // stats->SetOptFit(gStyle->GetOptFit());
685 // stats->SetOptStat(gStyle->GetOptStat());
689 stats->SetTextFont(gStyle->GetStatFont());
690 if (gStyle->GetStatFont()%10 > 2)
694 stats->SetName("stats");
695
697 stats->SetTextAlign(12);
698 stats->SetBit(kCanDelete);
699 stats->SetBit(kMustCleanup);
700 }
701
702 return stats;
703 };
704
705 auto check_graph_funcs = [&](TGraph *gr, TList *funcs = nullptr) {
706 if (!funcs && gr)
708 if (!funcs)
709 return;
710
711 TIter fiter(funcs);
712 TPaveStats *stats = nullptr;
713 bool has_tf1 = false;
714
715 while (auto fobj = fiter()) {
716 if (fobj->InheritsFrom(TPaveStats::Class()))
717 stats = dynamic_cast<TPaveStats *> (fobj);
718 else if (fobj->InheritsFrom(TF1::Class())) {
719 check_save_tf1(fobj);
720 has_tf1 = true;
721 }
722 }
723
724 if (!stats && has_tf1 && gr && !gr->TestBit(TGraph::kNoStats)) {
725 stats = create_stats();
726 if (stats) {
727 stats->SetParent(funcs);
728 funcs->Add(stats);
729 }
730 }
731 };
732
733 iter.Reset();
734
735 bool first_obj = true;
736
737 if (process_primitives)
738 pad_status._has_specials = false;
739
740 while ((obj = iter()) != nullptr) {
741 if (obj->InheritsFrom(TPad::Class())) {
742 flush_master();
743 CreatePadSnapshot(paddata.NewSubPad(), (TPad *)obj, version, nullptr);
744 } else if (!process_primitives) {
745 continue;
746 } else if (obj->InheritsFrom(TH1K::Class())) {
747 flush_master();
748 TH1K *hist = static_cast<TH1K *>(obj);
749
750 Int_t nbins = hist->GetXaxis()->GetNbins();
751
752 TH1D *h1 = new TH1D("__dummy_name__", hist->GetTitle(), nbins, hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
753 h1->SetDirectory(nullptr);
754 h1->SetName(hist->GetName());
755 hist->TAttLine::Copy(*h1);
756 hist->TAttFill::Copy(*h1);
757 hist->TAttMarker::Copy(*h1);
758 for (Int_t n = 1; n <= nbins; ++n)
759 h1->SetBinContent(n, hist->GetBinContent(n));
760
761 TIter fiter(hist->GetListOfFunctions());
762 while (auto fobj = fiter())
763 h1->GetListOfFunctions()->Add(fobj->Clone());
764
766
767 } else if (obj->InheritsFrom(TH1::Class())) {
768 flush_master();
769
770 TH1 *hist = static_cast<TH1 *>(obj);
771 hist->BufferEmpty();
772
773 TPaveStats *stats = nullptr;
774 TObject *palette = nullptr;
775
776 TIter fiter(hist->GetListOfFunctions());
777 while (auto fobj = fiter()) {
778 if (fobj->InheritsFrom(TPaveStats::Class()))
779 stats = dynamic_cast<TPaveStats *> (fobj);
780 else if (fobj->InheritsFrom("TPaletteAxis"))
781 palette = fobj;
782 else if (fobj->InheritsFrom(TF1::Class()))
783 check_save_tf1(fobj);
784 }
785
786 TString hopt = iter.GetOption();
787 TString o = hopt;
788 o.ToUpper();
789
790 if (!stats && (first_obj || o.Contains("SAMES"))) {
791 stats = create_stats();
792 if (stats) {
793 stats->SetParent(hist);
794 hist->GetListOfFunctions()->Add(stats);
795 }
796 }
797
798 if (!palette && CanCreateObject("TPaletteAxis") && checkNeedPalette(hist, o)) {
799 std::stringstream exec;
800 exec << "new TPaletteAxis(0,0,0,0, (TH1*)" << std::hex << std::showbase << (size_t)hist << ");";
801 palette = (TObject *)gROOT->ProcessLine(exec.str().c_str());
802 if (palette)
803 hist->GetListOfFunctions()->AddFirst(palette);
804 }
805
806 paddata.NewPrimitive(obj, hopt.Data()).SetSnapshot(TWebSnapshot::kObject, obj);
807
808 if (hist->GetDimension() == 2)
809 check_cutg_in_options(iter.GetOption());
810
811 first_obj = false;
812 } else if (obj->InheritsFrom(TGraph::Class())) {
813 flush_master();
814
815 TGraph *gr = static_cast<TGraph *>(obj);
816
817 check_graph_funcs(gr);
818
819 TString gropt = iter.GetOption();
820
821 // ensure histogram exists on server to draw it properly on clients side
822 if (!IsReadOnly() && (first_obj || gropt.Index("A", 0, TString::kIgnoreCase) != kNPOS ||
823 (gropt.Index("X+", 0, TString::kIgnoreCase) != kNPOS) || (gropt.Index("X+", 0, TString::kIgnoreCase) != kNPOS)))
824 gr->GetHistogram();
825
826 paddata.NewPrimitive(obj, gropt.Data()).SetSnapshot(TWebSnapshot::kObject, obj);
827
828 first_obj = false;
829 } else if (obj->InheritsFrom(TGraph2D::Class())) {
830 flush_master();
831
832 TGraph2D *gr2d = static_cast<TGraph2D *>(obj);
833
834 check_graph_funcs(nullptr, gr2d->GetListOfFunctions());
835
836 // ensure correct range of histogram
837 if (!IsReadOnly() && first_obj) {
838 TString gropt = iter.GetOption();
839 gropt.ToUpper();
840 Bool_t zscale = gropt.Contains("TRI1") || gropt.Contains("TRI2") || gropt.Contains("COL");
841 Bool_t real_draw = gropt.Contains("TRI") || gropt.Contains("LINE") || gropt.Contains("ERR") || gropt.Contains("P0");
842
843 TString hopt = !real_draw ? iter.GetOption() : (zscale ? "lego2z" : "lego2");
844 if (title) hopt.Append(";;use_pad_title");
845
846 // if gr2d not draw - let create histogram with correspondent content
847 auto hist = gr2d->GetHistogram(real_draw ? "empty" : "");
848
849 paddata.NewPrimitive(gr2d, hopt.Data(), "#hist").SetSnapshot(TWebSnapshot::kObject, hist);
850 }
851
852 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
853 first_obj = false;
854 } else if (obj->InheritsFrom(TMultiGraph::Class())) {
855 flush_master();
856
857 TMultiGraph *mgr = static_cast<TMultiGraph *>(obj);
858 TIter fiter(mgr->GetListOfFunctions());
859 while (auto fobj = fiter()) {
860 if (fobj->InheritsFrom(TF1::Class()))
861 check_save_tf1(fobj);
862 }
863
864 TIter giter(mgr->GetListOfGraphs());
865 while (auto gobj = giter())
866 check_graph_funcs(static_cast<TGraph *>(gobj));
867
868 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
869
870 first_obj = false;
871 } else if (obj->InheritsFrom(THStack::Class())) {
872 flush_master();
873
874 THStack *hs = static_cast<THStack *>(obj);
875
876 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
877
878 first_obj = hs->GetNhists() > 0; // real drawing only if there are histograms
879 } else if (obj->InheritsFrom(TScatter::Class())) {
880 flush_master();
881
882 TScatter *scatter = static_cast<TScatter *>(obj);
883
884 TObject *palette = nullptr;
885
886 TIter fiter(scatter->GetGraph()->GetListOfFunctions());
887 while (auto fobj = fiter()) {
888 if (fobj->InheritsFrom("TPaletteAxis"))
889 palette = fobj;
890 }
891
892 // ensure histogram exists on server to draw it properly on clients side
893 if (!IsReadOnly() && first_obj)
894 scatter->GetHistogram();
895
896 if (!palette && CanCreateObject("TPaletteAxis")) {
897 std::stringstream exec;
898 exec << "new TPaletteAxis(0,0,0,0,0,0);";
899 palette = (TObject *)gROOT->ProcessLine(exec.str().c_str());
900 if (palette)
901 scatter->GetGraph()->GetListOfFunctions()->AddFirst(palette);
902 }
903
904 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
905
906 first_obj = false;
907 } else if (obj->InheritsFrom(TF1::Class())) {
908 flush_master();
909 auto f1 = static_cast<TF1 *> (obj);
910
911 TString f1opt = iter.GetOption();
912
913 check_save_tf1(obj, true);
914 if (fTF1UseSave > 1)
915 f1opt.Append(";force_saved");
916 else if (fTF1UseSave == 1)
917 f1opt.Append(";prefer_saved");
918
919 if (first_obj) {
920 auto hist = f1->GetHistogram();
921 paddata.NewPrimitive(hist, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, hist);
922 f1opt.Append(";webcanv_hist");
923 }
924
925 if (f1->IsA() == TF2::Class())
926 check_cutg_in_options(iter.GetOption());
927
929
930 first_obj = false;
931
932 } else if (obj->InheritsFrom(TGaxis::Class())) {
933 flush_master();
934 auto gaxis = static_cast<TGaxis *> (obj);
935 auto func = gaxis->GetFunction();
936 if (func)
937 paddata.NewPrimitive(func, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, func);
938
939 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
940 } else if (obj->InheritsFrom(TFrame::Class())) {
941 flush_master();
942 if (frame && (obj == frame)) {
943 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
944 frame = nullptr; // add frame only once
945 }
946 } else if (IsJSSupportedClass(obj, usemaster)) {
947 flush_master();
948 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
949 } else {
950 CreateObjectSnapshot(paddata, pad, obj, iter.GetOption(), usemaster ? &masterps : nullptr);
951 }
952 }
953
954 flush_master();
955
956 bool provide_colors = false;
957
958 if ((GetPaletteDelivery() > 2) || ((GetPaletteDelivery() == 2) && resfunc)) {
959 // provide colors: either for each subpad (> 2) or only for canvas (== 2)
960 provide_colors = process_primitives;
961 } else if ((GetPaletteDelivery() == 1) && resfunc) {
962 // check that colors really changing, using hash
963
965 auto hash = CalculateColorsHash();
966 if ((hash != fColorsHash) || (fColorsVersion == 0)) {
967 fColorsHash = hash;
969 }
970 }
971
972 provide_colors = fColorsVersion > version;
973 }
974
975 // add colors after painting is performed - new colors may be generated only during painting
976 if (provide_colors)
977 AddColorsPalette(paddata);
978
979 if (!resfunc)
980 return;
981
982 // now hide all primitives to perform I/O
983 std::vector<TList *> all_primitives(fAllPads.size());
984 for (unsigned n = 0; n < fAllPads.size(); ++n) {
985 all_primitives[n] = fAllPads[n]->fPrimitives;
986 fAllPads[n]->fPrimitives = nullptr;
987 }
988
989 // execute function to prevent storing of colors with custom TCanvas streamer
991
992 // invoke callback for streaming
993 resfunc(&paddata);
994
995 // and restore back primitives - delete any temporary if necessary
996 for (unsigned n = 0; n < fAllPads.size(); ++n) {
997 if (fAllPads[n]->fPrimitives)
998 delete fAllPads[n]->fPrimitives;
999 fAllPads[n]->fPrimitives = all_primitives[n];
1000 }
1001 fAllPads.clear();
1002}
1003
1004//////////////////////////////////////////////////////////////////////////////////////////////////
1005/// Add control message for specified connection
1006/// Same control message can be overwritten many time before it really sends to the client
1007/// If connid == 0, message will be add to all connections
1008/// After ctrl message is add to the output, short timer is activated and message send afterwards
1009
1010void TWebCanvas::AddCtrlMsg(unsigned connid, const std::string &key, const std::string &value)
1011{
1012 Bool_t new_ctrl = kFALSE;
1013
1014 for (auto &conn : fWebConn) {
1015 if (conn.match(connid)) {
1016 conn.fCtrl[key] = value;
1017 new_ctrl = kTRUE;
1018 }
1019 }
1020
1021 if (new_ctrl && fTimer->IsSlow())
1023}
1024
1025
1026//////////////////////////////////////////////////////////////////////////////////////////////////
1027/// Add message to send queue for specified connection
1028/// If connid == 0, message will be add to all connections
1029
1030void TWebCanvas::AddSendQueue(unsigned connid, const std::string &msg)
1031{
1032 for (auto &conn : fWebConn) {
1033 if (conn.match(connid))
1034 conn.fSend.emplace(msg);
1035 }
1036}
1037
1038
1039//////////////////////////////////////////////////////////////////////////////////////////////////
1040/// Check if any data should be send to client
1041/// If connid != 0, only selected connection will be checked
1042
1044{
1045 if (!Canvas())
1046 return kFALSE;
1047
1048 bool isMoreData = false, isAnySend = false;
1049
1050 for (auto &conn : fWebConn) {
1051
1052 bool isConnData = !conn.fCtrl.empty() || !conn.fSend.empty() ||
1053 ((conn.fCheckedVersion < fCanvVersion) && (conn.fSendVersion == conn.fDrawVersion));
1054
1055 while ((conn.is_batch() && !connid) || (conn.match(connid) && fWindow && fWindow->CanSend(conn.fConnId, true))) {
1056 // check if any control messages still there to keep timer running
1057
1058 std::string buf;
1059
1060 if (!conn.fCtrl.empty()) {
1062 conn.fCtrl.clear();
1063 } else if (!conn.fSend.empty()) {
1064 std::swap(buf, conn.fSend.front());
1065 conn.fSend.pop();
1066 } else if ((conn.fCheckedVersion < fCanvVersion) && (conn.fSendVersion == conn.fDrawVersion)) {
1067
1068 buf = "SNAP6:"s + std::to_string(fCanvVersion) + ":"s;
1069
1070 TCanvasWebSnapshot holder(IsReadOnly(), true, false); // readonly, set ids, batchmode
1071
1072 holder.SetFixedSize(fFixedSize); // set fixed size flag
1073
1074 // scripts send only when canvas drawn for the first time
1075 if (!conn.fSendVersion)
1076 holder.SetScripts(fCustomScripts);
1077
1078 holder.SetHighlightConnect(Canvas()->HasConnection("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)"));
1079
1080 CreatePadSnapshot(holder, Canvas(), conn.fSendVersion, [&buf, &conn, this](TPadWebSnapshot *snap) {
1081 if (conn.is_batch()) {
1082 // for batch connection only calling of CreatePadSnapshot is important
1083 buf.clear();
1084 return;
1085 }
1086
1087 auto json = TBufferJSON::ToJSON(snap, fJsonComp);
1088 auto hash = json.Hash();
1089 if (conn.fLastSendHash && (conn.fLastSendHash == hash) && conn.fSendVersion) {
1090 // prevent looping when same data send many times
1091 buf.clear();
1092 } else {
1093 buf.append(json.Data());
1094 conn.fLastSendHash = hash;
1095 }
1096 });
1097
1098 conn.fCheckedVersion = fCanvVersion;
1099
1100 conn.fSendVersion = fCanvVersion;
1101
1102 if (buf.empty())
1103 conn.fDrawVersion = fCanvVersion;
1104 } else {
1105 isConnData = false;
1106 break;
1107 }
1108
1109 if (!buf.empty() && !conn.is_batch()) {
1110 fWindow->Send(conn.fConnId, buf);
1111 isAnySend = true;
1112 }
1113 }
1114
1115 if (isConnData)
1116 isMoreData = true;
1117 }
1118
1119 if (fTimer->IsSlow() && isMoreData)
1120 fTimer->SetSlow(kFALSE);
1121
1122 return isAnySend;
1123}
1124
1125//////////////////////////////////////////////////////////////////////////////////////////
1126/// Close web canvas - not implemented
1127
1129{
1130}
1131
1132//////////////////////////////////////////////////////////////////////////////////////////
1133/// Show canvas in specified place.
1134/// If parameter args not specified, default ROOT web display will be used
1135
1137{
1138 if (!fWindow) {
1140
1141 fWindow->SetConnLimit(0); // configure connections limit
1142
1143 fWindow->SetDefaultPage("file:rootui5sys/canv/canvas6.html");
1144
1145 fWindow->SetCallBacks(
1146 // connection
1147 [this](unsigned connid) {
1148 fWebConn.emplace_back(connid);
1149 CheckDataToSend(connid);
1150 },
1151 // data
1152 [this](unsigned connid, const std::string &arg) {
1153 ProcessData(connid, arg);
1155 },
1156 // disconnect
1157 [this](unsigned connid) {
1158 unsigned indx = 0;
1159 for (auto &c : fWebConn) {
1160 if (c.fConnId == connid) {
1161 fWebConn.erase(fWebConn.begin() + indx);
1162 break;
1163 }
1164 indx++;
1165 }
1166 });
1167 }
1168
1169 auto w = Canvas()->GetWindowWidth(), h = Canvas()->GetWindowHeight();
1170 if ((w > 0) && (w < 50000) && (h > 0) && (h < 30000))
1171 fWindow->SetGeometry(w, h);
1172
1177
1178 fWindow->Show(args);
1179}
1180
1181//////////////////////////////////////////////////////////////////////////////////////////
1182/// Show canvas in browser window
1183
1185{
1186 if (gROOT->IsWebDisplayBatch())
1187 return;
1188
1190 args.SetWidgetKind("TCanvas");
1191 args.SetSize(Canvas()->GetWindowWidth(), Canvas()->GetWindowHeight());
1192 args.SetPos(Canvas()->GetWindowTopX(), Canvas()->GetWindowTopY());
1193
1194 ShowWebWindow(args);
1195}
1196
1197//////////////////////////////////////////////////////////////////////////////////////////
1198/// Function used to send command to browser to toggle menu, toolbar, editors, ...
1199
1200void TWebCanvas::ShowCmd(const std::string &arg, Bool_t show)
1201{
1202 AddCtrlMsg(0, arg, show ? "1"s : "0"s);
1203}
1204
1205//////////////////////////////////////////////////////////////////////////////////////////
1206/// Activate object in editor in web browser
1207
1209{
1210 if (!pad || !obj) return;
1211
1212 UInt_t hash = TString::Hash(&obj, sizeof(obj));
1213
1214 AddCtrlMsg(0, "edit"s, std::to_string(hash));
1215}
1216
1217//////////////////////////////////////////////////////////////////////////////////////////
1218/// Returns kTRUE if web canvas has graphical editor
1219
1221{
1222 return (fClientBits & TCanvas::kShowEditor) != 0;
1223}
1224
1225//////////////////////////////////////////////////////////////////////////////////////////
1226/// Returns kTRUE if web canvas has menu bar
1227
1229{
1230 return (fClientBits & TCanvas::kMenuBar) != 0;
1231}
1232
1233//////////////////////////////////////////////////////////////////////////////////////////
1234/// Returns kTRUE if web canvas has status bar
1235
1237{
1238 return (fClientBits & TCanvas::kShowEventStatus) != 0;
1239}
1240
1241//////////////////////////////////////////////////////////////////////////////////////////
1242/// Returns kTRUE if tooltips are activated in web canvas
1243
1245{
1246 return (fClientBits & TCanvas::kShowToolTips) != 0;
1247}
1248
1249//////////////////////////////////////////////////////////////////////////////////////////
1250/// Set window position of web canvas
1251
1253{
1254 AddCtrlMsg(0, "x"s, std::to_string(x));
1255 AddCtrlMsg(0, "y"s, std::to_string(y));
1256}
1257
1258//////////////////////////////////////////////////////////////////////////////////////////
1259/// Set window size of web canvas
1260
1262{
1263 AddCtrlMsg(0, "w"s, std::to_string(w));
1264 AddCtrlMsg(0, "h"s, std::to_string(h));
1265}
1266
1267//////////////////////////////////////////////////////////////////////////////////////////
1268/// Set window title of web canvas
1269
1270void TWebCanvas::SetWindowTitle(const char *newTitle)
1271{
1272 AddCtrlMsg(0, "title"s, newTitle);
1273}
1274
1275//////////////////////////////////////////////////////////////////////////////////////////
1276/// Set canvas size of web canvas
1277
1279{
1280 fFixedSize = kTRUE;
1281 AddCtrlMsg(0, "cw"s, std::to_string(cw));
1282 AddCtrlMsg(0, "ch"s, std::to_string(ch));
1283 if ((cw > 0) && (ch > 0)) {
1284 Canvas()->fCw = cw;
1285 Canvas()->fCh = ch;
1286 } else {
1287 // temporary value, will be reported back from client
1288 Canvas()->fCw = Canvas()->fWindowWidth;
1290 }
1291}
1292
1293//////////////////////////////////////////////////////////////////////////////////////////
1294/// Iconify browser window
1295
1297{
1298 AddCtrlMsg(0, "winstate"s, "iconify"s);
1299}
1300
1301//////////////////////////////////////////////////////////////////////////////////////////
1302/// Raise browser window
1303
1305{
1306 AddCtrlMsg(0, "winstate"s, "raise"s);
1307}
1308
1309//////////////////////////////////////////////////////////////////////////////////////////
1310/// Assign clients bits
1311
1313{
1314 fClientBits = bits;
1319}
1320
1321//////////////////////////////////////////////////////////////////////////////////////////////////
1322/// Decode all pad options, which includes ranges plus objects options
1323
1324Bool_t TWebCanvas::DecodePadOptions(const std::string &msg, bool process_execs)
1325{
1326 if (IsReadOnly() || msg.empty())
1327 return kFALSE;
1328
1329 auto arr = TBufferJSON::FromJSON<std::vector<TWebPadOptions>>(msg);
1330
1331 if (!arr)
1332 return kFALSE;
1333
1334 Bool_t need_update = kFALSE;
1335
1336 TPad *pad_with_execs = nullptr;
1337 TExec *hist_exec = nullptr;
1338
1339 for (unsigned n = 0; n < arr->size(); ++n) {
1340 auto &r = arr->at(n);
1341
1342 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(r.snapid));
1343
1344 if (!pad)
1345 continue;
1346
1347 if (pad == Canvas()) {
1348 AssignStatusBits(r.bits);
1349 Canvas()->fCw = r.cw;
1350 Canvas()->fCh = r.ch;
1351 if (r.w.size() == 4) {
1352 fWindowGeometry = r.w;
1357 }
1358 }
1359
1360 // only if get OPTIONS message from client allow to change gPad
1361 if (r.active && (pad != gPad) && process_execs)
1362 gPad = pad;
1363
1364 if ((pad->GetTickx() != r.tickx) || (pad->GetTicky() != r.ticky))
1365 pad->SetTicks(r.tickx, r.ticky);
1366 if ((pad->GetGridx() != (r.gridx > 0)) || (pad->GetGridy() != (r.gridy > 0)))
1367 pad->SetGrid(r.gridx, r.gridy);
1368 pad->fLogx = r.logx;
1369 pad->fLogy = r.logy;
1370 pad->fLogz = r.logz;
1371
1372 pad->SetLeftMargin(r.mleft);
1373 pad->SetRightMargin(r.mright);
1374 pad->SetTopMargin(r.mtop);
1375 pad->SetBottomMargin(r.mbottom);
1376
1377 if (r.ranges) {
1378 // avoid call of original methods, set members directly
1379 // pad->Range(r.px1, r.py1, r.px2, r.py2);
1380 // pad->RangeAxis(r.ux1, r.uy1, r.ux2, r.uy2);
1381
1382 pad->fX1 = r.px1;
1383 pad->fX2 = r.px2;
1384 pad->fY1 = r.py1;
1385 pad->fY2 = r.py2;
1386
1387 pad->fUxmin = r.ux1;
1388 pad->fUxmax = r.ux2;
1389 pad->fUymin = r.uy1;
1390 pad->fUymax = r.uy2;
1391 }
1392
1393 // pad->SetPad(r.mleft, r.mbottom, 1-r.mright, 1-r.mtop);
1394
1395 pad->fAbsXlowNDC = r.xlow;
1396 pad->fAbsYlowNDC = r.ylow;
1397 pad->fAbsWNDC = r.xup - r.xlow;
1398 pad->fAbsHNDC = r.yup - r.ylow;
1399
1400 if (pad == Canvas()) {
1401 pad->fXlowNDC = r.xlow;
1402 pad->fYlowNDC = r.ylow;
1403 pad->fXUpNDC = r.xup;
1404 pad->fYUpNDC = r.yup;
1405 pad->fWNDC = r.xup - r.xlow;
1406 pad->fHNDC = r.yup - r.ylow;
1407 } else {
1408 auto mother = pad->GetMother();
1409 if (mother->GetAbsWNDC() > 0. && mother->GetAbsHNDC() > 0.) {
1410 pad->fXlowNDC = (r.xlow - mother->GetAbsXlowNDC()) / mother->GetAbsWNDC();
1411 pad->fYlowNDC = (r.ylow - mother->GetAbsYlowNDC()) / mother->GetAbsHNDC();
1412 pad->fXUpNDC = (r.xup - mother->GetAbsXlowNDC()) / mother->GetAbsWNDC();
1413 pad->fYUpNDC = (r.yup - mother->GetAbsYlowNDC()) / mother->GetAbsHNDC();
1414 pad->fWNDC = (r.xup - r.xlow) / mother->GetAbsWNDC();
1415 pad->fHNDC = (r.yup - r.ylow) / mother->GetAbsHNDC();
1416 }
1417 }
1418
1419 // copy of code from TPad::ResizePad()
1420
1421 Double_t pxlow = r.xlow * r.cw;
1422 Double_t pylow = (1-r.ylow) * r.ch;
1423 Double_t pxrange = (r.xup - r.xlow) * r.cw;
1424 Double_t pyrange = -1*(r.yup - r.ylow) * r.ch;
1425
1426 Double_t rounding = 0.00005;
1427 Double_t xrange = r.px2 - r.px1;
1428 Double_t yrange = r.py2 - r.py1;
1429
1430 if ((xrange != 0.) && (pxrange != 0)) {
1431 // Linear X axis
1432 pad->fXtoAbsPixelk = rounding + pxlow - pxrange*r.px1/xrange; //origin at left
1433 pad->fXtoPixelk = rounding + -pxrange*r.px1/xrange;
1434 pad->fXtoPixel = pxrange/xrange;
1435 pad->fAbsPixeltoXk = r.px1 - pxlow*xrange/pxrange;
1436 pad->fPixeltoXk = r.px1;
1437 pad->fPixeltoX = xrange/pxrange;
1438 }
1439
1440 if ((yrange != 0.) && (pyrange != 0.)) {
1441 // Linear Y axis
1442 pad->fYtoAbsPixelk = rounding + pylow - pyrange*r.py1/yrange; //origin at top
1443 pad->fYtoPixelk = rounding + -pyrange - pyrange*r.py1/yrange;
1444 pad->fYtoPixel = pyrange/yrange;
1445 pad->fAbsPixeltoYk = r.py1 - pylow*yrange/pyrange;
1446 pad->fPixeltoYk = r.py1;
1447 pad->fPixeltoY = yrange/pyrange;
1448 }
1449
1451
1452 TObjLink *objlnk = nullptr;
1453
1454 TH1 *hist = static_cast<TH1 *>(FindPrimitive(sid_pad_histogram, 1, pad, &objlnk));
1455
1456 if (hist) {
1457
1458 TObject *hist_holder = objlnk ? objlnk->GetObject() : nullptr;
1459 if (hist_holder == hist)
1460 hist_holder = nullptr;
1461
1462 Bool_t no_entries = hist->GetEntries();
1463 Bool_t is_stack = hist_holder && (hist_holder->IsA() == THStack::Class());
1464
1465 Double_t hmin = 0., hmax = 0.;
1466
1467 if (r.zx1 == r.zx2)
1468 hist->GetXaxis()->SetRange(0, 0);
1469 else
1470 hist->GetXaxis()->SetRangeUser(r.zx1, r.zx2);
1471
1472 if (hist->GetDimension() == 1) {
1473 hmin = r.zy1;
1474 hmax = r.zy2;
1475 if ((hmin == hmax) && !no_entries && !is_stack) {
1476 // if there are no zooming on Y and histogram has no entries, hmin/hmax should be set to full range
1477 hmin = pad->fLogy ? TMath::Power(pad->fLogy < 2 ? 10 : pad->fLogy, r.uy1) : r.uy1;
1478 hmax = pad->fLogy ? TMath::Power(pad->fLogy < 2 ? 10 : pad->fLogy, r.uy2) : r.uy2;
1479 }
1480 } else if (r.zy1 == r.zy2) {
1481 hist->GetYaxis()->SetRange(0, 0);
1482 } else {
1483 hist->GetYaxis()->SetRangeUser(r.zy1, r.zy2);
1484 }
1485
1486 if (hist->GetDimension() == 2) {
1487 hmin = r.zz1;
1488 hmax = r.zz2;
1489 if ((hmin == hmax) && !no_entries) {
1490 // z scale is not transformed
1491 hmin = r.uz1;
1492 hmax = r.uz2;
1493 }
1494 } else if (hist->GetDimension() == 3) {
1495 if (r.zz1 == r.zz2) {
1496 hist->GetZaxis()->SetRange(0, 0);
1497 } else {
1498 hist->GetZaxis()->SetRangeUser(r.zz1, r.zz2);
1499 }
1500 }
1501
1502 if (hmin == hmax)
1503 hmin = hmax = -1111;
1504
1505 if (is_stack) {
1506 TString opt = objlnk->GetOption();
1507 if (!opt.Contains("nostack", TString::kIgnoreCase) && !opt.Contains("lego", TString::kIgnoreCase)) {
1508 hist->SetMinimum(hmin);
1509 hist->SetMaximum(hmax);
1510 hist->SetBit(TH1::kIsZoomed, hmin != hmax);
1511 }
1512 } else if (!hist_holder || (hist_holder->IsA() == TScatter::Class())) {
1513 hist->SetMinimum(hmin);
1514 hist->SetMaximum(hmax);
1515 } else {
1516 auto SetMember = [hist_holder](const char *name, Double_t value) {
1517 auto offset = hist_holder->IsA()->GetDataMemberOffset(name);
1518 if (offset > 0)
1519 *((Double_t *)((char*) hist_holder + offset)) = value;
1520 else
1521 ::Error("SetMember", "Cannot find %s data member in %s", name, hist_holder->ClassName());
1522 };
1523
1524 // directly set min/max in classes like THStack, TGraph, TMultiGraph
1525 SetMember("fMinimum", hmin);
1526 SetMember("fMaximum", hmax);
1527 }
1528
1529 TIter next(hist->GetListOfFunctions());
1530 while (auto fobj = next())
1531 if (!hist_exec && fobj->InheritsFrom(TExec::Class())) {
1532 hist_exec = (TExec *) fobj;
1533 need_update = kTRUE;
1534 }
1535 }
1536
1537 std::map<std::string, int> idmap;
1538
1539 for (auto &item : r.primitives) {
1540 auto iter = idmap.find(item.snapid);
1541 int idcnt = 1;
1542 if (iter == idmap.end())
1543 idmap[item.snapid] = 1;
1544 else
1545 idcnt = ++iter->second;
1546
1547 ProcessObjectOptions(item, pad, idcnt);
1548 }
1549
1550 // without special objects no need for explicit update of the pad
1551 if (fPadsStatus[pad]._has_specials) {
1552 pad->Modified(kTRUE);
1553 need_update = kTRUE;
1554 }
1555
1556 if (process_execs && (gPad == pad))
1557 pad_with_execs = pad;
1558 }
1559
1560 ProcessExecs(pad_with_execs, hist_exec);
1561
1562 if (fUpdatedSignal) fUpdatedSignal(); // invoke signal
1563
1564 return need_update;
1565}
1566
1567//////////////////////////////////////////////////////////////////////////////////////////////////
1568/// Process TExec objects in the pad
1569
1571{
1572 auto execs = pad ? pad->GetListOfExecs() : nullptr;
1573
1574 if ((!execs || !execs->GetSize()) && !extra)
1575 return;
1576
1577 auto saveps = gVirtualPS;
1578 TWebPS ps;
1579 gVirtualPS = &ps;
1580
1581 auto savex = gVirtualX;
1582 TVirtualX x;
1583 gVirtualX = &x;
1584
1585 TIter next(execs);
1586 while (auto obj = next()) {
1587 auto exec = dynamic_cast<TExec *>(obj);
1588 if (exec)
1589 exec->Exec();
1590 }
1591
1592 if (extra)
1593 extra->Exec();
1594
1595 gVirtualPS = saveps;
1596 gVirtualX = savex;
1597}
1598
1599//////////////////////////////////////////////////////////////////////////////////////////
1600/// Execute one or several methods for selected object
1601/// String can be separated by ";;" to let execute several methods at once
1602void TWebCanvas::ProcessLinesForObject(TObject *obj, const std::string &lines)
1603{
1604 std::string buf = lines;
1605
1606 Int_t indx = 0;
1607
1608 while (obj && !buf.empty()) {
1609 std::string sub = buf;
1610 auto pos = buf.find(";;");
1611 if (pos == std::string::npos) {
1612 sub = buf;
1613 buf.clear();
1614 } else {
1615 sub = buf.substr(0,pos);
1616 buf = buf.substr(pos+2);
1617 }
1618 if (sub.empty()) continue;
1619
1620 std::stringstream exec;
1621 exec << "((" << obj->ClassName() << " *) " << std::hex << std::showbase << (size_t)obj << ")->" << sub << ";";
1622 if (indx < 3 || gDebug > 0)
1623 Info("ProcessLinesForObject", "Obj %s Execute %s", obj->GetName(), exec.str().c_str());
1624 gROOT->ProcessLine(exec.str().c_str());
1625 indx++;
1626 }
1627}
1628
1629//////////////////////////////////////////////////////////////////////////////////////////
1630/// Handle data from web browser
1631/// Returns kFALSE if message was not processed
1632
1633Bool_t TWebCanvas::ProcessData(unsigned connid, const std::string &arg)
1634{
1635 if (arg.empty())
1636 return kTRUE;
1637
1638 // try to identify connection for given WS request
1639 unsigned indx = 0; // first connection is batch and excluded
1640 while(++indx < fWebConn.size()) {
1641 if (fWebConn[indx].fConnId == connid)
1642 break;
1643 }
1644 if (indx >= fWebConn.size())
1645 return kTRUE;
1646
1647 Bool_t is_main_connection = indx == 1; // first connection allow to make changes
1648
1649 struct FlagGuard {
1650 Bool_t &flag;
1651 FlagGuard(Bool_t &_flag) : flag(_flag) { flag = true; }
1652 ~FlagGuard() { flag = false; }
1653 };
1654
1655 FlagGuard guard(fProcessingData);
1656
1657 const char *cdata = arg.c_str();
1658
1659 if (arg == "KEEPALIVE") {
1660 // do nothing
1661
1662 } else if (arg == "QUIT") {
1663
1664 // use window manager to correctly terminate http server
1665 fWindow->TerminateROOT();
1666
1667 } else if (arg.compare(0, 7, "READY6:") == 0) {
1668
1669 // this is reply on drawing of ROOT6 snapshot
1670 // it confirms when drawing of specific canvas version is completed
1671
1672 cdata += 7;
1673
1674 const char *separ = strchr(cdata, ':');
1675 if (!separ) {
1676 fWebConn[indx].fDrawVersion = std::stoll(cdata);
1677 } else {
1678 fWebConn[indx].fDrawVersion = std::stoll(std::string(cdata, separ - cdata));
1679 if (is_main_connection && !IsReadOnly())
1680 if (DecodePadOptions(separ+1, false))
1682 }
1683
1684 } else if (arg == "RELOAD") {
1685
1686 // trigger reload of canvas data
1687 fWebConn[indx].reset();
1688
1689 } else if (arg.compare(0, 5, "SAVE:") == 0) {
1690
1691 // save image produced by the client side - like png or svg
1692 const char *img = cdata + 5;
1693
1694 const char *separ = strchr(img, ':');
1695 if (separ) {
1696 TString filename(img, separ - img);
1697 img = separ + 1;
1698
1699 std::ofstream ofs(filename.Data());
1700
1701 if (filename.Index(".svg") != kNPOS) {
1702 // ofs << "<?xml version=\"1.0\" standalone=\"no\"?>";
1703 ofs << img;
1704 } else {
1705 TString binary = TBase64::Decode(img);
1706 ofs.write(binary.Data(), binary.Length());
1707 }
1708 ofs.close();
1709
1710 Info("ProcessData", "File %s has been created", filename.Data());
1711 }
1712
1713 } else if (arg.compare(0, 8, "PRODUCE:") == 0) {
1714
1715 // create ROOT, PDF, ... files using native ROOT functionality
1716 Canvas()->Print(arg.c_str() + 8);
1717
1718 } else if (arg.compare(0, 9, "OPTIONS6:") == 0) {
1719
1720 if (is_main_connection && !IsReadOnly())
1721 if (DecodePadOptions(arg.substr(9), true))
1723
1724 } else if (arg.compare(0, 11, "STATUSBITS:") == 0) {
1725
1726 if (is_main_connection) {
1727 AssignStatusBits(std::stoul(arg.substr(11)));
1728 if (fUpdatedSignal) fUpdatedSignal(); // invoke signal
1729 }
1730 } else if (arg.compare(0, 10, "HIGHLIGHT:") == 0) {
1731 if (is_main_connection) {
1732 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(10));
1733 if (!arr || (arr->size() != 4)) {
1734 Error("ProcessData", "Wrong arguments count %d in highlight message", (int)(arr ? arr->size() : -1));
1735 } else {
1736 auto pad = dynamic_cast<TVirtualPad *>(FindPrimitive(arr->at(0)));
1737 auto obj = FindPrimitive(arr->at(1));
1738 int argx = std::stoi(arr->at(2));
1739 int argy = std::stoi(arr->at(3));
1740 if (pad && obj) {
1741 Canvas()->Highlighted(pad, obj, argx, argy);
1743 }
1744 }
1745 }
1746 } else if (ROOT::RWebWindow::IsFileDialogMessage(arg)) {
1747
1749
1750 } else if (arg == "FITPANEL"s) {
1751
1752 TH1 *hist = nullptr;
1753 TIter iter(Canvas()->GetListOfPrimitives());
1754 while (auto obj = iter()) {
1755 hist = dynamic_cast<TH1 *>(obj);
1756 if (hist) break;
1757 }
1758
1759 TString cmd = TString::Format("auto panel = std::make_shared<ROOT::Experimental::RFitPanel>(\"FitPanel\");"
1760 "panel->AssignCanvas(\"%s\");"
1761 "panel->AssignHistogram((TH1 *)0x%zx);"
1762 "panel->Show();"
1763 "panel->ClearOnClose(panel);", Canvas()->GetName(), (size_t) hist);
1764
1765 gROOT->ProcessLine(cmd.Data());
1766
1767 } else if (arg == "START_BROWSER"s) {
1768
1769 gROOT->ProcessLine("new TBrowser;");
1770
1771 } else if (IsReadOnly()) {
1772
1773 // all following messages are not allowed in readonly mode
1774 return kFALSE;
1775
1776 } else if (arg.compare(0, 6, "EVENT:") == 0) {
1777 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(6));
1778 if (!arr || (arr->size() != 5)) {
1779 Error("ProcessData", "Wrong arguments count %d in event message", (int)(arr ? arr->size() : -1));
1780 } else {
1781 auto pad = dynamic_cast<TPad *>(FindPrimitive(arr->at(0)));
1782 std::string kind = arr->at(1);
1783 int event = -1;
1784 if (kind == "move"s) event = kMouseMotion;
1785 int argx = std::stoi(arr->at(2));
1786 int argy = std::stoi(arr->at(3));
1787 auto selobj = FindPrimitive(arr->at(4));
1788
1789 if ((event >= 0) && pad && (pad == gPad)) {
1790 Canvas()->fEvent = event;
1791 Canvas()->fEventX = argx;
1792 Canvas()->fEventY = argy;
1793
1794 Canvas()->fSelected = selobj;
1795
1796 ProcessExecs(pad);
1797 }
1798 }
1799
1800 } else if (arg.compare(0, 8, "GETMENU:") == 0) {
1801
1802 TObject *obj = FindPrimitive(arg.substr(8));
1803 if (!obj)
1804 obj = Canvas();
1805
1806 TWebMenuItems items(arg.c_str() + 8);
1807 items.PopulateObjectMenu(obj, obj->IsA());
1808 std::string buf = "MENU:";
1809 buf.append(TBufferJSON::ToJSON(&items, 103).Data());
1810
1811 AddSendQueue(connid, buf);
1812
1813 } else if (arg.compare(0, 8, "PRIMIT6:") == 0) {
1814
1815 if (IsFirstConn(connid) && !IsReadOnly()) { // only first connection can modify object
1816
1817 auto opt = TBufferJSON::FromJSON<TWebObjectOptions>(arg.c_str() + 8);
1818
1819 if (opt) {
1820 TPad *modpad = ProcessObjectOptions(*opt, nullptr);
1821
1822 // indicate that pad was modified
1823 if (modpad)
1824 modpad->Modified();
1825 }
1826 }
1827
1828 } else if (arg.compare(0, 11, "PADCLICKED:") == 0) {
1829
1830 auto click = TBufferJSON::FromJSON<TWebPadClick>(arg.c_str() + 11);
1831
1832 if (click && IsFirstConn(connid) && !IsReadOnly()) {
1833
1834 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(click->padid));
1835
1836 if (pad && pad->InheritsFrom(TButton::Class())) {
1837 auto btn = (TButton *) pad;
1838 const char *mthd = btn->GetMethod();
1839 if (mthd && *mthd) {
1840 TVirtualPad::TContext ctxt(gROOT->GetSelectedPad(), kTRUE, kTRUE);
1841 gROOT->ProcessLine(mthd);
1842 }
1843 return kTRUE;
1844 }
1845
1846 if (pad && (pad != gPad)) {
1847 gPad = pad;
1851 }
1852
1853 if (!click->objid.empty()) {
1854 auto selobj = FindPrimitive(click->objid);
1855 Canvas()->SetClickSelected(selobj);
1856 Canvas()->fSelected = selobj;
1857 if (pad && selobj && fObjSelectSignal)
1858 fObjSelectSignal(pad, selobj);
1859 }
1860
1861 if ((click->x >= 0) && (click->y >= 0)) {
1862 Canvas()->fEvent = click->dbl ? kButton1Double : kButton1Up;
1863 Canvas()->fEventX = click->x;
1864 Canvas()->fEventY = click->y;
1865 if (click->dbl && fPadDblClickedSignal)
1866 fPadDblClickedSignal(pad, click->x, click->y);
1867 else if (!click->dbl && fPadClickedSignal)
1868 fPadClickedSignal(pad, click->x, click->y);
1869 }
1870
1871 ProcessExecs(pad);
1872 }
1873
1874 } else if (arg.compare(0, 8, "OBJEXEC:") == 0) {
1875
1876 auto buf = arg.substr(8);
1877 auto pos = buf.find(":");
1878
1879 if ((pos > 0) && IsFirstConn(connid) && !IsReadOnly()) { // only first client can execute commands
1880 auto sid = buf.substr(0, pos);
1881 buf.erase(0, pos + 1);
1882
1883 TObjLink *lnk = nullptr;
1884 TPad *objpad = nullptr;
1885
1886 TObject *obj = FindPrimitive(sid, 1, nullptr, &lnk, &objpad);
1887
1888 if (obj && !buf.empty()) {
1889
1890 ProcessLinesForObject(obj, buf);
1891
1892 if (objpad)
1893 objpad->Modified();
1894 else
1895 Canvas()->Modified();
1896
1898 }
1899 }
1900
1901 } else if (arg.compare(0, 12, "EXECANDSEND:") == 0) {
1902
1903 // execute method and send data, used by drawing projections
1904
1905 std::string buf = arg.substr(12);
1906 std::string reply;
1907 TObject *obj = nullptr;
1908
1909 auto pos = buf.find(":");
1910
1911 if ((pos > 0) && IsFirstConn(connid) && !IsReadOnly()) {
1912 // only first client can execute commands
1913 reply = buf.substr(0, pos);
1914 buf.erase(0, pos + 1);
1915 pos = buf.find(":");
1916 if (pos > 0) {
1917 auto sid = buf.substr(0, pos);
1918 buf.erase(0, pos + 1);
1919 obj = FindPrimitive(sid);
1920 }
1921 }
1922
1923 if (obj && !buf.empty() && !reply.empty()) {
1924 std::stringstream exec;
1925 exec << "((" << obj->ClassName() << " *) " << std::hex << std::showbase << (size_t)obj
1926 << ")->" << buf << ";";
1927 if (gDebug > 0)
1928 Info("ProcessData", "Obj %s Exec %s", obj->GetName(), exec.str().c_str());
1929
1930 auto res = gROOT->ProcessLine(exec.str().c_str());
1931 TObject *resobj = (TObject *)(res);
1932 if (resobj) {
1933 std::string send = reply;
1934 send.append(":");
1935 send.append(TBufferJSON::ToJSON(resobj, 23).Data());
1936 AddSendQueue(connid, send);
1937 if (reply[0] == 'D')
1938 delete resobj; // delete object if first symbol in reply is D
1939 }
1940 }
1941
1942 } else if (arg.compare(0, 6, "CLEAR:") == 0) {
1943 std::string snapid = arg.substr(6);
1944
1945 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(snapid));
1946
1947 if (pad) {
1948 pad->Clear();
1949 pad->Modified();
1951 } else {
1952 Error("ProcessData", "Not found pad with id %s to clear\n", snapid.c_str());
1953 }
1954 } else if (arg.compare(0, 7, "DIVIDE:") == 0) {
1955 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
1956 if (arr && arr->size() == 2) {
1957 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(arr->at(0)));
1958 int nn = 0, n1 = 0, n2 = 0;
1959
1960 std::string divide = arr->at(1);
1961 auto p = divide.find('x');
1962 if (p == std::string::npos)
1963 p = divide.find('X');
1964
1965 if (p != std::string::npos) {
1966 n1 = std::stoi(divide.substr(0,p));
1967 n2 = std::stoi(divide.substr(p+1));
1968 } else {
1969 nn = std::stoi(divide);
1970 }
1971
1972 if (pad && ((nn > 1) || (n1*n2 > 1))) {
1973 pad->Clear();
1974 pad->Modified();
1975 if (nn > 1)
1976 pad->DivideSquare(nn);
1977 else
1978 pad->Divide(n1, n2);
1979 pad->cd(1);
1981 }
1982 }
1983
1984 } else if (arg.compare(0, 8, "DRAWOPT:") == 0) {
1985 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(8));
1986 if (arr && arr->size() == 2) {
1987 TObjLink *objlnk = nullptr;
1988 FindPrimitive(arr->at(0), 1, nullptr, &objlnk);
1989 if (objlnk)
1990 objlnk->SetOption(arr->at(1).c_str());
1991 }
1992 } else if (arg.compare(0, 8, "RESIZED:") == 0) {
1993 auto arr = TBufferJSON::FromJSON<std::vector<int>>(arg.substr(8));
1994 if (arr && arr->size() == 7) {
1995 // set members directly to avoid redrawing of the client again
1996 Canvas()->fCw = arr->at(4);
1997 Canvas()->fCh = arr->at(5);
1998 fFixedSize = arr->at(6) > 0;
1999 arr->resize(4);
2000 fWindowGeometry = *arr;
2005 }
2006 } else if (arg.compare(0, 7, "POPOBJ:") == 0) {
2007 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
2008 if (arr && arr->size() == 2) {
2009 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(arr->at(0)));
2010 TObject *obj = FindPrimitive(arr->at(1), 0, pad);
2011 if (pad && obj && (obj != pad->GetListOfPrimitives()->Last())) {
2012 TIter next(pad->GetListOfPrimitives());
2013 while (auto o = next())
2014 if (obj == o) {
2015 TString opt = next.GetOption();
2016 pad->GetListOfPrimitives()->Remove(obj);
2017 pad->GetListOfPrimitives()->AddLast(obj, opt.Data());
2018 pad->Modified();
2019 break;
2020 }
2021 }
2022 }
2023 } else if (arg == "INTERRUPT"s) {
2024 gROOT->SetInterrupt();
2025 } else {
2026 // unknown message, probably should be processed by other implementation
2027 return kFALSE;
2028 }
2029
2030 return kTRUE;
2031}
2032
2033//////////////////////////////////////////////////////////////////////////////////////////
2034/// Returns true if any pad in the canvas were modified
2035/// Reset modified flags, increment canvas version (if inc_version is true)
2036
2038{
2039 if (fPadsStatus.find(pad) == fPadsStatus.end())
2040 fPadsStatus[pad] = PadStatus{0, true, true};
2041
2042 auto &entry = fPadsStatus[pad];
2043 entry._detected = true;
2044 if (pad->IsModified()) {
2045 pad->Modified(kFALSE);
2046 entry._modified = true;
2047 }
2048
2049 TIter iter(pad->GetListOfPrimitives());
2050 while (auto obj = iter()) {
2051 if (obj->InheritsFrom(TPad::Class()))
2052 CheckPadModified(static_cast<TPad *>(obj));
2053 }
2054}
2055
2056//////////////////////////////////////////////////////////////////////////////////////////
2057/// Check if any pad on the canvas was modified
2058/// If yes, increment version of correspondent pad
2059/// Returns true when canvas really modified
2060
2062{
2063 // clear temporary flags
2064 for (auto &entry : fPadsStatus) {
2065 entry.second._detected = false;
2066 entry.second._modified = force_modified;
2067 }
2068
2069 // scan sub-pads
2071
2072 // remove no-longer existing pads
2073 bool is_any_modified = false;
2074 for(auto iter = fPadsStatus.begin(); iter != fPadsStatus.end(); ) {
2075 if (iter->second._modified)
2076 is_any_modified = true;
2077 if (!iter->second._detected)
2078 fPadsStatus.erase(iter++);
2079 else
2080 iter++;
2081 }
2082
2083 // if any pad modified, increment canvas version and set version of modified pads
2084 if (is_any_modified) {
2085 fCanvVersion++;
2086 for(auto &entry : fPadsStatus)
2087 if (entry.second._modified)
2088 entry.second.fVersion = fCanvVersion;
2089 }
2090
2091 return is_any_modified;
2092}
2093
2094
2095//////////////////////////////////////////////////////////////////////////////////////////
2096/// Returns window geometry including borders and menus
2097
2099{
2100 if (fWindowGeometry.size() == 4) {
2101 x = fWindowGeometry[0];
2102 y = fWindowGeometry[1];
2103 w = fWindowGeometry[2];
2104 h = fWindowGeometry[3];
2105 } else {
2106 x = Canvas()->fWindowTopX;
2107 y = Canvas()->fWindowTopY;
2108 w = Canvas()->fWindowWidth;
2109 h = Canvas()->fWindowHeight;
2110 }
2111 return 0;
2112}
2113
2114
2115//////////////////////////////////////////////////////////////////////////////////////////
2116/// if canvas or any subpad was modified,
2117/// scan all primitives in the TCanvas and subpads and convert them into
2118/// the structure which will be delivered to JSROOT client
2119
2121{
2123
2125
2126 if (!fProcessingData && !IsAsyncMode() && !async)
2128
2129 return kTRUE;
2130}
2131
2132//////////////////////////////////////////////////////////////////////////////////////////
2133/// Increment canvas version and force sending data to client - do not wait for reply
2134
2136{
2137 CheckCanvasModified(true);
2138
2139 if (!fWindow) {
2140 TCanvasWebSnapshot holder(IsReadOnly(), false, true); // readonly, set ids, batchmode
2141 CreatePadSnapshot(holder, Canvas(), 0, nullptr);
2142 } else {
2144 }
2145}
2146
2147//////////////////////////////////////////////////////////////////////////////////////////
2148/// Wait when specified version of canvas was painted and confirmed by browser
2149
2151{
2152 if (!fWindow)
2153 return kTRUE;
2154
2155 // simple polling loop until specified version delivered to the clients
2156 // first 500 loops done without sleep, then with 1ms sleep and last 500 with 100 ms sleep
2157
2158 long cnt = 0, cnt_limit = GetLongerPolling() ? 5500 : 1500;
2159
2160 if (gDebug > 2)
2161 Info("WaitWhenCanvasPainted", "version %ld", (long)ver);
2162
2163 while (cnt++ < cnt_limit) {
2164
2165 if (!fWindow->HasConnection(0, false)) {
2166 if (gDebug > 2)
2167 Info("WaitWhenCanvasPainted", "no connections - abort");
2168 return kFALSE; // wait ~1 min if no new connection established
2169 }
2170
2171 if ((fWebConn.size() > 1) && (fWebConn[1].fDrawVersion >= ver)) {
2172 if (gDebug > 2)
2173 Info("WaitWhenCanvasPainted", "ver %ld got painted", (long)ver);
2174 return kTRUE;
2175 }
2176
2178 if (cnt > 500)
2179 gSystem->Sleep((cnt < cnt_limit - 500) ? 1 : 100); // increase sleep interval when do very often
2180 }
2181
2182 if (gDebug > 2)
2183 Info("WaitWhenCanvasPainted", "timeout");
2184
2185 return kFALSE;
2186}
2187
2188//////////////////////////////////////////////////////////////////////////////////////////
2189/// Create JSON painting output for given pad
2190/// Produce JSON can be used for offline drawing with JSROOT
2191
2192TString TWebCanvas::CreatePadJSON(TPad *pad, Int_t json_compression, Bool_t batchmode)
2193{
2194 TString res;
2195 if (!pad)
2196 return res;
2197
2198 TCanvas *c = dynamic_cast<TCanvas *>(pad);
2199 if (c) {
2200 res = CreateCanvasJSON(c, json_compression, batchmode);
2201 } else {
2202 auto imp = std::make_unique<TWebCanvas>(pad->GetCanvas(), pad->GetName(), 0, 0, pad->GetWw(), pad->GetWh(), kTRUE);
2203
2204 TPadWebSnapshot holder(true, false, batchmode); // readonly, no ids, batchmode
2205
2206 imp->CreatePadSnapshot(holder, pad, 0, [&res, json_compression](TPadWebSnapshot *snap) {
2207 res = TBufferJSON::ToJSON(snap, json_compression);
2208 });
2209 }
2210
2211 return res;
2212}
2213
2214//////////////////////////////////////////////////////////////////////////////////////////
2215/// Create JSON painting output for given canvas
2216/// Produce JSON can be used for offline drawing with JSROOT
2217
2219{
2220 TString res;
2221
2222 if (!c)
2223 return res;
2224
2225 {
2226 auto imp = std::make_unique<TWebCanvas>(c, c->GetName(), 0, 0, c->GetWw(), c->GetWh(), kTRUE);
2227
2228 TCanvasWebSnapshot holder(true, false, batchmode); // readonly, no ids, batchmode
2229
2230 imp->CreatePadSnapshot(holder, c, 0, [&res, json_compression](TPadWebSnapshot *snap) {
2231 res = TBufferJSON::ToJSON(snap, json_compression);
2232 });
2233 }
2234
2235 return res;
2236}
2237
2238//////////////////////////////////////////////////////////////////////////////////////////
2239/// Create JSON painting output for given canvas and store into the file
2240/// See TBufferJSON::ExportToFile() method for more details about option
2241/// If option string starts with symbol 'b', JSON for batch mode will be generated
2242
2244{
2245 Int_t res = 0;
2246 Bool_t batchmode = kFALSE;
2247 if (option && *option == 'b') {
2248 batchmode = kTRUE;
2249 ++option;
2250 }
2251
2252 if (!c)
2253 return res;
2254
2255 {
2256 auto imp = std::make_unique<TWebCanvas>(c, c->GetName(), 0, 0, c->GetWw(), c->GetWh(), kTRUE);
2257
2258 TCanvasWebSnapshot holder(true, false, batchmode); // readonly, no ids, batchmode
2259
2260 imp->CreatePadSnapshot(holder, c, 0, [&res, filename, option](TPadWebSnapshot *snap) {
2262 });
2263 }
2264
2265 return res;
2266}
2267
2268//////////////////////////////////////////////////////////////////////////////////////////
2269/// Create image using batch (headless) capability of Chrome or Firefox browsers
2270/// Supported png, jpeg, svg, pdf formats
2271
2272bool TWebCanvas::ProduceImage(TPad *pad, const char *fileName, Int_t width, Int_t height)
2273{
2274 if (!pad)
2275 return false;
2276
2278 if (!json.Length())
2279 return false;
2280
2281 if (!width && !height) {
2282 if ((pad->GetCanvas() == pad) || (pad->IsA() == TCanvas::Class())) {
2283 width = pad->GetWw();
2284 height = pad->GetWh();
2285 } else {
2286 width = (Int_t) (pad->GetAbsWNDC() * pad->GetCanvas()->GetWw());
2287 height = (Int_t) (pad->GetAbsHNDC() * pad->GetCanvas()->GetWh());
2288 }
2289 }
2290
2291 return ROOT::RWebDisplayHandle::ProduceImage(fileName, json.Data(), width, height);
2292}
2293
2294//////////////////////////////////////////////////////////////////////////////////////////
2295/// Create images for several pads using batch (headless) capability of Chrome or Firefox browsers
2296/// Supported png, jpeg, svg, pdf, webp formats
2297/// One can include %d qualifier which will be replaced by image index using printf functionality.
2298/// If for pdf format %d qualifier not specified, all images will be stored in single PDF file.
2299/// For all other formats %d qualifier will be add before extension automatically
2300
2301bool TWebCanvas::ProduceImages(std::vector<TPad *> pads, const char *filename, Int_t width, Int_t height)
2302{
2303 if (pads.empty())
2304 return false;
2305
2306 std::vector<std::string> jsons;
2307 std::vector<Int_t> widths, heights;
2308
2309 bool isMultiPdf = (strstr(filename, ".pdf") || strstr(filename, ".PDF")) && strstr(filename, "%");
2310 bool is_multipdf_ok = true;
2311
2312 for (unsigned n = 0; n < pads.size(); ++n) {
2313 auto pad = pads[n];
2314
2316 if (!json.Length())
2317 continue;
2318
2319 Int_t w = width, h = height;
2320
2321 if (!w && !h) {
2322 if ((pad->GetCanvas() == pad) || (pad->IsA() == TCanvas::Class())) {
2323 w = pad->GetWw();
2324 h = pad->GetWh();
2325 } else {
2326 w = (Int_t) (pad->GetAbsWNDC() * pad->GetCanvas()->GetWw());
2327 h = (Int_t) (pad->GetAbsHNDC() * pad->GetCanvas()->GetWh());
2328 }
2329 }
2330
2331 if (isMultiPdf) {
2332 TString pdfname = TString::Format(filename, (int)n);
2333 if (!ROOT::RWebDisplayHandle::ProduceImage(pdfname.Data(), json.Data(), w, h))
2334 is_multipdf_ok = false;
2335 } else {
2336 jsons.emplace_back(json.Data());
2337 widths.emplace_back(w);
2338 heights.emplace_back(h);
2339 }
2340 }
2341
2342 if (isMultiPdf)
2343 return is_multipdf_ok;
2344
2345 return ROOT::RWebDisplayHandle::ProduceImages(filename, jsons, widths, heights);
2346}
2347
2348
2349//////////////////////////////////////////////////////////////////////////////////////////
2350/// Process data for single primitive
2351/// Returns object pad if object was modified
2352
2354{
2355 TObjLink *lnk = nullptr;
2356 TPad *objpad = nullptr;
2357 TObject *obj = FindPrimitive(item.snapid, idcnt, pad, &lnk, &objpad);
2358
2359 if (item.fcust.compare("exec") == 0) {
2360 auto pos = item.opt.find("(");
2361 if (obj && (pos != std::string::npos) && obj->IsA()->GetMethodAllAny(item.opt.substr(0,pos).c_str())) {
2362 std::stringstream exec;
2363 exec << "((" << obj->ClassName() << " *) " << std::hex << std::showbase
2364 << (size_t)obj << ")->" << item.opt << ";";
2365 if (gDebug > 0)
2366 Info("ProcessObjectOptions", "Obj %s Execute %s", obj->GetName(), exec.str().c_str());
2367 gROOT->ProcessLine(exec.str().c_str());
2368 } else {
2369 Error("ProcessObjectOptions", "Fail to execute %s for object %p %s", item.opt.c_str(), obj, obj ? obj->ClassName() : "---");
2370 objpad = nullptr;
2371 }
2372 return objpad;
2373 }
2374
2375 bool modified = false;
2376
2377 if (obj && lnk) {
2378 auto pos = item.opt.find(";;use_"); // special coding of extra options
2379 if (pos != std::string::npos) item.opt.resize(pos);
2380
2381 if (gDebug > 0)
2382 Info("ProcessObjectOptions", "Set draw option %s for object %s %s", item.opt.c_str(),
2383 obj->ClassName(), obj->GetName());
2384
2385 lnk->SetOption(item.opt.c_str());
2386
2387 modified = true;
2388 }
2389
2390 if (item.fcust.compare(0,10,"auto_exec:") == 0) {
2391 ProcessLinesForObject(obj, item.fcust.substr(10));
2392 } else if (item.fcust.compare("frame") == 0) {
2393 if (obj && obj->InheritsFrom(TFrame::Class())) {
2394 TFrame *frame = static_cast<TFrame *>(obj);
2395 if (item.fopt.size() >= 4) {
2396 frame->SetX1(item.fopt[0]);
2397 frame->SetY1(item.fopt[1]);
2398 frame->SetX2(item.fopt[2]);
2399 frame->SetY2(item.fopt[3]);
2400 modified = true;
2401 }
2402 }
2403 } else if (item.fcust.compare(0,4,"pave") == 0) {
2404 if (obj && obj->InheritsFrom(TPave::Class())) {
2405 TPave *pave = static_cast<TPave *>(obj);
2406 if ((item.fopt.size() >= 4) && objpad) {
2407 TVirtualPad::TContext ctxt(objpad, kFALSE);
2408
2409 // first time need to overcome init problem
2410 pave->ConvertNDCtoPad();
2411
2412 pave->SetX1NDC(item.fopt[0]);
2413 pave->SetY1NDC(item.fopt[1]);
2414 pave->SetX2NDC(item.fopt[2]);
2415 pave->SetY2NDC(item.fopt[3]);
2416 modified = true;
2417
2418 pave->ConvertNDCtoPad();
2419 }
2420 if ((item.fcust.length() > 4) && pave->InheritsFrom(TPaveStats::Class())) {
2421 // add text lines for statsbox
2422 auto stats = static_cast<TPaveStats *>(pave);
2423 stats->Clear();
2424 size_t pos_start = 6, pos_end;
2425 while ((pos_end = item.fcust.find(";;", pos_start)) != std::string::npos) {
2426 stats->AddText(item.fcust.substr(pos_start, pos_end - pos_start).c_str());
2427 pos_start = pos_end + 2;
2428 }
2429 stats->AddText(item.fcust.substr(pos_start).c_str());
2430 }
2431 }
2432 } else if (item.fcust.compare(0,9,"func_fail") == 0) {
2433 if (fTF1UseSave <= 0) {
2434 fTF1UseSave = 1;
2435 modified = true;
2436 }
2437 }
2438
2439 return modified ? objpad : nullptr;
2440}
2441
2442//////////////////////////////////////////////////////////////////////////////////////////////////
2443/// Search of object with given id in list of primitives
2444/// One could specify pad where search could be start
2445/// Also if object is in list of primitives, one could ask for entry link for such object,
2446/// This can allow to change draw option
2447
2448TObject *TWebCanvas::FindPrimitive(const std::string &sid, int idcnt, TPad *pad, TObjLink **objlnk, TPad **objpad)
2449{
2450 if (sid.empty() || (sid == "0"s))
2451 return nullptr;
2452
2453 if (!pad)
2454 pad = Canvas();
2455
2456 std::string subelement;
2457 long unsigned id = 0;
2458 bool search_hist = (sid == sid_pad_histogram);
2459 if (!search_hist) {
2460 auto separ = sid.find("#");
2461
2462 if (separ == std::string::npos) {
2463 id = std::stoul(sid);
2464 } else {
2465 subelement = sid.substr(separ + 1);
2466 id = std::stoul(sid.substr(0, separ));
2467 }
2468 if (TString::Hash(&pad, sizeof(pad)) == id)
2469 return pad;
2470 }
2471
2472 for (auto lnk = pad->GetListOfPrimitives()->FirstLink(); lnk != nullptr; lnk = lnk->Next()) {
2473 TObject *obj = lnk->GetObject();
2474 if (!obj) continue;
2475
2476 if (!search_hist && (TString::Hash(&obj, sizeof(obj)) != id)) {
2477 if (obj->InheritsFrom(TPad::Class())) {
2478 obj = FindPrimitive(sid, idcnt, (TPad *)obj, objlnk, objpad);
2479 if (objpad && !*objpad)
2480 *objpad = pad;
2481 if (obj)
2482 return obj;
2483 }
2484 continue;
2485 }
2486
2487 // one may require to access n-th object
2488 if (!search_hist && --idcnt > 0)
2489 continue;
2490
2491 if (objpad)
2492 *objpad = pad;
2493
2494 if (objlnk)
2495 *objlnk = lnk;
2496
2497 if (search_hist)
2498 subelement = "hist";
2499
2500 auto getHistogram = [](TObject *container) -> TH1* {
2501 auto offset = container->IsA()->GetDataMemberOffset("fHistogram");
2502 if (offset > 0)
2503 return *((TH1 **)((char *)container + offset));
2504 ::Error("getHistogram", "Cannot access fHistogram data member in %s", container->ClassName());
2505 return nullptr;
2506 };
2507
2508 while(!subelement.empty() && obj) {
2509 // do not return link if sub-selement is searched - except for histogram
2510 if (!search_hist && objlnk)
2511 *objlnk = nullptr;
2512
2513 std::string kind = subelement;
2514 auto separ = kind.find("#");
2515 if (separ == std::string::npos) {
2516 subelement.clear();
2517 } else {
2518 kind.resize(separ);
2519 subelement = subelement.substr(separ + 1);
2520 }
2521
2522 TH1 *h1 = obj->InheritsFrom(TH1::Class()) ? static_cast<TH1 *>(obj) : nullptr;
2523 TGraph *gr = obj->InheritsFrom(TGraph::Class()) ? static_cast<TGraph *>(obj) : nullptr;
2524 TGraph2D *gr2d = obj->InheritsFrom(TGraph2D::Class()) ? static_cast<TGraph2D *>(obj) : nullptr;
2525 TScatter *scatter = obj->InheritsFrom(TScatter::Class()) ? static_cast<TScatter *>(obj) : nullptr;
2526 TMultiGraph *mg = obj->InheritsFrom(TMultiGraph::Class()) ? static_cast<TMultiGraph *>(obj) : nullptr;
2527 THStack *hs = obj->InheritsFrom(THStack::Class()) ? static_cast<THStack *>(obj) : nullptr;
2528 TF1 *f1 = obj->InheritsFrom(TF1::Class()) ? static_cast<TF1 *>(obj) : nullptr;
2529
2530 if (kind.compare("hist") == 0) {
2531 if (h1)
2532 obj = h1;
2533 else if (gr)
2534 obj = getHistogram(gr);
2535 else if (mg)
2536 obj = getHistogram(mg);
2537 else if (hs && (hs->GetNhists() > 0))
2538 obj = getHistogram(hs);
2539 else if (scatter)
2540 obj = getHistogram(scatter);
2541 else if (f1)
2542 obj = getHistogram(f1);
2543 else if (gr2d)
2544 obj = getHistogram(gr2d);
2545 else
2546 obj = nullptr;
2547 } else if (kind.compare("x") == 0) {
2548 obj = h1 ? h1->GetXaxis() : nullptr;
2549 } else if (kind.compare("y") == 0) {
2550 obj = h1 ? h1->GetYaxis() : nullptr;
2551 } else if (kind.compare("z") == 0) {
2552 obj = h1 ? h1->GetZaxis() : nullptr;
2553 } else if ((kind.compare(0,5,"func_") == 0) || (kind.compare(0,5,"indx_") == 0)) {
2554 auto funcname = kind.substr(5);
2555 TList *col = nullptr;
2556 if (h1)
2557 col = h1->GetListOfFunctions();
2558 else if (gr)
2559 col = gr->GetListOfFunctions();
2560 else if (mg)
2561 col = mg->GetListOfFunctions();
2562 else if (scatter->GetGraph())
2563 col = scatter->GetGraph()->GetListOfFunctions();
2564 if (!col)
2565 obj = nullptr;
2566 else if (kind.compare(0,5,"func_") == 0)
2567 obj = col->FindObject(funcname.c_str());
2568 else
2569 obj = col->At(std::stoi(funcname));
2570 } else if (kind.compare(0,7,"graphs_") == 0) {
2571 TList *graphs = mg ? mg->GetListOfGraphs() : nullptr;
2572 obj = graphs ? graphs->At(std::stoi(kind.substr(7))) : nullptr;
2573 } else if (kind.compare(0,6,"hists_") == 0) {
2574 TList *hists = hs ? hs->GetHists() : nullptr;
2575 obj = hists ? hists->At(std::stoi(kind.substr(6))) : nullptr;
2576 } else if (kind.compare(0,6,"stack_") == 0) {
2577 auto stack = hs ? hs->GetStack() : nullptr;
2578 obj = stack ? stack->At(std::stoi(kind.substr(6))) : nullptr;
2579 } else if (kind.compare(0,7,"member_") == 0) {
2580 auto member = kind.substr(7);
2581 auto offset = obj->IsA() ? obj->IsA()->GetDataMemberOffset(member.c_str()) : 0;
2582 obj = (offset > 0) ? *((TObject **)((char *) obj + offset)) : nullptr;
2583 } else {
2584 obj = nullptr;
2585 }
2586 }
2587
2588 if (!search_hist || obj)
2589 return obj;
2590 }
2591
2592 return nullptr;
2593}
2594
2595//////////////////////////////////////////////////////////////////////////////////////////////////
2596/// Static method to create TWebCanvas instance
2597/// Used by plugin manager
2598
2600{
2601 Bool_t readonly = gEnv->GetValue("WebGui.FullCanvas", (Int_t) 1) == 0;
2602
2603 auto imp = new TWebCanvas(c, name, x, y, width, height, readonly);
2604
2605 c->fWindowTopX = x;
2606 c->fWindowTopY = y;
2607 c->fWindowWidth = width;
2608 c->fWindowHeight = height;
2609 if (!gROOT->IsBatch() && (height > 25))
2610 height -= 25;
2611 c->fCw = width;
2612 c->fCh = height;
2613
2614 return imp;
2615}
@ kMouseMotion
Definition Buttons.h:23
@ kButton1Double
Definition Buttons.h:24
@ kButton1Up
Definition Buttons.h:19
nlohmann::json json
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
short Font_t
Definition RtypesCore.h:88
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t hmin
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t hmax
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void funcs
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char name[80]
Definition TGX11.cxx:110
@ kCanDelete
Definition TObject.h:367
@ kMustCleanup
Definition TObject.h:368
Int_t gDebug
Definition TROOT.cxx:597
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
@ kReadPermission
Definition TSystem.h:45
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
R__EXTERN TVirtualPS * gVirtualPS
Definition TVirtualPS.h:81
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
static std::vector< WebFont_t > gWebFonts
static const std::string sid_pad_histogram
Color * colors
Definition X3DBuffer.c:21
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
EBrowserKind GetBrowserKind() const
returns configured browser kind, see EBrowserKind for supported values
RWebDisplayArgs & SetWidgetKind(const std::string &kind)
set widget kind
RWebDisplayArgs & SetSize(int w, int h)
set preferable web window width and height
RWebDisplayArgs & SetPos(int x=-1, int y=-1)
set preferable web window x and y position, negative is default
@ kCEF
Chromium Embedded Framework - local display with CEF libs.
@ kQt5
Qt5 QWebEngine libraries - Chromium code packed in qt5.
@ kQt6
Qt6 QWebEngine libraries - Chromium code packed in qt6.
static bool ProduceImages(const std::string &fname, const std::vector< std::string > &jsons, const std::vector< int > &widths, const std::vector< int > &heights, const char *batch_file=nullptr)
Produce image file(s) using JSON data as source Invokes JSROOT drawing functionality in headless brow...
static bool ProduceImage(const std::string &fname, const std::string &json, int width=800, int height=600, const char *batch_file=nullptr)
Produce image file using JSON data as source Invokes JSROOT drawing functionality in headless browser...
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static bool EmbedFileDialog(const std::shared_ptr< RWebWindow > &window, unsigned connid, const std::string &args)
Create dialog instance to use as embedded dialog inside provided widget Loads libROOTBrowserv7 and tr...
static bool IsFileDialogMessage(const std::string &msg)
Check if this could be the message send by client to start new file dialog If returns true,...
Array of integers (32 bits per element).
Definition TArrayI.h:27
const Int_t * GetArray() const
Definition TArrayI.h:43
Int_t GetSize() const
Definition TArray.h:47
static TClass * Class()
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition TAttPad.cxx:99
virtual void SetLeftMargin(Float_t leftmargin)
Set Pad left margin in fraction of the pad width.
Definition TAttPad.cxx:109
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition TAttPad.cxx:119
Float_t GetRightMargin() const
Definition TAttPad.h:45
virtual void SetTopMargin(Float_t topmargin)
Set Pad top margin in fraction of the pad height.
Definition TAttPad.cxx:129
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:42
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:46
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:47
Double_t GetXmax() const
Definition TAxis.h:140
Double_t GetXmin() const
Definition TAxis.h:139
Int_t GetNbins() const
Definition TAxis.h:125
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition TAxis.cxx:1080
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1052
static TString Decode(const char *data)
Decode a base64 string date into a generic TString.
Definition TBase64.cxx:131
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:107
virtual void SetY2(Double_t y2)
Definition TBox.h:65
virtual void SetX1(Double_t x1)
Definition TBox.h:62
virtual void SetX2(Double_t x2)
Definition TBox.h:63
virtual void SetY1(Double_t y1)
Definition TBox.h:64
static Int_t ExportToFile(const char *filename, const TObject *obj, const char *option=nullptr)
Convert object into JSON and store in text file Returns size of the produce file Used in TObject::Sav...
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
Definition TBufferJSON.h:75
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
Definition TBufferJSON.h:39
@ kMapAsObject
store std::map, std::unordered_map as JSON object
Definition TBufferJSON.h:41
@ kSameSuppression
zero suppression plus compress many similar values together
Definition TBufferJSON.h:45
A TButton object is a user interface object.
Definition TButton.h:18
static TClass * Class()
ABC describing GUI independent main window (with menubar, scrollbars and a drawing area).
Definition TCanvasImp.h:30
TCanvas * Canvas() const
Definition TCanvasImp.h:58
void SetScripts(const std::string &src)
void SetFixedSize(bool on=true)
void SetHighlightConnect(bool on=true)
The Canvas class.
Definition TCanvas.h:23
UInt_t fCw
Width of the canvas along X (pixels)
Definition TCanvas.h:43
UInt_t GetWindowHeight() const
Definition TCanvas.h:162
void SetClickSelectedPad(TPad *pad)
Definition TCanvas.h:211
Int_t fWindowTopX
Top X position of window (in pixels)
Definition TCanvas.h:39
Int_t fEventX
! Last X mouse position in canvas
Definition TCanvas.h:46
TVirtualPadPainter * GetCanvasPainter()
Access and (probably) creation of pad painter.
Definition TCanvas.cxx:2603
UInt_t fWindowWidth
Width of window (including borders, etc.)
Definition TCanvas.h:41
Int_t fEventY
! Last Y mouse position in canvas
Definition TCanvas.h:47
UInt_t fWindowHeight
Height of window (including menubar, borders, etc.)
Definition TCanvas.h:42
TObject * fSelected
! Currently selected object
Definition TCanvas.h:49
UInt_t fCh
Height of the canvas along Y (pixels)
Definition TCanvas.h:44
UInt_t GetWindowWidth() const
Definition TCanvas.h:161
Int_t fWindowTopY
Top Y position of window (in pixels)
Definition TCanvas.h:40
void SetClickSelected(TObject *obj)
Definition TCanvas.h:209
@ kShowToolTips
Definition TCanvas.h:97
@ kShowEventStatus
Definition TCanvas.h:89
@ kMenuBar
Definition TCanvas.h:91
@ kShowEditor
Definition TCanvas.h:93
UInt_t GetWw() const override
Definition TCanvas.h:163
UInt_t GetWh() const override
Definition TCanvas.h:164
virtual void Highlighted(TVirtualPad *pad, TObject *obj, Int_t x, Int_t y)
Emit Highlighted() signal.
Definition TCanvas.cxx:1610
static TClass * Class()
Int_t fEvent
! Type of current or last handled event
Definition TCanvas.h:45
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Longptr_t GetDataMemberOffset(const char *membername) const
return offset for member name.
Definition TClass.cxx:3477
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5704
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4874
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4384
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
The color creation and management class.
Definition TColor.h:21
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition TColor.cxx:1467
static TClass * Class()
static Bool_t DefinedColors(Int_t set_always_on=0)
Static method returning kTRUE if some new colors have been defined after initialisation or since the ...
Definition TColor.cxx:1488
static TClass * Class()
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
TExec is a utility class that can be used to execute a C++ command when some event happens in a pad.
Definition TExec.h:26
virtual void Exec(const char *command="")
Execute the command referenced by this object.
Definition TExec.cxx:143
static TClass * Class()
1-Dim function class
Definition TF1.h:233
virtual TH1 * GetHistogram() const
Return a pointer to the histogram used to visualise the function Note that this histogram is managed ...
Definition TF1.cxx:1586
static TClass * Class()
@ kNotDraw
Definition TF1.h:346
virtual Bool_t IsValid() const
Return kTRUE if the function is valid.
Definition TF1.cxx:2882
virtual void Save(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax, Double_t zmin, Double_t zmax)
Save values of function in array fSave.
Definition TF1.cxx:3161
TClass * IsA() const override
Definition TF1.h:748
static TClass * Class()
Define a Frame.
Definition TFrame.h:19
static TClass * Class()
The axis painter class.
Definition TGaxis.h:24
static TClass * Class()
TF1 * GetFunction() const
Definition TGaxis.h:77
Graphics object made of three arrays X, Y and Z with the same number of points each.
Definition TGraph2D.h:41
static TClass * Class()
TH2D * GetHistogram(Option_t *option="")
By default returns a pointer to the Delaunay histogram.
Definition TGraph2D.cxx:979
TList * GetListOfFunctions() const
Definition TGraph2D.h:110
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
@ kNoStats
Don't draw stats box.
Definition TGraph.h:75
TList * GetListOfFunctions() const
Definition TGraph.h:125
virtual TH1F * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases.
Definition TGraph.cxx:1411
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:669
TH1K class supports the nearest K Neighbours method, widely used in cluster analysis.
Definition TH1K.h:26
Double_t GetBinContent(Int_t bin) const override
Return content of global bin number bin.
Definition TH1K.cxx:116
static TClass * Class()
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8905
TAxis * GetZaxis()
Definition TH1.h:326
static TClass * Class()
virtual Int_t GetDimension() const
Definition TH1.h:283
@ kNoTitle
Don't draw the histogram title.
Definition TH1.h:170
@ kIsZoomed
Bit set when zooming on Y axis.
Definition TH1.h:169
TAxis * GetXaxis()
Definition TH1.h:324
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:403
TAxis * GetYaxis()
Definition TH1.h:325
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:404
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9190
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4423
TList * GetListOfFunctions() const
Definition TH1.h:244
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:8928
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
Definition TH1.cxx:1414
The Histogram stack class.
Definition THStack.h:40
TList * GetHists() const
Definition THStack.h:72
TObjArray * GetStack()
Return pointer to Stack. Build it if not yet done.
Definition THStack.cxx:600
Int_t GetNhists() const
Return the number of histograms in the stack.
Definition THStack.cxx:591
static TClass * Class()
Option_t * GetOption() const
void Reset()
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
void Add(TObject *obj) override
Definition TList.h:83
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition TList.cxx:150
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:691
virtual TObjLink * FirstLink() const
Definition TList.h:104
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition TList.cxx:98
A TMultiGraph is a collection of TGraph (or derived) objects.
Definition TMultiGraph.h:34
TList * GetListOfGraphs() const
Definition TMultiGraph.h:68
static TClass * Class()
TList * GetListOfFunctions()
Return pointer to list of functions.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
An array of TObjects.
Definition TObjArray.h:31
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:223
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:403
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:780
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:483
virtual TClass * IsA() const
Definition TObject.h:243
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Definition TObject.cxx:607
TPadWebSnapshot & NewSubPad()
Create new entry for subpad.
TWebSnapshot & NewPrimitive(TObject *obj=nullptr, const std::string &opt="", const std::string &suffix="")
Create new entry in list of primitives.
TWebSnapshot & NewSpecials()
Create new entry in list of primitives in the front.
void SetHasExecs(bool on=true)
void SetWithoutPrimitives(bool on=true)
void SetActive(bool on=true)
bool IsSetObjectIds() const
bool IsBatchMode() const
The most important graphics class in the ROOT system.
Definition TPad.h:28
Int_t GetTicky() const override
Definition TPad.h:237
Double_t fAbsYlowNDC
Absolute Y top left corner of pad in NDC [0,1].
Definition TPad.h:70
Double_t fXtoAbsPixelk
Conversion coefficient for X World to absolute pixel.
Definition TPad.h:41
virtual void DivideSquare(Int_t n, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
"n" is the total number of sub-pads.
Definition TPad.cxx:1245
static TClass * Class()
Double_t fWNDC
Width of pad along X in Normalized Coordinates (NDC)
Definition TPad.h:66
void SetView(TView *view=nullptr) override
Set the current TView. Delete previous view if view=0.
Definition TPad.cxx:6082
TVirtualViewer3D * GetViewer3D(Option_t *type="") override
Create/obtain handle to 3D viewer.
Definition TPad.cxx:7038
Double_t fPixeltoYk
Conversion coefficient for pixel to Y World.
Definition TPad.h:59
void SetGrid(Int_t valuex=1, Int_t valuey=1) override
Definition TPad.h:332
Double_t fPixeltoY
yworld = fPixeltoYk + fPixeltoY*ypixel
Definition TPad.h:60
Double_t fAbsXlowNDC
Absolute X top left corner of pad in NDC [0,1].
Definition TPad.h:69
TList * GetListOfExecs() const override
Definition TPad.h:244
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
Definition TPad.cxx:1153
Double_t fXtoPixel
xpixel = fXtoPixelk + fXtoPixel*xworld
Definition TPad.h:43
Bool_t GetGridx() const override
Definition TPad.h:233
Double_t fX2
X of upper X coordinate.
Definition TPad.h:38
Double_t fPixeltoX
xworld = fPixeltoXk + fPixeltoX*xpixel
Definition TPad.h:57
Double_t fYtoPixel
ypixel = fYtoPixelk + fYtoPixel*yworld
Definition TPad.h:46
Double_t fAbsWNDC
Absolute Width of pad along X in NDC.
Definition TPad.h:71
UInt_t GetWw() const override
Get Ww.
Definition TPad.cxx:2741
Double_t fX1
X of lower X coordinate.
Definition TPad.h:36
TList * GetListOfPrimitives() const override
Definition TPad.h:243
Double_t fUymin
Minimum value on the Y axis.
Definition TPad.h:75
Int_t fLogz
(=0 if Z linear scale, =1 if log scale)
Definition TPad.h:93
Double_t fYtoPixelk
Conversion coefficient for Y World to pixel.
Definition TPad.h:45
Double_t fPixeltoXk
Conversion coefficient for pixel to X World.
Definition TPad.h:56
Bool_t IsModified() const override
Definition TPad.h:272
Double_t fY1
Y of lower Y coordinate.
Definition TPad.h:37
Double_t fYlowNDC
Y bottom left corner of pad in NDC [0,1].
Definition TPad.h:63
Double_t fAbsPixeltoXk
Conversion coefficient for absolute pixel to X World.
Definition TPad.h:55
void Clear(Option_t *option="") override
Delete all pad primitives.
Definition TPad.cxx:626
Int_t GetTickx() const override
Definition TPad.h:236
Double_t fUymax
Maximum value on the Y axis.
Definition TPad.h:77
TVirtualPad * GetMother() const override
Definition TPad.h:257
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7256
TView * GetView() const override
Definition TPad.h:252
TClass * IsA() const override
Definition TPad.h:416
Bool_t GetGridy() const override
Definition TPad.h:234
Double_t fAbsHNDC
Absolute Height of pad along Y in NDC.
Definition TPad.h:72
void SetFixedAspectRatio(Bool_t fixed=kTRUE) override
Fix pad aspect ratio to current value if fixed is true.
Definition TPad.cxx:5918
Int_t fLogx
(=0 if X linear scale, =1 if log scale)
Definition TPad.h:91
Double_t GetAbsWNDC() const override
Definition TPad.h:220
UInt_t GetWh() const override
Get Wh.
Definition TPad.cxx:2733
TCanvas * GetCanvas() const override
Definition TPad.h:260
Double_t fXUpNDC
Definition TPad.h:64
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:597
void Print(const char *filename="") const override
This method is equivalent to SaveAs("filename"). See TPad::SaveAs for details.
Definition TPad.cxx:4700
TFrame * GetFrame() override
Get frame.
Definition TPad.cxx:2859
Double_t fYUpNDC
Definition TPad.h:65
Double_t fYtoAbsPixelk
Conversion coefficient for Y World to absolute pixel.
Definition TPad.h:44
Double_t fXtoPixelk
Conversion coefficient for X World to pixel.
Definition TPad.h:42
Int_t fLogy
(=0 if Y linear scale, =1 if log scale)
Definition TPad.h:92
Double_t fHNDC
Height of pad along Y in Normalized Coordinates (NDC)
Definition TPad.h:67
Double_t fXlowNDC
X bottom left corner of pad in NDC [0,1].
Definition TPad.h:62
Double_t fUxmin
Minimum value on the X axis.
Definition TPad.h:74
Double_t GetAbsHNDC() const override
Definition TPad.h:221
void SetTicks(Int_t valuex=1, Int_t valuey=1) override
Definition TPad.h:352
Double_t fUxmax
Maximum value on the X axis.
Definition TPad.h:76
Double_t fY2
Y of upper Y coordinate.
Definition TPad.h:39
Double_t fAbsPixeltoYk
Conversion coefficient for absolute pixel to Y World.
Definition TPad.h:58
const char * GetName() const override
Returns name of object.
Definition TPad.h:258
The histogram statistics painter class.
Definition TPaveStats.h:18
virtual void SetStatFormat(const char *format="6.4g")
Change (i.e. set) the format for printing statistics.
virtual void SetFitFormat(const char *format="5.4g")
Change (i.e. set) the format for printing fit parameters in statistics box.
void SetParent(TObject *obj) override
Definition TPaveStats.h:52
static TClass * Class()
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
static TClass * Class()
void Clear(Option_t *option="") override
Clear all lines in this pavetext.
virtual TText * GetLine(Int_t number) const
Get Pointer to line number in this pavetext.
A TBox with a bordersize and a shadow option.
Definition TPave.h:19
virtual void SetY1NDC(Double_t y1)
Definition TPave.h:84
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Definition TPave.cxx:139
virtual void SetName(const char *name="")
Definition TPave.h:79
virtual void SetBorderSize(Int_t bordersize=4)
Sets the border size of the TPave box and shadow.
Definition TPave.h:77
virtual void SetY2NDC(Double_t y2)
Definition TPave.h:85
static TClass * Class()
virtual void SetX1NDC(Double_t x1)
Definition TPave.h:82
virtual void SetX2NDC(Double_t x2)
Definition TPave.h:83
A TScatter is able to draw four variables scatter plot on a single plot.
Definition TScatter.h:32
TGraph * GetGraph() const
Get the graph holding X and Y positions.
Definition TScatter.h:58
TH2F * GetHistogram() const
Get the graph histogram used for drawing axis.
Definition TScatter.cxx:159
static TClass * Class()
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
@ kIgnoreCase
Definition TString.h:277
Ssiz_t Last(char c) const
Find last occurrence of a character c.
Definition TString.cxx:931
void ToUpper()
Change string to upper case.
Definition TString.cxx:1195
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition TString.cxx:677
TString & Append(const char *cs)
Definition TString.h:572
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
Int_t GetOptStat() const
Definition TStyle.h:243
Color_t GetStatTextColor() const
Definition TStyle.h:256
Int_t GetOptTitle() const
Definition TStyle.h:244
Float_t GetStatFontSize() const
Definition TStyle.h:259
Float_t GetStatX() const
Definition TStyle.h:262
Float_t GetPadRightMargin() const
Definition TStyle.h:212
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1212
Float_t GetStatY() const
Definition TStyle.h:263
Color_t GetTitleFillColor() const
Definition TStyle.h:269
Style_t GetTitleStyle() const
Definition TStyle.h:271
Color_t GetStatColor() const
Definition TStyle.h:255
Float_t GetStatH() const
Definition TStyle.h:265
static TClass * Class()
Width_t GetTitleBorderSize() const
Definition TStyle.h:273
Width_t GetStatBorderSize() const
Definition TStyle.h:257
Color_t GetTitleTextColor() const
Definition TStyle.h:270
Style_t GetStatStyle() const
Definition TStyle.h:260
Float_t GetStatW() const
Definition TStyle.h:264
const char * GetFitFormat() const
Definition TStyle.h:198
const char * GetStatFormat() const
Definition TStyle.h:261
Style_t GetStatFont() const
Definition TStyle.h:258
Float_t GetTitleFontSize() const
Definition TStyle.h:272
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1274
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1296
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:416
static Long_t SelfId()
Static method returning the id for the current thread.
Definition TThread.cxx:549
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:243
void SetTime(Long_t milliSec)
Definition TTimer.h:91
See TView3D.
Definition TView.h:25
static TView * CreateView(Int_t system=1, const Double_t *rmin=nullptr, const Double_t *rmax=nullptr)
Create a concrete default 3-d view via the plug-in manager.
Definition TView.cxx:27
virtual void SetAutoRange(Bool_t autorange=kTRUE)=0
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition TVirtualPS.h:30
To make it possible to use GL for 2D graphic in a TPad/TCanvas.
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:61
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
Semi-Abstract base class defining a generic interface to the underlying, low level,...
Definition TVirtualX.h:46
void SetSlow(Bool_t slow=kTRUE)
TWebCanvasTimer(TWebCanvas &canv)
Bool_t IsSlow() const
void Timeout() override
used to send control messages to clients
TWebCanvas & fCanv
Basic TCanvasImp ABI implementation for Web-based Graphics Provides painting of main ROOT classes in ...
Definition TWebCanvas.h:35
TVirtualPadPainter * CreatePadPainter() override
Creates web-based pad painter.
void ForceUpdate() override
Increment canvas version and force sending data to client - do not wait for reply.
void AddCustomClass(const std::string &clname, bool with_derived=false)
Assign custom class.
static TString CreatePadJSON(TPad *pad, Int_t json_compression=0, Bool_t batchmode=kFALSE)
Create JSON painting output for given pad Produce JSON can be used for offline drawing with JSROOT.
void SetCanvasSize(UInt_t w, UInt_t h) override
Set canvas size of web canvas.
UInt_t fColorsHash
! last hash of colors/palette
Definition TWebCanvas.h:107
Int_t fTF1UseSave
! use save buffer for TF1/TF2, 0:off, 1:prefer, 2:force
Definition TWebCanvas.h:108
void ShowCmd(const std::string &arg, Bool_t show)
Function used to send command to browser to toggle menu, toolbar, editors, ...
Long64_t fColorsVersion
! current colors/palette version, checked every time when new snapshot created
Definition TWebCanvas.h:106
std::string fCustomScripts
! custom JavaScript code or URL on JavaScript files to load before start drawing
Definition TWebCanvas.h:98
virtual Bool_t IsReadOnly() const
Definition TWebCanvas.h:177
std::shared_ptr< ROOT::RWebWindow > fWindow
Definition TWebCanvas.h:88
virtual Bool_t IsJSSupportedClass(TObject *obj, Bool_t many_primitives=kFALSE)
Returns kTRUE when object is fully supported on JSROOT side In ROOT7 Paint function will just return ...
void AddCtrlMsg(unsigned connid, const std::string &key, const std::string &value)
Add control message for specified connection Same control message can be overwritten many time before...
void SetCustomScripts(const std::string &src)
Configures custom script for canvas.
ObjectSelectSignal_t fObjSelectSignal
! signal emitted when new object selected in the pad
Definition TWebCanvas.h:116
PadClickedSignal_t fPadClickedSignal
! signal emitted when simple mouse click performed on the pad
Definition TWebCanvas.h:114
void SetLongerPolling(Bool_t on)
Definition TWebCanvas.h:233
UInt_t fStyleHash
! last hash of gStyle
Definition TWebCanvas.h:105
virtual Bool_t CanCreateObject(const std::string &)
Definition TWebCanvas.h:159
void ShowWebWindow(const ROOT::RWebDisplayArgs &user_args="")
Show canvas in specified place.
Int_t fPrimitivesMerge
! number of PS primitives, which will be merged together
Definition TWebCanvas.h:96
void Show() override
Show canvas in browser window.
Bool_t WaitWhenCanvasPainted(Long64_t ver)
Wait when specified version of canvas was painted and confirmed by browser.
std::vector< std::string > fCustomClasses
! list of custom classes, which can be delivered as is to client
Definition TWebCanvas.h:99
Bool_t IsAsyncMode() const
Definition TWebCanvas.h:242
UInt_t CalculateColorsHash()
Calculate hash function for all colors and palette.
Bool_t HasStatusBar() const override
Returns kTRUE if web canvas has status bar.
void Close() override
Close web canvas - not implemented.
static bool ProduceImages(std::vector< TPad * > pads, const char *filename, Int_t width=0, Int_t height=0)
Create images for several pads using batch (headless) capability of Chrome or Firefox browsers Suppor...
Bool_t HasMenuBar() const override
Returns kTRUE if web canvas has menu bar.
Int_t InitWindow() override
Initialize window for the web canvas At this place canvas is not yet register to the list of canvases...
void CheckPadModified(TPad *pad)
Returns true if any pad in the canvas were modified Reset modified flags, increment canvas version (i...
void RaiseWindow() override
Raise browser window.
static bool ProduceImage(TPad *pad, const char *filename, Int_t width=0, Int_t height=0)
Create image using batch (headless) capability of Chrome or Firefox browsers Supported png,...
void ActivateInEditor(TPad *pad, TObject *obj)
Activate object in editor in web browser.
std::vector< WebConn > fWebConn
! connections
Definition TWebCanvas.h:83
PadSignal_t fActivePadChangedSignal
! signal emitted when active pad changed in the canvas
Definition TWebCanvas.h:113
Bool_t GetLongerPolling() const
Definition TWebCanvas.h:234
UInt_t fClientBits
! latest status bits from client like editor visible or not
Definition TWebCanvas.h:92
std::function< void(TPadWebSnapshot *)> PadPaintingReady_t
Function called when pad painting produced.
Definition TWebCanvas.h:55
Int_t fPaletteDelivery
! colors palette delivery 0:never, 1:once, 2:always, 3:per subpad
Definition TWebCanvas.h:95
Bool_t fProcessingData
! flag used to prevent blocking methods when process data is invoked
Definition TWebCanvas.h:102
Bool_t HasToolTips() const override
Returns kTRUE if tooltips are activated in web canvas.
std::vector< TPad * > fAllPads
! list of all pads recognized during streaming
Definition TWebCanvas.h:93
friend class TWebCanvasTimer
Definition TWebCanvas.h:37
TWebCanvasTimer * fTimer
! timer to submit control messages
Definition TWebCanvas.h:84
Long64_t fCanvVersion
! actual canvas version, changed with every new Modified() call
Definition TWebCanvas.h:91
bool IsCustomClass(const TClass *cl) const
Checks if class belongs to custom.
std::vector< int > fWindowGeometry
! last received window geometry
Definition TWebCanvas.h:109
TPad * ProcessObjectOptions(TWebObjectOptions &item, TPad *pad, int idcnt=1)
Process data for single primitive Returns object pad if object was modified.
void CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps=nullptr)
Creates representation of the object for painting in web browser.
void AddColorsPalette(TPadWebSnapshot &master)
Add special canvas objects with list of colors and color palette.
Long64_t fStyleVersion
! current gStyle object version, checked every time when new snapshot created
Definition TWebCanvas.h:104
void AddSendQueue(unsigned connid, const std::string &msg)
Add message to send queue for specified connection If connid == 0, message will be add to all connect...
void SetWindowPosition(Int_t x, Int_t y) override
Set window position of web canvas.
UpdatedSignal_t fUpdatedSignal
! signal emitted when canvas updated or state is changed
Definition TWebCanvas.h:112
Int_t fJsonComp
! compression factor for messages send to the client
Definition TWebCanvas.h:97
Bool_t IsFirstConn(unsigned connid) const
Definition TWebCanvas.h:147
~TWebCanvas() override
Destructor.
Bool_t fReadOnly
!< configured display
Definition TWebCanvas.h:90
std::map< TPad *, PadStatus > fPadsStatus
! map of pads in canvas and their status flags
Definition TWebCanvas.h:86
static Font_t AddFont(const char *name, const char *ttffile, Int_t precision=2)
Add font to static list of fonts upported by the canvas Name specifies name of the font,...
void AddCustomFonts(TPadWebSnapshot &master)
Add special canvas objects with custom fonts.
Bool_t CheckDataToSend(unsigned connid=0)
Check if any data should be send to client If connid != 0, only selected connection will be checked.
Bool_t PerformUpdate(Bool_t async) override
if canvas or any subpad was modified, scan all primitives in the TCanvas and subpads and convert them...
void AssignStatusBits(UInt_t bits)
Assign clients bits.
virtual Bool_t ProcessData(unsigned connid, const std::string &arg)
Handle data from web browser Returns kFALSE if message was not processed.
void ProcessLinesForObject(TObject *obj, const std::string &lines)
Execute one or several methods for selected object String can be separated by ";;" to let execute sev...
TWebCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height, Bool_t readonly=kTRUE)
Constructor.
static Int_t StoreCanvasJSON(TCanvas *c, const char *filename, const char *option="")
Create JSON painting output for given canvas and store into the file See TBufferJSON::ExportToFile() ...
void Iconify() override
Iconify browser window.
void SetWindowTitle(const char *newTitle) override
Set window title of web canvas.
UInt_t GetWindowGeometry(Int_t &x, Int_t &y, UInt_t &w, UInt_t &h) override
Returns window geometry including borders and menus.
static TCanvasImp * NewCanvas(TCanvas *c, const char *name, Int_t x, Int_t y, UInt_t width, UInt_t height)
Static method to create TWebCanvas instance Used by plugin manager.
static TString CreateCanvasJSON(TCanvas *c, Int_t json_compression=0, Bool_t batchmode=kFALSE)
Create JSON painting output for given canvas Produce JSON can be used for offline drawing with JSROOT...
Bool_t HasEditor() const override
Returns kTRUE if web canvas has graphical editor.
Int_t fStyleDelivery
! gStyle delivery to clients: 0:never, 1:once, 2:always
Definition TWebCanvas.h:94
PadClickedSignal_t fPadDblClickedSignal
! signal emitted when simple mouse click performed on the pad
Definition TWebCanvas.h:115
void ProcessExecs(TPad *pad, TExec *extra=nullptr)
Process TExec objects in the pad.
void CreatePadSnapshot(TPadWebSnapshot &paddata, TPad *pad, Long64_t version, PadPaintingReady_t func)
Create snapshot for pad and all primitives Callback function is used to create JSON in the middle of ...
Bool_t CheckCanvasModified(bool force_modified=false)
Check if any pad on the canvas was modified If yes, increment version of correspondent pad Returns tr...
virtual Bool_t DecodePadOptions(const std::string &, bool process_execs=false)
Decode all pad options, which includes ranges plus objects options.
Int_t GetPaletteDelivery() const
Definition TWebCanvas.h:228
void SetWindowSize(UInt_t w, UInt_t h) override
Set window size of web canvas.
TObject * FindPrimitive(const std::string &id, int idcnt=1, TPad *pad=nullptr, TObjLink **objlnk=nullptr, TPad **objpad=nullptr)
Search of object with given id in list of primitives One could specify pad where search could be star...
Bool_t fFixedSize
! is canvas size fixed
Definition TWebCanvas.h:110
Int_t GetStyleDelivery() const
Definition TWebCanvas.h:225
void PopulateObjectMenu(void *obj, TClass *cl)
Class used to transport drawing options from the client.
std::vector< double > fopt
custom float array
std::string fcust
custom string
std::string snapid
id of the object
std::string opt
drawing options
void CreatePainting()
Definition TWebPS.cxx:26
Bool_t IsEmptyPainting() const
Definition TWebPS.h:32
TWebPainting * TakePainting()
Definition TWebPS.h:34
TWebPainting * GetPainting()
Definition TWebPS.h:33
Implement TVirtualPadPainter which abstracts painting operations.
Object used to store paint operations and deliver them to JSROOT.
void AddColor(Int_t indx, TColor *col)
Add custom color to operations.
void AddOper(const std::string &oper)
Add next custom operator to painting Operations are separated by semicolons Following operations are ...
@ kStyle
gStyle object
@ kObject
object itself
@ kSVG
list of SVG primitives
@ kSubPad
subpad
@ kFont
custom web font
@ kColors
list of ROOT colors + palette
void SetSnapshot(Int_t kind, TObject *snapshot, Bool_t owner=kFALSE)
SetUse pointer to assign object id - TString::Hash.
void SetObjectIDAsPtr(void *ptr, const std::string &suffix="")
Use pointer to assign object id - TString::Hash.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
TH1F * h1
Definition legend1.C:5
TF1 * f1
Definition legend1.C:11
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:721
bool _detected
! if pad was detected during last scan
Definition TWebCanvas.h:78
TString fName
TString fFormat
WebFont_t()=default
TString fData
WebFont_t(Int_t indx, const TString &name, const TString &fmt, const TString &data)