Logo ROOT   6.08/07
Reference Guide
TAttMarker.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Rene Brun 12/05/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "Riostream.h"
13 #include "Strlen.h"
14 #include "TAttMarker.h"
15 #include "TVirtualPad.h"
16 #include "TStyle.h"
17 #include "TVirtualX.h"
18 #include "TVirtualPadEditor.h"
19 #include "TColor.h"
20 
22 
23 /** \class TAttMarker
24 \ingroup Base
25 \ingroup GraphicsAtt
26 
27 Marker Attributes class.
28 
29 This class is used (in general by secondary inheritance)
30 by many other classes (graphics, histograms). It holds all the markers
31 attributes.
32 
33 ## Marker attributes
34 The marker attributes are:
35 
36  - [Marker color](#M1)
37  - [Marker style](#M2)
38  - [Marker size](#M3)
39 
40 ## <a name="M1"></a> Marker color
41 The marker color is a color index (integer) pointing in the ROOT color
42 table.
43 The marker color of any class inheriting from `TAttMarker` can
44 be changed using the method `SetMarkerColor` and retrieved using the
45 method `GetMarkerColor`.
46 The following table shows the first 50 default colors.
47 
48 Begin_Macro
49 {
50  TCanvas *c = new TCanvas("c","Marker colors",0,0,500,200);
51  c->DrawColorTable();
52 }
53 End_Macro
54 
55 ### Color transparency
56 
57 `SetMarkerColorAlpha()`, allows to set a transparent color.
58 In the following example the marker color of the histogram `histo`
59 is set to blue with a transparency of 35%. The color `kBlue`
60 itself remains fully opaque.
61 
62 ~~~ {.cpp}
63 histo->SetMarkerColorAlpha(kBlue, 0.35);
64 ~~~
65 
66 The transparency is available on all platforms when the `flagOpenGL.CanvasPreferGL` is set to `1`
67 in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
68 it is visible with PDF, PNG, Gif, JPEG, SVG ... but not PostScript.
69 
70 ## <a name="M2"></a> Marker style
71 
72 The Marker style defines the markers' shape.
73 The marker style of any class inheriting from `TAttMarker` can
74 be changed using the method `SetMarkerStyle` and retrieved using the
75 method `GetMarkerStyle`.
76 
77 The following list gives the currently supported markers (screen
78 and PostScript) style. Each marker style is identified by an integer number
79 (first column) corresponding to a marker shape (second column) and can be also
80 accessed via a global name (third column).
81 
82 ~~~ {.cpp}
83  Marker number Marker shape Marker name
84  1 dot kDot
85  2 + kPlus
86  3 * kStar
87  4 o kCircle
88  5 x kMultiply
89  6 small dot kFullDotSmall
90  7 medium dot kFullDotMedium
91  8 large scalable dot kFullDotLarge
92  9 -->19 large scalable dot
93  20 full circle kFullCircle
94  21 full square kFullSquare
95  22 full triangle up kFullTriangleUp
96  23 full triangle down kFullTriangleDown
97  24 open circle kOpenCircle
98  25 open square kOpenSquare
99  26 open triangle up kOpenTriangleUp
100  27 open diamond kOpenDiamond
101  28 open cross kOpenCross
102  29 full star kFullStar
103  30 open star kOpenStar
104  31 *
105  32 open triangle down kOpenTriangleDown
106  33 full diamond kFullDiamond
107  34 full cross kFullCross
108 ~~~
109 
110 Begin_Macro
111 {
112  TCanvas *c = new TCanvas("c","Marker types",0,0,500,200);
113  TMarker marker;
114  marker.DisplayMarkerTypes();
115 }
116 End_Macro
117 
118 ## <a name="M3"></a> Marker size
119 
120 Various marker sizes are shown in the figure below. The default marker size=1
121 is shown in the top left corner. Marker sizes smaller than 1 can be
122 specified. The marker size does not refer to any coordinate systems, it is an
123 absolute value. Therefore the marker size is not affected by any change
124 in TPad's scale. A marker size equal to 1 correspond to 8 pixels.
125 That is, a square marker with size 1 will be drawn with a side equal to 8
126 pixels on the screen.
127 
128 The marker size of any class inheriting from `TAttMarker` can
129 be changed using the method `SetMarkerSize` and retrieved using the
130 method `GetMarkerSize`.
131 
132 Begin_Macro
133 {
134  c = new TCanvas("c","Marker sizes",0,0,500,200);
135  TMarker marker;
136  marker.SetMarkerStyle(3);
137  Double_t x = 0;
138  Double_t dx = 1/6.0;
139  for (Int_t i=1; i<6; i++) {
140  x += dx;
141  marker.SetMarkerSize(i*0.2); marker.DrawMarker(x,.165);
142  marker.SetMarkerSize(i*0.8); marker.DrawMarker(x,.495);
143  marker.SetMarkerSize(i*1.0); marker.DrawMarker(x,.835);
144  }
145 }
146 End_Macro
147 
148 Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They
149 are meant to be very fast to draw and are always drawn with the same number of
150 pixels; therefore `SetMarkerSize` does not apply on them. To have a
151 "scalable dot" a filled circle should be used instead, i.e. the marker style
152 number 20. By default (if `SetMarkerStyle` is not specified), the marker
153 style used is 1. That's the most common one to draw scatter plots.
154 */
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// TAttMarker default constructor.
158 ///
159 /// Default text attributes are taking from the current style.
160 
162 {
163  if (!gStyle) {fMarkerColor=1; fMarkerStyle=1; fMarkerSize=1; return;}
164  fMarkerColor = gStyle->GetMarkerColor();
165  fMarkerStyle = gStyle->GetMarkerStyle();
166  fMarkerSize = gStyle->GetMarkerSize();
167 }
168 
169 ////////////////////////////////////////////////////////////////////////////////
170 /// TAttMarker normal constructor.
171 ///
172 /// Text attributes are taking from the argument list
173 /// - color : Marker Color Index
174 /// - style : Marker style (from 1 to 30)
175 /// - size : marker size (float)
176 
178 {
179  fMarkerColor = color;
180  fMarkerSize = msize;
182 }
183 
184 ////////////////////////////////////////////////////////////////////////////////
185 /// TAttMarker destructor.
186 
188 {
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 /// Copy this marker attributes to a new TAttMarker.
193 
194 void TAttMarker::Copy(TAttMarker &attmarker) const
195 {
196  attmarker.fMarkerColor = fMarkerColor;
197  attmarker.fMarkerStyle = fMarkerStyle;
198  attmarker.fMarkerSize = fMarkerSize;
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 /// Change current marker attributes if necessary.
203 
205 {
206  if (!gPad) return;
207  if (!gPad->IsBatch()) {
208  gVirtualX->SetMarkerColor(fMarkerColor);
209  gVirtualX->SetMarkerSize (fMarkerSize);
210  gVirtualX->SetMarkerStyle(fMarkerStyle);
211  }
212 
213  gPad->SetAttMarkerPS(fMarkerColor,fMarkerStyle,fMarkerSize);
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Reset this marker attributes to the default values.
218 
220 {
221  fMarkerColor = 1;
222  fMarkerStyle = 1;
223  fMarkerSize = 1;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// Save line attributes as C++ statement(s) on output stream out.
228 
229 void TAttMarker::SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef, Int_t sizdef)
230 {
231  if (fMarkerColor != coldef) {
232  if (fMarkerColor > 228) {
234  out<<" "<<name<<"->SetMarkerColor(ci);" << std::endl;
235  } else
236  out<<" "<<name<<"->SetMarkerColor("<<fMarkerColor<<");"<<std::endl;
237  }
238  if (fMarkerStyle != stydef) {
239  out<<" "<<name<<"->SetMarkerStyle("<<fMarkerStyle<<");"<<std::endl;
240  }
241  if (fMarkerSize != sizdef) {
242  out<<" "<<name<<"->SetMarkerSize("<<fMarkerSize<<");"<<std::endl;
243  }
244 }
245 
246 ////////////////////////////////////////////////////////////////////////////////
247 /// Invoke the DialogCanvas Marker attributes.
248 
250 {
252 }
253 
254 ////////////////////////////////////////////////////////////////////////////////
255 /// Set a transparent marker color. malpha defines the percentage of
256 /// the color opacity from 0. (fully transparent) to 1. (fully opaque).
257 
259 {
260  fMarkerColor = TColor::GetColorTransparent(mcolor, malpha);
261 }
short Style_t
Definition: RtypesCore.h:76
float Float_t
Definition: RtypesCore.h:53
float Size_t
Definition: RtypesCore.h:83
const char Option_t
Definition: RtypesCore.h:62
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
static void SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition: TColor.cxx:2021
TAttMarker()
TAttMarker default constructor.
Definition: TAttMarker.cxx:161
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:29
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
Definition: TAttMarker.cxx:249
int Int_t
Definition: RtypesCore.h:41
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:194
virtual Style_t GetMarkerStyle() const
Return the marker style.
Definition: TAttMarker.h:37
Marker Attributes class.
Definition: TAttMarker.h:24
virtual void SetMarkerColorAlpha(Color_t mcolor, Float_t malpha)
Set a transparent marker color.
Definition: TAttMarker.cxx:258
virtual Size_t GetMarkerSize() const
Return the marker size.
Definition: TAttMarker.h:38
virtual void SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1, Int_t sizdef=1)
Save line attributes as C++ statement(s) on output stream out.
Definition: TAttMarker.cxx:229
short Color_t
Definition: RtypesCore.h:79
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:28
virtual void Modify()
Change current marker attributes if necessary.
Definition: TAttMarker.cxx:204
#define gVirtualX
Definition: TVirtualX.h:362
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1879
virtual void ResetAttMarker(Option_t *toption="")
Reset this marker attributes to the default values.
Definition: TAttMarker.cxx:219
static void UpdateMarkerAttributes(Int_t col, Int_t sty, Float_t msiz)
Update marker attributes via the pad editor.
#define ClassImp(name)
Definition: Rtypes.h:279
TCanvas * style()
Definition: style.C:1
virtual ~TAttMarker()
TAttMarker destructor.
Definition: TAttMarker.cxx:187
#define gPad
Definition: TVirtualPad.h:289
virtual Color_t GetMarkerColor() const
Return the marker color.
Definition: TAttMarker.h:36
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:27
char name[80]
Definition: TGX11.cxx:109