Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.12/07
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 // Show how to display v6 objects in a v7 TCanvas.
26 
27 void draw_v6()
28 {
29  using namespace ROOT;
30 
31  static constexpr int npoints = 4;
32  double x[npoints] = {0., 1., 2., 3.};
33  double y[npoints] = {.1, .2, .3, .4};
34  auto gr = std::make_shared<TGraph>(npoints, x, y);
35  auto canvas = Experimental::TCanvas::Create("v7 TCanvas showing a v6 TGraph");
36  canvas->Draw(gr);
37 
38  canvas->Show(); // new window should popup and async update will be triggered
39 
40  // canvas->Show("opera"); // one could specify program name which should show canvas (like chromium or firefox)
41  // canvas->Show("/usr/bin/chromium --app=$url &"); // one could use $url parameter, which replaced with canvas URL
42 
43  // synchronous, wait until painting is finished
44  canvas->Update(false,
45  [](bool res) { std::cout << "First Update done = " << (res ? "true" : "false") << std::endl; });
46 
47  // canvas->Modified(); // when uncommented, invalidate canvas and force repainting with next Update()
48 
49  // call Update again, should return immediately if canvas was not modified
50  canvas->Update(false,
51  [](bool res) { std::cout << "Second Update done = " << (res ? "true" : "false") << std::endl; });
52 
53  // request to create PNG file in asynchronous mode and specify lambda function as callback
54  // when request processed by the client, callback invoked with result value
55  canvas->SaveAs("draw.png", true,
56  [](bool res) { std::cout << "Producing PNG done res = " << (res ? "true" : "false") << std::endl; });
57 
58  // this function executed in synchronous mode (async = false is default),
59  // mean previous file saving will be completed as well at this point
60  canvas->SaveAs("draw.svg"); // synchronous
61 
62  // hide canvas after 10 seconds - close all connections and close all opened windows
63  // gSystem->Sleep(10000);
64  // canvas->Hide();
65 }
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:470
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:63