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 <iostream>
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](\ref ATTMARKER1)
37 - [Marker style](\ref ATTMARKER2)
38 - [Marker line width](\ref ATTMARKER21)
39 - [Marker size](\ref M3)
40
41\anchor ATTMARKER1
42## Marker color
43The marker color is a color index (integer) pointing in the ROOT color
44table.
45The marker color of any class inheriting from `TAttMarker` can
46be changed using the method `SetMarkerColor` and retrieved using the
47method `GetMarkerColor`.
48The following table shows the first 50 default colors.
49
50Begin_Macro
51{
52 TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
53 c->DrawColorTable();
54 return c;
55}
56End_Macro
57
58### Color transparency
59
60`SetMarkerColorAlpha()`, allows to set a transparent color.
61In the following example the marker color of the histogram `histo`
62is set to blue with a transparency of 35%. The color `kBlue`
63itself remains fully opaque.
64
65~~~ {.cpp}
66histo->SetMarkerColorAlpha(kBlue, 0.35);
67~~~
68
69The transparency is available on all platforms when the flag `OpenGL.CanvasPreferGL` is set to `1`
70in `$ROOTSYS/etc/system.rootrc`, or on Mac with the Cocoa backend. On the file output
71it is visible with PDF, PNG, Gif, JPEG, SVG, TeX ... but not PostScript.
72
73\anchor ATTMARKER2
74## Marker style
75
76The Marker style defines the markers' shape.
77The marker style of any class inheriting from `TAttMarker` can
78be changed using the method `SetMarkerStyle` and retrieved using the
79method `GetMarkerStyle`.
80
81The following list gives the currently supported markers (screen
82and PostScript) style. Each marker style is identified by an integer number
83(first column) corresponding to a marker shape (second column) and can be also
84accessed via a global name (third column).
85
86~~~ {.cpp}
87 Marker number Marker shape Marker name
88 1 dot kDot
89 2 + kPlus
90 3 * kStar
91 4 o kCircle
92 5 x kMultiply
93 6 small dot kFullDotSmall
94 7 medium dot kFullDotMedium
95 8 large scalable dot kFullDotLarge
96 9 -->19 large scalable dot
97 20 full circle kFullCircle
98 21 full square kFullSquare
99 22 full triangle up kFullTriangleUp
100 23 full triangle down kFullTriangleDown
101 24 open circle kOpenCircle
102 25 open square kOpenSquare
103 26 open triangle up kOpenTriangleUp
104 27 open diamond kOpenDiamond
105 28 open cross kOpenCross
106 29 full star kFullStar
107 30 open star kOpenStar
108 31 *
109 32 open triangle down kOpenTriangleDown
110 33 full diamond kFullDiamond
111 34 full cross kFullCross
112 35 open diamond cross kOpenDiamondCross
113 36 open square diagonal kOpenSquareDiagonal
114 37 open three triangle kOpenThreeTriangles
115 38 octagon with cross kOctagonCross
116 39 full three trangles kFullThreeTriangles
117 40 open four triangleX kOpenFourTrianglesX
118 41 full four triangleX kFullFourTrianglesX
119 42 open double diamond kOpenDoubleDiamond
120 43 full double diamond kFullDoubleDiamond
121 44 open four triangle+ kOpenFourTrianglesPlus
122 45 full four triangle+ kFullFourTrianglesPlus
123 46 open cross X kOpenCrossX
124 47 full cross X kFullCrossX
125 48 four squares X kFourSquaresX
126 49 four squares+ kFourSquaresPlus
127~~~
128
129Begin_Macro
130{
131 TCanvas *c = new TCanvas("c","Marker types",0,0,500,200);
132 TMarker marker;
133 marker.DisplayMarkerTypes();
134}
135End_Macro
136
137\anchor ATTMARKER21
138### Marker line width
139
140The line width of a marker is not actually a marker attribute since it does
141only apply to open marker symbols and marker symbols consisting of lines. All
142of these marker symbols are redefined with thicker lines by style numbers
143starting from 50:
144
145~~~ {.cpp}
146 Marker numbers Line width
147 50 - 67 2
148 68 - 85 3
149 86 - 103 4
150 104 - 121 5
151 ...
152~~~
153
154Begin_Macro
155{
156 TCanvas *c = new TCanvas("c","Marker line widths",0,0,600,266);
157 TMarker marker;
158 marker.DisplayMarkerLineWidths();
159}
160End_Macro
161
162\anchor M3
163## Marker size
164
165Various marker sizes are shown in the figure below. The default marker size=1
166is shown in the top left corner. Marker sizes smaller than 1 can be
167specified. The marker size does not refer to any coordinate systems, it is an
168absolute value. Therefore the marker size is not affected by any change
169in TPad's scale. A marker size equal to 1 correspond to 8 pixels.
170That is, a square marker with size 1 will be drawn with a side equal to 8
171pixels on the screen.
172
173The marker size of any class inheriting from `TAttMarker` can
174be changed using the method `SetMarkerSize` and retrieved using the
175method `GetMarkerSize`.
176
177Begin_Macro
178{
179 c = new TCanvas("c","Marker sizes",0,0,500,200);
180 TMarker marker;
181 marker.SetMarkerStyle(3);
182 Double_t x = 0;
183 Double_t dx = 1/6.0;
184 for (Int_t i=1; i<6; i++) {
185 x += dx;
186 marker.SetMarkerSize(i*0.2); marker.DrawMarker(x,.165);
187 marker.SetMarkerSize(i*0.8); marker.DrawMarker(x,.495);
188 marker.SetMarkerSize(i*1.0); marker.DrawMarker(x,.835);
189 }
190}
191End_Macro
192
193Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They
194are meant to be very fast to draw and are always drawn with the same number of
195pixels; therefore `SetMarkerSize` does not apply on them. To have a
196"scalable dot" a filled circle should be used instead, i.e. the marker style
197number 20. By default (if `SetMarkerStyle` is not specified), the marker
198style used is 1. That's the most common one to draw scatter plots.
199*/
200
201////////////////////////////////////////////////////////////////////////////////
202/// TAttMarker default constructor.
203///
204/// Default text attributes are taking from the current style.
205
207{
208 if (!gStyle) {fMarkerColor=1; fMarkerStyle=1; fMarkerSize=1; return;}
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// TAttMarker normal constructor.
216///
217/// Text attributes are taking from the argument list
218/// - color : Marker Color Index
219/// - style : Marker style (from 1 to 30)
220/// - size : marker size (float)
221
223{
224 fMarkerColor = color;
225 fMarkerSize = msize;
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// TAttMarker destructor.
231
233{
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Copy this marker attributes to a new TAttMarker.
238
239void TAttMarker::Copy(TAttMarker &attmarker) const
240{
241 attmarker.fMarkerColor = fMarkerColor;
242 attmarker.fMarkerStyle = fMarkerStyle;
243 attmarker.fMarkerSize = fMarkerSize;
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// Internal helper function that returns the corresponding marker style with
248/// line width 1 for the given style.
249
251{
252 if (style <= 49)
253 return style;
254
255 switch ((style - 50) % 18) {
256 case 0:
257 return 2;
258 case 1:
259 return 3;
260 case 2:
261 return 5;
262 case 3:
263 return 24;
264 case 4:
265 return 25;
266 case 5:
267 return 26;
268 case 6:
269 return 27;
270 case 7:
271 return 28;
272 case 8:
273 return 30;
274 case 9:
275 return 32;
276 case 10:
277 return 35;
278 case 11:
279 return 36;
280 case 12:
281 return 37;
282 case 13:
283 return 38;
284 case 14:
285 return 40;
286 case 15:
287 return 42;
288 case 16:
289 return 44;
290 case 17:
291 return 46;
292 default:
293 return style;
294 }
295}
296
297////////////////////////////////////////////////////////////////////////////////
298/// Internal helper function that returns the line width of the given marker
299/// style (0 = filled marker)
300
302{
303 if (style >= 50)
304 return ((style - 50) / 18) + 2;
305 else if (style == 2 || style == 3 || style == 4 || style == 5
306 || style == 24 || style == 25 || style == 26 || style == 27
307 || style == 28 || style == 30 || style == 31 || style == 32
308 || style == 35 || style == 36 || style == 37 || style == 38
309 || style == 40 || style == 42 || style == 44 || style == 46)
310 return 1;
311 else
312 return 0;
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Change current marker attributes if necessary.
317
319{
320 if (!gPad) return;
321 if (!gPad->IsBatch()) {
322 gVirtualX->SetMarkerColor(fMarkerColor);
323 gVirtualX->SetMarkerSize (fMarkerSize);
324 gVirtualX->SetMarkerStyle(fMarkerStyle);
325 }
326
327 gPad->SetAttMarkerPS(fMarkerColor,fMarkerStyle,fMarkerSize);
328}
329
330////////////////////////////////////////////////////////////////////////////////
331/// Reset this marker attributes to the default values.
332
334{
335 fMarkerColor = 1;
336 fMarkerStyle = 1;
337 fMarkerSize = 1;
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Save line attributes as C++ statement(s) on output stream out.
342
343void TAttMarker::SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef, Int_t sizdef)
344{
345 if (fMarkerColor != coldef) {
346 if (fMarkerColor > 228) {
348 out<<" "<<name<<"->SetMarkerColor(ci);" << std::endl;
349 } else
350 out<<" "<<name<<"->SetMarkerColor("<<fMarkerColor<<");"<<std::endl;
351 }
352 if (fMarkerStyle != stydef) {
353 out<<" "<<name<<"->SetMarkerStyle("<<fMarkerStyle<<");"<<std::endl;
354 }
355 if (fMarkerSize != sizdef) {
356 out<<" "<<name<<"->SetMarkerSize("<<fMarkerSize<<");"<<std::endl;
357 }
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// Invoke the DialogCanvas Marker attributes.
362
364{
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// Set a transparent marker color. malpha defines the percentage of
370/// the color opacity from 0. (fully transparent) to 1. (fully opaque).
371
373{
375}
int Int_t
Definition: CPyCppyy.h:43
float Size_t
Definition: RtypesCore.h:96
short Width_t
Definition: RtypesCore.h:91
short Color_t
Definition: RtypesCore.h:92
short Style_t
Definition: RtypesCore.h:89
float Float_t
Definition: RtypesCore.h:57
const char Option_t
Definition: RtypesCore.h:66
#define ClassImp(name)
Definition: Rtypes.h:364
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
#define gPad
Definition: TVirtualPad.h:287
#define gVirtualX
Definition: TVirtualX.h:338
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:343
virtual void Modify()
Change current marker attributes if necessary.
Definition: TAttMarker.cxx:318
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
static Width_t GetMarkerLineWidth(Style_t style)
Internal helper function that returns the line width of the given marker style (0 = filled marker)
Definition: TAttMarker.cxx:301
virtual ~TAttMarker()
TAttMarker destructor.
Definition: TAttMarker.cxx:232
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
Definition: TAttMarker.cxx:363
virtual void ResetAttMarker(Option_t *toption="")
Reset this marker attributes to the default values.
Definition: TAttMarker.cxx:333
void Copy(TAttMarker &attmarker) const
Copy this marker attributes to a new TAttMarker.
Definition: TAttMarker.cxx:239
TAttMarker()
TAttMarker default constructor.
Definition: TAttMarker.cxx:206
virtual void SetMarkerColorAlpha(Color_t mcolor, Float_t malpha)
Set a transparent marker color.
Definition: TAttMarker.cxx:372
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:24
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
static Style_t GetMarkerStyleBase(Style_t style)
Internal helper function that returns the corresponding marker style with line width 1 for the given ...
Definition: TAttMarker.cxx:250
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:2127
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition: TColor.cxx:1985
static void UpdateMarkerAttributes(Int_t col, Int_t sty, Float_t msiz)
Update marker attributes via the pad editor.
static const std::string name("name")
TCanvas * style()
Definition: style.C:1