Logo ROOT   6.14/05
Reference Guide
draw_v6.cxx
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_v7
3 ///
4 /// \macro_code
5 ///
6 /// \date 2017-06-02
7 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
8 /// is welcome!
9 /// \author Axel Naumann <axel@cern.ch>
10 
11 /*************************************************************************
12  * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
13  * All rights reserved. *
14  * *
15  * For the licensing terms see $ROOTSYS/LICENSE. *
16  * For the list of contributors see $ROOTSYS/README/CREDITS. *
17  *************************************************************************/
18 
19 R__LOAD_LIBRARY(libGpad);
20 
21 #include <ROOT/TObjectDrawable.hxx>
22 #include <ROOT/TCanvas.hxx>
23 #include <TGraph.h>
24 
25 #include <iostream>
26 
27 // Show how to display v6 objects in a v7 TCanvas.
28 
29 void draw_v6()
30 {
31  using namespace ROOT;
32 
33  static constexpr int npoints = 4;
34  double x[npoints] = {0., 1., 2., 3.};
35  double y[npoints] = {.1, .2, .3, .4};
36  auto gr = std::make_shared<TGraph>(npoints, x, y);
37  auto canvas = Experimental::TCanvas::Create("v7 TCanvas showing a v6 TGraph");
38  canvas->Draw(gr, "AL");
39 
40  canvas->Show(); // new window should popup and async update will be triggered
41 
42  // canvas->Show("opera"); // one could specify program name which should show canvas (like chromium or firefox)
43  // canvas->Show("/usr/bin/chromium --app=$url &"); // one could use $url parameter, which replaced with canvas URL
44 
45  // synchronous, wait until painting is finished
46  canvas->Update(false,
47  [](bool res) { std::cout << "First Update done = " << (res ? "true" : "false") << std::endl; });
48 
49  // canvas->Modified(); // when uncommented, invalidate canvas and force repainting with next Update()
50 
51  // call Update again, should return immediately if canvas was not modified
52  canvas->Update(false,
53  [](bool res) { std::cout << "Second Update done = " << (res ? "true" : "false") << std::endl; });
54 
55  // request to create PNG file in asynchronous mode and specify lambda function as callback
56  // when request processed by the client, callback invoked with result value
57  canvas->SaveAs("draw.png", true,
58  [](bool res) { std::cout << "Producing PNG done res = " << (res ? "true" : "false") << std::endl; });
59 
60  // this function executed in synchronous mode (async = false is default),
61  // mean previous file saving will be completed as well at this point
62  canvas->SaveAs("draw.svg"); // synchronous
63 
64  // hide canvas after 10 seconds - close all connections and close all opened windows
65  // gSystem->Sleep(10000);
66  // canvas->Hide();
67 }
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Double_t x[n]
Definition: legend1.C:17
#define R__LOAD_LIBRARY(LIBRARY)
Definition: Rtypes.h:467
TGraphErrors * gr
Definition: legend1.C:25
Double_t y[n]
Definition: legend1.C:17
static std::shared_ptr< TCanvas > Create(const std::string &title)
Definition: TCanvas.cxx:74