I ran into a strange issue. Let me start with the following reproducer:
auto t = new TTree();
int a = 0;
int b = 0;
t->Branch("a", &a);
t->Branch("b", &b);
t->Fill();
a = 1;
b = 1;
t->Fill();
a = 2;
b = 3;
t->Fill();
auto c = new TCanvas();
gStyle->SetPalette(kRust);
t->Draw("a:b", "", "*L PLC PMC");
t->Draw("a:b+1", "", "SAME *L PLC PMC");
t->Draw("a:b+0.5", "", "SAME *L PLC PMC");
c->SaveAs("c1.root");
delete c;
c = new TCanvas();
gStyle->SetPalette(kRust);
t->Draw("a:b", "", "*L PLC PMC");
t->Draw("a:b+1", "", "SAME *L PLC PMC");
t->Draw("a:b+0.5", "", "SAME *L PLC PMC");
c->SaveAs("c2.root");
delete c;
What makes me scratch my head is that both canvases are visualized with the expected colour palettes when browsed with TBrowser. However, when loaded to the latest JSROOT at Read a ROOT file , c1 is visualized with the expected colour palette, while c2 is displayed with the default one (I guess). Am I doing something wrong or this could be a bug?
Best,
Piotr
ROOT Version: 6.30/01 Platform: Linux Mint 21.2 Cinnamon Compiler: GCC 12.2.0
Colors management is complicated topic in ROOT.
Not always custom colors and custom palette preserved when TCanvas stored in the ROOT file.
Your macro demonstrates exactly this problem - only first canvas includes colors and palette.
You can add:
TColor::DefinedColors(1);
to ensure storage of ROOT colors with every canvas.
Generally I recommend to use default colors in ROOT and configure custom palette in JSROOT directly. You always can do it with &palette=97 URL parameter or via “Settings/Drawing/Palette” context menu. Settings can be stored in the browser localStorage and reused then many times.
I add small fix to JSROOT which improves handling of custom ROOT colors, but some side effects may remain
Your macro demonstrates exactly this problem - only first canvas includes colors and palette.
Aha! So the fact that I could see both canvases with kRust when inspecting via TBrowser was just a matter of opening them in the “good” order. Indeed when I open c2 first, I see the default colour palette.
Unfortunately we are at 6.30/01 now, so I won’t be able to use that immediately, but I will keep that waiting to be used, thanks! As far as I can tell, there is no way I can work this around before we bump ROOT in ALICE.
Thanks! We are usually able to bump JSROOT more freely, so I will check your latest release once it’s there.