1 #include "TGraphInteractive.h" 2 #include "TVirtualPad.h" 10 Acclaim::GuiParent::~GuiParent(){
16 void Acclaim::GuiParent::deleteChildren(){
17 for(
unsigned i=0; i < fChildren.size(); i++){
28 size_t Acclaim::GuiParent::addGuiChild(
const TGraph& gr, Option_t* drawOpt){
30 TGraphInteractive* grChild =
new TGraphInteractive(&gr, drawOpt);
31 return addGuiChild(grChild);
37 size_t Acclaim::GuiParent::addGuiChild(TGraphInteractive* grPtr){
39 grPtr->fParent =
this;
40 fChildren.push_back(grPtr);
42 return fChildren.size();
48 size_t Acclaim::GuiParent::copyChildren(
const GuiParent* that){
49 for(UInt_t i=0; i < that->fChildren.size(); i++){
50 if(that->fChildren[i]){
51 this->addGuiChild(*that->fChildren[i], that->fChildren[i]->fDrawOpt);
54 return fChildren.size();
60 void Acclaim::GuiParent::removeReference(TGraphInteractive* gr){
61 UInt_t hash = gr->Hash();
62 for(
unsigned i=0; i < fChildren.size(); i++){
63 if(fChildren[i] && fChildren[i]->Hash() == hash){
73 TString passedOpt = opt;
76 if(dynamic_cast<TH2*>(
this)){
79 else if(dynamic_cast<TGraph*>(
this)){
85 for(UInt_t i=0; i < fChildren.size(); i++){
87 TString childDrawOpt = fChildren[i]->GetDrawOpt();
88 childDrawOpt.ReplaceAll(
"same",
"");
89 childDrawOpt.ReplaceAll(
"a",
"");
90 childDrawOpt +=
"same";
91 fChildren[i]->Draw(childDrawOpt);
110 for(UInt_t i=0; i < fChildren.size(); i++){
111 if(fChildren[i] && strcmp(fChildren[i]->GetName(), name)==0){
112 return grChild = fChildren[i];
142 Acclaim::TGraphInteractive::TGraphInteractive(
const TGraph* gr, Option_t* drawOpt)
144 fParent(NULL), fDrawOpt(drawOpt)
147 SetName(gr->GetName());
148 SetTitle(gr->GetTitle());
149 GetXaxis()->SetTitle(gr->GetXaxis()->GetTitle());
150 GetYaxis()->SetTitle(gr->GetYaxis()->GetTitle());
151 SetFillColor(gr->GetFillColor());
152 SetFillStyle(gr->GetFillStyle());
154 SetLineColor(gr->GetLineColor());
155 SetLineWidth(gr->GetLineWidth());
156 SetLineStyle(gr->GetLineStyle());
158 SetMarkerColor(gr->GetMarkerColor());
159 SetMarkerStyle(gr->GetMarkerStyle());
160 SetMarkerSize(gr->GetMarkerSize());
162 GetXaxis()->SetTitle(gr->GetXaxis()->GetTitle());
163 GetYaxis()->SetTitle(gr->GetYaxis()->GetTitle());
164 TString title = gr->GetTitle();
165 if(title.Contains(
";")){
166 Ssiz_t p = title.First(
';');
172 GetXaxis()->SetRange(gr->GetXaxis()->GetFirst(), gr->GetXaxis()->GetLast());
177 Acclaim::TGraphInteractive::TGraphInteractive(
int n,
const double* x,
const double* y, Option_t* drawOpt)
192 Acclaim::TGraphInteractive::~TGraphInteractive(){
196 fParent->removeReference(
this);
211 const GuiParent* next = this->getParent();
215 next = current->getParent();
225 TString passedOpt(opt);
240 if(fChildren.size() > 0){
241 int firstBin = GetXaxis()->GetFirst();
242 int lastBin = GetXaxis()->GetLast();
243 double lowerLimit = GetXaxis()->GetBinLowEdge(firstBin);
244 double upperLimit = GetXaxis()->GetBinUpEdge(lastBin);
246 double yMax=0, yMin=0, xMax=0, xMin=0;
247 RootTools::getMaxMinWithinLimits(
this, yMax, xMax, yMin, xMin, lowerLimit, upperLimit);
249 for(
unsigned i=0; i < fChildren.size(); i++){
253 TString drawOpt = fChildren[i]->GetDrawOpt();
254 drawOpt.ReplaceAll(
"same",
"");
255 drawOpt.ReplaceAll(
"a",
"");
258 fChildren[i]->Draw(drawOpt);
260 double childMax, childMin;
261 RootTools::getMaxMinWithinLimits(fChildren[i], childMax, xMax, childMin, xMin, lowerLimit, upperLimit);
273 double padding = 0.1*(yMax - yMin);
274 SetMaximum(yMax + padding);
275 SetMinimum(yMin - padding);
280 void Acclaim::TGraphInteractive::ExecuteEvent(
int event,
int px,
int py){
283 if(event==kButton1Double){
290 copy->copyChildren(grP);
291 copy->SetBit(kCanDelete);
299 TGraphAligned::ExecuteEvent(event, px, py);
GuiParent * findOriginator() const
Inherit from this to draw interactive TGraphs on top of you.
const TGraphInteractive * findChild(const char *name)
A minimalistic extension to TGraphAligned for some GUI bells and whistles.
virtual void DrawGroup(Option_t *opt="")
Must be overloaded by children (TGraphInteractive*) to return pointer to parent
virtual void DrawGroup(Option_t *opt="")
Must be overloaded by children (TGraphInteractive*) to return pointer to parent