225 :
TPave(
x1,
y1,
x2,
y2,4,
option),
TAttText(12,0,1,
gStyle->GetLegendFont(),0)
228 if (header && strlen(header) > 0) {
258 :
TPave(
w,
h,
w,
h,4,
option),
TAttText(12,0,1,
gStyle->GetLegendFont(),0)
261 if (header && strlen(header) > 0) {
281 legend.TLegend::Copy(*
this);
290 lg.TLegend::Copy(*
this);
319 const char *lab = label;
321 if (obj && (!label || strlen(label)==0)) lab = obj->
GetTitle();
343 Error(
"AddEntry",
"need to create a canvas first");
352 TList *lop =
gPad->GetListOfPrimitives();
355 while(
auto o = next()) {
387 auto &tgt =
static_cast<TLegend &
> (obj);
394 if (tgt.fPrimitives) {
395 tgt.fPrimitives->Delete();
396 delete tgt.fPrimitives;
397 tgt.fPrimitives =
nullptr;
400 tgt.fPrimitives =
new TList();
414 if ( !entry )
return;
433 if ( !entry )
return;
434 gROOT->SetSelectedPrimitive( entry );
444 if ( !entry )
return;
445 gROOT->SetSelectedPrimitive( entry );
455 if ( !entry )
return;
456 gROOT->SetSelectedPrimitive( entry );
466 if ( !entry )
return;
467 gROOT->SetSelectedPrimitive( entry );
478 Error(
"GetEntry",
"need to create a canvas first");
492 if (nColumns > 0) xspace = (
fX2 -
fX1)/nColumns;
495 if (xspace > 0.) ix = (
Int_t)(xmouse/xspace)+1;
496 if (ix > nColumns) ix = nColumns;
500 if (iy > nRows) iy = nRows;
508 for (
Int_t i=1; i<= nloops; i++)
523 TString opt = first->GetOption();
525 if ( opt.
Contains(
"h") )
return first->GetLabel();
536 Error(
"InsertEntry",
"need to create a canvas first");
566 Warning(
"Paint",
"Legend too large to be automatically placed; a default position is used");
587 if ( nEntries == 0 )
return 0;
606 Warning(
"TLegend::SetNColumns",
"illegal value nColumns = %d; keeping fNColumns = %d", nColumns,
fNColumns);
618 if ( nRows == 0 )
return;
641 std::vector<Double_t> columnWidths(
fNColumns, 0.);
648 Double_t maxentrywidth = 0, maxentryheight = 0;
657 if (tfont%10 == 3) --tfont;
660 if ( entrytex.
GetYsize() > maxentryheight ) {
661 maxentryheight = entrytex.
GetYsize();
666 if ( entrytex.
GetXsize() > maxentrywidth ) {
667 maxentrywidth = entrytex.
GetXsize();
670 if ( entrytex.
GetXsize() > columnWidths[iColumn] ) {
671 columnWidths[iColumn] = entrytex.
GetXsize();
677 for(
int i=0; i<
fNColumns; i++) tmpMaxWidth += columnWidths[i];
678 if ( tmpMaxWidth > maxentrywidth) maxentrywidth = tmpMaxWidth;
696 columnWidths[k] = 0.;
698 TLatex entrytex( 0, 0, entry->GetLabel() );
700 Style_t tfont = entry->GetTextFont();
702 if (autosize && tfont%10 == 3) --tfont;
705 TString opt = entry->GetOption();
708 if ( entrytex.
GetXsize() > columnWidths[iColumn] ) {
709 columnWidths[iColumn] = entrytex.
GetXsize();
715 double totalWidth = 0.0;
716 for(
int i=0; i<
fNColumns; i++) totalWidth += columnWidths[i];
718 else totalWidth /= (1.0 -
fMargin);
720 columnWidths[i] = columnWidths[i]/totalWidth*(
x2-
x1) + margin;
731 if(iColumn == 0) ytext -= yspace;
746 if (autosize && tfont%10 == 3) --tfont;
759 if ( opt.
Contains(
"h") ) entrymargin = margin/10.;
762 x2 =
x1 + columnWidths[iColumn];
766 if (halign == 1)
x =
x1 + entrymargin;
767 if (halign == 2)
x = 0.5*( (
x1+entrymargin) +
x2 );
768 if (halign == 3)
x =
x2 - entrymargin/10.;
779 if (yspace2 < tsizepad) {
789 entry->TAttText::Copy(entrytex);
814 if (eobjopt.
Contains(
"z")) endcaps = 0;
815 if (eobjopt.
Contains(
">")) endcaps = 2;
816 if (eobjopt.
Contains(
"|>")) endcaps = 3;
819 float arrow_shift = 0.3;
820 if (endcaps == 3) arrow_shift = 0.2;
840 entry->TAttFill::Modify();
843 yf[0] = ysym - wl*yspace*0.35;
847 yf[2] = ysym + wu*yspace*0.35;
850 for (
Int_t i=0;i<4;i++) {
851 xf[i] =
gPad->GetX1() + xf[i]*(
gPad->GetX2()-
gPad->GetX1());
852 yf[i] =
gPad->GetY1() + yf[i]*(
gPad->GetY2()-
gPad->GetY1());
854 gPad->PaintFillArea(4,xf,yf);
860 TMarker entrymarker( xsym, ysym, 0 );
867 entry->TAttMarker::Copy(entrymarker);
872 auto DrawEndCaps = [&]() {
874 TLine entrytop1(xsym-barw, ysym + yspace*0.30, xsym+barw, ysym + yspace*0.30);
876 entry->TAttLine::Copy(entrytop1);
878 TLine entrytop2(xsym-barw, ysym - yspace*0.30, xsym+barw, ysym - yspace*0.30);
880 entry->TAttLine::Copy(entrytop2);
882 }
else if (endcaps == 2) {
883 Double_t xe1[3] = {xsym-barw, xsym ,xsym+barw};
884 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
887 entry->TAttLine::Copy(ple1);
889 Double_t xe2[3] = {xsym-barw, xsym ,xsym+barw};
890 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
893 entry->TAttLine::Copy(ple2);
895 }
else if (endcaps == 3) {
899 Double_t xe1[3] = {xsym-barw, xsym ,xsym+barw};
900 Double_t ye1[3] = {ysym+yspace*0.20, ysym + yspace*0.30 ,ysym+yspace*0.20};
901 Double_t xe2[3] = {xsym-barw, xsym ,xsym+barw};
902 Double_t ye2[3] = {ysym-yspace*0.20, ysym - yspace*0.30 ,ysym-yspace*0.20};
903 for (
Int_t i=0;i<3;i++) {
904 xe1[i] =
gPad->GetX1() + xe1[i]*(
gPad->GetX2()-
gPad->GetX1());
905 ye1[i] =
gPad->GetY1() + ye1[i]*(
gPad->GetY2()-
gPad->GetY1());
906 xe2[i] =
gPad->GetX1() + xe2[i]*(
gPad->GetX2()-
gPad->GetX1());
907 ye2[i] =
gPad->GetY1() + ye2[i]*(
gPad->GetY2()-
gPad->GetY1());
940 TLine entryline( xsym - boxw, ysym, xsym + boxw, ysym );
942 entry->TAttLine::Copy(entryline);
945 entryline.
PaintLineNDC( xsym - boxw, ysym + yspace*0.35,
946 xsym + boxw, ysym + yspace*0.35);
947 entryline.
PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
948 xsym + boxw, ysym - yspace*0.35);
949 entryline.
PaintLineNDC( xsym + boxw, ysym - yspace*0.35,
950 xsym + boxw, ysym + yspace*0.35);
951 entryline.
PaintLineNDC( xsym - boxw, ysym - yspace*0.35,
952 xsym - boxw, ysym + yspace*0.35);
957 entryline.
PaintLineNDC( xsym, ysym - yspace*arrow_shift,
958 xsym, ysym + yspace*arrow_shift);
961 TLine entryline1(xsym, ysym + sy, xsym, ysym + yspace*arrow_shift);
963 entry->TAttLine::Copy(entryline1);
965 TLine entryline2(xsym, ysym - sy, xsym, ysym - yspace*arrow_shift);
967 entry->TAttLine::Copy(entryline2);
982 TLine entryline(xsym, ysym - yspace*arrow_shift,
983 xsym, ysym + yspace*arrow_shift);
985 entry->TAttLine::Copy(entryline);
989 TLine entryline1(xsym, ysym + sy, xsym, ysym + yspace*arrow_shift);
991 entry->TAttLine::Copy(entryline1);
993 TLine entryline2(xsym, ysym - sy, xsym, ysym - yspace*arrow_shift);
995 entry->TAttLine::Copy(entryline2);
1023 if (entry->GetObject() == obj)
1024 entry->SetObject((
TObject *)
nullptr);
1035 out <<
" " << std::endl;
1040 out <<
" TLegend *";
1045 <<
"NULL" <<
"," <<quote<<
fOption <<quote<<
");" << std::endl;
1047 out<<
" leg->SetBorderSize("<<
fBorderSize<<
");"<<std::endl;
1057 out <<
" leg->Draw();"<<std::endl;
1066 if ( entry ) entry->
SetLabel( label );
Option_t Option_t SetTextSize
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t textsize
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t SetFillColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize fs
Option_t Option_t TPoint TPoint const char y1
R__EXTERN TStyle * gStyle
Fill Area Attributes class.
virtual Color_t GetFillColor() const
Return the fill area color.
virtual Style_t GetFillStyle() const
Return the fill area style.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetFillAttributes()
Invoke the DialogCanvas Fill attributes.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
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 Color_t GetLineColor() const
Return the line color.
virtual Width_t GetLineWidth() const
Return the line width.
virtual void SetLineAttributes()
Invoke the DialogCanvas Line attributes.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
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 Style_t GetMarkerStyle() const
Return the marker style.
virtual Size_t GetMarkerSize() const
Return the marker size.
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
virtual Float_t GetTextSize() const
Return the text size.
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
virtual Short_t GetTextAlign() const
Return the text alignment.
virtual Font_t GetTextFont() const
Return the text font.
virtual Color_t GetTextColor() const
Return the text color.
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
virtual Float_t GetTextAngle() const
Return the text angle.
virtual void SetTextAttributes()
Invoke the DialogCanvas Text attributes.
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
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 SetTextSize(Float_t tsize=1)
Set the text size.
void Copy(TAttText &atttext) const
Copy this text attributes to a new TAttText.
Double_t fX1
X of 1st point.
Double_t fY2
Y of 2nd point.
Double_t fX2
X of 2nd point.
Double_t fY1
Y of 1st point.
void Print(Option_t *option="") const override
Default print for collections, calls Print(option, 1).
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
The Histogram stack class.
To draw Mathematical Formula.
Double_t GetXsize()
Return size of the formula along X in pad coordinates when the text precision is smaller than 3.
Double_t GetYsize()
Return size of the formula along Y in pad coordinates when the text precision is smaller than 3.
void Paint(Option_t *option="") override
Paint.
Storage class for one entry of a TLegend.
virtual TObject * GetObject() const
virtual void SetLabel(const char *label="")
virtual void SetOption(Option_t *option="lpf")
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 ....
virtual const char * GetLabel() const
Option_t * GetOption() const override
This class displays a legend box (TPaveText) containing several legend entries.
void Copy(TObject &obj) const override
Copy this legend into "obj".
TLegendEntry * AddEntry(const TObject *obj, const char *label="", Option_t *option="lpf")
Add a new entry to this legend.
void SetNColumns(Int_t nColumns)
Set the number of columns for the legend.
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
virtual void SetHeader(const char *header="", Option_t *option="")
Sets the header, which is the "title" that appears at the top of the legend.
virtual void DeleteEntry()
Delete entry at the mouse position.
TLegendEntry * GetEntry() const
Get entry pointed to by the mouse.
void Clear(Option_t *option="") override
Clear all entries in this legend, including the header.
Float_t fEntrySeparation
Separation between entries, as a fraction of The space allocated to one entry.
virtual void EditEntryAttMarker()
Edit the marker attributes for the entry pointed by the mouse.
void SavePrimitive(std::ostream &out, Option_t *option="") override
Save this legend as C++ statements on output stream out to be used with the SaveAs ....
virtual void EditEntryAttText()
Edit the text attributes for the entry pointed by the mouse.
void Paint(Option_t *option="") override
Paint this legend with its current attributes.
Int_t GetNColumns() const
void RecursiveRemove(TObject *obj) override
Reset the legend entries pointing to "obj".
Float_t fMargin
Fraction of total width used for symbol.
Int_t GetNRows() const
Get the number of rows.
TList * fPrimitives
List of TLegendEntries.
Int_t fNColumns
Number of columns in the legend.
Float_t fColumnSeparation
Separation between columns, as a fraction of The space allowed to one column.
TLegend()
Default constructor.
virtual void EditEntryAttLine()
Edit the line attributes for the entry pointed by the mouse.
~TLegend() override
Default destructor.
virtual void SetEntryOption(Option_t *option)
Edit the option of the entry pointed to by the mouse.
TLegend & operator=(const TLegend &)
Assignment operator.
virtual void SetEntryLabel(const char *label)
Edit the label of the entry pointed to by the mouse.
void Print(Option_t *option="") const override
Dump this TLegend and its contents.
virtual void PaintPrimitives()
Paint the entries (list of primitives) for this legend.
virtual void EditEntryAttFill()
Edit the fill attributes for the entry pointed by the mouse.
virtual const char * GetHeader() const
Returns the header, which is the title that appears at the top of the legend.
virtual void InsertEntry(const char *objectName="", const char *label="", Option_t *option="lpf")
Add a new entry before the entry at the mouse position.
Use the TLine constructor to create a simple line.
@ kLineNDC
Use NDC coordinates.
void Paint(Option_t *option="") override
Paint this line with its current attributes.
virtual void PaintLineNDC(Double_t u1, Double_t v1, Double_t u2, Double_t v2)
Draw this line with new coordinates in NDC.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
TObject * Remove(TObject *obj) override
Remove object from the list.
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
void Paint(Option_t *option="") override
Paint this marker with its current attributes.
A TMultiGraph is a collection of TGraph (or derived) objects.
Mother of all ROOT objects.
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
virtual void AppendPad(Option_t *option="")
Append graphics object to current pad.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const char * GetTitle() const
Returns title of object.
A TBox with a bordersize and a shadow option.
void Print(Option_t *option="") const override
Dump this pave with its attributes.
Double_t GetY2NDC() const
Int_t GetBorderSize() const
virtual void ConvertNDCtoPad()
Convert pave coordinates from NDC to Pad coordinates.
Double_t GetX2NDC() const
void Copy(TObject &pave) const override
Copy this pave to pave.
Int_t fBorderSize
window box bordersize in pixels
Double_t fX2NDC
X2 point in NDC coordinates.
Double_t GetY1NDC() const
virtual void SetBorderSize(Int_t bordersize=4)
Sets the border size of the TPave box and shadow.
TString fOption
Pave style.
Double_t fY2NDC
Y2 point in NDC coordinates.
Double_t fX1NDC
X1 point in NDC coordinates.
Double_t fY1NDC
Y1 point in NDC coordinates.
Double_t GetX1NDC() const
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.
Defined by an array on N points in a 2-D space.
void Paint(Option_t *option="") override
Paint this polyline with its current attributes.
void ToLower()
Change string to lower-case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Width_t GetLegendBorderSize() const
Double_t GetLegendTextSize() const
Float_t GetEndErrorSize() const
Style_t GetLegendFont() const
Color_t GetLegendFillColor() const
virtual void SetNDC(Bool_t isNDC=kTRUE)
Set NDC mode on if isNDC = kTRUE, off otherwise.
Double_t Ceil(Double_t x)
Rounds x upward, returning the smallest integral value that is not less than x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.