ROOT » CORE » BASE » TAttLine

class TAttLine


Line Attributes class

This class is used (in general by secondary inheritance) by many other classes (graphics, histograms). It holds all the line attributes.

Line attributes

Line attributes are:

Line Color

The line color is a color index (integer) pointing in the ROOT color table. The line color of any class inheriting from TAttLine can be changed using the method SetLineColor and retrieved using the method GetLineColor. The following table shows the first 50 default colors.
output of html602/MACRO_TAttLine_1.gif
{
   TCanvas *c = new TCanvas("c","Line colors",0,0,500,200);
   c->DrawColorTable();
   return c;
}

Color transparency

SetLineColorAlpha(), allows to set a transparent color. In the following example the line color of the histogram histo is set to blue with a transparency of 35%. The color kBlue itself remains fully opaque.

histo->SetLineColorAlpha(kBlue, 0.35);

The transparency is available on all platforms when the flagOpenGL.CanvasPreferGL is set to 1 in $ROOTSYS/etc/system.rootrc, or on Mac with the Cocoa backend. On the file output it is visible with PDF, PNG, Gif, JPEG, SVG ... but not PostScript.

Line Width

The line width is expressed in pixel units. The line width of any class inheriting from TAttLine can be changed using the method SetLineWidth and retrieved using the method GetLineWidth. The following picture shows the line widths from 1 to 10 pixels.
output of html602/MACRO_TAttLine_3.gif
{
   TCanvas *Lw = new TCanvas("Lw","test",500,200);
   TText  t;
   t.SetTextAlign(32);
   t.SetTextSize(0.08);
   Int_t i=1;
   for (float s=0.1; s<1.0 ; s+=0.092) {
      TLine *lh = new TLine(0.15,s,.85,s);
      lh->SetLineWidth(i);
      t.DrawText(0.1,s,Form("%d",i++));
      lh->Draw();
   }
   return Lw;
}

Line Style

Line styles are identified via integer numbers. The line style of any class inheriting from TAttLine can be changed using the method SetLineStyle and retrieved using the method GetLineStyle.
The first 10 line styles are predefined as shown on the following picture:
output of html602/MACRO_TAttLine_5.gif
{
   TCanvas *Ls = new TCanvas("Ls","test",500,200);
   TText  t;
   t.SetTextAlign(32);
   t.SetTextSize(0.08);
   Int_t i=1;
   for (float s=0.1; s<1.0 ; s+=0.092) {
      TLine *lh = new TLine(0.15,s,.85,s);
      lh->SetLineStyle(i);
      t.DrawText(0.1,s,Form("%d",i++));
      lh->Draw();
   }
   return Ls;
}

Additional line styles can be defined using TStyle::SetLineStyleString.
For example the line style number 11 can be defined as follow:
   gStyle->SetLineStyleString(11,"400 200");
Existing line styles (1 to 10) can be redefined using the same method.
 

Function Members (Methods)

public:
virtual~TAttLine()
static TClass*Class()
voidCopy(TAttLine& attline) const
Int_tDistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
virtual Color_tGetLineColor() const
virtual Style_tGetLineStyle() const
virtual Width_tGetLineWidth() const
virtual TClass*IsA() const
virtual voidModify()
TAttLine&operator=(const TAttLine&)
virtual voidResetAttLine(Option_t* option = "")
virtual voidSaveLineAttributes(ostream& out, const char* name, Int_t coldef = 1, Int_t stydef = 1, Int_t widdef = 1)
virtual voidSetLineAttributes()MENU
virtual voidSetLineColor(Color_t lcolor)
virtual voidSetLineColorAlpha(Color_t lcolor, Float_t lalpha)
virtual voidSetLineStyle(Style_t lstyle)
virtual voidSetLineWidth(Width_t lwidth)
virtual voidShowMembers(TMemberInspector& insp) const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
TAttLine()
TAttLine(const TAttLine&)
TAttLine(Color_t lcolor, Style_t lstyle, Width_t lwidth)

Data Members

protected:
Color_tfLineColorline color
Style_tfLineStyleline style
Width_tfLineWidthline width

Class Charts

Inheritance Inherited Members Includes Libraries
Class Charts

Function documentation

TAttLine()
 AttLine default constructor.
TAttLine(Color_t lcolor, Style_t lstyle, Width_t lwidth)
 AttLine normal constructor.
 Line attributes are taking from the argument list
   color : must be one of the valid color index
   style : 1=solid, 2=dash, 3=dash-dot, 4=dot-dot. New styles can be
           defined using TStyle::SetLineStyleString.
   width : expressed in pixel units
~TAttLine()
 AttLine destructor.
void Copy(TAttLine& attline) const
 Copy this line attributes to a new TAttLine.
Int_t DistancetoLine(Int_t px, Int_t py, Double_t xp1, Double_t yp1, Double_t xp2, Double_t yp2)
 Compute distance from point px,py to a line.
 Compute the closest distance of approach from point px,py to this line.
 The distance is computed in pixels units.

 Algorithm:

   A(x1,y1)         P                             B(x2,y2)
   -----------------+------------------------------
                    |
                    |
                    |
                    |
                   M(x,y)

 Let us call  a = distance AM     A=a**2
              b = distance BM     B=b**2
              c = distance AB     C=c**2
              d = distance PM     D=d**2
              u = distance AP     U=u**2
              v = distance BP     V=v**2     c = u + v

 D = A - U
 D = B - V  = B -(c-u)**2
    ==> u = (A -B +C)/2c
void Modify()
 Change current line attributes if necessary.
void ResetAttLine(Option_t* option = "")
 Reset this line attributes to default values.
void SaveLineAttributes(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.
void SetLineAttributes()
 Invoke the DialogCanvas Line attributes.
void SetLineColorAlpha(Color_t lcolor, Float_t lalpha)
 Set a transparent line color. lalpha defines the percentage of
 the color opacity from 0. (fully transparent) to 1. (fully opaque).
TAttLine()
Color_t GetLineColor() const
{return fLineColor;}
Style_t GetLineStyle() const
{return fLineStyle;}
Width_t GetLineWidth() const
{return fLineWidth;}
void SetLineColor(Color_t lcolor)
{ fLineColor = lcolor;}
void SetLineStyle(Style_t lstyle)
{ fLineStyle = lstyle;}
void SetLineWidth(Width_t lwidth)
{ fLineWidth = lwidth;}