Logo ROOT  
Reference Guide
TGraphEditor.cxx
Go to the documentation of this file.
1// @(#)root/ged:$Id$
2// Author: Carsten Hof 16/08/04
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12
13//////////////////////////////////////////////////////////////////////////
14// //
15// TGraphEditor //
16// //
17// Implements GUI for graph attributes. //
18// //
19// Title': set the title of the graph //
20// Change the Shape of the graph: //
21// 'No Line' = " ": just draw unconnected points //
22// 'Simple Line' = "L":simple poly line between every point is drawn//
23// 'Smooth Line' = "C":smooth curve is drawn //
24// 'Bar Chart' = "B": A bar chart is drawn at each point //
25// 'Fill Area' = "F": A fill area is drawn //
26// Check box: 'Marker On/Off' Set Marker visible/invisible //
27// //
28//////////////////////////////////////////////////////////////////////////
29//Begin_Html
30/*
31<img src="gif/TGraphEditor.gif">
32*/
33//End_Html
34
35#include "TGComboBox.h"
36#include "TGButtonGroup.h"
37#include "TGraphEditor.h"
38#include "TGTextEntry.h"
39#include "TGToolTip.h"
40#include "TGLabel.h"
41#include "TGraph.h"
42#include "TVirtualPad.h"
43#include "TGraphErrors.h"
44
46
48 kShape = 0,
58};
59
60//______________________________________________________________________________
61
63 Int_t height, UInt_t options, Pixel_t back)
64 : TGedFrame(p, width, height, options | kVerticalFrame, back)
65{
66 // Constructor of graph editor.
67
68 fGraph = 0;
69 // TextEntry to change the title
70 MakeTitle("Title");
71
72 fTitlePrec = 2;
73 fTitle = new TGTextEntry(this, new TGTextBuffer(50), kGRAPH_TITLE);
75 fTitle->SetToolTipText("Enter the graph title string");
76 // better take kLHintsLeft and Right - Right is not working at the moment
77 AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
78
79 // Radio Buttons to change the draw options of the graph
80 TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
81 fgr = new TGButtonGroup(f2,3,1,3,5,"Shape");
83 fShape = new TGRadioButton(fgr,"No Line",kSHAPE_NOLINE); // no draw option
84 fShape->SetToolTipText("The points are not connected by a line");
85 fShape0 = new TGRadioButton(fgr,"Smooth Line ",kSHAPE_SMOOTH); // option C
86 fShape0->SetToolTipText("Draw a smooth graph curve");
87 fShape1 = new TGRadioButton(fgr,"Simple Line ",kSHAPE_SIMPLE); // option L
88 fShape1->SetToolTipText("Draw a simple poly-line between the graph points");
89 fShape2 = new TGRadioButton(fgr,"Bar Chart",kSHAPE_BAR); // option B
90 fShape2->SetToolTipText("Draw a bar chart at each graph point");
91 fShape3 = new TGRadioButton(fgr,"Fill area",kSHAPE_FILL); // option F
92 fShape3->SetToolTipText("A fill area is drawn");
93
95 fgr->Show();
97 f2->AddFrame(fgr, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
98
99 // CheckBox to activate/deactivate the drawing of the Marker
100 fMarkerOnOff = new TGCheckButton(f2,"Show Marker",kMARKER_ONOFF);
101 fMarkerOnOff->SetToolTipText("Make Marker visible/invisible");
102 f2->AddFrame(fMarkerOnOff, new TGLayoutHints(kLHintsTop, 5, 1, 0, 3));
103 AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
104
105 // Exclusion zone parameters
106 MakeTitle("Exclusion Zone");
107 TGCompositeFrame *f3 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
108 AddFrame(f3, new TGLayoutHints(kLHintsTop, 1, 1, 5, 0));
109
111 fExSide->SetToolTipText("Zone is drawing side");
112 f3->AddFrame(fExSide, new TGLayoutHints(kLHintsTop, 5, 1, 0, 0));
113
117 fWidthCombo->Resize(91, 20);
118 f3->AddFrame(fWidthCombo, new TGLayoutHints(kLHintsLeft, 7, 1, 1, 1));
120}
121
122//______________________________________________________________________________
123
125{
126 // Destructor of graph editor.
127
128 // children of TGButonGroup are not deleted
129 delete fShape;
130 delete fShape0;
131 delete fShape1;
132 delete fShape2;
133 delete fShape3;
134 delete fShape1lh;
135}
136
137//______________________________________________________________________________
138
140{
141 // Connect signals to slots.
142
143 fTitle->Connect("TextChanged(const char *)","TGraphEditor",this,"DoTitle(const char *)");
144 fgr->Connect("Clicked(Int_t)","TGraphEditor",this,"DoShape()");
145 fMarkerOnOff->Connect("Toggled(Bool_t)","TGraphEditor",this,"DoMarkerOnOff(Bool_t)");
146 fWidthCombo->Connect("Selected(Int_t)", "TGraphEditor", this, "DoGraphLineWidth()");
147 fExSide->Connect("Clicked()","TGraphEditor",this,"DoGraphLineWidth()");
148
149 fInit = kFALSE; // connect the slots to the signals only once
150}
151
152//______________________________________________________________________________
153
155{
156 // Pick up the used values of graph attributes.
157
158 fGraph = (TGraph *)obj;
160
161 // set the Title TextEntry
162 const char *text = fGraph->GetTitle();
164
165 TString opt = GetDrawOption();
166 opt.ToUpper();
167 Int_t i=0;
169 // Remove characters which appear twice in the draw option
170 TString dum = opt;
171 Int_t l = opt.Length()-1;
172 while (i < l) {
173 dum.Remove(dum.First(opt[i]),1);
174 if (dum.Contains(opt[i])){
175 opt.Remove(opt.First(opt[i]),1);
176 l--;
177 i--;
178 make=kTRUE;
179 }
180 i++;
181 }
182 // initialise the RadioButton group which shows the drawoption
183 if (opt.Contains("C")) {
185 fDrawShape='C';
186 } else if (opt.Contains("L")) {
188 fDrawShape='L';
189 } else if (opt.Contains("B")){
191 fDrawShape='B';
192 } else if (opt.Contains("F")){
194 fDrawShape='F';
195 } else {
197 fDrawShape=' ';
198 }
199 if (make) SetDrawOption(opt);
200 // if the draw option is A, P, AP the P option cannot be removed,
201 // we deactivate the CheckBox
202 // also initialising the MarkerOnOff checkbutton (== P option)
203 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
204 if (!opt.Contains("P"))
205 opt +="P";
207 } else if (opt.Contains("P")) {
210
211 // Exclusion zone parameters
215
218}
219
220//______________________________________________________________________________
221
223{
224 // Slot for setting the graph title.
225
226 if (fAvoidSignal) return;
228 Update();
229}
230
231//______________________________________________________________________________
232
234{
235 // Slot connected to the draw options.
236
237 if (fAvoidSignal) return;
238 TString opt;
240 opt = fGraph->GetDrawOption();
241 else
242 opt = GetDrawOption();
243
244 opt.ToUpper();
245 Int_t s = 0;
247 else if (fShape0->GetState() == kButtonDown) s = kSHAPE_SMOOTH;
248 else if (fShape1->GetState() == kButtonDown) s = kSHAPE_SIMPLE;
249 else if (fShape2->GetState() == kButtonDown) s = kSHAPE_BAR;
250 else s = kSHAPE_FILL;
251
252 switch (s) {
253
254 // change draw option to No Line:
255 case kSHAPE_NOLINE: {
256 if (opt.Contains(fDrawShape))
257 opt.Remove(opt.First(fDrawShape),1);
258 fDrawShape = ' ';
260 break;
261 }
262
263 // change draw option to Smooth Line (C)
264 case kSHAPE_SMOOTH: {
265 if (fDrawShape == ' ')
266 opt +="C";
267 else if (opt.Contains(fDrawShape))
268 opt.Replace(opt.First(fDrawShape),1,'C');
269 fDrawShape = 'C';
270 break;
271 }
272
273 // change draw option to Simple Line (L)
274 case kSHAPE_SIMPLE: {
275 if (fDrawShape == ' ')
276 opt +="L";
277 else if (opt.Contains(fDrawShape))
278 opt.Replace(opt.First(fDrawShape),1,'L');
279 fDrawShape='L';
280 break;
281 }
282
283 // change draw option to Bar Chart (B)
284 case kSHAPE_BAR: {
285 if (fDrawShape == ' ')
286 opt +="B";
287 else if (opt.Contains(fDrawShape))
288 opt.Replace(opt.First(fDrawShape),1,'B');
289 fDrawShape='B';
290 break;
291 }
292
293 // change draw option to Fill Area (F)
294 case kSHAPE_FILL: {
295 if (fDrawShape == ' ')
296 opt +="F";
297 else if (opt.Contains(fDrawShape))
298 opt.Replace(opt.First(fDrawShape),1,'F');
299 fDrawShape='F';
300 break;
301 }
302 }
303
304 if (gPad && gPad->GetVirtCanvas())
305 gPad->GetVirtCanvas()->SetCursor(kWatch);
306 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
307
308 // set/reset the Marker CheckBox
309 if (opt.Contains("P"))
311 else
313 if (opt=="A" || opt=="AP" || opt=="PA" || opt == "P") {
314 if (!opt.Contains("P"))
315 opt +="P";
317 }
318
319 // set/reset the exclusion zone CheckBox
320 if (opt.Contains("L") || opt.Contains("C")) {
324 } else {
327 }
328
329 SetDrawOption(opt);
330 if (gPad && gPad->GetVirtCanvas())
331 gPad->GetVirtCanvas()->SetCursor(kPointer);
332 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
333}
334
335//______________________________________________________________________________
336
338{
339 // Slot for setting markers as visible/invisible.
340
341 if (fAvoidSignal) return;
343 t.ToUpper();
344
345 // showing the marker:
346 if (on) {
347 if (!t.Contains("P")) t+="P";
349 } else {
350 // remove the marker option P
351 while (t.Contains("P")) t.Remove(t.First("P"),1);
353 }
354 SetDrawOption(t);
355}
356
357//______________________________________________________________________________
358
360{
361 // Slot connected to the graph line width.
362
363 if (fAvoidSignal) return;
365 Int_t lineWidth = TMath::Abs(fGraph->GetLineWidth()%100);
366 Int_t side = 1;
367 if (fExSide->GetState() == kButtonDown) side = -1;
368 fGraph->SetLineWidth(side*(100*width+lineWidth));
369 Update();
370}
371
void Class()
Definition: Class.C:29
ULong_t Pixel_t
Definition: GuiTypes.h:39
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
include TDocParser_001 C image html pict1_TDocParser_001 png width
Definition: TDocParser.cxx:121
@ kButtonDown
Definition: TGButton.h:54
@ kButtonDisabled
Definition: TGButton.h:56
@ kButtonUp
Definition: TGButton.h:53
@ kButtonEngaged
Definition: TGButton.h:55
@ kChildFrame
Definition: TGFrame.h:57
@ kSunkenFrame
Definition: TGFrame.h:61
@ kVerticalFrame
Definition: TGFrame.h:59
@ kDoubleBorder
Definition: TGFrame.h:63
@ kFitWidth
Definition: TGFrame.h:64
@ kHorizontalFrame
Definition: TGFrame.h:60
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsTop
Definition: TGLayout.h:34
EGraphWid
@ kGRAPH_LINE_WIDTH
@ kGRAPH_TITLE
@ kMARKER_ONOFF
@ kShape
@ kSHAPE_SMOOTH
@ kSHAPE_SIMPLE
@ kSHAPE_BAR
@ kGRAPH_LINE_SIDE
@ kSHAPE_FILL
@ kSHAPE_NOLINE
#define gPad
Definition: TVirtualPad.h:286
#define gVirtualX
Definition: TVirtualX.h:345
@ kWatch
Definition: TVirtualX.h:47
@ kPointer
Definition: TVirtualX.h:47
virtual Width_t GetLineWidth() const
Return the line width.
Definition: TAttLine.h:35
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetRadioButtonExclusive(Bool_t flag=kTRUE)
If enable is kTRUE, this button group will treat radio buttons as mutually exclusive,...
virtual void Show()
Show group of buttons.
virtual void SetLayoutHints(TGLayoutHints *l, TGButton *button=0)
Set layout hints for the specified button or if button=0 for all buttons.
virtual void SetButton(Int_t id, Bool_t down=kTRUE)
Sets the button with id to be on/down, and if this is an exclusive group, all other button in the gro...
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:395
virtual EButtonState GetState() const
Definition: TGButton.h:112
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1200
virtual Int_t GetSelected() const
Definition: TGComboBox.h:134
virtual void Select(Int_t id, Bool_t emit=kTRUE)
Make the selected item visible in the combo box window and emit signals according to the second param...
Definition: TGComboBox.cxx:450
virtual void SetEnabled(Bool_t on=kTRUE)
Set state of combo box. If kTRUE=enabled, kFALSE=disabled.
Definition: TGComboBox.cxx:638
TGCompositeFrame(const TGCompositeFrame &)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void ChangeOptions(UInt_t options)
Change composite frame options. Options is an OR of the EFrameTypes.
Definition: TGFrame.cxx:1025
static Pixel_t GetWhitePixel()
Get white pixel value.
Definition: TGFrame.cxx:691
virtual UInt_t GetDefaultHeight() const
Definition: TGFrame.h:238
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
Handle_t GetId() const
Definition: TGObject.h:47
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set radio button state.
Definition: TGButton.cxx:1563
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line.
virtual void Associate(const TGWindow *w)
Definition: TGWidget.h:84
virtual Option_t * GetDrawOption() const
Get draw options of the selected object.
Definition: TGedFrame.cxx:81
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition: TGedFrame.cxx:145
Bool_t fInit
Definition: TGedFrame.h:53
virtual void MakeTitle(const char *title)
Create attribute frame title.
Definition: TGedFrame.cxx:96
virtual void Update()
Update the current pad when an attribute is changed via GUI.
Definition: TGedFrame.cxx:73
Bool_t fAvoidSignal
Definition: TGedFrame.h:56
virtual void SetModel(TObject *obj)
TGLayoutHints * fShape1lh
Definition: TGraphEditor.h:45
virtual void DoMarkerOnOff(Bool_t on)
TGRadioButton * fShape0
Definition: TGraphEditor.h:41
virtual ~TGraphEditor()
virtual void DoShape()
TGraph * fGraph
Definition: TGraphEditor.h:38
virtual void DoGraphLineWidth()
TGRadioButton * fShape
Definition: TGraphEditor.h:40
TGCheckButton * fMarkerOnOff
Definition: TGraphEditor.h:46
virtual void ConnectSignals2Slots()
TGButtonGroup * fgr
Definition: TGraphEditor.h:39
Int_t fTitlePrec
Definition: TGraphEditor.h:37
virtual void DoTitle(const char *text)
TGRadioButton * fShape2
Definition: TGraphEditor.h:43
TGCheckButton * fExSide
Definition: TGraphEditor.h:48
TGraphEditor(const TGWindow *p=0, Int_t width=140, Int_t height=30, UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground())
TGRadioButton * fShape3
Definition: TGraphEditor.h:44
TGLineWidthComboBox * fWidthCombo
Definition: TGraphEditor.h:47
TGRadioButton * fShape1
Definition: TGraphEditor.h:42
TGTextEntry * fTitle
Definition: TGraphEditor.h:36
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2312
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition: TObject.cxx:341
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition: TObject.cxx:443
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:867
Basic string class.
Definition: TString.h:131
Ssiz_t Length() const
Definition: TString.h:405
TString & Replace(Ssiz_t pos, Ssiz_t n, const char *s)
Definition: TString.h:677
Ssiz_t First(char c) const
Find first occurrence of a character c.
Definition: TString.cxx:499
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
TString & Remove(Ssiz_t pos)
Definition: TString.h:668
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
TText * text
constexpr std::array< decltype(std::declval< F >()(std::declval< int >())), N > make(F f)
static constexpr double s
Short_t Abs(Short_t d)
Definition: TMathBase.h:120
auto * l
Definition: textangle.C:4