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
6/// performed
7///
8/// \macro_image (rcanvas_js)
9/// \macro_code
10///
11/// \date 2021-07-05
12/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
13/// is welcome!
14/// \author Sergey Linev <s.linev@gsi.de>
15
16/*************************************************************************
17 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
18 * All rights reserved. *
19 * *
20 * For the licensing terms see $ROOTSYS/LICENSE. *
21 * For the list of contributors see $ROOTSYS/README/CREDITS. *
22 *************************************************************************/
23
25#include <ROOT/RCanvas.hxx>
26#include "TGraph.h"
27
28#include <iostream>
29
30using namespace ROOT::Experimental;
31
32void rcanvas_update()
33{
34 static constexpr int npoints = 10;
35 double x[npoints] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
36 double y[npoints] = {.1, .2, .3, .2, .1, .2, .3, .2, .1, .2};
37 auto gr = new TGraph(npoints, x, y);
38
39 auto canvas = RCanvas::Create("Demo of RCanvas update");
40
41 canvas->Draw<TObjectDrawable>(gr, "AL");
42
43 // new window in web browser should popup and async update will be triggered
44 canvas->Show();
45
46 // synchronous, wait until drawing is really finished
47 canvas->Update(false,
48 [](bool res) { std::cout << "First sync update done = " << (res ? "true" : "false") << std::endl; });
49
50 // modify TGraph making different form
51 gr->SetPoint(1, 1., .3);
52 gr->SetPoint(3, 3., .1);
53 gr->SetPoint(5, 5., .3);
54 gr->SetPoint(7, 7., .1);
55 gr->SetPoint(9, 9., .3);
56
57 // invalidate canvas and force repainting with next Update()
58 canvas->Modified();
59
60 // call Update again, return before actual drawing will be performed by the browser
61 canvas->Update(
62 true, [](bool res) { std::cout << "Second async update done = " << (res ? "true" : "false") << std::endl; });
63
64 std::cout << "This message appear normally before second async update" << std::endl;
65}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:2291
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
TGraphErrors * gr
Definition legend1.C:25