253 const char *header,
Option_t *option)
254 :
TPave(x1,y1,x2,y2,4,option),
TAttText(12,0,1,
gStyle->GetLegendFont(),0)
257 if ( header && strlen(header) > 0) {
287 :
TPave(w,h,w,h,4,option),
TAttText(12,0,1,
gStyle->GetLegendFont(),0)
290 if ( header && strlen(header) > 0) {
318 ((
TLegend&)legend).Copy(*
this);
361 const char *lab = label;
363 if (obj && (!label || strlen(label)==0)) lab = obj->
GetTitle();
385 Error(
"AddEntry",
"need to create a canvas first");
394 TList *lop =
gPad->GetListOfPrimitives();
398 while( (o=next()) ) {
413 return AddEntry( obj, label, option );
444 if ( !entry )
return;
463 if ( !entry )
return;
464 gROOT->SetSelectedPrimitive( entry );
474 if ( !entry )
return;
475 gROOT->SetSelectedPrimitive( entry );
485 if ( !entry )
return;
486 gROOT->SetSelectedPrimitive( entry );
496 if ( !entry )
return;
497 gROOT->SetSelectedPrimitive( entry );
508 Error(
"GetEntry",
"need to create a canvas first");
513 if ( nRows == 0 )
return 0;
521 if (nColumns > 0) xspace = (
fX2 -
fX1)/nColumns;
524 if (xspace > 0.) ix = (
Int_t)(xmouse/xspace)+1;
525 if (ix > nColumns) ix = nColumns;
529 if (iy > nRows) iy = nRows;
565 Error(
"InsertEntry",
"need to create a canvas first");
595 Warning(
"Paint",
"Legend to large to be automatically placed. A default position is used");
616 if ( nEntries == 0 )
return 0;
635 Warning(
"TLegend::SetNColumns",
"illegal value nColumns = %d; keeping fNColumns = %d", nColumns,
fNColumns);
647 if ( nRows == 0 )
return;
673 if ( textsize == 0 ) {
678 Double_t maxentrywidth = 0, maxentryheight = 0;
687 if (tfont%10 == 3) --tfont;
688 entrytex.SetTextFont(tfont);
689 entrytex.SetTextSize(textsize);
690 if ( entrytex.GetYsize() > maxentryheight ) {
691 maxentryheight = entrytex.GetYsize();
696 if ( entrytex.GetXsize() > maxentrywidth ) {
697 maxentrywidth = entrytex.GetXsize();
700 if ( entrytex.GetXsize() > columnWidths[iColumn] ) {
701 columnWidths[iColumn] = entrytex.GetXsize();
707 for(
int i=0; i<
fNColumns; i++) tmpMaxWidth += columnWidths[i];
708 if ( tmpMaxWidth > maxentrywidth) maxentrywidth = tmpMaxWidth;
732 if (autosize && tfont%10 == 3) --tfont;
733 entrytex.SetTextFont(tfont);
734 if(entry->
GetTextSize() == 0) entrytex.SetTextSize(textsize);
738 if ( entrytex.GetXsize() > columnWidths[iColumn] ) {
739 columnWidths[iColumn] = entrytex.GetXsize();
745 double totalWidth = 0.0;
746 for(
int i=0; i<
fNColumns; i++) totalWidth += columnWidths[i];
748 else totalWidth /= (1.0 -
fMargin);
750 columnWidths[i] = columnWidths[i]/totalWidth*(x2-
x1) + margin;
761 if(iColumn == 0) ytext -= yspace;
776 if (autosize && tfont%10 == 3) --tfont;
789 if ( opt.
Contains(
"h") ) entrymargin = margin/10.;
792 x2 = x1 + columnWidths[iColumn];
796 if (halign == 1) x = x1 + entrymargin;
797 if (halign == 2) x = 0.5*( (x1+entrymargin) + x2 );
798 if (halign == 3) x = x2 - entrymargin/10.;
808 if (tfont%10 == 3) tsizepad = (
gPad->AbsPixeltoY(0) -
gPad->AbsPixeltoY(textsize))/(
gPad->GetY2() -
gPad->GetY1());
809 if (yspace2 < tsizepad) {
819 entry->TAttText::Copy(entrytex);
844 if (eobjopt.
Contains(
"z")) endcaps = 0;
845 if (eobjopt.
Contains(
">")) endcaps = 2;
846 if (eobjopt.
Contains(
"|>")) endcaps = 3;
858 entry->TAttFill::Modify();
861 yf[0] = ysym - yspace*0.35;
865 yf[2] = ysym + yspace*0.35;
868 for (
Int_t i=0;i<4;i++) {
869 xf[i] =
gPad->GetX1() + xf[i]*(
gPad->GetX2()-
gPad->GetX1());
870 yf[i] =
gPad->GetY1() + yf[i]*(
gPad->GetY2()-
gPad->GetY1());
872 gPad->PaintFillArea(4,xf,yf);
878 TMarker entrymarker( xsym, ysym, 0 );
885 entry->TAttMarker::Copy(entrymarker);
897 TLine entryline( xsym - boxw, ysym, xsym + boxw, ysym );
899 entry->TAttLine::Copy(entryline);
905 if ( boxwidth > margin ) boxwidth = margin;
907 entryline.
PaintLineNDC( xsym - boxw, ysym + yspace*0.35,
908 xsym + boxw, ysym + yspace*0.35);
909 entryline.
PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
910 xsym + boxw, ysym - yspace*0.35);
911 entryline.
PaintLineNDC( xsym + boxw, ysym - yspace*0.35,
912 xsym + boxw, ysym + yspace*0.35);
913 entryline.
PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
914 xsym - boxw, ysym + yspace*0.35);
920 xsym, ysym + yspace*0.30);
923 TLine entryline1(xsym, ysym + sy, xsym, ysym + yspace*0.30);
925 entry->TAttLine::Copy(entryline1);
927 TLine entryline2(xsym, ysym - sy, xsym, ysym - yspace*0.30);
929 entry->TAttLine::Copy(entryline2);
933 TLine entrytop1(xsym-boxw*0.15, ysym + yspace*0.30, xsym+boxw*0.15, ysym + yspace*0.30);
935 entry->TAttLine::Copy(entrytop1);
937 TLine entrytop2(xsym-boxw*0.15, ysym - yspace*0.30, xsym+boxw*0.15, ysym - yspace*0.30);
939 entry->TAttLine::Copy(entrytop2);
941 }
else if (endcaps == 2) {
942 Double_t xe1[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
943 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
946 entry->TAttLine::Copy(ple1);
948 Double_t xe2[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
949 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
952 entry->TAttLine::Copy(ple2);
953 }
else if (endcaps == 3) {
954 Double_t xe1[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
955 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
956 Double_t xe2[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
957 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
958 for (
Int_t i=0;i<3;i++) {
959 xe1[i] =
gPad->GetX1() + xe1[i]*(
gPad->GetX2()-
gPad->GetX1());
960 ye1[i] =
gPad->GetY1() + ye1[i]*(
gPad->GetY2()-
gPad->GetY1());
961 xe2[i] =
gPad->GetX1() + xe2[i]*(
gPad->GetX2()-
gPad->GetX1());
962 ye2[i] =
gPad->GetY1() + ye2[i]*(
gPad->GetY2()-
gPad->GetY1());
966 ple1.SetFillStyle(1001);
984 TLine entryline(xsym, ysym - yspace*0.30,
985 xsym, ysym + yspace*0.30);
987 entry->TAttLine::Copy(entryline);
991 TLine entryline1(xsym, ysym + sy, xsym, ysym + yspace*0.30);
993 entry->TAttLine::Copy(entryline1);
995 TLine entryline2(xsym, ysym - sy, xsym, ysym - yspace*0.30);
997 entry->TAttLine::Copy(entryline2);
1001 TLine entrytop1(xsym-boxw*0.15, ysym + yspace*0.30, xsym+boxw*0.15, ysym + yspace*0.30);
1003 entry->TAttLine::Copy(entrytop1);
1005 TLine entrytop2(xsym-boxw*0.15, ysym - yspace*0.30, xsym+boxw*0.15, ysym - yspace*0.30);
1007 entry->TAttLine::Copy(entrytop2);
1009 }
else if (endcaps == 2) {
1010 Double_t xe1[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
1011 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
1014 entry->TAttLine::Copy(ple1);
1016 Double_t xe2[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
1017 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
1020 entry->TAttLine::Copy(ple2);
1022 }
else if (endcaps == 3) {
1023 Double_t xe1[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
1024 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
1025 Double_t xe2[3] = {xsym-boxw*0.15, xsym ,xsym+boxw*0.15};
1026 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
1027 for (
Int_t i=0;i<3;i++) {
1028 xe1[i] =
gPad->GetX1() + xe1[i]*(
gPad->GetX2()-
gPad->GetX1());
1029 ye1[i] =
gPad->GetY1() + ye1[i]*(
gPad->GetY2()-
gPad->GetY1());
1030 xe2[i] =
gPad->GetX1() + xe2[i]*(
gPad->GetX2()-
gPad->GetX1());
1031 ye2[i] =
gPad->GetY1() + ye2[i]*(
gPad->GetY2()-
gPad->GetY1());
1035 ple1.SetFillStyle(1001);
1048 delete [] columnWidths;
1079 out <<
" " << std::endl;
1084 out <<
" TLegend *";
1089 <<
"NULL" <<
"," <<quote<<
fOption <<quote<<
");" << std::endl;
1091 out<<
" leg->SetBorderSize("<<
fBorderSize<<
");"<<std::endl;
1101 out <<
" leg->Draw();"<<std::endl;
1110 if ( entry ) entry->
SetLabel( label );
1119 if ( entry ) entry->
SetOption( option );
virtual void Clear(Option_t *option="")
Clear all entries in this legend, including the header.
Style_t GetLegendFont() const
TBox & operator=(const TBox &)
Assignment operator.
virtual void SetLineAttributes()
Invoke the DialogCanvas Line attributes.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void Print(Option_t *option="") const
Dump this pave with its attributes.
virtual void SetFillAttributes()
Invoke the DialogCanvas Fill attributes.
Int_t fNColumns
Number of columns in the legend.
This class displays a legend box (TPaveText) containing several legend entries.
The Histogram stack class.
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
virtual Color_t GetTextColor() const
Return the text color.
virtual Short_t GetTextAlign() const
Return the text alignment.
virtual void EditEntryAttFill()
Edit the fill attributes for the entry pointed by the mouse.
R__EXTERN TStyle * gStyle
virtual void Draw(Option_t *option="")
Draw this legend with its current attributes.
Color_t GetLegendFillColor() const
virtual Float_t GetTextAngle() const
Return the text angle.
Double_t fY2
Y of 2nd point.
TLegend & operator=(const TLegend &)
Assignment operator.
virtual void EditEntryAttText()
Edit the text attributes for the entry pointed by the mouse.
A TMultiGraph is a collection of TGraph (or derived) objects.
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Storage class for one entry of a TLegend.
virtual void SetTextAttributes()
Invoke the DialogCanvas Text attributes.
virtual void EditEntryAttMarker()
Edit the marker attributes for the entry pointed by the mouse.
void Copy(TObject &pave) const
Copy this pave to pave.
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
Short_t Min(Short_t a, Short_t b)
void ToLower()
Change string to lower-case.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
virtual void SaveEntry(std::ostream &out, const char *name)
Save this TLegendEntry as C++ statements on output stream out to be used with the SaveAs ...
Width_t GetLegendBorderSize() const
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
virtual void DeleteEntry()
Delete entry at the mouse position.
Double_t GetLegendTextSize() const
virtual void SetEntryLabel(const char *label)
Edit the label of the entry pointed to by the mouse.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
A TBox with a bordersize and a shadow option.
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Double_t fY1
Y of 1st point.
virtual Style_t GetMarkerStyle() const
Return the marker style.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
virtual void Print(Option_t *option="") const
Dump this TLegend and its contents.
static const double x2[5]
virtual void PaintLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2)
Draw this line with new coordinates in NDC.
virtual void SetObject(TObject *obj)
(re)set the obj pointed to by this entry
Fill Area Attributes class.
Int_t GetNColumns() const
Double_t fX1NDC
X1 point in NDC coordinates.
virtual void SaveLineAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t widdef=1)
Save line attributes as C++ statement(s) on output stream out.
virtual Float_t GetTextSize() const
Return the text size.
virtual void InsertEntry(const char *objectName="", const char *label="", Option_t *option="lpf")
Add a new entry before the entry at the mouse position.
To draw Mathematical Formula.
virtual const char * GetHeader() const
Returns the header, which is the title that appears at the top of the legend.
virtual Option_t * GetOption() const
virtual Size_t GetMarkerSize() const
Return the marker size.
virtual void Paint(Option_t *option="")
Paint this line with its current attributes.
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save this legend as C++ statements on output stream out to be used with the SaveAs ...
TLegendEntry * GetEntry() const
Get entry pointed to by the mouse.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
virtual void SetLabel(const char *label="")
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
virtual void Paint(Option_t *option="")
Paint this marker with its current attributes.
virtual void EditEntryAttLine()
Edit the line attributes for the entry pointed by the mouse.
Double_t GetX1NDC() const
void SetNColumns(Int_t nColumns)
Set the number of columns for the legend.
virtual void SaveTextAttributes(std::ostream &out, const char *name, Int_t alidef=12, Float_t angdef=0, Int_t coldef=1, Int_t fondef=61, Float_t sizdef=1)
Save text attributes as C++ statement(s) on output stream out.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Float_t fColumnSeparation
Separation between columns, as a fraction of The space allowed to one column.
virtual Font_t GetTextFont() const
Return the text font.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
Int_t GetNRows() const
Get the number of rows.
Double_t fX2
X of 2nd point.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
virtual TObject * GetObject() const
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void SetOption(Option_t *option="lpf")
Double_t fX1
X of 1st point.
TLegend()
Default constructor.
Double_t GetY1NDC() const
virtual void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Int_t fBorderSize
window box bordersize in pixels
Float_t fEntrySeparation
Separation between entries, as a fraction of The space allocated to one entry.
Double_t GetY2NDC() const
virtual Color_t GetLineColor() const
Return the line color.
virtual const char * GetLabel() const
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Double_t fY2NDC
Y2 point in NDC coordinates.
static const double x1[5]
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
Double_t GetX2NDC() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
virtual void RecursiveRemove(TObject *obj)
Reset the legend entries pointing to "obj".
Double_t fX2NDC
X2 point in NDC coordinates.
Binding & operator=(OUT(*fun)(void))
Mother of all ROOT objects.
TList * fPrimitives
List of TLegendEntries.
Float_t fMargin
Fraction of total width used for symbol.
virtual const char * GetTitle() const
Returns title of object.
virtual ~TLegend()
Default destructor.
virtual void Add(TObject *obj)
Double_t Ceil(Double_t x)
Defined by an array on N points in a 2-D space.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void Paint(Option_t *option="")
Paint this polyline with its current attributes.
Double_t fY1NDC
Y1 point in NDC coordinates.
virtual void Paint(Option_t *option="")
Paint this legend with its current attributes.
virtual void PaintPave(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Int_t bordersize=4, Option_t *option="br")
Draw this pave with new coordinates.
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
TString fOption
Pave style.
virtual Int_t GetSize() const
virtual void Copy(TObject &obj) const
Copy this legend into "obj".
virtual void SetBorderSize(Int_t bordersize=4)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void PaintPrimitives()
Paint the entries (list of primitives) for this legend.
virtual void SetEntryOption(Option_t *option)
Edit the option of the entry pointed to by the mouse.
Int_t GetBorderSize() const
virtual void SetHeader(const char *header="", Option_t *option="")
Sets the header, which is the "title" that appears at the top of the legend.