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