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