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