Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rframe.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_rcanvas
3///
4/// This ROOT 7 example shows how to create a frame.
5///
6/// \macro_image (rcanvas_js)
7/// \macro_code
8///
9/// \date 2020-02-20
10/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
11/// is welcome!
12/// \author Sergey Linev <s.linev@gsi.de>
13
14/*************************************************************************
15 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
16 * All rights reserved. *
17 * *
18 * For the licensing terms see $ROOTSYS/LICENSE. *
19 * For the list of contributors see $ROOTSYS/README/CREDITS. *
20 *************************************************************************/
21
22#include "ROOT/RCanvas.hxx"
23#include "ROOT/RColor.hxx"
24#include "ROOT/RFrameTitle.hxx"
25#include "ROOT/RFrame.hxx"
26#include "ROOT/RStyle.hxx"
27#include "ROOT/RLine.hxx"
28#include "ROOT/RText.hxx"
29#include "ROOT/RBox.hxx"
30
31using namespace ROOT::Experimental;
32
33auto rframe_style = RStyle::Parse("frame { x_ticks_width: 3; y_ticks_width: 3; }"
34 "title { margin: 0.02; height: 0.1; text_color: blue; text_size: 0.07; }"
35 "line { line_width: 2; }"
36 "text { text_align: 13; text_size: 0.03; }");
37
38void rframe()
39{
40 // Create a canvas to be displayed.
41 auto canvas = RCanvas::Create("RFrame with drawAxes enabled");
42
43 // configure RFrame with direct API calls
44 auto frame = canvas->AddFrame();
45 // frame->fill.color = RColor::kBlue;
46 // frame->fill.style = RAttrFill::kSolid;
47 frame->border.color = RColor::kBlue;
48 frame->border.width = 3;
49 frame->margins = 0.2_normal; // set all margins first
50 frame->margins.top = 0.25_normal;
51
52 // let frame draw axes without need of any histogram
53 frame->drawAxes = true;
54
55 frame->x.min = 0;
56 frame->x.max = 100;
57 // frame->x.log = 2.;
58 frame->x.zoomMin = 5.;
59 frame->x.zoomMax = 95.;
60 frame->x.line.color = RColor::kGreen; // or in CSS "x_line_color: green;"
61
62 frame->y.min = 0;
63 frame->y.max = 100;
64 frame->y.zoomMin = 5;
65 frame->y.zoomMax = 95;
66 frame->y.line.color = RColor::kBlue; // or in CSS "y_line_color: blue;"
67
68 auto title = canvas->Draw<RFrameTitle>("Frame title");
69 title->margin = 0.01_normal;
70 title->height = 0.1_normal;
71
72 // draw line over the frame
73 auto line0 = canvas->Draw<RLine>(RPadPos(100_px, .9_normal), RPadPos(900_px , .9_normal));
74 auto text0 = canvas->Draw<RText>(RPadPos(100_px, .9_normal + 5_px), "Line drawn on pad, fix pixel length");
75 text0->text.align = RAttrText::kLeftBottom;
76
77 // draw line under the frame
78 auto line1 = canvas->Draw<RLine>(RPadPos(.1_normal, .1_normal), RPadPos(.9_normal, .1_normal));
79 auto text1 = canvas->Draw<RText>(RPadPos(.1_normal, .1_normal), "Line drawn on pad, normalized coordinates");
80
81 // draw on left size of frame, but bound to frame, moved with frame
82 auto line2 = canvas->Draw<RLine>(RPadPos(-.2_normal, -.1_normal), RPadPos(-.2_normal , 1.1_normal));
83 line2->onFrame = true; // or via CSS "onFrame: true;"
84 line2->line.color = RColor::kRed;
85
86 auto text2 = canvas->Draw<RText>(RPadPos(-.2_normal - 5_px, -.1_normal), "Line drawn on frame, normalized coordinates");
87 text2->onFrame = true; // or via CSS "onFrame: true;"
88 text2->text.angle = 90;
89 text2->text.align = RAttrText::kLeftBottom;
90
91 // draw on right size of frame, user coordiante, moved and zoomed with frame
92 auto line3 = canvas->Draw<RLine>(RPadPos(110_user, -.1_normal), RPadPos(110_user, 1.1_normal));
93 line3->onFrame = true; // or via CSS "onFrame: true;"
94 line3->line.color = RColor::kRed;
95
96 auto text3 = canvas->Draw<RText>(RPadPos(110_user, -.1_normal), "Line drawn on frame, user coordinates");
97 text3->onFrame = true; // or via CSS "onFrame: true;"
98 text3->text.angle = 90;
99
100 // draw box before line at same position as line ending with 40x40 px size and clipping on
101 auto box4 = canvas->Draw<RBox>(RPadPos(80_user - 20_px, 80_user - 20_px), RPadPos(80_user + 20_px, 80_user + 20_px));
102 box4->fill.color = RColor::kBlue;
103 box4->fill.style = RAttrFill::kSolid;
104 box4->clipping = true; // or via CSS "clipping: true;"
105 box4->onFrame = true; // or via CSS "onFrame: true;"
106
107 // draw line in the frame, allowed to set user coordinate
108 auto line4 = canvas->Draw<RLine>(RPadPos(20_user, 20_user), RPadPos(80_user, 80_user));
109 line4->clipping = true; // or via CSS "clipping: true;"
110 line4->onFrame = true; // or via CSS "onFrame: true;"
111
112 auto text4 = canvas->Draw<RText>(RPadPos(20_user, 20_user), "clipping on");
113 text4->onFrame = true; // or via CSS "onFrame: true;"
114 text4->clipping = true; // or via CSS "clipping: true;"
115
116 // draw box before line at same position as line ending with 40x40 px size
117 auto box5 = canvas->Draw<RBox>(RPadPos(80_user - 20_px, 20_user - 20_px), RPadPos(80_user + 20_px, 20_user + 20_px));
118 box5->fill.color = RColor::kYellow;
119 box5->fill.style = RAttrFill::kSolid;
120 box5->onFrame = true; // or via CSS "onFrame: true;"
121
122 // draw line in the frame, but disable default cutting by the frame borders
123 auto line5 = canvas->Draw<RLine>(RPadPos(20_user, 80_user), RPadPos(80_user, 20_user));
124 line5->onFrame = true; // or via CSS "onFrame: true;"
125
126 auto text5 = canvas->Draw<RText>(RPadPos(20_user, 80_user), "clipping off");
127 text5->onFrame = true; // or via CSS "onFrame: true;"
128 text5->text.align = RAttrText::kLeftBottom;
129
130 canvas->UseStyle(rframe_style);
131
132 canvas->Show();
133}
A position (horizontal and vertical) in a RPad.
Definition RPadPos.hxx:28