Skip to content

Commit 85fd59a

Browse files
committed
Preserve TH2Poly bin color after painting
Restore old color - to make it possible draw TH2Poly with different option afterwards
1 parent d5cb745 commit 85fd59a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

hist/histpainter/src/THistPainter.cxx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ is the color change between cells.
10511051
10521052
The color palette in TStyle can be modified via `gStyle->SetPalette()`.
10531053
1054-
All the non-empty bins are painted. Empty bins (bins with content and error equal to 0) are
1054+
All the non-empty bins are painted. Empty bins (bins with content and error equal to 0) are
10551055
not painted unless some bins have a negative content because in that case the null bins
10561056
might be not empty.
10571057
@@ -9881,25 +9881,28 @@ void THistPainter::PaintTH2PolyColorLevels(Option_t *)
98819881
theColor = Int_t((color+0.99)*Float_t(ncolors)/Float_t(ndivz));
98829882
if (theColor > ncolors-1) theColor = ncolors-1;
98839883

9884+
auto rootColor = gStyle->GetColorPalette(theColor);
9885+
98849886
// Paint the TGraph bins.
98859887
if (poly->IsA() == TGraph::Class()) {
98869888
TGraph *g = (TGraph*)poly;
9887-
g->SetFillColor(gStyle->GetColorPalette(theColor));
9889+
auto origin = g->GetFillColor();
9890+
g->SetFillColor(rootColor);
98889891
g->TAttFill::Modify();
98899892
g->Paint("F");
9893+
g->SetFillColor(origin);
98909894
}
98919895

98929896
// Paint the TMultiGraph bins.
98939897
if (poly->IsA() == TMultiGraph::Class()) {
98949898
TMultiGraph *mg = (TMultiGraph*)poly;
9895-
TList *gl = mg->GetListOfGraphs();
9896-
if (!gl) return;
9897-
TGraph *g;
9898-
TIter nextg(gl);
9899-
while ((g = (TGraph*) nextg())) {
9900-
g->SetFillColor(gStyle->GetColorPalette(theColor));
9899+
TIter nextg(mg->GetListOfGraphs());
9900+
while (auto g = (TGraph*) nextg()) {
9901+
auto origin = g->GetFillColor();
9902+
g->SetFillColor(rootColor);
99019903
g->TAttFill::Modify();
99029904
g->Paint("F");
9905+
g->SetFillColor(origin);
99039906
}
99049907
}
99059908
}

0 commit comments

Comments
 (0)