200 TLegend::TLegend(): TPave(0.3,0.15,0.3,0.15,4,
"brNDC"),
201 TAttText(12,0,1,gStyle->GetLegendFont(),0)
205 SetBorderSize(gStyle->GetLegendBorderSize());
206 SetFillColor(gStyle->GetLegendFillColor());
223 TLegend::TLegend( Double_t x1, Double_t y1,Double_t x2, Double_t y2,
224 const char *header, Option_t *option)
225 :TPave(x1,y1,x2,y2,4,option), TAttText(12,0,1,gStyle->GetLegendFont(),0)
227 fPrimitives =
new TList;
228 if ( header && strlen(header) > 0) {
229 TLegendEntry *headerEntry =
new TLegendEntry( 0, header,
"h" );
230 headerEntry->SetTextAlign(0);
231 headerEntry->SetTextAngle(0);
232 headerEntry->SetTextColor(0);
233 headerEntry->SetTextFont(gStyle->GetLegendFont());
234 headerEntry->SetTextSize(0);
235 fPrimitives->AddFirst(headerEntry);
238 SetBorderSize(gStyle->GetLegendBorderSize());
239 SetFillColor(gStyle->GetLegendFillColor());
257 TLegend::TLegend( Double_t w, Double_t h,
const char *header, Option_t *option)
258 :TPave(w,h,w,h,4,option), TAttText(12,0,1,gStyle->GetLegendFont(),0)
260 fPrimitives =
new TList;
261 if ( header && strlen(header) > 0) {
262 TLegendEntry *headerEntry =
new TLegendEntry( 0, header,
"h" );
263 headerEntry->SetTextAlign(0);
264 headerEntry->SetTextAngle(0);
265 headerEntry->SetTextColor(0);
266 headerEntry->SetTextFont(gStyle->GetLegendFont());
267 headerEntry->SetTextSize(0);
268 fPrimitives->AddFirst(headerEntry);
271 SetBorderSize(gStyle->GetLegendBorderSize());
272 SetFillColor(gStyle->GetLegendFillColor());
278 TLegend::TLegend(
const TLegend &legend ) : TPave(legend), TAttText(legend),
281 if (legend.fPrimitives) {
282 fPrimitives =
new TList();
283 TListIter it(legend.fPrimitives);
284 while (TLegendEntry *e = (TLegendEntry *)it.Next()) {
285 TLegendEntry *newentry =
new TLegendEntry(*e);
286 fPrimitives->Add(newentry);
289 ((TLegend&)legend).Copy(*
this);
295 TLegend& TLegend::operator=(
const TLegend &lg)
298 TPave::operator=(lg);
299 TAttText::operator=(lg);
300 fPrimitives=lg.fPrimitives;
301 fEntrySeparation=lg.fEntrySeparation;
303 fNColumns=lg.fNColumns;
313 if (fPrimitives) fPrimitives->Delete();
330 TLegendEntry *TLegend::AddEntry(
const TObject *obj,
const char *label, Option_t *option)
332 const char *lab = label;
334 if (obj && (!label || strlen(label)==0)) lab = obj->GetTitle();
335 TLegendEntry *newentry =
new TLegendEntry( obj, lab, option );
336 if ( !fPrimitives ) fPrimitives =
new TList;
337 fPrimitives->Add(newentry);
353 TLegendEntry *TLegend::AddEntry(
const char *name,
const char *label, Option_t *option)
356 Error(
"AddEntry",
"need to create a canvas first");
360 TObject *obj = gPad->FindObject(name);
365 TList *lop = gPad->GetListOfPrimitives();
369 while( (o=next()) ) {
370 if ( o->InheritsFrom(TMultiGraph::Class() ) ) {
371 TList * grlist = ((TMultiGraph *)o)->GetListOfGraphs();
372 obj = grlist->FindObject(name);
375 if ( o->InheritsFrom(THStack::Class() ) ) {
376 TList * hlist = ((THStack *)o)->GetHists();
377 obj = hlist->FindObject(name);
384 return AddEntry( obj, label, option );
390 void TLegend::Clear( Option_t *)
392 if (!fPrimitives)
return;
393 fPrimitives->Delete();
399 void TLegend::Copy( TObject &obj )
const
402 TAttText::Copy((TLegend&)obj);
403 ((TLegend&)obj).fEntrySeparation = fEntrySeparation;
404 ((TLegend&)obj).fMargin = fMargin;
405 ((TLegend&)obj).fNColumns = fNColumns;
411 void TLegend::DeleteEntry()
413 if ( !fPrimitives )
return;
414 TLegendEntry* entry = GetEntry();
415 if ( !entry )
return;
416 fPrimitives->Remove(entry);
423 void TLegend::Draw( Option_t *option )
431 void TLegend::EditEntryAttFill()
433 TLegendEntry* entry = GetEntry();
434 if ( !entry )
return;
435 gROOT->SetSelectedPrimitive( entry );
436 entry->SetFillAttributes();
442 void TLegend::EditEntryAttLine()
444 TLegendEntry* entry = GetEntry();
445 if ( !entry )
return;
446 gROOT->SetSelectedPrimitive( entry );
447 entry->SetLineAttributes();
453 void TLegend::EditEntryAttMarker()
455 TLegendEntry* entry = GetEntry();
456 if ( !entry )
return;
457 gROOT->SetSelectedPrimitive( entry );
458 entry->SetMarkerAttributes();
464 void TLegend::EditEntryAttText()
466 TLegendEntry* entry = GetEntry();
467 if ( !entry )
return;
468 gROOT->SetSelectedPrimitive( entry );
469 entry->SetTextAttributes();
476 TLegendEntry *TLegend::GetEntry()
const
479 Error(
"GetEntry",
"need to create a canvas first");
483 Int_t nRows = GetNRows();
484 if ( nRows == 0 )
return 0;
486 Double_t ymouse = gPad->AbsPixeltoY(gPad->GetEventY())-fY1;
487 Double_t yspace = (fY2 - fY1)/nRows;
489 Int_t nColumns = GetNColumns();
490 Double_t xmouse = gPad->AbsPixeltoX(gPad->GetEventX())-fX1;
491 Double_t xspace = 0.;
492 if (nColumns > 0) xspace = (fX2 - fX1)/nColumns;
495 if (xspace > 0.) ix = (Int_t)(xmouse/xspace)+1;
496 if (ix > nColumns) ix = nColumns;
499 Int_t iy = nRows-(Int_t)(ymouse/yspace);
500 if (iy > nRows) iy = nRows;
503 Int_t nloops = TMath::Min(ix+(nColumns*(iy-1)), fPrimitives->GetSize());
505 TIter next(fPrimitives);
506 TLegendEntry *entry = 0;
508 for (Int_t i=1; i<= nloops; i++) entry = (TLegendEntry *)next();
517 const char *TLegend::GetHeader()
const
519 if ( !fPrimitives )
return 0;
520 TIter next(fPrimitives);
522 if (( first = (TLegendEntry*)next() )) {
523 TString opt = first->GetOption();
525 if ( opt.Contains(
"h") )
return first->GetLabel();
533 void TLegend::InsertEntry(
const char* objectName,
const char* label, Option_t* option)
536 Error(
"InsertEntry",
"need to create a canvas first");
540 TLegendEntry* beforeEntry = GetEntry();
541 TObject *obj = gPad->FindObject( objectName );
545 TLegendEntry *newentry =
new TLegendEntry( obj, label, option );
547 if ( !fPrimitives ) fPrimitives =
new TList;
549 fPrimitives->AddBefore( (TObject*)beforeEntry, (TObject*)newentry );
551 fPrimitives->Add((TObject*)newentry);
558 void TLegend::Paint( Option_t* option )
561 if (fX1 == fX2 && fY1 == fY2) {
562 if (gPad->PlaceBox(
this, fX1, fY1, fX1, fY1)) {
566 Warning(
"Paint",
"Legend to large to be automatically placed. A default position is used");
575 TPave::ConvertNDCtoPad();
576 TPave::PaintPave(fX1,fY1,fX2,fY2,GetBorderSize(),option);
583 Int_t TLegend::GetNRows()
const
586 if ( fPrimitives ) nEntries = fPrimitives->GetSize();
587 if ( nEntries == 0 )
return 0;
590 if(GetHeader() != NULL) nRows = 1 + (Int_t) TMath::Ceil((Double_t) (nEntries-1)/fNColumns);
591 else nRows = (Int_t) TMath::Ceil((Double_t) nEntries/fNColumns);
603 void TLegend::SetNColumns(Int_t nColumns)
606 Warning(
"TLegend::SetNColumns",
"illegal value nColumns = %d; keeping fNColumns = %d", nColumns, fNColumns);
609 fNColumns = nColumns;
615 void TLegend::PaintPrimitives()
617 Int_t nRows = GetNRows();
618 if ( nRows == 0 )
return;
625 Double_t x1 = fX1NDC;
626 Double_t y1 = fY1NDC;
627 Double_t x2 = fX2NDC;
628 Double_t y2 = fY2NDC;
629 Double_t margin = fMargin*( x2-x1 )/fNColumns;
630 Double_t boxwidth = margin;
631 Double_t boxw = boxwidth*0.35;
632 Double_t yspace = (y2-y1)/nRows;
633 Double_t yspace2 = yspace/2.;
634 Double_t textsize = GetTextSize();
635 Double_t save_textsize = textsize;
637 SetTextSize(gStyle->GetLegendTextSize());
638 textsize = GetTextSize();
640 Bool_t autosize = kFALSE;
641 Double_t* columnWidths =
new Double_t[fNColumns];
642 memset(columnWidths, 0, fNColumns*
sizeof(Double_t));
644 if ( textsize == 0 ) {
646 textsize = ( 1. - fEntrySeparation ) * yspace;
649 Double_t maxentrywidth = 0, maxentryheight = 0;
650 TIter nextsize(fPrimitives);
651 TLegendEntry *entrysize;
653 while (( entrysize = (TLegendEntry *)nextsize() )) {
654 TLatex entrytex( 0, 0, entrysize->GetLabel() );
656 Style_t tfont = entrysize->GetTextFont();
657 if (tfont == 0) tfont = GetTextFont();
658 if (tfont%10 == 3) --tfont;
659 entrytex.SetTextFont(tfont);
660 entrytex.SetTextSize(textsize);
661 if ( entrytex.GetYsize() > maxentryheight ) {
662 maxentryheight = entrytex.GetYsize();
664 TString opt = entrysize->GetOption();
666 if ( opt.Contains(
"h") ) {
667 if ( entrytex.GetXsize() > maxentrywidth ) {
668 maxentrywidth = entrytex.GetXsize();
671 if ( entrytex.GetXsize() > columnWidths[iColumn] ) {
672 columnWidths[iColumn] = entrytex.GetXsize();
675 iColumn %= fNColumns;
677 Double_t tmpMaxWidth = 0.0;
678 for(
int i=0; i<fNColumns; i++) tmpMaxWidth += columnWidths[i];
679 if ( tmpMaxWidth > maxentrywidth) maxentrywidth = tmpMaxWidth;
682 Double_t tmpsize_h = maxentryheight /(gPad->GetY2() - gPad->GetY1());
683 textsize = TMath::Min( textsize, tmpsize_h );
684 Double_t tmpsize_w = textsize*(fX2-fX1)*(1.0-fMargin)/maxentrywidth;
685 if(fNColumns > 1) tmpsize_w = textsize*(fX2-fX1)*(1.0-fMargin-fColumnSeparation)/maxentrywidth;
686 textsize = TMath::Min( textsize, tmpsize_w );
687 SetTextSize( textsize );
694 TIter next(fPrimitives);
697 memset(columnWidths, 0, fNColumns*
sizeof(Double_t));
698 while (( entry = (TLegendEntry *)next() )) {
699 TLatex entrytex( 0, 0, entry->GetLabel() );
701 Style_t tfont = entry->GetTextFont();
702 if (tfont == 0) tfont = GetTextFont();
703 if (autosize && tfont%10 == 3) --tfont;
704 entrytex.SetTextFont(tfont);
705 if(entry->GetTextSize() == 0) entrytex.SetTextSize(textsize);
706 TString opt = entry->GetOption();
708 if (!opt.Contains(
"h")) {
709 if ( entrytex.GetXsize() > columnWidths[iColumn] ) {
710 columnWidths[iColumn] = entrytex.GetXsize();
713 iColumn %= fNColumns;
716 double totalWidth = 0.0;
717 for(
int i=0; i<fNColumns; i++) totalWidth += columnWidths[i];
718 if(fNColumns > 1) totalWidth /= (1.0-fMargin-fColumnSeparation);
719 else totalWidth /= (1.0 - fMargin);
720 for(
int i=0; i<fNColumns; i++) {
721 columnWidths[i] = columnWidths[i]/totalWidth*(x2-x1) + margin;
725 Double_t ytext = y2 + 0.5*yspace;
728 TIter next(fPrimitives);
731 while (( entry = (TLegendEntry *)next() )) {
732 if(iColumn == 0) ytext -= yspace;
736 Short_t talign = entry->GetTextAlign();
737 Float_t tangle = entry->GetTextAngle();
738 Color_t tcolor = entry->GetTextColor();
739 Style_t tfont = entry->GetTextFont();
740 Size_t tsize = entry->GetTextSize();
742 if (talign == 0) entry->SetTextAlign(GetTextAlign());
743 if (tangle == 0) entry->SetTextAngle(GetTextAngle());
744 if (tcolor == 0) entry->SetTextColor(GetTextColor());
746 tfont = GetTextFont();
747 if (autosize && tfont%10 == 3) --tfont;
748 entry->SetTextFont(tfont);
750 if (tsize == 0) entry->SetTextSize(GetTextSize());
753 Int_t halign = entry->GetTextAlign()/10;
754 Double_t entrymargin = margin;
756 TString opt = entry->GetOption();
760 if ( opt.Contains(
"h") ) entrymargin = margin/10.;
761 else if (fNColumns > 1) {
762 for(
int i=0; i<iColumn; i++) x1 += columnWidths[i] + fColumnSeparation*(fX2NDC-fX1NDC)/(fNColumns-1);
763 x2 = x1 + columnWidths[iColumn];
765 iColumn %= fNColumns;
767 if (halign == 1) x = x1 + entrymargin;
768 if (halign == 2) x = 0.5*( (x1+entrymargin) + x2 );
769 if (halign == 3) x = x2 - entrymargin/10.;
770 Int_t valign = entry->GetTextAlign()%10;
772 if (valign == 1) y = ytext - (1. - fEntrySeparation)* yspace2;
773 if (valign == 3) y = ytext + (1. - fEntrySeparation)* yspace2;
778 Float_t tsizepad = textsize;
779 if (tfont%10 == 3) tsizepad = (gPad->AbsPixeltoY(0) - gPad->AbsPixeltoY(textsize))/(gPad->GetY2() - gPad->GetY1());
780 if (yspace2 < tsizepad) {
781 entry->SetTextAlign(10*halign+1);
782 y = ytext - (1. - fEntrySeparation)* yspace2/2.;
788 TLatex entrytex( x, y, entry->GetLabel() );
790 entry->TAttText::Copy(entrytex);
794 entry->SetTextAlign(talign);
795 entry->SetTextAngle(tangle);
796 entry->SetTextColor(tcolor);
797 entry->SetTextFont(tfont);
798 entry->SetTextSize(tsize);
801 Double_t xsym = x1 + margin/2.;
802 Double_t ysym = ytext;
804 TObject *eobj = entry->GetObject();
810 TString eobjopt = eobj->GetDrawOption();
812 if (eobjopt.Contains(
"e1") && eobj->InheritsFrom(TH1::Class())) endcaps = 1;
813 if (eobj->InheritsFrom(TGraph::Class())) {
815 if (eobjopt.Contains(
"z")) endcaps = 0;
816 if (eobjopt.Contains(
">")) endcaps = 2;
817 if (eobjopt.Contains(
"|>")) endcaps = 3;
823 if ( opt.Contains(
"f")) {
824 if (eobj && eobj->InheritsFrom(TAttFill::Class())) {
825 dynamic_cast<TAttFill*
>(eobj)->Copy(*entry);
829 entry->TAttFill::Modify();
830 Double_t xf[4],yf[4];
832 yf[0] = ysym - yspace*0.35;
836 yf[2] = ysym + yspace*0.35;
839 for (Int_t i=0;i<4;i++) {
840 xf[i] = gPad->GetX1() + xf[i]*(gPad->GetX2()-gPad->GetX1());
841 yf[i] = gPad->GetY1() + yf[i]*(gPad->GetY2()-gPad->GetY1());
843 gPad->PaintFillArea(4,xf,yf);
848 Double_t symbolsize = 0.;
849 TMarker entrymarker( xsym, ysym, 0 );
851 if ( opt.Contains(
"p")) {
852 if (eobj && eobj->InheritsFrom(TAttMarker::Class())) {
853 dynamic_cast<TAttMarker*
>(eobj)->Copy(*entry);
855 entrymarker.SetNDC();
856 entry->TAttMarker::Copy(entrymarker);
857 if (entrymarker.GetMarkerStyle() >= 5 ) symbolsize = entrymarker.GetMarkerSize();
862 if ( opt.Contains(
"l") || opt.Contains(
"f")) {
864 if (eobj && eobj->InheritsFrom(TAttLine::Class())) {
865 dynamic_cast<TAttLine*
>(eobj)->Copy(*entry);
868 TLine entryline( xsym - boxw, ysym, xsym + boxw, ysym );
869 entryline.SetBit(TLine::kLineNDC);
870 entry->TAttLine::Copy(entryline);
872 if ( opt.Contains(
"f") && !opt.Contains(
"l")) {
875 (gPad->GetX2()-gPad->GetX1())/(gPad->GetY2()-gPad->GetY1());
876 if ( boxwidth > margin ) boxwidth = margin;
878 entryline.PaintLineNDC( xsym - boxw, ysym + yspace*0.35,
879 xsym + boxw, ysym + yspace*0.35);
880 entryline.PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
881 xsym + boxw, ysym - yspace*0.35);
882 entryline.PaintLineNDC( xsym + boxw, ysym - yspace*0.35,
883 xsym + boxw, ysym + yspace*0.35);
884 entryline.PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
885 xsym - boxw, ysym + yspace*0.35);
888 if (opt.Contains(
"e")) {
889 if ( !opt.Contains(
"p")) {
890 entryline.PaintLineNDC( xsym, ysym - yspace*0.30,
891 xsym, ysym + yspace*0.30);
893 Double_t sy = (fY2NDC-fY1NDC)*((0.5*(gPad->PixeltoY(0) - gPad->PixeltoY(Int_t(symbolsize*8.))))/(fY2-fY1));
894 TLine entryline1(xsym, ysym + sy, xsym, ysym + yspace*0.30);
895 entryline1.SetBit(TLine::kLineNDC);
896 entry->TAttLine::Copy(entryline1);
898 TLine entryline2(xsym, ysym - sy, xsym, ysym - yspace*0.30);
899 entryline2.SetBit(TLine::kLineNDC);
900 entry->TAttLine::Copy(entryline2);
903 Double_t barw = boxw*0.1*gStyle->GetEndErrorSize();
905 TLine entrytop1(xsym-barw, ysym + yspace*0.30, xsym+barw, ysym + yspace*0.30);
906 entrytop1.SetBit(TLine::kLineNDC);
907 entry->TAttLine::Copy(entrytop1);
909 TLine entrytop2(xsym-barw, ysym - yspace*0.30, xsym+barw, ysym - yspace*0.30);
910 entrytop2.SetBit(TLine::kLineNDC);
911 entry->TAttLine::Copy(entrytop2);
913 }
else if (endcaps == 2) {
914 Double_t xe1[3] = {xsym-barw, xsym ,xsym+barw};
915 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
916 TPolyLine ple1(3,xe1,ye1);
917 ple1.SetBit(TLine::kLineNDC);
918 entry->TAttLine::Copy(ple1);
920 Double_t xe2[3] = {xsym-barw, xsym ,xsym+barw};
921 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
922 TPolyLine ple2(3,xe2,ye2);
923 ple2.SetBit(TLine::kLineNDC);
924 entry->TAttLine::Copy(ple2);
925 }
else if (endcaps == 3) {
926 Double_t xe1[3] = {xsym-barw, xsym ,xsym+barw};
927 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
928 Double_t xe2[3] = {xsym-barw, xsym ,xsym+barw};
929 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
930 for (Int_t i=0;i<3;i++) {
931 xe1[i] = gPad->GetX1() + xe1[i]*(gPad->GetX2()-gPad->GetX1());
932 ye1[i] = gPad->GetY1() + ye1[i]*(gPad->GetY2()-gPad->GetY1());
933 xe2[i] = gPad->GetX1() + xe2[i]*(gPad->GetX2()-gPad->GetX1());
934 ye2[i] = gPad->GetY1() + ye2[i]*(gPad->GetY2()-gPad->GetY1());
936 TPolyLine ple1(3,xe1,ye1);
937 ple1.SetFillColor(entry->GetLineColor());
938 ple1.SetFillStyle(1001);
940 TPolyLine ple2(3,xe2,ye2);
941 ple2.SetFillColor(entry->GetLineColor());
942 ple2.SetFillStyle(1001);
951 if (opt.Contains(
"e") && !(opt.Contains(
"l") || opt.Contains(
"f"))) {
952 if (eobj && eobj->InheritsFrom(TAttLine::Class())) {
953 dynamic_cast<TAttLine*
>(eobj)->Copy(*entry);
955 if ( !opt.Contains(
"p")) {
956 TLine entryline(xsym, ysym - yspace*0.30,
957 xsym, ysym + yspace*0.30);
958 entryline.SetBit(TLine::kLineNDC);
959 entry->TAttLine::Copy(entryline);
962 Double_t sy = (fY2NDC-fY1NDC)*((0.5*(gPad->PixeltoY(0) - gPad->PixeltoY(Int_t(symbolsize*8.))))/(fY2-fY1));
963 TLine entryline1(xsym, ysym + sy, xsym, ysym + yspace*0.30);
964 entryline1.SetBit(TLine::kLineNDC);
965 entry->TAttLine::Copy(entryline1);
967 TLine entryline2(xsym, ysym - sy, xsym, ysym - yspace*0.30);
968 entryline2.SetBit(TLine::kLineNDC);
969 entry->TAttLine::Copy(entryline2);
972 Double_t barw = boxw*0.1*gStyle->GetEndErrorSize();
974 TLine entrytop1(xsym-barw, ysym + yspace*0.30, xsym+barw, ysym + yspace*0.30);
975 entrytop1.SetBit(TLine::kLineNDC);
976 entry->TAttLine::Copy(entrytop1);
978 TLine entrytop2(xsym-barw, ysym - yspace*0.30, xsym+barw, ysym - yspace*0.30);
979 entrytop2.SetBit(TLine::kLineNDC);
980 entry->TAttLine::Copy(entrytop2);
982 }
else if (endcaps == 2) {
983 Double_t xe1[3] = {xsym-barw, xsym ,xsym+barw};
984 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
985 TPolyLine ple1(3,xe1,ye1);
986 ple1.SetBit(TLine::kLineNDC);
987 entry->TAttLine::Copy(ple1);
989 Double_t xe2[3] = {xsym-barw, xsym ,xsym+barw};
990 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
991 TPolyLine ple2(3,xe2,ye2);
992 ple2.SetBit(TLine::kLineNDC);
993 entry->TAttLine::Copy(ple2);
995 }
else if (endcaps == 3) {
996 Double_t xe1[3] = {xsym-barw, xsym ,xsym+barw};
997 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
998 Double_t xe2[3] = {xsym-barw, xsym ,xsym+barw};
999 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
1000 for (Int_t i=0;i<3;i++) {
1001 xe1[i] = gPad->GetX1() + xe1[i]*(gPad->GetX2()-gPad->GetX1());
1002 ye1[i] = gPad->GetY1() + ye1[i]*(gPad->GetY2()-gPad->GetY1());
1003 xe2[i] = gPad->GetX1() + xe2[i]*(gPad->GetX2()-gPad->GetX1());
1004 ye2[i] = gPad->GetY1() + ye2[i]*(gPad->GetY2()-gPad->GetY1());
1006 TPolyLine ple1(3,xe1,ye1);
1007 ple1.SetFillColor(entry->GetLineColor());
1008 ple1.SetFillStyle(1001);
1010 TPolyLine ple2(3,xe2,ye2);
1011 ple2.SetFillColor(entry->GetLineColor());
1012 ple2.SetFillStyle(1001);
1018 if ( opt.Contains(
"p")) entrymarker.Paint();
1020 SetTextSize(save_textsize);
1021 delete [] columnWidths;
1027 void TLegend::Print( Option_t* option )
const
1029 TPave::Print( option );
1030 if (fPrimitives) fPrimitives->Print();
1036 void TLegend::RecursiveRemove(TObject *obj)
1038 TIter next(fPrimitives);
1039 TLegendEntry *entry;
1040 while (( entry = (TLegendEntry *)next() )) {
1041 if (entry->GetObject() == obj) entry->SetObject((TObject*)0);
1049 void TLegend::SavePrimitive(std::ostream &out, Option_t* )
1052 out <<
" " << std::endl;
1054 if ( gROOT->ClassSaved( TLegend::Class() ) ) {
1057 out <<
" TLegend *";
1060 out <<
"leg = new TLegend("<<GetX1NDC()<<
","<<GetY1NDC()<<
","
1061 <<GetX2NDC()<<
","<<GetY2NDC()<<
","
1062 <<
"NULL" <<
"," <<quote<< fOption <<quote<<
");" << std::endl;
1063 if (fBorderSize != 4) {
1064 out<<
" leg->SetBorderSize("<<fBorderSize<<
");"<<std::endl;
1066 SaveTextAttributes(out,
"leg",12,0,1,42,0);
1067 SaveLineAttributes(out,
"leg",-1,-1,-1);
1068 SaveFillAttributes(out,
"leg",-1,-1);
1069 if ( fPrimitives ) {
1070 TIter next(fPrimitives);
1071 TLegendEntry *entry;
1072 while (( entry = (TLegendEntry *)next() )) entry->SaveEntry(out,
"leg");
1074 out <<
" leg->Draw();"<<std::endl;
1080 void TLegend::SetEntryLabel(
const char* label )
1082 TLegendEntry* entry = GetEntry();
1083 if ( entry ) entry->SetLabel( label );
1089 void TLegend::SetEntryOption( Option_t* option )
1091 TLegendEntry* entry = GetEntry();
1092 if ( entry ) entry->SetOption( option );
1099 void TLegend::SetHeader(
const char *header, Option_t* option )
1103 if ( !fPrimitives ) fPrimitives =
new TList;
1104 TIter next(fPrimitives);
1105 TLegendEntry *first;
1106 if (( first = (TLegendEntry*)next() )) {
1107 opt = first->GetOption();
1109 if ( opt.Contains(
"h") ) {
1110 first->SetLabel(header);
1113 if ( opt.Contains(
"c") ) first->SetTextAlign(22);
1114 else first->SetTextAlign(0);
1118 first =
new TLegendEntry( 0, header,
"h" );
1121 if ( opt.Contains(
"c") ) first->SetTextAlign(22);
1122 else first->SetTextAlign(0);
1123 first->SetTextAngle(0);
1124 first->SetTextColor(0);
1125 first->SetTextFont(GetTextFont());
1126 first->SetTextSize(0);
1127 fPrimitives->AddFirst((TObject*)first);