Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rcanvas_update.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This macro shows how ROOT RCanvas::Update method is working.
5/// One can do sync and/or async depending how important is that graphics is updated before next action will be performed
6///
7/// \macro_image (rcanvas_js)
8/// \macro_code
9///
10/// \date 2021-07-05
11/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
12/// is welcome!
13/// \author Sergey Linev <s.linev@gsi.de>
14
15/*************************************************************************
16 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
17 * All rights reserved. *
18 * *
19 * For the licensing terms see $ROOTSYS/LICENSE. *
20 * For the list of contributors see $ROOTSYS/README/CREDITS. *
21 *************************************************************************/
22
24#include <ROOT/RCanvas.hxx>
25#include "TGraph.h"
26
27#include <iostream>
28
29using namespace ROOT::Experimental;
30
31void rcanvas_update()
32{
33 static constexpr int npoints = 10;
34 double x[npoints] = { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. };
35 double y[npoints] = { .1, .2, .3, .2, .1, .2, .3, .2, .1, .2 };
36 auto gr = new TGraph(npoints, x, y);
37
38 auto canvas = RCanvas::Create("Demo of RCanvas update");
39
40 canvas->Draw<TObjectDrawable>(gr, "AL");
41
42 // new window in web browser should popup and async update will be triggered
43 canvas->Show();
44
45 // synchronous, wait until drawing is really finished
46 canvas->Update(false, [](bool res) { std::cout << "First sync update done = " << (res ? "true" : "false") << std::endl; });
47
48 // modify TGraph making different form
49 gr->SetPoint(1, 1., .3);
50 gr->SetPoint(3, 3., .1);
51 gr->SetPoint(5, 5., .3);
52 gr->SetPoint(7, 7., .1);
53 gr->SetPoint(9, 9., .3);
54
55 // invalidate canvas and force repainting with next Update()
56 canvas->Modified();
57
58 // call Update again, return before actual drawing will be performed by the browser
59 canvas->Update(true, [](bool res) { std::cout << "Second async update done = " << (res ? "true" : "false") << std::endl; });
60
61 std::cout << "This message appear normally before second async update" << std::endl;
62}
Provides v7 drawing facilities for TObject types (TGraph, TH1, TH2, etc).
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Definition TGraph.cxx:2347
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25