Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
inframe.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_webcanv
3/// \notebook -js
4/// Drawing primitives inside and outside of the frame.
5///
6/// In normal ROOT graphics all objects drawn on the pad and therefore
7/// requires special treatment to be able drawn only inside frame borders.
8/// In web-based graphics objects automatically clipped by frame border - if drawn inside frame.
9/// Macro demonstrates usage of "frame" draw option for TLine, TBox, TMarker and TLatex classes.
10/// If user interactively change zooming range "in-frame" objects automatically clipped.
11///
12/// Functionality available only in web-based graphics
13///
14/// \macro_image (tcanvas_js)
15/// \macro_code
16///
17/// \author Sergey Linev
18
19void inframe()
20{
21 auto c1 = new TCanvas("c1", "Drawing inside frame", 1200, 800);
22
23 if (!gROOT->IsBatch() && !c1->IsWeb())
24 ::Warning("inframe.cxx", "macro may not work without enabling web-based canvas");
25
26 c1->DrawFrame(0., 0., 10., 10., "Usage of \"frame\" draw options");
27
28
29 auto latex = new TLatex(3., 8., "Text in the frame");
30 latex->SetTextColor(kCyan);
31 latex->SetTextSize(0.08);
32 latex->SetTextAlign(22);
33 c1->Add(latex, "frame");
34
35 // draw line and label on the pad
36 auto l1 = new TLine(-0.5, 5, 10.5, 5);
37 l1->SetLineColor(kBlue);
38 c1->Add(l1);
39
40 auto tl1 = new TLatex(0.5, 5, "line outside");
41 tl1->SetTextColor(kBlue);
42 tl1->SetTextAlign(13);
43 c1->Add(tl1);
44
45 // draw line and label in the frame
46 auto l2 = new TLine(-0.5, 5.2, 10.5, 5.2);
47 l2->SetLineColor(kGreen);
48 c1->Add(l2, "frame");
49
50 auto tl2 = new TLatex(0.5, 5.3, "line inside");
51 tl2->SetTextColor(kGreen);
52 tl2->SetTextAlign(11);
53 c1->Add(tl2, "frame");
54
55 // draw box and label on the pad
56 auto b1 = new TBox(-0.5, 1, 4, 3);
57 b1->SetFillColor(kBlue);
58 c1->Add(b1);
59
60 auto tb1 = new TLatex(0.5, 3.1, "box outside");
61 tb1->SetTextColor(kBlue);
62 tb1->SetTextAlign(11);
63 c1->Add(tb1);
64
65 // draw box and label in the frame
66 auto b2 = new TBox(6, 1, 10.5, 3);
67 b2->SetFillColor(kGreen);
68 c1->Add(b2, "frame");
69
70 auto b2_dash = new TBox(6, 1, 10.5, 3);
71 b2_dash->SetFillStyle(0);
72 b2_dash->SetLineColor(kRed);
73 b2_dash->SetLineStyle(kDotted);
74 b2_dash->SetLineWidth(3);
75 c1->Add(b2_dash); // show clipped
76
77 auto tb2 = new TLatex(6.5, 3.1, "box inside");
78 tb2->SetTextColor(kGreen);
79 tb2->SetTextAlign(11);
80 c1->Add(tb2, "frame");
81
82 // draw marker and label on the pad
83 auto m1 = new TMarker(9.5, 7., 29);
84 m1->SetMarkerColor(kBlue);
85 m1->SetMarkerSize(3);
86 c1->Add(m1);
87
88 auto tm1 = new TLatex(9.3, 7., "outside");
89 tm1->SetTextColor(kBlue);
90 tm1->SetTextAlign(32);
91 c1->Add(tm1);
92
93 // draw marker and label in the frame
94 auto m2 = new TMarker(9.5, 8., 34);
95 m2->SetMarkerColor(kGreen);
96 m2->SetMarkerSize(3);
97 c1->Add(m2, "frame");
98
99 auto tm2 = new TLatex(9.3, 8., "inside");
100 tm2->SetTextColor(kGreen);
101 tm2->SetTextAlign(32);
102 c1->Add(tm2, "frame");
103
104}
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kDotted
Definition TAttLine.h:48
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
#define gROOT
Definition TROOT.h:406
Create a Box.
Definition TBox.h:22
The Canvas class.
Definition TCanvas.h:23
To draw Mathematical Formula.
Definition TLatex.h:18
Use the TLine constructor to create a simple line.
Definition TLine.h:22
Manages Markers.
Definition TMarker.h:22
return c1
Definition legend1.C:41