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