Handle Unzoom signal on yaxis of TH2

Hi,

I juste realized that the Unzoom method of TAxis didn’t emit the signal in the case of an y axis for a TH2 histogram… What is the reason for that, and is there an other way to re-implement the TAxis class to solve this problem ?

Thanks in advance

Cheers

Jérémie


ROOT Version: v6-10-06
Platform: Ubuntu 16.04
Compiler: 5.4.0


I do not see why the y axis should be special . Does it work for X ? do you have a small code showing this behaviour ?

Look in the core : if axis is not “xaxis” and hobj1->GetDimension() == 2, it returns, and the signal is not send

void TAxis::UnZoom()
{
if (!gPad) return;
gPad->SetView();

//unzoom object owning this axis
SetRange(0,0);
TH1 *hobj1 = (TH1*)GetParent();
if (!strstr(GetName(),"xaxis")) {
   if (!hobj1) return;
   if (hobj1->GetDimension() == 2) {
      if (strstr(GetName(),"zaxis")) {
         hobj1->SetMinimum();
         hobj1->SetMaximum();
         hobj1->ResetBit(TH1::kIsZoomed);
      }
      return;
   }
   if (strcmp(hobj1->GetName(),"hframe") == 0 ) {
      hobj1->SetMinimum(fXmin);
      hobj1->SetMaximum(fXmax);
   } else {
      if (fXmin==hobj1->GetMinimum() && fXmax==hobj1->GetMaximum()) {
         hobj1->SetMinimum(fXmin);
         hobj1->SetMaximum(fXmax);
      } else {
         hobj1->SetMinimum();
         hobj1->SetMaximum();
      }
      hobj1->ResetBit(TH1::kIsZoomed);
   }
}
//must unzoom all histograms in the pad
TIter next(gPad->GetListOfPrimitives());
TObject *obj;
while ((obj= next())) {
   if (!obj->InheritsFrom(TH1::Class())) continue;
   TH1 *hobj = (TH1*)obj;
   if (hobj == hobj1) continue;
   if (!strstr(GetName(),"xaxis")) {
      if (hobj->GetDimension() == 2) {
         if (strstr(GetName(),"zaxis")) {
            hobj->SetMinimum();
            hobj->SetMaximum();
            hobj->ResetBit(TH1::kIsZoomed);
         } else {
            hobj->GetYaxis()->SetRange(0,0);
         }
         return;
      }
      if (strcmp(hobj->GetName(),"hframe") == 0 ) {
         hobj->SetMinimum(fXmin);
         hobj->SetMaximum(fXmax);
      } else {
         hobj->SetMinimum();
         hobj->SetMaximum();
         hobj->ResetBit(TH1::kIsZoomed);
      }
   } else {
      hobj->GetXaxis()->SetRange(0,0);
   }
}

gPad->UnZoomed();

}

And yes it works for x, and for y in case of TH1 histograms

Yes it seems there is not special case for the y-axis. I have no answer right away.

And is there a way to get the signal from the click on the TAxis contextmenu ?

May be @bellenot can help you.

You can use the TCanvas::ProcessedEvent(Int_t event, Int_t x, Int_t y, TObject *selected); signal, and check for the kButton3Up event

Yes but this will not tell me that this is the command Unzoom that has been launched

You’re right. And I’m afraid there is no other solution than using the gPad->UnZoomed() one. And if it doesn’t work properly, then it should be fixed…

@dudouet May be you can make a Jira report about this issue.

Ok so for your information, see below the solution I found for this, but this is quite nasty. I am working with a canvas divided in 36 pads, and I want that when an unzoom is made on one pad, it is applied to all of them:

void MyClass::HandleMovement(Int_t EventType, Int_t EventX, Int_t EventY, TObject *selected){

///To get the signal correctly
if(selected != nullptr && (EventType == kButton3Down || EventType == kButton1Down) && selected->InheritsFrom("TAxis")){

    fLastAxis = (TAxis*)selected;

    TH1 *hist = (TH1*)fLastAxis->GetParent();
    if(EventType == kButton3Down && ((TString)fLastAxis->GetName())=="yaxis" && hist && hist->GetDimension()==2){
        fLastAxis->SetName("xaxis");
        fDoY_TH2_Unzoom = true;
    }
}


///To rename the yaxis correctly just after clicking on unzoom
if(fLastAxis && ( selected !=fLastSelected ) && fDoY_TH2_Unzoom){
    fDoY_TH2_Unzoom = false;
    fLastAxis->SetName("yaxis");
}

fLastSelected = selected;
}

May be the new HighLight mechanism can be of some help in your case:

https://root.cern/doc/master/classTHistPainter.html#HP30
https://root.cern/doc/master/hlHisto1_8C.html
https://root.cern/doc/master/hlHisto2_8C.html
https://root.cern/doc/master/hlHisto3_8C.html
https://root.cern/doc/master/hlHisto4_8C.html
https://root.cern/doc/master/hlGraph2_8C.html

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.