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"
18#include "THttpServer.h"
19
20#include "TSystem.h"
21#include "TStyle.h"
22#include "TCanvas.h"
23#include "TButton.h"
24#include "TFrame.h"
25#include "TPaveText.h"
26#include "TPaveStats.h"
27#include "TText.h"
28#include "TROOT.h"
29#include "TClass.h"
30#include "TColor.h"
31#include "TObjArray.h"
32#include "TArrayI.h"
33#include "TList.h"
34#include "TF1.h"
35#include "TF2.h"
36#include "TH1.h"
37#include "TH2.h"
38#include "TH1K.h"
39#include "THStack.h"
40#include "TMultiGraph.h"
41#include "TEnv.h"
42#include "TError.h"
43#include "TGraph.h"
44#include "TGraphPolar.h"
45#include "TGraphPolargram.h"
46#include "TGraph2D.h"
47#include "TGaxis.h"
48#include "TScatter.h"
49#include "TCutG.h"
50#include "TBufferJSON.h"
51#include "TBase64.h"
52#include "TAtt3D.h"
53#include "TView.h"
54#include "TExec.h"
55#include "TVirtualX.h"
56#include "TMath.h"
57#include "TTimer.h"
58#include "TThread.h"
59
60#include <cstdio>
61#include <cstring>
62#include <fstream>
63#include <iostream>
64#include <memory>
65#include <sstream>
66#include <vector>
67
68
69class TWebCanvasTimer : public TTimer {
74public:
76
77 Bool_t IsSlow() const { return fSlow; }
78 void SetSlow(Bool_t slow = kTRUE)
79 {
80 fSlow = slow;
81 fSlowCnt = 0;
82 SetTime(slow ? 1000 : 10);
83 }
84
85 /// used to send control messages to clients
86 void Timeout() override
87 {
88 if (fProcessing || fCanv.fProcessingData) return;
92 if (res) {
93 fSlowCnt = 0;
94 } else if (++fSlowCnt > 10 && !IsSlow()) {
96 }
97 }
98};
99
100
101/** \class TWebCanvas
102\ingroup webgui6
103\ingroup webwidgets
104
105Basic TCanvasImp ABI implementation for Web-based Graphics
106Provides painting of main ROOT classes in web browsers using [JSROOT](https://root.cern/js/)
107
108Following settings parameters can be useful for TWebCanvas:
109
110 WebGui.FullCanvas: 1 read-only mode (0), full-functional canvas (1) (default - 1)
111 WebGui.StyleDelivery: 1 provide gStyle object to JSROOT client (default - 1)
112 WebGui.PaletteDelivery: 1 provide color palette to JSROOT client (default - 1)
113 WebGui.TF1UseSave: 1 used saved values for function drawing: 0 - off, 1 - if client fail to evaluate function, 2 - always (default - 1)
114
115TWebCanvas is used by default in interactive ROOT session. To use web-based canvas in batch mode for image
116generation, one should explicitly specify `--web` option when starting ROOT:
117
118 [shell] root -b --web tutorials/hsimple.root -e 'hpxpy->Draw("colz"); c1->SaveAs("image.png");'
119
120If for any reasons TWebCanvas does not provide required functionality, one always can disable it.
121Either by specifying `root --web=off` when starting ROOT or by setting `Canvas.Name: TRootCanvas` in rootrc file.
122
123*/
124
125using namespace std::string_literals;
126
127static const std::string sid_pad_histogram = "__pad_histogram__";
128
129
130struct WebFont_t {
135 WebFont_t() = default;
136 WebFont_t(Int_t indx, const TString &name, const TString &fmt, const TString &data) : fIndx(indx), fName(name), fFormat(fmt), fData(data) {}
137};
138
139static std::vector<WebFont_t> gWebFonts;
140
141std::string TWebCanvas::gCustomScripts = {};
142std::vector<std::string> TWebCanvas::gCustomClasses = {};
143
146std::vector<std::string> TWebCanvas::gBatchFiles;
147std::vector<std::string> TWebCanvas::gBatchJsons;
148std::vector<int> TWebCanvas::gBatchWidths;
149std::vector<int> TWebCanvas::gBatchHeights;
150
151//////////////////////////////////////////////////////////////////////////////////////////////////
152/// Configure batch image mode for web graphics.
153/// Allows to process many images with single headless browser invocation and increase performance of image production.
154/// When many canvases are stored as image in difference places, they first collected in batch and then processed when at least `n`
155/// images are prepared. Only then headless browser invoked and create all these images at once.
156/// This allows to significantly increase performance of image production in web mode
157
159{
161 if (gBatchImageMode <= gBatchJsons.size())
163}
164
165//////////////////////////////////////////////////////////////////////////////////////////////////
166/// Flush batch images
167
169{
170 bool res = true;
171
172 if (gBatchJsons.size() > 0)
174
175 gBatchFiles.clear();
176 gBatchJsons.clear();
177 gBatchWidths.clear();
178 gBatchHeights.clear();
179
180 return res;
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Constructor
185
187 : TCanvasImp(c, name, x, y, width, height)
188{
189 // Workaround for multi-threaded environment
190 // Ensure main thread id picked when canvas implementation is created -
191 // otherwise it may be assigned in other thread and screw-up gPad access.
192 // Workaround may not work if main thread id was wrongly initialized before
193 // This resolves issue https://github.com/root-project/root/issues/15498
195
196 fTimer = new TWebCanvasTimer(*this);
197
198 fReadOnly = readonly;
199 fStyleDelivery = gEnv->GetValue("WebGui.StyleDelivery", 1);
200 fPaletteDelivery = gEnv->GetValue("WebGui.PaletteDelivery", 1);
201 fPrimitivesMerge = gEnv->GetValue("WebGui.PrimitivesMerge", 100);
202 fTF1UseSave = gEnv->GetValue("WebGui.TF1UseSave", (Int_t) 1);
204
205 fWebConn.emplace_back(0); // add special connection which only used to perform updates
206
207 fTimer->TurnOn();
208
209 // fAsyncMode = kTRUE;
210}
211
212
213////////////////////////////////////////////////////////////////////////////////
214/// Destructor
215
217{
218 delete fTimer;
219}
220
221
222//////////////////////////////////////////////////////////////////////////////////////////////////
223/// Add font to static list of fonts supported by the canvas
224/// Name specifies name of the font, second is font file with .ttf or .woff2 extension
225/// Only True Type Fonts (ttf) are supported by PDF
226/// Returns font index which can be used in
227/// auto font_indx = TWebCanvas::AddFont("test", "test.ttf", 2);
228/// gStyle->SetStatFont(font_indx);
229
230Font_t TWebCanvas::AddFont(const char *name, const char *fontfile, Int_t precision)
231{
232 Font_t maxindx = 22;
233 for (auto &entry : gWebFonts) {
234 if (entry.fName == name)
235 return precision > 0 ? entry.fIndx*10 + precision : entry.fIndx;
236 if (entry.fIndx > maxindx)
237 maxindx = entry.fIndx;
238 }
239
240 TString fullname = fontfile, fmt = "ttf";
241 auto pos = fullname.Last('.');
242 if (pos != kNPOS) {
243 fmt = fullname(pos+1, fullname.Length() - pos);
244 fmt.ToLower();
245 if ((fmt != "ttf") && (fmt != "woff2")) {
246 ::Error("TWebCanvas::AddFont", "Unsupported font file extension %s", fmt.Data());
247 return (Font_t) -1;
248 }
249 }
250
251 gSystem->ExpandPathName(fullname);
252
253 if (gSystem->AccessPathName(fullname.Data(), kReadPermission)) {
254 ::Error("TWebCanvas::AddFont", "Not possible to read font file %s", fullname.Data());
255 return (Font_t) -1;
256 }
257
258 std::ifstream is(fullname.Data(), std::ios::in | std::ios::binary);
259 std::string res;
260 if (is) {
261 is.seekg(0, std::ios::end);
262 res.resize(is.tellg());
263 is.seekg(0, std::ios::beg);
264 is.read((char *)res.data(), res.length());
265 if (!is)
266 res.clear();
267 }
268
269 if (res.empty()) {
270 ::Error("TWebCanvas::AddFont", "Fail to read font file %s", fullname.Data());
271 return (Font_t) -1;
272 }
273
274 TString base64 = TBase64::Encode(res.c_str(), res.length());
275
276 maxindx++;
277
278 gWebFonts.emplace_back(maxindx, name, fmt, base64);
279
280 return precision > 0 ? maxindx*10 + precision : maxindx;
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Initialize window for the web canvas
285/// At this place canvas is not yet register to the list of canvases - one cannot call RWebWindow::Show()
286
288{
289 return 111222333; // should not be used at all
290}
291
292////////////////////////////////////////////////////////////////////////////////
293/// Creates web-based pad painter
294
296{
297 return new TWebPadPainter();
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Returns kTRUE when object is fully supported on JSROOT side
302/// In ROOT7 Paint function will just return appropriate flag that object can be displayed on JSROOT side
303
305{
306 if (!obj)
307 return kTRUE;
308
309 static const struct {
310 const char *name{nullptr};
311 bool with_derived{false};
312 bool reduse_by_many{false};
313 } supported_classes[] = {{"TH1", true},
314 {"TF1", true},
315 {"TGraph", true},
316 {"TScatter"},
317 {"TFrame"},
318 {"THStack"},
319 {"TMultiGraph"},
320 {"TGraphPolargram", true},
321 {"TPave", true},
322 {"TGaxis"},
323 {"TPave", true},
324 {"TArrow"},
325 {"TBox", false, true}, // can be handled via TWebPainter, disable for large number of primitives (like in greyscale.C)
326 {"TWbox"}, // some extra calls which cannot be handled via TWebPainter
327 {"TLine", false, true}, // can be handler via TWebPainter, disable for large number of primitives (like in greyscale.C)
328 {"TEllipse", true, true}, // can be handled via TWebPainter, disable for large number of primitives (like in greyscale.C)
329 {"TText"},
330 {"TLatex"},
331 {"TLink"},
332 {"TAnnotation"},
333 {"TMathText"},
334 {"TMarker"},
335 {"TPolyMarker"},
336 {"TPolyLine", true, true}, // can be handled via TWebPainter, simplify colors handling
337 {"TPolyMarker3D"},
338 {"TPolyLine3D"},
339 {"TGraphTime"},
340 {"TGraph2D"},
341 {"TGraph2DErrors"},
342 {"TGraphTime"},
343 {"TASImage"},
344 {"TRatioPlot"},
345 {"TSpline"},
346 {"TSpline3"},
347 {"TSpline5"},
348 {"TGeoManager"},
349 {"TGeoVolume"},
350 {}};
351
352 // fast check of class name
353 for (int i = 0; supported_classes[i].name != nullptr; ++i)
354 if ((!many_primitives || !supported_classes[i].reduse_by_many) && (strcmp(supported_classes[i].name, obj->ClassName()) == 0))
355 return kTRUE;
356
357 // now check inheritance only for configured classes
358 for (int i = 0; supported_classes[i].name != nullptr; ++i)
359 if (supported_classes[i].with_derived && (!many_primitives || !supported_classes[i].reduse_by_many))
360 if (obj->InheritsFrom(supported_classes[i].name))
361 return kTRUE;
362
363 return IsCustomClass(obj->IsA());
364}
365
366//////////////////////////////////////////////////////////////////////////////////////////////////
367/// Configures custom script for canvas.
368/// If started with "modules:" prefix, module(s) will be imported with `loadModules` function of JSROOT.
369/// If custom path was configured in RWebWindowsManager::AddServerLocation, it can be used in module paths.
370/// If started with "load:" prefix, code will be loaded with `loadScript` function of JSROOT (old, deprecated way)
371/// Script also can be a plain JavaScript code which imports JSROOT and provides draw function for custom classes
372/// See tutorials/visualisation/webgui/custom/custom.mjs demonstrating such example
373
374void TWebCanvas::SetCustomScripts(const std::string &src)
375{
377}
378
379//////////////////////////////////////////////////////////////////////////////////////////////////
380/// Returns configured custom script
381
383{
384 return gCustomScripts;
385}
386
387//////////////////////////////////////////////////////////////////////////////////////////////////
388/// For batch mode special handling of scripts are required
389/// Headless browser not able to load modules from the file system
390/// Therefore custom web-canvas modules and scripts has to be loaded in advance and processed
391
392std::string TWebCanvas::ProcessCustomScripts(bool batch)
393{
394 if (!batch || gCustomScripts.empty() || (gCustomScripts.find("modules:") != 0))
395 return gCustomScripts;
396
398
399 std::string content;
400
401 std::string modules_names = gCustomScripts.substr(8);
402
403 std::map<std::string, bool> mapped_funcs;
404
405 while (!modules_names.empty()) {
406 std::string modname;
407 auto p = modules_names.find(";");
408 if (p == std::string::npos) {
409 modname = modules_names;
410 modules_names.clear();
411 } else {
412 modname = modules_names.substr(0, p);
413 modules_names = modules_names.substr(p+1);
414 }
415
416 p = modname.find("/");
417 if ((p == std::string::npos) || modname.empty())
418 continue;
419
420 std::string pathname = modname.substr(0, p+1);
421 std::string filename = modname.substr(p+1);
422
423 auto fpath = loc[pathname];
424
425 if (fpath.empty())
426 continue;
427
428 auto cont = THttpServer::ReadFileContent(fpath + filename);
429 if (cont.empty())
430 continue;
431
432 // check that special mark is in the script
433 auto pmark = cont.find("$$jsroot_batch_conform$$");
434 if (pmark == std::string::npos)
435 continue;
436
437 // process line like this
438 // import { ObjectPainter, addMoveHandler, addDrawFunc, ensureTCanvas } from 'jsroot';
439
440 static const std::string str1 = "import {";
441 static const std::string str2 = "} from 'jsroot';";
442
443 auto p1 = cont.find(str1);
444 auto p2 = cont.find(str2, p1);
445 if ((p1 == std::string::npos) || (p2 == std::string::npos) || (p2 > pmark))
446 continue;
447
448 TString globs;
449
450 TString funcs = cont.substr(p1 + 8, p2 - p1 - 8).c_str();
451 auto arr = funcs.Tokenize(",");
452
453 TIter next(arr);
454 while (auto obj = next()) {
455 TString name = obj->GetName();
457 if (!mapped_funcs[name.Data()]) {
458 globs.Append(TString::Format("globalThis.%s = JSROOT.%s;\n", name.Data(), name.Data()));
459 mapped_funcs[name.Data()] = true;
460 }
461 }
462 delete arr;
463
464 cont.erase(p1, p2 + str2.length() - p1);
465
466 cont.insert(p1, globs.Data());
467
468 content.append(cont);
469 }
470
471 return content;
472}
473
474
475//////////////////////////////////////////////////////////////////////////////////////////////////
476/// Assign custom class
477
478void TWebCanvas::AddCustomClass(const std::string &clname, bool with_derived)
479{
480 if (with_derived)
481 gCustomClasses.emplace_back("+"s + clname);
482 else
483 gCustomClasses.emplace_back(clname);
484}
485
486//////////////////////////////////////////////////////////////////////////////////////////////////
487/// Checks if class belongs to custom
488
490{
491 for (auto &name : gCustomClasses) {
492 if (name[0] == '+') {
493 if (cl->InheritsFrom(name.substr(1).c_str()))
494 return true;
495 } else if (name.compare(cl->GetName()) == 0) {
496 return true;
497 }
498 }
499 return false;
500}
501
502//////////////////////////////////////////////////////////////////////////////////////////////////
503/// Creates representation of the object for painting in web browser
504
505void TWebCanvas::CreateObjectSnapshot(TPadWebSnapshot &master, TPad *pad, TObject *obj, const char *opt, TWebPS *masterps)
506{
507 if (IsJSSupportedClass(obj, masterps != nullptr)) {
508 master.NewPrimitive(obj, opt).SetSnapshot(TWebSnapshot::kObject, obj);
509 return;
510 }
511
512 // painter is not necessary for batch canvas, but keep configuring it for a while
513 auto *painter = dynamic_cast<TWebPadPainter *>(Canvas()->GetCanvasPainter());
514
515 TView *view = nullptr;
516
518
519 gPad = pad;
520
521 if (obj->InheritsFrom(TAtt3D::Class()) && !pad->GetView()) {
522 pad->GetViewer3D("pad");
523 view = TView::CreateView(1, 0, 0); // Cartesian view by default
524 pad->SetView(view);
525
526 // Set view to perform first auto-range (scaling) pass
527 view->SetAutoRange(kTRUE);
528 }
529
530 TVirtualPS *saveps = gVirtualPS;
531
532 TWebPS ps;
533 ps.GetPainting()->SetClassName(obj->ClassName());
534 ps.GetPainting()->SetObjectName(obj->GetName());
535 gVirtualPS = masterps ? masterps : &ps;
536 if (painter)
537 painter->SetPainting(ps.GetPainting());
538
539 // calling Paint function for the object
540 obj->Paint(opt);
541
542 if (view) {
543 view->SetAutoRange(kFALSE);
544 // call 3D paint once again to make real drawing
545 obj->Paint(opt);
546 pad->SetView(nullptr);
547 }
548
549 if (painter)
550 painter->SetPainting(nullptr);
551
552 gVirtualPS = saveps;
553
554 fPadsStatus[pad]._has_specials = true;
555
556 // if there are master PS, do not create separate entries
557 if (!masterps && !ps.IsEmptyPainting())
559}
560
561//////////////////////////////////////////////////////////////////////////////////////////////////
562/// Calculate hash function for all colors and palette
563
565{
566 UInt_t hash = 0;
567
568 TObjArray *colors = (TObjArray *)gROOT->GetListOfColors();
569
570 if (colors) {
571 for (Int_t n = 0; n <= colors->GetLast(); ++n)
572 if (colors->At(n))
573 hash += TString::Hash(colors->At(n), TColor::Class()->Size());
574 }
575
577
578 hash += TString::Hash(pal.GetArray(), pal.GetSize() * sizeof(Int_t));
579
580 return hash;
581}
582
583
584//////////////////////////////////////////////////////////////////////////////////////////////////
585/// Add special canvas objects with list of colors and color palette
586
588{
589 TObjArray *colors = (TObjArray *)gROOT->GetListOfColors();
590
591 if (!colors)
592 return;
593
594 //Int_t cnt = 0;
595 //for (Int_t n = 0; n <= colors->GetLast(); ++n)
596 // if (colors->At(n))
597 // cnt++;
598 //if (cnt <= 598)
599 // return; // normally there are 598 colors defined
600
602
603 auto listofcols = new TWebPainting;
604 for (Int_t n = 0; n <= colors->GetLast(); ++n)
605 listofcols->AddColor(n, (TColor *)colors->At(n));
606
607 // store palette in the buffer
608 auto *tgt = listofcols->Reserve(pal.GetSize());
609 for (Int_t i = 0; i < pal.GetSize(); i++)
610 tgt[i] = pal[i];
611 listofcols->FixSize();
612
613 master.NewSpecials().SetSnapshot(TWebSnapshot::kColors, listofcols, kTRUE);
614}
615
616//////////////////////////////////////////////////////////////////////////////////////////////////
617/// Add special canvas objects with custom fonts
618
620{
621 for (auto &entry : gWebFonts) {
622 TString code = TString::Format("%d:%s:%s:%s", entry.fIndx, entry.fName.Data(), entry.fFormat.Data(), entry.fData.Data());
623 auto custom_font = new TWebPainting;
624 custom_font->AddOper(code.Data());
625 master.NewSpecials().SetSnapshot(TWebSnapshot::kFont, custom_font, kTRUE);
626 }
627}
628
629//////////////////////////////////////////////////////////////////////////////////////////////////
630/// Create snapshot for pad and all primitives
631/// Callback function is used to create JSON in the middle of data processing -
632/// when all misc objects removed from canvas list of primitives or histogram list of functions
633/// After that objects are moved back to their places
634
636{
637 auto &pad_status = fPadsStatus[pad];
638
639 // send primitives if version 0 or actual pad version grater than already send version
640 bool process_primitives = (version == 0) || (pad_status.fVersion > version);
641
642 if (paddata.IsSetObjectIds()) {
643 paddata.SetActive(pad == gPad);
644 paddata.SetObjectIDAsPtr(pad);
645 }
646 paddata.SetSnapshot(TWebSnapshot::kSubPad, pad); // add ref to the pad
647 paddata.SetWithoutPrimitives(!process_primitives);
648 paddata.SetHasExecs(pad->GetListOfExecs()); // if pad execs are there provide more events from client
649
650 // check style changes every time when creating canvas snapshot
651 if (resfunc && (GetStyleDelivery() > 0)) {
652
654 auto hash = TString::Hash(gStyle, TStyle::Class()->Size());
655 if ((hash != fStyleHash) || (fStyleVersion == 0)) {
656 fStyleHash = hash;
658 }
659 }
660
661 if (fStyleVersion > version)
663 }
664
665 // for the first time add custom fonts to the canvas snapshot
666 if (resfunc && (version == 0))
667 AddCustomFonts(paddata);
668
669 fAllPads.emplace_back(pad);
670
671 TList *primitives = pad->GetListOfPrimitives();
672
673 TWebPS masterps;
674 bool usemaster = primitives ? (primitives->GetSize() > fPrimitivesMerge) : false;
675
676 TIter iter(primitives);
677 TObject *obj = nullptr;
678 TFrame *frame = nullptr;
679 TPaveText *title = nullptr;
680 TGraphPolar *first_polar = nullptr;
681 TGraphPolargram *polargram = nullptr;
682 TString polargram_drawopt = "-";
683 bool need_frame = false, has_histo = false, need_palette = false;
684 std::string need_title;
685
686 auto checkNeedPalette = [](TH1* hist, const TString &opt) {
687 auto check = [&opt](const TString &arg) {
688 return opt.Contains(arg + "Z") || opt.Contains(arg + "HZ");
689 };
690
691 return ((hist->GetDimension() == 2) && (check("COL") || check("LEGO") || check("LEGO4") || check("SURF2"))) ||
692 ((hist->GetDimension() == 3) && (check("BOX2") || check("BOX3")));
693 };
694
695 while (process_primitives && ((obj = iter()) != nullptr)) {
696 TString opt = iter.GetOption();
697 opt.ToUpper();
698
699 if (obj->InheritsFrom(THStack::Class())) {
700 // workaround for THStack, create extra components before sending to client
701 if (!opt.Contains("PADS") && !opt.Contains("SAME")) {
702 Bool_t do_rebuild_stack = kFALSE;
703
704 auto hs = static_cast<THStack *>(obj);
705
706 if (!opt.Contains("NOSTACK") && !opt.Contains("CANDLE") && !opt.Contains("VIOLIN") && !IsReadOnly() && !fUsedObjs[hs]) {
707 do_rebuild_stack = kTRUE;
708 fUsedObjs[hs] = true;
709 }
710
711 if (strlen(obj->GetTitle()) > 0)
712 need_title = obj->GetTitle();
713 TVirtualPad::TContext ctxt(pad, kFALSE);
714 hs->BuildPrimitives(iter.GetOption(), do_rebuild_stack);
715 has_histo = true;
716 need_frame = true;
717 }
718 } else if (obj->InheritsFrom(TMultiGraph::Class())) {
719 // workaround for TMultiGraph
720 if (opt.Contains("A")) {
721 auto mg = static_cast<TMultiGraph *>(obj);
723 mg->GetHistogram(); // force creation of histogram without any drawings
724 has_histo = true;
725 if (strlen(obj->GetTitle()) > 0)
726 need_title = obj->GetTitle();
727 need_frame = true;
728 }
729 } else if (obj->InheritsFrom(TFrame::Class())) {
730 if (!frame)
731 frame = static_cast<TFrame *>(obj);
732 } else if (obj->InheritsFrom(TH1::Class())) {
733 need_frame = true;
734 has_histo = true;
735 if (!obj->TestBit(TH1::kNoTitle) && !opt.Contains("SAME") && !opt.Contains("AXIS") && !opt.Contains("AXIG") && (strlen(obj->GetTitle()) > 0))
736 need_title = obj->GetTitle();
737 if (checkNeedPalette(static_cast<TH1*>(obj), opt))
738 need_palette = true;
739 } else if (obj->InheritsFrom(TGraphPolar::Class())) {
740 auto polar = static_cast<TGraphPolar *> (obj);
741 if (!first_polar) {
742 first_polar = polar;
743 need_title = first_polar->GetTitle();
744 polargram = first_polar->GetPolargram();
745 if (!polargram) {
746 polargram = first_polar->CreatePolargram(opt);
747 polargram_drawopt = opt.Contains("N") ? "N" : "";
748 if (opt.Contains("O")) polargram_drawopt.Append("O");
749 }
750 }
751 polar->SetPolargram(polargram);
752 } else if (obj->InheritsFrom(TGraph::Class())) {
753 if (opt.Contains("A")) {
754 need_frame = true;
755 if (!has_histo && (strlen(obj->GetTitle()) > 0) && !obj->TestBit(TH1::kNoTitle))
756 need_title = obj->GetTitle();
757 }
758 } else if (obj->InheritsFrom(TGraph2D::Class())) {
759 if (!has_histo && (strlen(obj->GetTitle()) > 0))
760 need_title = obj->GetTitle();
761 } else if (obj->InheritsFrom(TScatter::Class())) {
762 need_frame = need_palette = true;
763 if (strlen(obj->GetTitle()) > 0)
764 need_title = obj->GetTitle();
765 } else if (obj->InheritsFrom(TF1::Class())) {
766 if (!opt.Contains("SAME")) {
767 need_frame = !obj->InheritsFrom(TF2::Class());
768 if (!has_histo && (strlen(obj->GetTitle()) > 0))
769 need_title = obj->GetTitle();
770 }
771 } else if (obj->InheritsFrom(TPaveText::Class())) {
772 if (strcmp(obj->GetName(), "title") == 0)
773 title = static_cast<TPaveText *>(obj);
774 } else if (obj->InheritsFrom(TButton::Class())) {
775 auto btn = (TButton *) obj;
776 auto text = dynamic_cast<TText *> (btn->GetListOfPrimitives()->First());
777 if (text) {
778 text->SetTitle(btn->GetTitle());
779 text->SetTextSize(btn->GetTextSize());
780 text->SetTextFont(btn->GetTextFont());
781 text->SetTextAlign(btn->GetTextAlign());
782 text->SetTextColor(btn->GetTextColor());
783 text->SetTextAngle(btn->GetTextAngle());
784 }
785 }
786 }
787
788 if (need_frame && !frame && primitives && CanCreateObject("TFrame")) {
789 if (!IsReadOnly() && need_palette && (pad->GetRightMargin() < 0.12) && (pad->GetRightMargin() == gStyle->GetPadRightMargin()))
790 pad->SetRightMargin(0.12);
791
792 frame = pad->GetFrame();
793 if(frame)
794 primitives->AddFirst(frame, "");
795 }
796
797 if (!need_title.empty() && gStyle->GetOptTitle()) {
798 if (title) {
799 auto line0 = title->GetLine(0);
800 if (line0 && !IsReadOnly()) line0->SetTitle(need_title.c_str());
801 } else if (primitives && CanCreateObject("TPaveText")) {
802 title = new TPaveText(0, 0, 0, 0, "blNDC");
805 title->SetName("title");
808 title->SetTextFont(gStyle->GetTitleFont(""));
809 if (gStyle->GetTitleFont("") % 10 > 2)
811 title->AddText(need_title.c_str());
812 title->SetBit(kCanDelete);
813 primitives->Add(title, title->GetOption());
814 }
815 }
816
817 if (polargram && (polargram_drawopt != "-"))
818 primitives->Add(polargram, polargram_drawopt);
819
820 auto flush_master = [&]() {
821 if (!usemaster || masterps.IsEmptyPainting()) return;
822
824 masterps.CreatePainting(); // create for next operations
825 };
826
827 auto check_cutg_in_options = [&](const TString &opt) {
828 auto p1 = opt.Index("["), p2 = opt.Index("]");
829 if ((p1 != kNPOS) && (p2 != kNPOS) && p2 > p1 + 1) {
830 TString cutname = opt(p1 + 1, p2 - p1 - 1);
831 TObject *cutg = primitives->FindObject(cutname.Data());
832 if (!cutg || (cutg->IsA() != TCutG::Class())) {
833 cutg = gROOT->GetListOfSpecials()->FindObject(cutname.Data());
834 if (cutg && cutg->IsA() == TCutG::Class())
835 paddata.NewPrimitive(cutg, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, cutg);
836 }
837 }
838 };
839
840 auto check_save_tf1 = [&](TObject *fobj, bool ignore_nodraw = false) {
841 if (!paddata.IsBatchMode() && (fTF1UseSave <= 0))
842 return;
843 if (!ignore_nodraw && fobj->TestBit(TF1::kNotDraw))
844 return;
845
846 auto f1 = static_cast<TF1 *>(fobj);
847 // check if TF1 can be used
848 if (!f1->IsValid())
849 return;
850
851 // in default case save buffer used as is
852 if ((fTF1UseSave == 1) && f1->HasSave())
853 return;
854
855 f1->Save(0, 0, 0, 0, 0, 0);
856 };
857
858 auto create_stats = [&]() {
859 TPaveStats *stats = nullptr;
860 if (CanCreateObject("TPaveStats")) {
861 stats = new TPaveStats(
864 gStyle->GetStatX(),
865 gStyle->GetStatY(), "brNDC");
866
867 // do not set optfit and optstat, they calling pad->Update,
868 // values correctly set already in TPaveStats constructor
869 // stats->SetOptFit(gStyle->GetOptFit());
870 // stats->SetOptStat(gStyle->GetOptStat());
874 stats->SetTextFont(gStyle->GetStatFont());
875 if (gStyle->GetStatFont()%10 > 2)
879 stats->SetName("stats");
880
882 stats->SetTextAlign(12);
883 stats->SetBit(kCanDelete);
884 stats->SetBit(kMustCleanup);
885 }
886
887 return stats;
888 };
889
890 auto check_graph_funcs = [&](TGraph *gr, TList *funcs = nullptr) {
891 if (!funcs && gr)
893 if (!funcs)
894 return;
895
896 TIter fiter(funcs);
897 TPaveStats *stats = nullptr;
898 bool has_tf1 = false;
899
900 while (auto fobj = fiter()) {
901 if (fobj->InheritsFrom(TPaveStats::Class()))
902 stats = dynamic_cast<TPaveStats *> (fobj);
903 else if (fobj->InheritsFrom(TF1::Class())) {
904 check_save_tf1(fobj);
905 has_tf1 = true;
906 }
907 }
908
909 if (!stats && has_tf1 && gr && !gr->TestBit(TGraph::kNoStats) && (gStyle->GetOptFit() > 0)) {
910 stats = create_stats();
911 if (stats) {
912 stats->SetOptStat(0);
913 stats->SetOptFit(gStyle->GetOptFit());
914 stats->SetParent(funcs);
915 funcs->Add(stats);
916 }
917 }
918 };
919
920 iter.Reset();
921
922 bool first_obj = true;
923
924 if (process_primitives)
925 pad_status._has_specials = false;
926
927 while ((obj = iter()) != nullptr) {
928 if (obj->InheritsFrom(TPad::Class())) {
929 flush_master();
930 CreatePadSnapshot(paddata.NewSubPad(), (TPad *)obj, version, nullptr);
931 } else if (!process_primitives) {
932 continue;
933 } else if (obj->InheritsFrom(TH1K::Class())) {
934 flush_master();
935 TH1K *hist = static_cast<TH1K *>(obj);
936
937 Int_t nbins = hist->GetXaxis()->GetNbins();
938
939 TH1D *h1 = new TH1D("__dummy_name__", hist->GetTitle(), nbins, hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
940 h1->SetDirectory(nullptr);
941 h1->SetName(hist->GetName());
942 hist->TAttLine::Copy(*h1);
943 hist->TAttFill::Copy(*h1);
944 hist->TAttMarker::Copy(*h1);
945 for (Int_t n = 1; n <= nbins; ++n)
946 h1->SetBinContent(n, hist->GetBinContent(n));
947
948 TIter fiter(hist->GetListOfFunctions());
949 while (auto fobj = fiter())
950 h1->GetListOfFunctions()->Add(fobj->Clone());
951
953
954 } else if (obj->InheritsFrom(TH1::Class())) {
955 flush_master();
956
957 TH1 *hist = static_cast<TH1 *>(obj);
958 hist->BufferEmpty();
959
960 TPaveStats *stats = nullptr;
961 TObject *palette = nullptr;
962
963 TIter fiter(hist->GetListOfFunctions());
964 while (auto fobj = fiter()) {
965 if (fobj->InheritsFrom(TPaveStats::Class()))
966 stats = dynamic_cast<TPaveStats *> (fobj);
967 else if (fobj->InheritsFrom("TPaletteAxis"))
968 palette = fobj;
969 else if (fobj->InheritsFrom(TF1::Class()))
970 check_save_tf1(fobj);
971 }
972
973 TString hopt = iter.GetOption();
974 TString o = hopt;
975 o.ToUpper();
976
977 if (!stats && (first_obj || o.Contains("SAMES")) && (gStyle->GetOptStat() > 0)) {
978 stats = create_stats();
979 if (stats) {
980 stats->SetParent(hist);
981 hist->GetListOfFunctions()->Add(stats);
982 }
983 }
984
985 if (!palette && CanCreateObject("TPaletteAxis") && checkNeedPalette(hist, o)) {
986 std::stringstream exec;
987 exec << "new TPaletteAxis(0,0,0,0, (TH1*)" << std::hex << std::showbase << (size_t)hist << ");";
988 palette = (TObject *)gROOT->ProcessLine(exec.str().c_str());
989 if (palette)
990 hist->GetListOfFunctions()->AddFirst(palette);
991 }
992
993 paddata.NewPrimitive(obj, hopt.Data()).SetSnapshot(TWebSnapshot::kObject, obj);
994
995 if (hist->GetDimension() == 2)
996 check_cutg_in_options(iter.GetOption());
997
998 first_obj = false;
999 } else if (obj->InheritsFrom(TGraphPolar::Class())) {
1000 flush_master();
1001
1002 auto polar = static_cast<TGraphPolar *>(obj);
1003
1004 check_graph_funcs(polar);
1005
1006 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1007
1008 first_obj = false;
1009 } else if (obj->InheritsFrom(TGraphPolargram::Class())) {
1010 // do nothing, object must be streamed with graphpolar
1011 } else if (obj->InheritsFrom(TGraph::Class())) {
1012 flush_master();
1013
1014 TGraph *gr = static_cast<TGraph *>(obj);
1015
1016 check_graph_funcs(gr);
1017
1018 TString gropt = iter.GetOption();
1019
1020 // ensure histogram exists on server to draw it properly on clients side
1021 if (!IsReadOnly() && (first_obj || gropt.Index("A", 0, TString::kIgnoreCase) != kNPOS ||
1022 (gropt.Index("X+", 0, TString::kIgnoreCase) != kNPOS) || (gropt.Index("Y+", 0, TString::kIgnoreCase) != kNPOS)))
1023 gr->GetHistogram();
1024
1025 paddata.NewPrimitive(obj, gropt.Data()).SetSnapshot(TWebSnapshot::kObject, obj);
1026
1027 first_obj = false;
1028 } else if (obj->InheritsFrom(TGraph2D::Class())) {
1029 flush_master();
1030
1031 TGraph2D *gr2d = static_cast<TGraph2D *>(obj);
1032
1033 check_graph_funcs(nullptr, gr2d->GetListOfFunctions());
1034
1035 // ensure correct range of histogram
1036 if (!IsReadOnly() && first_obj) {
1037 TString gropt = iter.GetOption();
1038 gropt.ToUpper();
1039 Bool_t zscale = gropt.Contains("TRI1") || gropt.Contains("TRI2") || gropt.Contains("COL");
1040 Bool_t cont5_draw = gropt.Contains("CONT5");
1041 Bool_t real_draw = gropt.Contains("TRI") || gropt.Contains("LINE") || gropt.Contains("ERR") || gropt.Contains("P") || cont5_draw;
1042
1043 TString hopt = !real_draw ? iter.GetOption() : (cont5_draw ? "" : (zscale ? "lego2z" : "lego2"));
1044 if (title) hopt.Append(";;use_pad_title");
1045
1046 // if gr2d not draw - let create histogram with correspondent content
1047 auto hist = gr2d->GetHistogram(real_draw ? "empty" : "");
1048
1049 paddata.NewPrimitive(gr2d, hopt.Data(), "#hist").SetSnapshot(TWebSnapshot::kObject, hist);
1050 }
1051
1052 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1053 first_obj = false;
1054 } else if (obj->InheritsFrom(TMultiGraph::Class())) {
1055 flush_master();
1056
1057 TMultiGraph *mgr = static_cast<TMultiGraph *>(obj);
1058 TIter fiter(mgr->GetListOfFunctions());
1059 while (auto fobj = fiter()) {
1060 if (fobj->InheritsFrom(TF1::Class()))
1061 check_save_tf1(fobj);
1062 }
1063
1064 TIter giter(mgr->GetListOfGraphs());
1065 while (auto gobj = giter())
1066 check_graph_funcs(static_cast<TGraph *>(gobj));
1067
1068 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1069
1070 first_obj = false;
1071 } else if (obj->InheritsFrom(THStack::Class())) {
1072 flush_master();
1073
1074 THStack *hs = static_cast<THStack *>(obj);
1075
1076 TString hopt = iter.GetOption();
1077 hopt.ToLower();
1078 if (!hopt.Contains("nostack") && !hopt.Contains("candle") && !hopt.Contains("violin") && !hopt.Contains("pads")) {
1079 auto arr = hs->GetStack();
1080 arr->SetName(hs->GetName()); // mark list for JS
1081 paddata.NewPrimitive(arr, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, arr);
1082 }
1083
1084 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1085
1086 first_obj = hs->GetNhists() > 0; // real drawing only if there are histograms
1087 } else if (obj->InheritsFrom(TScatter::Class())) {
1088 flush_master();
1089
1090 TScatter *scatter = static_cast<TScatter *>(obj);
1091
1092 TObject *palette = nullptr;
1093
1094 TIter fiter(scatter->GetGraph()->GetListOfFunctions());
1095 while (auto fobj = fiter()) {
1096 if (fobj->InheritsFrom("TPaletteAxis"))
1097 palette = fobj;
1098 }
1099
1100 // ensure histogram exists on server to draw it properly on clients side
1101 if (!IsReadOnly() && first_obj)
1102 scatter->GetHistogram();
1103
1104 if (!palette && CanCreateObject("TPaletteAxis")) {
1105 std::stringstream exec;
1106 exec << "new TPaletteAxis(0,0,0,0,0,0);";
1107 palette = (TObject *)gROOT->ProcessLine(exec.str().c_str());
1108 if (palette)
1109 scatter->GetGraph()->GetListOfFunctions()->AddFirst(palette);
1110 }
1111
1112 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1113
1114 first_obj = false;
1115 } else if (obj->InheritsFrom(TF1::Class())) {
1116 flush_master();
1117 auto f1 = static_cast<TF1 *> (obj);
1118
1119 TString f1opt = iter.GetOption();
1120
1121 check_save_tf1(obj, true);
1122 if (fTF1UseSave > 1)
1123 f1opt.Append(";force_saved");
1124 else if (fTF1UseSave == 1)
1125 f1opt.Append(";prefer_saved");
1126
1127 if (first_obj) {
1128 auto hist = f1->GetHistogram();
1129 paddata.NewPrimitive(hist, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, hist);
1130 f1opt.Append(";webcanv_hist");
1131 }
1132
1133 if (f1->IsA() == TF2::Class())
1134 check_cutg_in_options(iter.GetOption());
1135
1137
1138 first_obj = false;
1139
1140 } else if (obj->InheritsFrom(TGaxis::Class())) {
1141 flush_master();
1142 auto gaxis = static_cast<TGaxis *> (obj);
1143 auto func = gaxis->GetFunction();
1144 if (func)
1145 paddata.NewPrimitive(func, "__ignore_drawing__").SetSnapshot(TWebSnapshot::kObject, func);
1146
1147 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1148 } else if (obj->InheritsFrom(TFrame::Class())) {
1149 flush_master();
1150 if (frame && (obj == frame)) {
1151 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1152 frame = nullptr; // add frame only once
1153 }
1154 } else if (IsJSSupportedClass(obj, usemaster)) {
1155 flush_master();
1156 paddata.NewPrimitive(obj, iter.GetOption()).SetSnapshot(TWebSnapshot::kObject, obj);
1157 } else {
1158 CreateObjectSnapshot(paddata, pad, obj, iter.GetOption(), usemaster ? &masterps : nullptr);
1159 }
1160 }
1161
1162 flush_master();
1163
1164 bool provide_colors = false;
1165
1166 if ((GetPaletteDelivery() > 2) || ((GetPaletteDelivery() == 2) && resfunc)) {
1167 // provide colors: either for each subpad (> 2) or only for canvas (== 2)
1168 provide_colors = process_primitives;
1169 } else if ((GetPaletteDelivery() == 1) && resfunc) {
1170 // check that colors really changing, using hash
1171
1173 auto hash = CalculateColorsHash();
1174 if ((hash != fColorsHash) || (fColorsVersion == 0)) {
1175 fColorsHash = hash;
1177 }
1178 }
1179
1180 provide_colors = fColorsVersion > version;
1181 }
1182
1183 // add colors after painting is performed - new colors may be generated only during painting
1184 if (provide_colors)
1185 AddColorsPalette(paddata);
1186
1187 if (!resfunc)
1188 return;
1189
1190 // now hide all primitives to perform I/O
1191 std::vector<TList *> all_primitives(fAllPads.size());
1192 for (unsigned n = 0; n < fAllPads.size(); ++n) {
1193 all_primitives[n] = fAllPads[n]->fPrimitives;
1194 fAllPads[n]->fPrimitives = nullptr;
1195 }
1196
1197 // execute function to prevent storing of colors with custom TCanvas streamer
1199
1200 // invoke callback for streaming
1201 resfunc(&paddata);
1202
1203 // and restore back primitives - delete any temporary if necessary
1204 for (unsigned n = 0; n < fAllPads.size(); ++n) {
1205 if (fAllPads[n]->fPrimitives)
1206 delete fAllPads[n]->fPrimitives;
1207 fAllPads[n]->fPrimitives = all_primitives[n];
1208 }
1209 fAllPads.clear();
1210 fUsedObjs.clear();
1211}
1212
1213//////////////////////////////////////////////////////////////////////////////////////////////////
1214/// Add control message for specified connection
1215/// Same control message can be overwritten many time before it really sends to the client
1216/// If connid == 0, message will be add to all connections
1217/// After ctrl message is add to the output, short timer is activated and message send afterwards
1218
1219void TWebCanvas::AddCtrlMsg(unsigned connid, const std::string &key, const std::string &value)
1220{
1221 Bool_t new_ctrl = kFALSE;
1222
1223 for (auto &conn : fWebConn) {
1224 if (conn.match(connid)) {
1225 conn.fCtrl[key] = value;
1226 new_ctrl = kTRUE;
1227 }
1228 }
1229
1230 if (new_ctrl && fTimer->IsSlow())
1232}
1233
1234
1235//////////////////////////////////////////////////////////////////////////////////////////////////
1236/// Add message to send queue for specified connection
1237/// If connid == 0, message will be add to all connections
1238
1239void TWebCanvas::AddSendQueue(unsigned connid, const std::string &msg)
1240{
1241 for (auto &conn : fWebConn) {
1242 if (conn.match(connid))
1243 conn.fSend.emplace(msg);
1244 }
1245}
1246
1247
1248//////////////////////////////////////////////////////////////////////////////////////////////////
1249/// Check if any data should be send to client
1250/// If connid != 0, only selected connection will be checked
1251
1253{
1254 if (!Canvas())
1255 return kFALSE;
1256
1257 bool isMoreData = false, isAnySend = false;
1258
1259 for (auto &conn : fWebConn) {
1260
1261 bool isConnData = !conn.fCtrl.empty() || !conn.fSend.empty() ||
1262 ((conn.fCheckedVersion < fCanvVersion) && (conn.fSendVersion == conn.fDrawVersion));
1263
1264 while ((conn.is_batch() && !connid) || (conn.match(connid) && fWindow && fWindow->CanSend(conn.fConnId, true))) {
1265 // check if any control messages still there to keep timer running
1266
1267 std::string buf;
1268
1269 if (!conn.fCtrl.empty()) {
1271 conn.fCtrl.clear();
1272 } else if (!conn.fSend.empty()) {
1273 std::swap(buf, conn.fSend.front());
1274 conn.fSend.pop();
1275 } else if ((conn.fCheckedVersion < fCanvVersion) && (conn.fSendVersion == conn.fDrawVersion)) {
1276
1277 buf = "SNAP6:"s + std::to_string(fCanvVersion) + ":"s;
1278
1279 TCanvasWebSnapshot holder(IsReadOnly(), true, false); // readonly, set ids, batchmode
1280
1281 holder.SetFixedSize(fFixedSize); // set fixed size flag
1282
1283 // scripts send only when canvas drawn for the first time
1284 if (!conn.fSendVersion)
1285 holder.SetScripts(ProcessCustomScripts(false));
1286
1287 holder.SetHighlightConnect(Canvas()->HasConnection("Highlighted(TVirtualPad*,TObject*,Int_t,Int_t)"));
1288
1289 CreatePadSnapshot(holder, Canvas(), conn.fSendVersion, [&buf, &conn, this](TPadWebSnapshot *snap) {
1290 if (conn.is_batch()) {
1291 // for batch connection only calling of CreatePadSnapshot is important
1292 buf.clear();
1293 return;
1294 }
1295
1296 auto json = TBufferJSON::ToJSON(snap, fJsonComp);
1297 auto hash = json.Hash();
1298 if (conn.fLastSendHash && (conn.fLastSendHash == hash) && conn.fSendVersion) {
1299 // prevent looping when same data send many times
1300 buf.clear();
1301 } else {
1302 buf.append(json.Data());
1303 conn.fLastSendHash = hash;
1304 }
1305 });
1306
1307 conn.fCheckedVersion = fCanvVersion;
1308
1309 conn.fSendVersion = fCanvVersion;
1310
1311 if (buf.empty())
1312 conn.fDrawVersion = fCanvVersion;
1313 } else {
1314 isConnData = false;
1315 break;
1316 }
1317
1318 if (!buf.empty() && !conn.is_batch()) {
1319 fWindow->Send(conn.fConnId, buf);
1320 isAnySend = true;
1321 }
1322 }
1323
1324 if (isConnData)
1325 isMoreData = true;
1326 }
1327
1328 if (fTimer->IsSlow() && isMoreData)
1329 fTimer->SetSlow(kFALSE);
1330
1331 return isAnySend;
1332}
1333
1334//////////////////////////////////////////////////////////////////////////////////////////
1335/// Close web canvas - not implemented
1336
1338{
1339}
1340
1341//////////////////////////////////////////////////////////////////////////////////////////
1342/// Show canvas in specified place.
1343/// If parameter args not specified, default ROOT web display will be used
1344
1346{
1347 if (!fWindow) {
1349
1350 fWindow->SetConnLimit(0); // configure connections limit
1351
1352 fWindow->SetDefaultPage("file:rootui5sys/canv/canvas6.html");
1353
1354 fWindow->SetCallBacks(
1355 // connection
1356 [this](unsigned connid) {
1357 if (fWindow->GetConnectionId(0) == connid)
1358 fWebConn.emplace(fWebConn.begin() + 1, connid);
1359 else
1360 fWebConn.emplace_back(connid);
1361 CheckDataToSend(connid);
1362 },
1363 // data
1364 [this](unsigned connid, const std::string &arg) {
1365 ProcessData(connid, arg);
1367 },
1368 // disconnect
1369 [this](unsigned connid) {
1370 unsigned indx = 0;
1371 for (auto &c : fWebConn) {
1372 if (c.fConnId == connid) {
1373 fWebConn.erase(fWebConn.begin() + indx);
1374 break;
1375 }
1376 indx++;
1377 }
1378 });
1379 }
1380
1381 auto w = Canvas()->GetWindowWidth(), h = Canvas()->GetWindowHeight();
1382 if ((w > 0) && (w < 50000) && (h > 0) && (h < 30000))
1383 fWindow->SetGeometry(w, h);
1384
1389
1390 fWindow->Show(args);
1391}
1392
1393//////////////////////////////////////////////////////////////////////////////////////////
1394/// Show canvas in browser window
1395
1397{
1398 if (gROOT->IsWebDisplayBatch())
1399 return;
1400
1402 args.SetWidgetKind("TCanvas");
1403 args.SetSize(Canvas()->GetWindowWidth(), Canvas()->GetWindowHeight());
1404 args.SetPos(Canvas()->GetWindowTopX(), Canvas()->GetWindowTopY());
1405
1406 ShowWebWindow(args);
1407}
1408
1409//////////////////////////////////////////////////////////////////////////////////////////
1410/// Function used to send command to browser to toggle menu, toolbar, editors, ...
1411
1412void TWebCanvas::ShowCmd(const std::string &arg, Bool_t show)
1413{
1414 AddCtrlMsg(0, arg, show ? "1"s : "0"s);
1415}
1416
1417//////////////////////////////////////////////////////////////////////////////////////////
1418/// Activate object in editor in web browser
1419
1421{
1422 if (!pad || !obj) return;
1423
1424 UInt_t hash = TString::Hash(&obj, sizeof(obj));
1425
1426 AddCtrlMsg(0, "edit"s, std::to_string(hash));
1427}
1428
1429//////////////////////////////////////////////////////////////////////////////////////////
1430/// Returns kTRUE if web canvas has graphical editor
1431
1433{
1434 return (fClientBits & TCanvas::kShowEditor) != 0;
1435}
1436
1437//////////////////////////////////////////////////////////////////////////////////////////
1438/// Returns kTRUE if web canvas has menu bar
1439
1441{
1442 return (fClientBits & TCanvas::kMenuBar) != 0;
1443}
1444
1445//////////////////////////////////////////////////////////////////////////////////////////
1446/// Returns kTRUE if web canvas has status bar
1447
1449{
1450 return (fClientBits & TCanvas::kShowEventStatus) != 0;
1451}
1452
1453//////////////////////////////////////////////////////////////////////////////////////////
1454/// Returns kTRUE if tooltips are activated in web canvas
1455
1457{
1458 return (fClientBits & TCanvas::kShowToolTips) != 0;
1459}
1460
1461//////////////////////////////////////////////////////////////////////////////////////////
1462/// Set window position of web canvas
1463
1465{
1466 AddCtrlMsg(0, "x"s, std::to_string(x));
1467 AddCtrlMsg(0, "y"s, std::to_string(y));
1468}
1469
1470//////////////////////////////////////////////////////////////////////////////////////////
1471/// Set window size of web canvas
1472
1474{
1475 AddCtrlMsg(0, "w"s, std::to_string(w));
1476 AddCtrlMsg(0, "h"s, std::to_string(h));
1477}
1478
1479//////////////////////////////////////////////////////////////////////////////////////////
1480/// Set window title of web canvas
1481
1482void TWebCanvas::SetWindowTitle(const char *newTitle)
1483{
1484 AddCtrlMsg(0, "title"s, newTitle);
1485}
1486
1487//////////////////////////////////////////////////////////////////////////////////////////
1488/// Set canvas size of web canvas
1489
1491{
1492 fFixedSize = kTRUE;
1493 AddCtrlMsg(0, "cw"s, std::to_string(cw));
1494 AddCtrlMsg(0, "ch"s, std::to_string(ch));
1495 if ((cw > 0) && (ch > 0)) {
1496 Canvas()->fCw = cw;
1497 Canvas()->fCh = ch;
1498 } else {
1499 // temporary value, will be reported back from client
1500 Canvas()->fCw = Canvas()->fWindowWidth;
1502 }
1503}
1504
1505//////////////////////////////////////////////////////////////////////////////////////////
1506/// Iconify browser window
1507
1509{
1510 AddCtrlMsg(0, "winstate"s, "iconify"s);
1511}
1512
1513//////////////////////////////////////////////////////////////////////////////////////////
1514/// Raise browser window
1515
1517{
1518 AddCtrlMsg(0, "winstate"s, "raise"s);
1519}
1520
1521//////////////////////////////////////////////////////////////////////////////////////////
1522/// Assign clients bits
1523
1525{
1526 fClientBits = bits;
1531}
1532
1533//////////////////////////////////////////////////////////////////////////////////////////////////
1534/// Decode all pad options, which includes ranges plus objects options
1535
1536Bool_t TWebCanvas::DecodePadOptions(const std::string &msg, bool process_execs)
1537{
1538 if (IsReadOnly() || msg.empty())
1539 return kFALSE;
1540
1541 auto arr = TBufferJSON::FromJSON<std::vector<TWebPadOptions>>(msg);
1542
1543 if (!arr)
1544 return kFALSE;
1545
1546 Bool_t need_update = kFALSE;
1547
1548 TPad *pad_with_execs = nullptr;
1549 TExec *hist_exec = nullptr;
1550
1551 for (unsigned n = 0; n < arr->size(); ++n) {
1552 auto &r = arr->at(n);
1553
1554 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(r.snapid));
1555
1556 if (!pad)
1557 continue;
1558
1559 if (pad == Canvas()) {
1560 AssignStatusBits(r.bits);
1561 Canvas()->fCw = r.cw;
1562 Canvas()->fCh = r.ch;
1563 if (r.w.size() == 4)
1565 }
1566
1567 // only if get OPTIONS message from client allow to change gPad
1568 if (r.active && (pad != gPad) && process_execs)
1569 gPad = pad;
1570
1571 if ((pad->GetTickx() != r.tickx) || (pad->GetTicky() != r.ticky))
1572 pad->SetTicks(r.tickx, r.ticky);
1573 if ((pad->GetGridx() != (r.gridx > 0)) || (pad->GetGridy() != (r.gridy > 0)))
1574 pad->SetGrid(r.gridx, r.gridy);
1575 pad->fLogx = r.logx;
1576 pad->fLogy = r.logy;
1577 pad->fLogz = r.logz;
1578
1579 pad->SetLeftMargin(r.mleft);
1580 pad->SetRightMargin(r.mright);
1581 pad->SetTopMargin(r.mtop);
1582 pad->SetBottomMargin(r.mbottom);
1583
1584 if (r.ranges) {
1585 // avoid call of original methods, set members directly
1586 // pad->Range(r.px1, r.py1, r.px2, r.py2);
1587 // pad->RangeAxis(r.ux1, r.uy1, r.ux2, r.uy2);
1588
1589 pad->fX1 = r.px1;
1590 pad->fX2 = r.px2;
1591 pad->fY1 = r.py1;
1592 pad->fY2 = r.py2;
1593
1594 pad->fUxmin = r.ux1;
1595 pad->fUxmax = r.ux2;
1596 pad->fUymin = r.uy1;
1597 pad->fUymax = r.uy2;
1598 }
1599
1600 // pad->SetPad(r.mleft, r.mbottom, 1-r.mright, 1-r.mtop);
1601
1602 pad->fAbsXlowNDC = r.xlow;
1603 pad->fAbsYlowNDC = r.ylow;
1604 pad->fAbsWNDC = r.xup - r.xlow;
1605 pad->fAbsHNDC = r.yup - r.ylow;
1606
1607 if (pad == Canvas()) {
1608 pad->fXlowNDC = r.xlow;
1609 pad->fYlowNDC = r.ylow;
1610 pad->fXUpNDC = r.xup;
1611 pad->fYUpNDC = r.yup;
1612 pad->fWNDC = r.xup - r.xlow;
1613 pad->fHNDC = r.yup - r.ylow;
1614 } else {
1615 auto mother = pad->GetMother();
1616 if (mother->GetAbsWNDC() > 0. && mother->GetAbsHNDC() > 0.) {
1617 pad->fXlowNDC = (r.xlow - mother->GetAbsXlowNDC()) / mother->GetAbsWNDC();
1618 pad->fYlowNDC = (r.ylow - mother->GetAbsYlowNDC()) / mother->GetAbsHNDC();
1619 pad->fXUpNDC = (r.xup - mother->GetAbsXlowNDC()) / mother->GetAbsWNDC();
1620 pad->fYUpNDC = (r.yup - mother->GetAbsYlowNDC()) / mother->GetAbsHNDC();
1621 pad->fWNDC = (r.xup - r.xlow) / mother->GetAbsWNDC();
1622 pad->fHNDC = (r.yup - r.ylow) / mother->GetAbsHNDC();
1623 }
1624 }
1625
1626 if (r.phi || r.theta) {
1627 pad->fPhi = r.phi;
1628 pad->fTheta = r.theta;
1629 }
1630
1631 // copy of code from TPad::ResizePad()
1632
1633 Double_t pxlow = r.xlow * r.cw;
1634 Double_t pylow = (1-r.ylow) * r.ch;
1635 Double_t pxrange = (r.xup - r.xlow) * r.cw;
1636 Double_t pyrange = -1*(r.yup - r.ylow) * r.ch;
1637
1638 Double_t rounding = 0.00005;
1639 Double_t xrange = r.px2 - r.px1;
1640 Double_t yrange = r.py2 - r.py1;
1641
1642 if ((xrange != 0.) && (pxrange != 0)) {
1643 // Linear X axis
1644 pad->fXtoAbsPixelk = rounding + pxlow - pxrange*r.px1/xrange; //origin at left
1645 pad->fXtoPixelk = rounding + -pxrange*r.px1/xrange;
1646 pad->fXtoPixel = pxrange/xrange;
1647 pad->fAbsPixeltoXk = r.px1 - pxlow*xrange/pxrange;
1648 pad->fPixeltoXk = r.px1;
1649 pad->fPixeltoX = xrange/pxrange;
1650 }
1651
1652 if ((yrange != 0.) && (pyrange != 0.)) {
1653 // Linear Y axis
1654 pad->fYtoAbsPixelk = rounding + pylow - pyrange*r.py1/yrange; //origin at top
1655 pad->fYtoPixelk = rounding + -pyrange - pyrange*r.py1/yrange;
1656 pad->fYtoPixel = pyrange/yrange;
1657 pad->fAbsPixeltoYk = r.py1 - pylow*yrange/pyrange;
1658 pad->fPixeltoYk = r.py1;
1659 pad->fPixeltoY = yrange/pyrange;
1660 }
1661
1663
1664 TObjLink *objlnk = nullptr;
1665
1666 TH1 *hist = static_cast<TH1 *>(FindPrimitive(sid_pad_histogram, 1, pad, &objlnk));
1667
1668 if (hist) {
1669
1670 TObject *hist_holder = objlnk ? objlnk->GetObject() : nullptr;
1671 if (hist_holder == hist)
1672 hist_holder = nullptr;
1673
1674 Bool_t no_entries = hist->GetEntries();
1675 Bool_t is_stack = hist_holder && (hist_holder->IsA() == THStack::Class());
1676
1677 Double_t hmin = 0., hmax = 0.;
1678
1679 if (r.zx1 == r.zx2)
1680 hist->GetXaxis()->SetRange(0, 0);
1681 else
1682 hist->GetXaxis()->SetRangeUser(r.zx1, r.zx2);
1683
1684 if (hist->GetDimension() == 1) {
1685 hmin = r.zy1;
1686 hmax = r.zy2;
1687 if ((hmin == hmax) && !no_entries && !is_stack) {
1688 // if there are no zooming on Y and histogram has no entries, hmin/hmax should be set to full range
1689 hmin = pad->fLogy ? TMath::Power(pad->fLogy < 2 ? 10 : pad->fLogy, r.uy1) : r.uy1;
1690 hmax = pad->fLogy ? TMath::Power(pad->fLogy < 2 ? 10 : pad->fLogy, r.uy2) : r.uy2;
1691 }
1692 } else if (r.zy1 == r.zy2) {
1693 hist->GetYaxis()->SetRange(0, 0);
1694 } else {
1695 hist->GetYaxis()->SetRangeUser(r.zy1, r.zy2);
1696 }
1697
1698 if (hist->GetDimension() == 2) {
1699 hmin = r.zz1;
1700 hmax = r.zz2;
1701 if ((hmin == hmax) && !no_entries) {
1702 // z scale is not transformed
1703 hmin = r.uz1;
1704 hmax = r.uz2;
1705 }
1706 } else if (hist->GetDimension() == 3) {
1707 if (r.zz1 == r.zz2) {
1708 hist->GetZaxis()->SetRange(0, 0);
1709 } else {
1710 hist->GetZaxis()->SetRangeUser(r.zz1, r.zz2);
1711 }
1712 }
1713
1714 if (hmin == hmax)
1715 hmin = hmax = -1111;
1716
1717 if (is_stack) {
1718 hist->SetMinimum(hmin);
1719 hist->SetMaximum(hmax);
1720 hist->SetBit(TH1::kIsZoomed, hmin != hmax);
1721 } else if (!hist_holder || (hist_holder->IsA() == TScatter::Class())) {
1722 hist->SetMinimum(hmin);
1723 hist->SetMaximum(hmax);
1724 } else {
1725 auto SetMember = [hist_holder](const char *name, Double_t value) {
1726 auto offset = hist_holder->IsA()->GetDataMemberOffset(name);
1727 if (offset > 0)
1728 *((Double_t *)((char*) hist_holder + offset)) = value;
1729 else
1730 ::Error("SetMember", "Cannot find %s data member in %s", name, hist_holder->ClassName());
1731 };
1732
1733 // directly set min/max in classes like THStack, TGraph, TMultiGraph
1734 SetMember("fMinimum", hmin);
1735 SetMember("fMaximum", hmax);
1736 }
1737
1738 TIter next(hist->GetListOfFunctions());
1739 while (auto fobj = next())
1740 if (!hist_exec && fobj->InheritsFrom(TExec::Class())) {
1741 hist_exec = (TExec *) fobj;
1742 need_update = kTRUE;
1743 }
1744 }
1745
1746 std::map<std::string, int> idmap;
1747
1748 for (auto &item : r.primitives) {
1749 auto iter = idmap.find(item.snapid);
1750 int idcnt = 1;
1751 if (iter == idmap.end())
1752 idmap[item.snapid] = 1;
1753 else
1754 idcnt = ++iter->second;
1755
1756 ProcessObjectOptions(item, pad, idcnt);
1757 }
1758
1759 // without special objects no need for explicit update of the pad
1760 if (fPadsStatus[pad]._has_specials) {
1761 pad->Modified(kTRUE);
1762 need_update = kTRUE;
1763 }
1764
1765 if (process_execs && (gPad == pad))
1766 pad_with_execs = pad;
1767 }
1768
1769 ProcessExecs(pad_with_execs, hist_exec);
1770
1771 if (fUpdatedSignal) fUpdatedSignal(); // invoke signal
1772
1773 return need_update;
1774}
1775
1776//////////////////////////////////////////////////////////////////////////////////////////////////
1777/// Process TExec objects in the pad
1778
1780{
1781 auto execs = pad ? pad->GetListOfExecs() : nullptr;
1782
1783 if ((!execs || !execs->GetSize()) && !extra)
1784 return;
1785
1786 auto saveps = gVirtualPS;
1787 TWebPS ps;
1788 gVirtualPS = &ps;
1789
1790 auto savex = gVirtualX;
1791 TVirtualX x;
1792 gVirtualX = &x;
1793
1794 TIter next(execs);
1795 while (auto obj = next()) {
1796 auto exec = dynamic_cast<TExec *>(obj);
1797 if (exec)
1798 exec->Exec();
1799 }
1800
1801 if (extra)
1802 extra->Exec();
1803
1804 gVirtualPS = saveps;
1805 gVirtualX = savex;
1806}
1807
1808//////////////////////////////////////////////////////////////////////////////////////////
1809/// Execute one or several methods for selected object
1810/// String can be separated by ";;" to let execute several methods at once
1811void TWebCanvas::ProcessLinesForObject(TObject *obj, const std::string &lines)
1812{
1813 std::string buf = lines;
1814
1815 Int_t indx = 0;
1816
1817 while (obj && !buf.empty()) {
1818 std::string sub = buf;
1819 auto pos = buf.find(";;");
1820 if (pos == std::string::npos) {
1821 sub = buf;
1822 buf.clear();
1823 } else {
1824 sub = buf.substr(0,pos);
1825 buf = buf.substr(pos+2);
1826 }
1827 if (sub.empty()) continue;
1828
1829 std::stringstream exec;
1830 exec << "((" << obj->ClassName() << " *) " << std::hex << std::showbase << (size_t)obj << ")->" << sub << ";";
1831 if (indx < 3 || gDebug > 0)
1832 Info("ProcessLinesForObject", "Obj %s Execute %s", obj->GetName(), exec.str().c_str());
1833 gROOT->ProcessLine(exec.str().c_str());
1834 indx++;
1835 }
1836}
1837
1838//////////////////////////////////////////////////////////////////////////////////////////
1839/// Handle data from web browser
1840/// Returns kFALSE if message was not processed
1841
1842Bool_t TWebCanvas::ProcessData(unsigned connid, const std::string &arg)
1843{
1844 if (arg.empty())
1845 return kTRUE;
1846
1847 // try to identify connection for given WS request
1848 unsigned indx = 0; // first connection is batch and excluded
1849 while(++indx < fWebConn.size()) {
1850 if (fWebConn[indx].fConnId == connid)
1851 break;
1852 }
1853 if (indx >= fWebConn.size())
1854 return kTRUE;
1855
1856 Bool_t is_main_connection = indx == 1; // first connection allow to make changes
1857
1858 struct FlagGuard {
1859 Bool_t &flag;
1860 FlagGuard(Bool_t &_flag) : flag(_flag) { flag = true; }
1861 ~FlagGuard() { flag = false; }
1862 };
1863
1864 FlagGuard guard(fProcessingData);
1865
1866 const char *cdata = arg.c_str();
1867
1868 if (arg == "KEEPALIVE") {
1869 // do nothing
1870
1871 } else if (arg == "QUIT") {
1872
1873 // use window manager to correctly terminate http server
1874 fWindow->TerminateROOT();
1875
1876 } else if (arg.compare(0, 7, "READY6:") == 0) {
1877
1878 // this is reply on drawing of ROOT6 snapshot
1879 // it confirms when drawing of specific canvas version is completed
1880
1881 cdata += 7;
1882
1883 const char *separ = strchr(cdata, ':');
1884 if (!separ) {
1885 fWebConn[indx].fDrawVersion = std::stoll(cdata);
1886 } else {
1887 fWebConn[indx].fDrawVersion = std::stoll(std::string(cdata, separ - cdata));
1888 if (is_main_connection && !IsReadOnly())
1889 if (DecodePadOptions(separ+1, false))
1891 }
1892
1893 } else if (arg == "RELOAD") {
1894
1895 // trigger reload of canvas data
1896 fWebConn[indx].reset();
1897
1898 } else if (arg.compare(0, 5, "SAVE:") == 0) {
1899
1900 // save image produced by the client side - like png or svg
1901 const char *img = cdata + 5;
1902
1903 const char *separ = strchr(img, ':');
1904 if (separ) {
1905 TString filename(img, separ - img);
1906 img = separ + 1;
1907
1908 std::ofstream ofs(filename.Data());
1909
1910 int filelen = -1;
1911
1912 if (filename.Index(".svg") != kNPOS) {
1913 // ofs << "<?xml version=\"1.0\" standalone=\"no\"?>";
1914 ofs << img;
1915 filelen = strlen(img);
1916 } else {
1917 TString binary = TBase64::Decode(img);
1918 ofs.write(binary.Data(), binary.Length());
1919 filelen = binary.Length();
1920 }
1921 ofs.close();
1922
1923 Info("ProcessData", "File %s size %d has been created", filename.Data(), filelen);
1924 }
1925
1926 } else if (arg.compare(0, 8, "PRODUCE:") == 0) {
1927
1928 // create ROOT, PDF, ... files using native ROOT functionality
1929 Canvas()->Print(arg.c_str() + 8);
1930
1931 } else if (arg.compare(0, 8, "GETMENU:") == 0) {
1932
1933 TObject *obj = FindPrimitive(arg.substr(8));
1934 if (!obj)
1935 obj = Canvas();
1936
1937 TWebMenuItems items(arg.c_str() + 8);
1938 items.PopulateObjectMenu(obj, obj->IsA());
1939 std::string buf = "MENU:";
1940 buf.append(TBufferJSON::ToJSON(&items, 103).Data());
1941
1942 AddSendQueue(connid, buf);
1943
1944 } else if (arg.compare(0, 11, "STATUSBITS:") == 0) {
1945
1946 if (is_main_connection) {
1947 AssignStatusBits(std::stoul(arg.substr(11)));
1948 if (fUpdatedSignal) fUpdatedSignal(); // invoke signal
1949 }
1950
1951 } else if (arg.compare(0, 10, "HIGHLIGHT:") == 0) {
1952
1953 if (is_main_connection) {
1954 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(10));
1955 if (!arr || (arr->size() != 4)) {
1956 Error("ProcessData", "Wrong arguments count %d in highlight message", (int)(arr ? arr->size() : -1));
1957 } else {
1958 auto pad = dynamic_cast<TVirtualPad *>(FindPrimitive(arr->at(0)));
1959 auto obj = FindPrimitive(arr->at(1));
1960 int argx = std::stoi(arr->at(2));
1961 int argy = std::stoi(arr->at(3));
1962 if (pad && obj) {
1963 Canvas()->Highlighted(pad, obj, argx, argy);
1965 }
1966 }
1967 }
1968
1969 } else if (ROOT::RWebWindow::IsFileDialogMessage(arg)) {
1970
1972
1973 } else if (IsReadOnly() || !is_main_connection) {
1974
1975 ///////////////////////////////////////////////////////////////////////////////////////
1976 // all following messages are not allowed in readonly mode or for secondary connections
1977
1978 return kFALSE;
1979
1980 } else if (arg.compare(0, 9, "OPTIONS6:") == 0) {
1981
1982 if (DecodePadOptions(arg.substr(9), true))
1984
1985 } else if (arg.compare(0, 9, "FITPANEL:") == 0) {
1986
1987 std::string chid = arg.substr(9);
1988
1989 TH1 *hist = nullptr;
1990 TIter iter(Canvas()->GetListOfPrimitives());
1991 while (auto obj = iter()) {
1992 hist = dynamic_cast<TH1 *>(obj);
1993 if (hist) break;
1994 }
1995
1996 TString showcmd;
1997 if (chid == "standalone")
1998 showcmd = "panel->Show()";
1999 else
2000 showcmd = TString::Format("auto wptr = (std::shared_ptr<ROOT::RWebWindow>*)0x%zx;"
2001 "panel->Show({*wptr, %u, %s})",
2002 (size_t) &fWindow, connid, chid.c_str());
2003
2004 auto cmd = TString::Format("auto panel = std::make_shared<ROOT::Experimental::RFitPanel>(\"FitPanel\");"
2005 "panel->AssignCanvas(\"%s\");"
2006 "panel->AssignHistogram((TH1 *)0x%zx);"
2007 "%s;panel->ClearOnClose(panel);",
2008 Canvas()->GetName(), (size_t) hist, showcmd.Data());
2009 gROOT->ProcessLine(cmd.Data());
2010 } else if (arg == "START_BROWSER"s) {
2011
2012 gROOT->ProcessLine("new TBrowser;");
2013
2014 } else if (arg.compare(0, 6, "EVENT:") == 0) {
2015 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(6));
2016 if (!arr || (arr->size() != 5)) {
2017 Error("ProcessData", "Wrong arguments count %d in event message", (int)(arr ? arr->size() : -1));
2018 } else {
2019 auto pad = dynamic_cast<TPad *>(FindPrimitive(arr->at(0)));
2020 std::string kind = arr->at(1);
2021 int event = -1;
2022 if (kind == "move"s) event = kMouseMotion;
2023 int argx = std::stoi(arr->at(2));
2024 int argy = std::stoi(arr->at(3));
2025 auto selobj = FindPrimitive(arr->at(4));
2026
2027 if ((event >= 0) && pad && (pad == gPad)) {
2028 Canvas()->fEvent = event;
2029 Canvas()->fEventX = argx;
2030 Canvas()->fEventY = argy;
2031
2032 Canvas()->fSelected = selobj;
2033
2034 ProcessExecs(pad);
2035 }
2036 }
2037
2038 } else if (arg.compare(0, 8, "PRIMIT6:") == 0) {
2039
2040 auto opt = TBufferJSON::FromJSON<TWebObjectOptions>(arg.c_str() + 8);
2041
2042 if (opt) {
2043 TPad *modpad = ProcessObjectOptions(*opt, nullptr);
2044
2045 // indicate that pad was modified
2046 if (modpad)
2047 modpad->Modified();
2048 }
2049
2050 } else if (arg.compare(0, 11, "PADCLICKED:") == 0) {
2051
2052 auto click = TBufferJSON::FromJSON<TWebPadClick>(arg.c_str() + 11);
2053
2054 if (click) {
2055
2056 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(click->padid));
2057
2058 if (pad && pad->InheritsFrom(TButton::Class())) {
2059 auto btn = (TButton *) pad;
2060 const char *mthd = btn->GetMethod();
2061 if (mthd && *mthd) {
2062 auto cpad = gROOT->GetSelectedPad();
2063 if (cpad)
2064 cpad->cd();
2065 gROOT->ProcessLine(mthd);
2066 }
2067 return kTRUE;
2068 }
2069
2070 if (pad && (pad != gPad)) {
2071 gPad = pad;
2075 }
2076
2077 if (!click->objid.empty()) {
2078 auto selobj = FindPrimitive(click->objid);
2079 Canvas()->SetClickSelected(selobj);
2080 Canvas()->fSelected = selobj;
2081 if (pad && selobj && fObjSelectSignal)
2082 fObjSelectSignal(pad, selobj);
2083 }
2084
2085 if ((click->x >= 0) && (click->y >= 0)) {
2086 Canvas()->fEvent = click->dbl ? kButton1Double : kButton1Up;
2087 Canvas()->fEventX = click->x;
2088 Canvas()->fEventY = click->y;
2089 if (click->dbl && fPadDblClickedSignal)
2090 fPadDblClickedSignal(pad, click->x, click->y);
2091 else if (!click->dbl && fPadClickedSignal)
2092 fPadClickedSignal(pad, click->x, click->y);
2093 }
2094
2095 ProcessExecs(pad);
2096 }
2097
2098 } else if (arg.compare(0, 8, "OBJEXEC:") == 0) {
2099
2100 auto buf = arg.substr(8);
2101 auto pos = buf.find(":");
2102
2103 if ((pos > 0) && (pos != std::string::npos)) {
2104 auto sid = buf.substr(0, pos);
2105 buf.erase(0, pos + 1);
2106
2107 TObjLink *lnk = nullptr;
2108 TPad *objpad = nullptr;
2109
2110 TObject *obj = FindPrimitive(sid, 1, nullptr, &lnk, &objpad);
2111
2112 if (obj && !buf.empty()) {
2113
2114 ProcessLinesForObject(obj, buf);
2115
2116 if (objpad)
2117 objpad->Modified();
2118 else
2119 Canvas()->Modified();
2120
2122 }
2123 }
2124
2125 } else if (arg.compare(0, 12, "EXECANDSEND:") == 0) {
2126
2127 // execute method and send data, used by drawing projections
2128
2129 std::string buf = arg.substr(12);
2130 std::string reply;
2131 TObject *obj = nullptr;
2132
2133 auto pos = buf.find(":");
2134
2135 if (pos > 0) {
2136 // only first client can execute commands
2137 reply = buf.substr(0, pos);
2138 buf.erase(0, pos + 1);
2139 pos = buf.find(":");
2140 if (pos > 0) {
2141 auto sid = buf.substr(0, pos);
2142 buf.erase(0, pos + 1);
2143 obj = FindPrimitive(sid);
2144 }
2145 }
2146
2147 if (obj && !buf.empty() && !reply.empty()) {
2148 std::stringstream exec;
2149 exec << "((" << obj->ClassName() << " *) " << std::hex << std::showbase << (size_t)obj
2150 << ")->" << buf << ";";
2151 if (gDebug > 0)
2152 Info("ProcessData", "Obj %s Exec %s", obj->GetName(), exec.str().c_str());
2153
2154 auto res = gROOT->ProcessLine(exec.str().c_str());
2155 TObject *resobj = (TObject *)(res);
2156 if (resobj) {
2157 std::string send = reply;
2158 send.append(":");
2159 send.append(TBufferJSON::ToJSON(resobj, 23).Data());
2160 AddSendQueue(connid, send);
2161 if (reply[0] == 'D')
2162 delete resobj; // delete object if first symbol in reply is D
2163 }
2164 }
2165
2166 } else if (arg.compare(0, 6, "CLEAR:") == 0) {
2167 std::string snapid = arg.substr(6);
2168
2169 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(snapid));
2170
2171 if (pad) {
2172 pad->Clear();
2173 pad->Modified();
2175 } else {
2176 Error("ProcessData", "Not found pad with id %s to clear\n", snapid.c_str());
2177 }
2178 } else if (arg.compare(0, 7, "DIVIDE:") == 0) {
2179 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
2180 if (arr && arr->size() == 2) {
2181 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(arr->at(0)));
2182 int nn = 0, n1 = 0, n2 = 0;
2183
2184 std::string divide = arr->at(1);
2185 auto p = divide.find('x');
2186 if (p == std::string::npos)
2187 p = divide.find('X');
2188
2189 if (p != std::string::npos) {
2190 n1 = std::stoi(divide.substr(0,p));
2191 n2 = std::stoi(divide.substr(p+1));
2192 } else {
2193 nn = std::stoi(divide);
2194 }
2195
2196 if (pad && ((nn > 1) || (n1*n2 > 1))) {
2197 pad->Clear();
2198 pad->Modified();
2199 if (nn > 1)
2200 pad->DivideSquare(nn);
2201 else
2202 pad->Divide(n1, n2);
2203 pad->cd(1);
2205 }
2206 }
2207
2208 } else if (arg.compare(0, 8, "DRAWOPT:") == 0) {
2209
2210 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(8));
2211 if (arr && arr->size() == 2) {
2212 TObjLink *objlnk = nullptr;
2213 FindPrimitive(arr->at(0), 1, nullptr, &objlnk);
2214 if (objlnk)
2215 objlnk->SetOption(arr->at(1).c_str());
2216 }
2217
2218 } else if (arg.compare(0, 8, "RESIZED:") == 0) {
2219
2220 auto arr = TBufferJSON::FromJSON<std::vector<int>>(arg.substr(8));
2221 if (arr && arr->size() == 7) {
2222 // set members directly to avoid redrawing of the client again
2223 Canvas()->fCw = arr->at(4);
2224 Canvas()->fCh = arr->at(5);
2225 fFixedSize = arr->at(6) > 0;
2226 arr->resize(4);
2227 SetWindowGeometry(*arr);
2228 }
2229
2230 } else if (arg.compare(0, 7, "POPOBJ:") == 0) {
2231
2232 auto arr = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
2233 if (arr && arr->size() == 2) {
2234 TPad *pad = dynamic_cast<TPad *>(FindPrimitive(arr->at(0)));
2235 TObject *obj = FindPrimitive(arr->at(1), 0, pad);
2236 if (pad && obj && (obj != pad->GetListOfPrimitives()->Last())) {
2237 TIter next(pad->GetListOfPrimitives());
2238 while (auto o = next())
2239 if (obj == o) {
2240 TString opt = next.GetOption();
2241 pad->Remove(obj, kFALSE);
2242 pad->Add(obj, opt.Data());
2243 break;
2244 }
2245 }
2246 }
2247
2248 } else if (arg.compare(0, 8, "SHOWURL:") == 0) {
2249
2251 args.SetUrl(arg.substr(8));
2252 args.SetStandalone(false);
2253
2255
2256 } else if (arg == "INTERRUPT"s) {
2257
2258 gROOT->SetInterrupt();
2259
2260 } else {
2261
2262 // unknown message, probably should be processed by other implementation
2263 return kFALSE;
2264
2265 }
2266
2267 return kTRUE;
2268}
2269
2270//////////////////////////////////////////////////////////////////////////////////////////
2271/// Returns true if any pad in the canvas were modified
2272/// Reset modified flags, increment canvas version (if inc_version is true)
2273
2275{
2276 if (fPadsStatus.find(pad) == fPadsStatus.end())
2277 fPadsStatus[pad] = PadStatus{0, true, true};
2278
2279 auto &entry = fPadsStatus[pad];
2280 entry._detected = true;
2281 if (pad->IsModified()) {
2282 pad->Modified(kFALSE);
2283 entry._modified = true;
2284 }
2285
2286 TIter iter(pad->GetListOfPrimitives());
2287 while (auto obj = iter()) {
2288 if (obj->InheritsFrom(TPad::Class()))
2289 CheckPadModified(static_cast<TPad *>(obj));
2290 }
2291}
2292
2293//////////////////////////////////////////////////////////////////////////////////////////
2294/// Check if any pad on the canvas was modified
2295/// If yes, increment version of correspondent pad
2296/// Returns true when canvas really modified
2297
2299{
2300 // clear temporary flags
2301 for (auto &entry : fPadsStatus) {
2302 entry.second._detected = false;
2303 entry.second._modified = force_modified;
2304 }
2305
2306 // scan sub-pads
2308
2309 // remove no-longer existing pads
2310 bool is_any_modified = false;
2311 for(auto iter = fPadsStatus.begin(); iter != fPadsStatus.end(); ) {
2312 if (iter->second._modified)
2313 is_any_modified = true;
2314 if (!iter->second._detected)
2315 fPadsStatus.erase(iter++);
2316 else
2317 iter++;
2318 }
2319
2320 // if any pad modified, increment canvas version and set version of modified pads
2321 if (is_any_modified) {
2322 fCanvVersion++;
2323 for(auto &entry : fPadsStatus)
2324 if (entry.second._modified)
2325 entry.second.fVersion = fCanvVersion;
2326 }
2327
2328 return is_any_modified;
2329}
2330
2331//////////////////////////////////////////////////////////////////////////////////////////
2332/// Set window geometry as array with coordinates and dimensions
2333
2334void TWebCanvas::SetWindowGeometry(const std::vector<int> &arr)
2335{
2336 fWindowGeometry = arr;
2337 Canvas()->fWindowTopX = arr[0];
2338 Canvas()->fWindowTopY = arr[1];
2339 Canvas()->fWindowWidth = arr[2];
2340 Canvas()->fWindowHeight = arr[3];
2341 if (fWindow) {
2342 // position is unreliable and cannot be used
2343 // fWindow->SetPosition(arr[0], arr[1]);
2344 fWindow->SetGeometry(arr[2], arr[3]);
2345 }
2346}
2347
2348//////////////////////////////////////////////////////////////////////////////////////////
2349/// Returns window geometry including borders and menus
2350
2352{
2353 if (fWindowGeometry.size() == 4) {
2354 x = fWindowGeometry[0];
2355 y = fWindowGeometry[1];
2356 w = fWindowGeometry[2];
2357 h = fWindowGeometry[3];
2358 } else {
2359 x = Canvas()->fWindowTopX;
2360 y = Canvas()->fWindowTopY;
2361 w = Canvas()->fWindowWidth;
2362 h = Canvas()->fWindowHeight;
2363 }
2364 return 0;
2365}
2366
2367
2368//////////////////////////////////////////////////////////////////////////////////////////
2369/// if canvas or any subpad was modified,
2370/// scan all primitives in the TCanvas and subpads and convert them into
2371/// the structure which will be delivered to JSROOT client
2372
2374{
2376
2378
2379 if (!fProcessingData && !IsAsyncMode() && !async)
2381
2382 return kTRUE;
2383}
2384
2385//////////////////////////////////////////////////////////////////////////////////////////
2386/// Increment canvas version and force sending data to client - do not wait for reply
2387
2389{
2390 CheckCanvasModified(true);
2391
2392 if (!fWindow) {
2393 TCanvasWebSnapshot holder(IsReadOnly(), false, true); // readonly, set ids, batchmode
2394
2395 holder.SetScripts(ProcessCustomScripts(true));
2396
2397 CreatePadSnapshot(holder, Canvas(), 0, nullptr);
2398 } else {
2400 }
2401}
2402
2403//////////////////////////////////////////////////////////////////////////////////////////
2404/// Wait when specified version of canvas was painted and confirmed by browser
2405
2407{
2408 if (!fWindow)
2409 return kTRUE;
2410
2411 // simple polling loop until specified version delivered to the clients
2412 // first 500 loops done without sleep, then with 1ms sleep and last 500 with 100 ms sleep
2413
2414 long cnt = 0, cnt_limit = GetLongerPolling() ? 5500 : 1500;
2415
2416 if (gDebug > 2)
2417 Info("WaitWhenCanvasPainted", "version %ld", (long)ver);
2418
2419 while (cnt++ < cnt_limit) {
2420
2421 if (!fWindow->HasConnection(0, false)) {
2422 if (gDebug > 2)
2423 Info("WaitWhenCanvasPainted", "no connections - abort");
2424 return kFALSE; // wait ~1 min if no new connection established
2425 }
2426
2427 if ((fWebConn.size() > 1) && (fWebConn[1].fDrawVersion >= ver)) {
2428 if (gDebug > 2)
2429 Info("WaitWhenCanvasPainted", "ver %ld got painted", (long)ver);
2430 return kTRUE;
2431 }
2432
2434 if (cnt > 500)
2435 gSystem->Sleep((cnt < cnt_limit - 500) ? 1 : 100); // increase sleep interval when do very often
2436 }
2437
2438 if (gDebug > 2)
2439 Info("WaitWhenCanvasPainted", "timeout");
2440
2441 return kFALSE;
2442}
2443
2444//////////////////////////////////////////////////////////////////////////////////////////
2445/// Create JSON painting output for given pad
2446/// Produce JSON can be used for offline drawing with JSROOT
2447
2448TString TWebCanvas::CreatePadJSON(TPad *pad, Int_t json_compression, Bool_t batchmode)
2449{
2450 TString res;
2451 if (!pad)
2452 return res;
2453
2454 TCanvas *c = dynamic_cast<TCanvas *>(pad);
2455 if (c) {
2456 res = CreateCanvasJSON(c, json_compression, batchmode);
2457 } else {
2458 auto imp = std::make_unique<TWebCanvas>(pad->GetCanvas(), pad->GetName(), 0, 0, pad->GetWw(), pad->GetWh(), kTRUE);
2459
2460 TPadWebSnapshot holder(true, false, batchmode); // readonly, no ids, batchmode
2461
2462 imp->CreatePadSnapshot(holder, pad, 0, [&res, json_compression](TPadWebSnapshot *snap) {
2463 res = TBufferJSON::ToJSON(snap, json_compression);
2464 });
2465 }
2466
2467 return res;
2468}
2469
2470//////////////////////////////////////////////////////////////////////////////////////////
2471/// Create JSON painting output for given canvas
2472/// Produce JSON can be used for offline drawing with JSROOT
2473
2475{
2476 TString res;
2477
2478 if (!c)
2479 return res;
2480
2481 {
2482 auto imp = std::make_unique<TWebCanvas>(c, c->GetName(), 0, 0, c->GetWw(), c->GetWh(), kTRUE);
2483
2484 TCanvasWebSnapshot holder(true, false, batchmode); // readonly, no ids, batchmode
2485
2486 holder.SetScripts(ProcessCustomScripts(batchmode));
2487
2488 imp->CreatePadSnapshot(holder, c, 0, [&res, json_compression](TPadWebSnapshot *snap) {
2489 res = TBufferJSON::ToJSON(snap, json_compression);
2490 });
2491 }
2492
2493 return res;
2494}
2495
2496//////////////////////////////////////////////////////////////////////////////////////////
2497/// Create JSON painting output for given canvas and store into the file
2498/// See TBufferJSON::ExportToFile() method for more details about option
2499/// If option string starts with symbol 'b', JSON for batch mode will be generated (default)
2500/// If option string starts with symbol 'i', JSON for interactive mode will be generated
2501
2503{
2504 Int_t res = 0;
2505 Bool_t batchmode = kTRUE;
2506 if (option) {
2507 if (*option == 'b') {
2508 batchmode = kTRUE;
2509 ++option;
2510 } else if (*option == 'i') {
2511 batchmode = kFALSE;
2512 ++option;
2513 }
2514 }
2515
2516 if (!c)
2517 return res;
2518
2519 {
2520 auto imp = std::make_unique<TWebCanvas>(c, c->GetName(), 0, 0, c->GetWw(), c->GetWh(), kTRUE);
2521
2522 TCanvasWebSnapshot holder(true, false, batchmode); // readonly, no ids, batchmode
2523
2524 holder.SetScripts(ProcessCustomScripts(batchmode));
2525
2526 imp->CreatePadSnapshot(holder, c, 0, [&res, filename, option](TPadWebSnapshot *snap) {
2528 });
2529 }
2530
2531 return res;
2532}
2533
2534//////////////////////////////////////////////////////////////////////////////////////////
2535/// Create image using batch (headless) capability of Chrome or Firefox browsers
2536/// Supported png, jpeg, svg, pdf formats
2537
2538bool TWebCanvas::ProduceImage(TPad *pad, const char *fileName, Int_t width, Int_t height)
2539{
2540 if (!pad)
2541 return false;
2542
2544 if (!json.Length())
2545 return false;
2546
2547 TString fname = fileName;
2548 const char *endings[4] = {"(", "[", "]", ")"};
2549 const char *suffix = nullptr;
2550 for (int n = 0; (n < 4) && !suffix; ++n) {
2551 if (fname.EndsWith(endings[n])) {
2552 fname.Resize(fname.Length() - 1);
2553 suffix = endings[n];
2554 }
2555 }
2556
2557 Bool_t append_batch = kTRUE, flush_batch = kTRUE;
2558
2559 std::string fmt = ROOT::RWebDisplayHandle::GetImageFormat(fname.Data());
2560 if (fmt.empty())
2561 return false;
2562
2563 if (suffix) {
2564 if (fmt != "pdf")
2565 return false;
2566 switch (*suffix) {
2567 case '(': gBatchMultiPdf = fname.Data(); flush_batch = kFALSE; break;
2568 case '[': gBatchMultiPdf = fname.Data(); append_batch = kFALSE; flush_batch = kFALSE; break;
2569 case ']': gBatchMultiPdf.clear(); append_batch = kFALSE; break;
2570 case ')': gBatchMultiPdf.clear(); fname.Append("+"); break;
2571 }
2572 } else if (fmt == "pdf") {
2573 if (!gBatchMultiPdf.empty()) {
2574 if (gBatchMultiPdf.compare(fileName) == 0) {
2575 append_batch = kTRUE;
2576 flush_batch = kFALSE;
2577 suffix = "+"; // to let append to the batch
2578 if ((gBatchFiles.size() > 0) && (gBatchFiles.back().compare(0, fname.Length(), fname.Data()) == 0))
2579 fname.Append("+"); // .pdf+ means appending image to previous
2580 } else {
2581 ::Error("TWebCanvas::ProduceImage", "Cannot change PDF name when multi-page PDF active");
2582 return false;
2583 }
2584 }
2585 } else if (!gBatchMultiPdf.empty()) {
2586 ::Error("TWebCanvas::ProduceImage", "Cannot produce other images when multi-page PDF active");
2587 return false;
2588 }
2589
2590 if (!width && !height) {
2591 if ((pad->GetCanvas() == pad) || (pad->IsA() == TCanvas::Class())) {
2592 width = pad->GetWw();
2593 height = pad->GetWh();
2594 } else {
2595 width = (Int_t) (pad->GetAbsWNDC() * pad->GetCanvas()->GetWw());
2596 height = (Int_t) (pad->GetAbsHNDC() * pad->GetCanvas()->GetWh());
2597 }
2598 }
2599
2600 if (!suffix && (!gBatchImageMode || (fmt == "s.pdf") || (fmt == "json") || (fmt == "s.png")))
2602
2603 if (append_batch) {
2604 gBatchFiles.emplace_back(fname.Data());
2605 gBatchJsons.emplace_back(json);
2606 gBatchWidths.emplace_back(width);
2607 gBatchHeights.emplace_back(height);
2608 }
2609
2610 if (!flush_batch || (gBatchJsons.size() < gBatchImageMode))
2611 return true;
2612
2613 return FlushBatchImages();
2614}
2615
2616//////////////////////////////////////////////////////////////////////////////////////////
2617/// Create images for several pads using batch (headless) capability of Chrome or Firefox browsers
2618/// Supported png, jpeg, svg, pdf, webp formats
2619/// One can include %d qualifier which will be replaced by image index using printf functionality.
2620/// If for pdf format %d qualifier not specified, all images will be stored in single PDF file.
2621/// For all other formats %d qualifier will be add before extension automatically
2622
2623bool TWebCanvas::ProduceImages(std::vector<TPad *> pads, const char *filename, Int_t width, Int_t height)
2624{
2625 if (pads.empty())
2626 return false;
2627
2628 std::vector<std::string> jsons;
2629 std::vector<Int_t> widths, heights;
2630
2631 for (unsigned n = 0; n < pads.size(); ++n) {
2632 auto pad = pads[n];
2633
2635 if (!json.Length())
2636 continue;
2637
2638 Int_t w = width, h = height;
2639
2640 if (!w && !h) {
2641 if ((pad->GetCanvas() == pad) || (pad->IsA() == TCanvas::Class())) {
2642 w = pad->GetWw();
2643 h = pad->GetWh();
2644 } else {
2645 w = (Int_t) (pad->GetAbsWNDC() * pad->GetCanvas()->GetWw());
2646 h = (Int_t) (pad->GetAbsHNDC() * pad->GetCanvas()->GetWh());
2647 }
2648 }
2649
2650 jsons.emplace_back(json.Data());
2651 widths.emplace_back(w);
2652 heights.emplace_back(h);
2653 }
2654
2656
2657 if (!gBatchImageMode || (fmt == "json") || (fmt == "s.png") || (fmt == "s.pdf"))
2658 return ROOT::RWebDisplayHandle::ProduceImages(filename, jsons, widths, heights);
2659
2660 auto fnames = ROOT::RWebDisplayHandle::ProduceImagesNames(filename, jsons.size());
2661
2662 gBatchFiles.insert(gBatchFiles.end(), fnames.begin(), fnames.end());
2663 gBatchJsons.insert(gBatchJsons.end(), jsons.begin(), jsons.end());
2664 gBatchWidths.insert(gBatchWidths.end(), widths.begin(), widths.end());
2665 gBatchHeights.insert(gBatchHeights.end(), heights.begin(), heights.end());
2666 if (gBatchJsons.size() < gBatchImageMode)
2667 return true;
2668
2669 return FlushBatchImages();
2670}
2671
2672
2673//////////////////////////////////////////////////////////////////////////////////////////
2674/// Process data for single primitive
2675/// Returns object pad if object was modified
2676
2678{
2679 TObjLink *lnk = nullptr;
2680 TPad *objpad = nullptr;
2681 TObject *obj = FindPrimitive(item.snapid, idcnt, pad, &lnk, &objpad);
2682
2683 if (item.fcust.compare("exec") == 0) {
2684 auto pos = item.opt.find("(");
2685 if (obj && (pos != std::string::npos) && obj->IsA()->GetMethodAllAny(item.opt.substr(0,pos).c_str())) {
2686 std::stringstream exec;
2687 exec << "((" << obj->ClassName() << " *) " << std::hex << std::showbase
2688 << (size_t)obj << ")->" << item.opt << ";";
2689 if (gDebug > 0)
2690 Info("ProcessObjectOptions", "Obj %s Execute %s", obj->GetName(), exec.str().c_str());
2691 gROOT->ProcessLine(exec.str().c_str());
2692 } else {
2693 Error("ProcessObjectOptions", "Fail to execute %s for object %p %s", item.opt.c_str(), obj, obj ? obj->ClassName() : "---");
2694 objpad = nullptr;
2695 }
2696 return objpad;
2697 }
2698
2699 bool modified = false;
2700
2701 if (obj && lnk) {
2702 auto pos = item.opt.find(";;use_"); // special coding of extra options
2703 if (pos != std::string::npos) item.opt.resize(pos);
2704
2705 if (gDebug > 0)
2706 Info("ProcessObjectOptions", "Set draw option %s for object %s %s", item.opt.c_str(),
2707 obj->ClassName(), obj->GetName());
2708
2709 lnk->SetOption(item.opt.c_str());
2710
2711 modified = true;
2712 }
2713
2714 if (item.fcust.compare(0,10,"auto_exec:") == 0) {
2715 ProcessLinesForObject(obj, item.fcust.substr(10));
2716 } else if (item.fcust.compare("frame") == 0) {
2717 if (obj && obj->InheritsFrom(TFrame::Class())) {
2718 TFrame *frame = static_cast<TFrame *>(obj);
2719 if (item.fopt.size() >= 4) {
2720 frame->SetX1(item.fopt[0]);
2721 frame->SetY1(item.fopt[1]);
2722 frame->SetX2(item.fopt[2]);
2723 frame->SetY2(item.fopt[3]);
2724 modified = true;
2725 }
2726 }
2727 } else if (item.fcust.compare(0,4,"pave") == 0) {
2728 if (obj && obj->InheritsFrom(TPave::Class())) {
2729 TPave *pave = static_cast<TPave *>(obj);
2730 if ((item.fopt.size() >= 4) && objpad) {
2731 TVirtualPad::TContext ctxt(objpad, kFALSE);
2732
2733 // first time need to overcome init problem
2734 pave->ConvertNDCtoPad();
2735
2736 pave->SetX1NDC(item.fopt[0]);
2737 pave->SetY1NDC(item.fopt[1]);
2738 pave->SetX2NDC(item.fopt[2]);
2739 pave->SetY2NDC(item.fopt[3]);
2740 modified = true;
2741
2742 pave->ConvertNDCtoPad();
2743 }
2744 if ((item.fcust.length() > 4) && pave->InheritsFrom(TPaveStats::Class())) {
2745 // add text lines for statsbox
2746 auto stats = static_cast<TPaveStats *>(pave);
2747 stats->Clear();
2748 size_t pos_start = 6, pos_end;
2749 while ((pos_end = item.fcust.find(";;", pos_start)) != std::string::npos) {
2750 stats->AddText(item.fcust.substr(pos_start, pos_end - pos_start).c_str());
2751 pos_start = pos_end + 2;
2752 }
2753 stats->AddText(item.fcust.substr(pos_start).c_str());
2754 }
2755 }
2756 } else if (item.fcust.compare(0,9,"func_fail") == 0) {
2757 if (fTF1UseSave <= 0) {
2758 fTF1UseSave = 1;
2759 modified = true;
2760 }
2761 }
2762
2763 return modified ? objpad : nullptr;
2764}
2765
2766//////////////////////////////////////////////////////////////////////////////////////////////////
2767/// Search of object with given id in list of primitives
2768/// One could specify pad where search could be start
2769/// Also if object is in list of primitives, one could ask for entry link for such object,
2770/// This can allow to change draw option
2771
2772TObject *TWebCanvas::FindPrimitive(const std::string &sid, int idcnt, TPad *pad, TObjLink **objlnk, TPad **objpad)
2773{
2774 if (sid.empty() || (sid == "0"s))
2775 return nullptr;
2776
2777 if (!pad)
2778 pad = Canvas();
2779
2780 std::string subelement;
2781 long unsigned id = 0;
2782 bool search_hist = (sid == sid_pad_histogram);
2783 if (!search_hist) {
2784 auto separ = sid.find("#");
2785
2786 if (separ == std::string::npos) {
2787 id = std::stoul(sid);
2788 } else {
2789 subelement = sid.substr(separ + 1);
2790 id = std::stoul(sid.substr(0, separ));
2791 }
2792 if (TString::Hash(&pad, sizeof(pad)) == id)
2793 return pad;
2794 }
2795
2796 for (auto lnk = pad->GetListOfPrimitives()->FirstLink(); lnk != nullptr; lnk = lnk->Next()) {
2797 TObject *obj = lnk->GetObject();
2798 if (!obj) continue;
2799
2800 if (!search_hist && (TString::Hash(&obj, sizeof(obj)) != id)) {
2801 if (obj->InheritsFrom(TPad::Class())) {
2802 obj = FindPrimitive(sid, idcnt, (TPad *)obj, objlnk, objpad);
2803 if (objpad && !*objpad)
2804 *objpad = pad;
2805 if (obj)
2806 return obj;
2807 }
2808 continue;
2809 }
2810
2811 // one may require to access n-th object
2812 if (!search_hist && --idcnt > 0)
2813 continue;
2814
2815 if (objpad)
2816 *objpad = pad;
2817
2818 if (objlnk)
2819 *objlnk = lnk;
2820
2821 if (search_hist)
2822 subelement = "hist";
2823
2824 auto getHistogram = [](TObject *container) -> TH1* {
2825 auto offset = container->IsA()->GetDataMemberOffset("fHistogram");
2826 if (offset > 0)
2827 return *((TH1 **)((char *)container + offset));
2828 ::Error("getHistogram", "Cannot access fHistogram data member in %s", container->ClassName());
2829 return nullptr;
2830 };
2831
2832 while(!subelement.empty() && obj) {
2833 // do not return link if sub-selement is searched - except for histogram
2834 if (!search_hist && objlnk)
2835 *objlnk = nullptr;
2836
2837 std::string kind = subelement;
2838 auto separ = kind.find("#");
2839 if (separ == std::string::npos) {
2840 subelement.clear();
2841 } else {
2842 kind.resize(separ);
2843 subelement = subelement.substr(separ + 1);
2844 }
2845
2846 TH1 *h1 = obj->InheritsFrom(TH1::Class()) ? static_cast<TH1 *>(obj) : nullptr;
2847 TGraph *gr = obj->InheritsFrom(TGraph::Class()) ? static_cast<TGraph *>(obj) : nullptr;
2848 TGraph2D *gr2d = obj->InheritsFrom(TGraph2D::Class()) ? static_cast<TGraph2D *>(obj) : nullptr;
2849 TScatter *scatter = obj->InheritsFrom(TScatter::Class()) ? static_cast<TScatter *>(obj) : nullptr;
2850 TMultiGraph *mg = obj->InheritsFrom(TMultiGraph::Class()) ? static_cast<TMultiGraph *>(obj) : nullptr;
2851 THStack *hs = obj->InheritsFrom(THStack::Class()) ? static_cast<THStack *>(obj) : nullptr;
2852 TF1 *f1 = obj->InheritsFrom(TF1::Class()) ? static_cast<TF1 *>(obj) : nullptr;
2853
2854 if (kind.compare("hist") == 0) {
2855 if (h1)
2856 obj = h1;
2857 else if (gr)
2858 obj = getHistogram(gr);
2859 else if (mg)
2860 obj = getHistogram(mg);
2861 else if (hs && (hs->GetNhists() > 0))
2862 obj = getHistogram(hs);
2863 else if (scatter)
2864 obj = getHistogram(scatter);
2865 else if (f1)
2866 obj = getHistogram(f1);
2867 else if (gr2d)
2868 obj = getHistogram(gr2d);
2869 else
2870 obj = nullptr;
2871 } else if (kind.compare("x") == 0) {
2872 obj = h1 ? h1->GetXaxis() : nullptr;
2873 } else if (kind.compare("y") == 0) {
2874 obj = h1 ? h1->GetYaxis() : nullptr;
2875 } else if (kind.compare("z") == 0) {
2876 obj = h1 ? h1->GetZaxis() : nullptr;
2877 } else if ((kind.compare(0,5,"func_") == 0) || (kind.compare(0,5,"indx_") == 0)) {
2878 auto funcname = kind.substr(5);
2879 TList *col = nullptr;
2880 if (h1)
2881 col = h1->GetListOfFunctions();
2882 else if (gr)
2883 col = gr->GetListOfFunctions();
2884 else if (mg)
2885 col = mg->GetListOfFunctions();
2886 else if (scatter->GetGraph())
2887 col = scatter->GetGraph()->GetListOfFunctions();
2888 if (!col)
2889 obj = nullptr;
2890 else if (kind.compare(0,5,"func_") == 0)
2891 obj = col->FindObject(funcname.c_str());
2892 else
2893 obj = col->At(std::stoi(funcname));
2894 } else if (kind.compare("polargram") == 0) {
2895 auto polar = dynamic_cast<TGraphPolar *>(obj);
2896 obj = polar ? polar->GetPolargram() : nullptr;
2897 } else if (kind.compare(0,7,"graphs_") == 0) {
2898 TList *graphs = mg ? mg->GetListOfGraphs() : nullptr;
2899 obj = graphs ? graphs->At(std::stoi(kind.substr(7))) : nullptr;
2900 } else if (kind.compare(0,6,"hists_") == 0) {
2901 TList *hists = hs ? hs->GetHists() : nullptr;
2902 obj = hists ? hists->At(std::stoi(kind.substr(6))) : nullptr;
2903 } else if (kind.compare(0,6,"stack_") == 0) {
2904 auto stack = hs ? hs->GetStack() : nullptr;
2905 obj = stack ? stack->At(std::stoi(kind.substr(6))) : nullptr;
2906 } else if (kind.compare(0,7,"member_") == 0) {
2907 auto member = kind.substr(7);
2908 auto offset = obj->IsA() ? obj->IsA()->GetDataMemberOffset(member.c_str()) : 0;
2909 obj = (offset > 0) ? *((TObject **)((char *) obj + offset)) : nullptr;
2910 } else {
2911 obj = nullptr;
2912 }
2913 }
2914
2915 if (!search_hist || obj)
2916 return obj;
2917 }
2918
2919 return nullptr;
2920}
2921
2922//////////////////////////////////////////////////////////////////////////////////////////////////
2923/// Static method to create TWebCanvas instance
2924/// Used by plugin manager
2925
2927{
2928 Bool_t readonly = gEnv->GetValue("WebGui.FullCanvas", (Int_t) 1) == 0;
2929
2930 auto imp = new TWebCanvas(c, name, x, y, width, height, readonly);
2931
2932 c->fWindowTopX = x;
2933 c->fWindowTopY = y;
2934 c->fWindowWidth = width;
2935 c->fWindowHeight = height;
2936 if (!gROOT->IsBatch() && (height > 25))
2937 height -= 25;
2938 c->fCw = width;
2939 c->fCh = height;
2940
2941 return imp;
2942}
2943
@ 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
unsigned int UInt_t
Definition RtypesCore.h:46
short Font_t
Definition RtypesCore.h:81
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:117
long long Long64_t
Definition RtypesCore.h:69
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
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 data
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 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
Option_t Option_t TPoint TPoint const char text
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:436
@ kReadPermission
Definition TSystem.h:45
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
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
void SetStandalone(bool on=true)
Set standalone mode for running browser, default on When disabled, normal browser window (or just tab...
RWebDisplayArgs & SetWidgetKind(const std::string &kind)
set widget kind
RWebDisplayArgs & SetSize(int w, int h)
set preferable web window width and height
RWebDisplayArgs & SetUrl(const std::string &url)
set window url
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 std::vector< std::string > ProduceImagesNames(const std::string &fname, unsigned nfiles=1)
Produce vector of file names for specified file pattern Depending from supported file forma.
static std::string GetImageFormat(const std::string &fname)
Detect image format There is special handling of ".screenshot.pdf" and ".screenshot....
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::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args)
Create web display.
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,...
static std::map< std::string, std::string > GetServerLocations()
Returns server locations as <std::string, std::string> Key is location name (with slash at the end) a...
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:38
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:40
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:44
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:46
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:48
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:49
Double_t GetXmax() const
Definition TAxis.h:142
Double_t GetXmin() const
Definition TAxis.h:141
Int_t GetNbins() const
Definition TAxis.h:127
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:1084
virtual void SetRange(Int_t first=0, Int_t last=0)
Set the viewing range for the axis using bin numbers.
Definition TAxis.cxx:1053
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:2616
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:1612
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:3546
Int_t Size() const
Return size of object of this class.
Definition TClass.cxx:5785
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4943
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4453
void SetName(const char *name)
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
The color creation and management class.
Definition TColor.h:22
static const TArrayI & GetPalette()
Static function returning the current active palette.
Definition TColor.cxx:1520
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:1541
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:1584
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:755
Bool_t HasSave() const
Return true if function has data in fSave buffer.
Definition TF1.h:466
static TClass * Class()
Define a Frame.
Definition TFrame.h:19
static TClass * Class()
The axis painter class.
Definition TGaxis.h:26
static TClass * Class()
TF1 * GetFunction() const
Definition TGaxis.h:79
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.
TList * GetListOfFunctions() const
Definition TGraph2D.h:112
To draw a polar graph.
Definition TGraphPolar.h:23
static TClass * Class()
TGraphPolargram * GetPolargram()
Definition TGraphPolar.h:39
TGraphPolargram * CreatePolargram(const char *opt)
Create polargram object for given draw options.
To draw polar axis.
static TClass * Class()
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:126
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:1430
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:682
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:8957
TAxis * GetZaxis()
Definition TH1.h:338
static TClass * Class()
virtual Int_t GetDimension() const
Definition TH1.h:295
@ kNoTitle
Don't draw the histogram title.
Definition TH1.h:180
@ kIsZoomed
Bit set when zooming on Y axis.
Definition TH1.h:179
TAxis * GetXaxis()
Definition TH1.h:336
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:416
TAxis * GetYaxis()
Definition TH1.h:337
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:417
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:9242
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4418
TList * GetListOfFunctions() const
Definition TH1.h:256
void SetName(const char *name) override
Change the name of this histogram.
Definition TH1.cxx:8980
virtual Int_t BufferEmpty(Int_t action=0)
Fill histogram with all entries in the buffer.
Definition TH1.cxx:1401
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:607
Int_t GetNhists() const
Return the number of histograms in the stack.
Definition THStack.cxx:598
static TClass * Class()
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
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:81
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:102
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:456
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:241
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:225
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Definition TObject.cxx:420
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:798
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:542
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:500
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:624
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:239
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:1341
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:6195
TVirtualViewer3D * GetViewer3D(Option_t *type="") override
Create/obtain handle to 3D viewer.
Definition TPad.cxx:7151
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:335
Double_t fPhi
phi angle to view as lego/surface
Definition TPad.h:80
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:246
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:1249
Double_t fXtoPixel
xpixel = fXtoPixelk + fXtoPixel*xworld
Definition TPad.h:43
Bool_t GetGridx() const override
Definition TPad.h:235
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
TObject * Remove(TObject *obj, Bool_t modified=kTRUE) override
Remove object from list of primitives When.
Definition TPad.cxx:5407
UInt_t GetWw() const override
Get Ww.
Definition TPad.cxx:2837
Double_t fX1
X of lower X coordinate.
Definition TPad.h:36
TList * GetListOfPrimitives() const override
Definition TPad.h:245
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:274
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:722
Int_t GetTickx() const override
Definition TPad.h:238
Double_t fUymax
Maximum value on the Y axis.
Definition TPad.h:77
TVirtualPad * GetMother() const override
Definition TPad.h:259
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7388
TView * GetView() const override
Definition TPad.h:254
TClass * IsA() const override
Definition TPad.h:419
Bool_t GetGridy() const override
Definition TPad.h:236
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:6031
Int_t fLogx
(=0 if X linear scale, =1 if log scale)
Definition TPad.h:91
Double_t GetAbsWNDC() const override
Definition TPad.h:222
UInt_t GetWh() const override
Get Wh.
Definition TPad.cxx:2829
TCanvas * GetCanvas() const override
Definition TPad.h:262
void Add(TObject *obj, Option_t *opt="", Bool_t modified=kTRUE) override
Add an object to list of primitives with speicified draw option When.
Definition TPad.cxx:418
Double_t fTheta
theta angle to view as lego/surface
Definition TPad.h:79
Double_t fXUpNDC
Definition TPad.h:64
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:693
void Print(const char *filename="") const override
This method is equivalent to SaveAs("filename"). See TPad::SaveAs for details.
Definition TPad.cxx:4798
TFrame * GetFrame() override
Get frame.
Definition TPad.cxx:2955
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:223
void SetTicks(Int_t valuex=1, Int_t valuey=1) override
Definition TPad.h:355
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
TVirtualPad * GetSelectedPad() const override
Get selected pad.
Definition TPad.cxx:2811
const char * GetName() const override
Returns name of object.
Definition TPad.h:260
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.
void SetOptStat(Int_t stat=1)
Set the stat option.
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:53
void SetOptFit(Int_t fit=1)
Set the fit option.
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()
Option_t * GetOption() const override
Definition TPave.h:57
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:165
static TClass * Class()
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
Definition TString.cxx:2244
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition TString.cxx:1163
const char * Data() const
Definition TString.h:376
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Definition TString.cxx:1152
@ kBoth
Definition TString.h:276
@ 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:245
Color_t GetStatTextColor() const
Definition TStyle.h:258
Int_t GetOptTitle() const
Definition TStyle.h:246
Float_t GetStatFontSize() const
Definition TStyle.h:261
Float_t GetStatX() const
Definition TStyle.h:264
Float_t GetPadRightMargin() const
Definition TStyle.h:214
Style_t GetTitleFont(Option_t *axis="X") const
Return title font.
Definition TStyle.cxx:1216
Float_t GetStatY() const
Definition TStyle.h:265
Color_t GetTitleFillColor() const
Definition TStyle.h:271
Style_t GetTitleStyle() const
Definition TStyle.h:273
Color_t GetStatColor() const
Definition TStyle.h:257
Float_t GetStatH() const
Definition TStyle.h:267
static TClass * Class()
Width_t GetTitleBorderSize() const
Definition TStyle.h:275
Width_t GetStatBorderSize() const
Definition TStyle.h:259
Color_t GetTitleTextColor() const
Definition TStyle.h:272
Style_t GetStatStyle() const
Definition TStyle.h:262
Float_t GetStatW() const
Definition TStyle.h:266
const char * GetFitFormat() const
Definition TStyle.h:199
const char * GetStatFormat() const
Definition TStyle.h:263
Int_t GetOptFit() const
Definition TStyle.h:244
Style_t GetStatFont() const
Definition TStyle.h:260
Float_t GetTitleFontSize() const
Definition TStyle.h:274
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
Base class for several text objects.
Definition TText.h:22
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
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
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.
static 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:106
Int_t fTF1UseSave
! use save buffer for TF1/TF2, 0:off, 1:prefer, 2:force
Definition TWebCanvas.h:107
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:105
virtual Bool_t IsReadOnly() const
Definition TWebCanvas.h:194
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...
static 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:115
PadClickedSignal_t fPadClickedSignal
! signal emitted when simple mouse click performed on the pad
Definition TWebCanvas.h:113
void SetLongerPolling(Bool_t on)
Definition TWebCanvas.h:250
UInt_t fStyleHash
! last hash of gStyle
Definition TWebCanvas.h:104
virtual Bool_t CanCreateObject(const std::string &)
Definition TWebCanvas.h:170
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:97
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.
static UInt_t gBatchImageMode
! configured batch size
Definition TWebCanvas.h:122
static std::string gCustomScripts
! custom JavaScript code or URL on JavaScript files to load before start drawing
Definition TWebCanvas.h:119
Bool_t IsAsyncMode() const
Definition TWebCanvas.h:254
UInt_t CalculateColorsHash()
Calculate hash function for all colors and palette.
void SetWindowGeometry(const std::vector< int > &arr)
Set window geometry as array with coordinates and dimensions.
Bool_t HasStatusBar() const override
Returns kTRUE if web canvas has status bar.
static std::vector< std::string > gCustomClasses
! list of custom classes, which can be delivered as is to client
Definition TWebCanvas.h:120
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:112
Bool_t GetLongerPolling() const
Definition TWebCanvas.h:251
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:96
Bool_t fProcessingData
! flag used to prevent blocking methods when process data is invoked
Definition TWebCanvas.h:101
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
static std::vector< std::string > gBatchJsons
! converted jsons batch job
Definition TWebCanvas.h:125
Long64_t fCanvVersion
! actual canvas version, changed with every new Modified() call
Definition TWebCanvas.h:91
std::vector< int > fWindowGeometry
! last received window geometry
Definition TWebCanvas.h:108
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.
std::map< TObject *, bool > fUsedObjs
! map of used objects during streaming
Definition TWebCanvas.h:94
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:103
static std::string gBatchMultiPdf
! name of current multi-page pdf file
Definition TWebCanvas.h:123
static void BatchImageMode(UInt_t n=100)
Configure batch image mode for web graphics.
std::vector< std::unique_ptr< ROOT::RWebDisplayHandle > > fHelpHandles
! array of handles for help widgets
Definition TWebCanvas.h:117
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:111
Int_t fJsonComp
! compression factor for messages send to the client
Definition TWebCanvas.h:98
static std::vector< int > gBatchWidths
! batch job widths
Definition TWebCanvas.h:126
~TWebCanvas() override
Destructor.
static std::string ProcessCustomScripts(bool batch)
For batch mode special handling of scripts are required Headless browser not able to load modules fro...
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 supported 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 std::vector< int > gBatchHeights
! batch job heights
Definition TWebCanvas.h:127
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() ...
static const std::string & GetCustomScripts()
Returns configured custom script.
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 std::vector< std::string > gBatchFiles
! file names for batch job
Definition TWebCanvas.h:124
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:95
PadClickedSignal_t fPadDblClickedSignal
! signal emitted when simple mouse click performed on the pad
Definition TWebCanvas.h:114
void ProcessExecs(TPad *pad, TExec *extra=nullptr)
Process TExec objects in the pad.
static bool FlushBatchImages()
Flush batch images.
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:245
void SetWindowSize(UInt_t w, UInt_t h) override
Set window size of web canvas.
static bool IsCustomClass(const TClass *cl)
Checks if class belongs to custom.
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:109
Int_t GetStyleDelivery() const
Definition TWebCanvas.h:242
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 SetObjectName(const std::string &objname)
void AddOper(const std::string &oper)
Add next custom operator to painting Operations are separated by semicolons Following operations are ...
void SetClassName(const std::string &classname)
@ 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.
std::ostream & Info()
Definition hadd.cxx:163
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:725
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)