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 auto latex = new TLatex(3., 8., "Text in the frame");
29 latex->SetTextColor(kCyan);
30 latex->SetTextSize(0.08);
31 latex->SetTextAlign(22);
32 c1->Add(latex, "frame");
33
34 // draw line and label on the pad
35 auto l1 = new TLine(-0.5, 5, 10.5, 5);
36 l1->SetLineColor(kBlue);
37 c1->Add(l1);
38
39 auto tl1 = new TLatex(0.5, 5, "line outside");
40 tl1->SetTextColor(kBlue);
41 tl1->SetTextAlign(13);
42 c1->Add(tl1);
43
44 // draw line and label in the frame
45 auto l2 = new TLine(-0.5, 5.2, 10.5, 5.2);
46 l2->SetLineColor(kGreen);
47 c1->Add(l2, "frame");
48
49 auto tl2 = new TLatex(0.5, 5.3, "line inside");
50 tl2->SetTextColor(kGreen);
51 tl2->SetTextAlign(11);
52 c1->Add(tl2, "frame");
53
54 // draw box and label on the pad
55 auto b1 = new TBox(-0.5, 1, 4, 3);
56 b1->SetFillColor(kBlue);
57 c1->Add(b1);
58
59 auto tb1 = new TLatex(0.5, 3.1, "box outside");
60 tb1->SetTextColor(kBlue);
61 tb1->SetTextAlign(11);
62 c1->Add(tb1);
63
64 // draw box and label in the frame
65 auto b2 = new TBox(6, 1, 10.5, 3);
66 b2->SetFillColor(kGreen);
67 c1->Add(b2, "frame");
68
69 auto b2_dash = new TBox(6, 1, 10.5, 3);
70 b2_dash->SetFillStyle(0);
71 b2_dash->SetLineColor(kRed);
72 b2_dash->SetLineStyle(kDotted);
73 b2_dash->SetLineWidth(3);
74 c1->Add(b2_dash); // show clipped
75
76 auto tb2 = new TLatex(6.5, 3.1, "box inside");
77 tb2->SetTextColor(kGreen);
78 tb2->SetTextAlign(11);
79 c1->Add(tb2, "frame");
80
81 // draw marker and label on the pad
82 auto m1 = new TMarker(9.5, 7., 29);
83 m1->SetMarkerColor(kBlue);
84 m1->SetMarkerSize(3);
85 c1->Add(m1);
86
87 auto tm1 = new TLatex(9.3, 7., "outside");
88 tm1->SetTextColor(kBlue);
89 tm1->SetTextAlign(32);
90 c1->Add(tm1);
91
92 // draw marker and label in the frame
93 auto m2 = new TMarker(9.5, 8., 34);
94 m2->SetMarkerColor(kGreen);
95 m2->SetMarkerSize(3);
96 c1->Add(m2, "frame");
97
98 auto tm2 = new TLatex(9.3, 8., "inside");
99 tm2->SetTextColor(kGreen);
100 tm2->SetTextAlign(32);
101 c1->Add(tm2, "frame");
102}
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
@ kDotted
Definition TAttLine.h:52
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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