[ROOT] box width for a entry of TLegend

From: Hajime Nanjyo (nanjyo@icepp.s.u-tokyo.ac.jp)
Date: Tue Jul 29 2003 - 13:40:05 MEST


Dear Rooters,

The box width of a entry of TLegend is strange for root 3.05/06 and 3.05/07.
I think there are some mistakes in the source code of
TLegend.cxx (Line445-Line461).
The original version of TLegend.cxx and my correction are shown below.
Please check the code.

Best Regards
Hajime

////////////////////////////////////////////////////////////////////
//1)CVS version of TLegend.cxx
////////////////////////////////////////////////////////////////////
      if ( opt.Contains("f") && !opt.Contains("l")) {
        // box total height is yspace*0.7
        Double_t boxwidth = yspace*
          (gPad->GetX2()-gPad->GetX1())/(gPad->GetY2()-gPad->GetY1());
        if ( boxwidth > margin ) boxwidth = margin;

        entryline.PaintLine( xsym - boxwidth, ysym + yspace*0.35,
                             xsym + boxwidth, ysym + yspace*0.35);
        entryline.PaintLine( xsym - boxwidth, ysym - yspace*0.35,
                             xsym + boxwidth, ysym - yspace*0.35);
        entryline.PaintLine( xsym + boxwidth, ysym - yspace*0.35,
                             xsym + boxwidth, ysym + yspace*0.35);
        entryline.PaintLine( xsym - boxwidth, ysym - yspace*0.35,
                             xsym - boxwidth, ysym + yspace*0.35);
      } else {
         entryline.Paint();
      }
////////////////////////////////////////////////////////////////////
//2)Corrected by me
////////////////////////////////////////////////////////////////////

      if ( opt.Contains("f") && !opt.Contains("l")) {
        // box total height is yspace*0.7
        Double_t boxwidth = yspace*
          (gPad->GetX2()-gPad->GetX1())/(gPad->GetY2()-gPad->GetY1());
        if ( boxwidth > margin ) boxwidth = margin;

        entryline.PaintLine( xsym - boxwidth*0.35, ysym + yspace*0.35,
                             xsym + boxwidth*0.35, ysym + yspace*0.35);
        entryline.PaintLine( xsym - boxwidth*0.35, ysym - yspace*0.35,
                             xsym + boxwidth*0.35, ysym - yspace*0.35);
        entryline.PaintLine( xsym + boxwidth*0.35, ysym - yspace*0.35,
                             xsym + boxwidth*0.35, ysym + yspace*0.35);
        entryline.PaintLine( xsym - boxwidth*0.35, ysym - yspace*0.35,
                             xsym - boxwidth*0.35, ysym + yspace*0.35);
      } else {
         entryline.Paint();
      }
////////////////////////////////////////////////////////////////////
//A simple script used for the check was listed below.
////////////////////////////////////////////////////////////////////
{
gROOT->SetStyle("Plain");
TH1F *h=new TH1F("h"," ",5,0,5);
h->SetFillStyle(3004);
h->SetFillColor(1);
h->Fill(3);
h->Draw();
TLegend *leg=new TLegend(0.2,0.2,0.4,0.4);
leg->AddEntry(h,"test","f");
leg->Draw();
}  



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET