Skip to content

Commit 9495e66

Browse files
authored
[hist] reset kAxisRange bit when fully unzooming (root-project#18226)
When unzoom with mouse wheel, properly reset kAxisRange bit. Adjust documentation
1 parent 9aa2fc5 commit 9495e66

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

graf2d/gpad/src/TPad.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,7 @@ void TPad::ExecuteEventAxis(Int_t event, Int_t px, Int_t py, TAxis *axis)
23712371
Int_t nbd, inc, bin1, bin2, first, last;
23722372
Double_t temp, xmin,xmax;
23732373
Bool_t opaque = gPad->OpaqueMoving();
2374+
bool resetAxisRange = false;
23742375
static std::unique_ptr<TBox> zoombox;
23752376
Double_t zbx1=0,zbx2=0,zby1=0,zby2=0;
23762377

@@ -2524,8 +2525,12 @@ void TPad::ExecuteEventAxis(Int_t event, Int_t px, Int_t py, TAxis *axis)
25242525
bin2 = axis->GetLast()+inc;
25252526
bin1 = TMath::Max(bin1, 1);
25262527
bin2 = TMath::Min(bin2, axis->GetNbins());
2528+
resetAxisRange = (bin1 == 1 && axis->GetFirst() == 1 && bin2 == axis->GetNbins() && axis->GetLast() == axis->GetNbins());
25272529
if (bin2>bin1) {
25282530
axis->SetRange(bin1,bin2);
2531+
}
2532+
if (resetAxisRange) axis->ResetBit(TAxis::kAxisRange);
2533+
if (bin2>bin1) {
25292534
gPad->Modified();
25302535
gPad->Update();
25312536
}

hist/hist/src/TAxis.cxx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ const char *TAxis::GetBinLabel(Int_t bin) const
457457
////////////////////////////////////////////////////////////////////////////////
458458
/// Return first bin on the axis
459459
/// i.e. 1 if no range defined
460-
/// NOTE: in some cases a zero is returned (see TAxis::SetRange)
460+
/// \note in some cases a zero is returned (see TAxis::SetRange)
461461

462462
Int_t TAxis::GetFirst() const
463463
{
@@ -468,7 +468,7 @@ Int_t TAxis::GetFirst() const
468468
////////////////////////////////////////////////////////////////////////////////
469469
/// Return last bin on the axis
470470
/// i.e. fNbins if no range defined
471-
/// NOTE: in some cases a zero is returned (see TAxis::SetRange)
471+
/// \note in some cases a zero is returned (see TAxis::SetRange)
472472

473473
Int_t TAxis::GetLast() const
474474
{
@@ -1017,7 +1017,6 @@ void TAxis::ChangeLabelByValue(Double_t labValue, Double_t labAngle, Double_t la
10171017
ml->SetText(labText);
10181018
}
10191019

1020-
10211020
////////////////////////////////////////////////////////////////////////////////
10221021
/// Set the viewing range for the axis using bin numbers.
10231022
///
@@ -1061,10 +1060,8 @@ void TAxis::SetRange(Int_t first, Int_t last)
10611060
fLast = std::min(last, nCells);
10621061
SetBit(kAxisRange, true);
10631062
}
1064-
10651063
}
10661064

1067-
10681065
////////////////////////////////////////////////////////////////////////////////
10691066
/// Set the viewing range for the axis from `ufirst` to `ulast` (in user coordinates,
10701067
/// that is, the "natural" axis coordinates).

hist/histpainter/src/THistPainter.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3641,12 +3641,16 @@ void THistPainter::ExecuteEvent(Int_t event, Int_t px, Int_t py)
36413641
bin2 = xaxis->GetLast()+1;
36423642
bin1 = TMath::Max(bin1, 1);
36433643
bin2 = TMath::Min(bin2, xaxis->GetNbins());
3644+
const bool resetXaxisRange = bin1 == 1 && xaxis->GetFirst() == 1 && bin2 == xaxis->GetNbins() && xaxis->GetLast() == xaxis->GetNbins();
36443645
if (bin2>bin1) xaxis->SetRange(bin1,bin2);
3646+
if (resetXaxisRange) xaxis->ResetBit(TAxis::kAxisRange);
36453647
bin1 = yaxis->GetFirst()-1;
36463648
bin2 = yaxis->GetLast()+1;
36473649
bin1 = TMath::Max(bin1, 1);
36483650
bin2 = TMath::Min(bin2, yaxis->GetNbins());
3651+
const bool resetYaxisRange = bin1 == 1 && yaxis->GetFirst() == 1 && bin2 == yaxis->GetNbins() && yaxis->GetLast() == yaxis->GetNbins();
36493652
if (bin2>bin1) yaxis->SetRange(bin1,bin2);
3653+
if (resetYaxisRange) yaxis->ResetBit(TAxis::kAxisRange);
36503654
}
36513655
gPad->Modified();
36523656
gPad->Update();

0 commit comments

Comments
 (0)