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 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\warning Non-symmetric symbols should be used carefully. See markerwarning.C
138
139\anchor ATTMARKER21
140### Marker line width
141
142The line width of a marker is not actually a marker attribute since it does
143only apply to open marker symbols and marker symbols consisting of lines. All
144of these marker symbols are redefined with thicker lines by style numbers
145starting from 50:
146
147~~~ {.cpp}
148 Marker numbers Line width
149 50 - 67 2
150 68 - 85 3
151 86 - 103 4
152 104 - 121 5
153 ...
154~~~
155
156Begin_Macro
157{
158 TCanvas *c = new TCanvas("c","Marker line widths",0,0,600,266);
159 TMarker marker;
160 marker.DisplayMarkerLineWidths();
161}
162End_Macro
163
164\anchor M3
165## Marker size
166
167Various marker sizes are shown in the figure below. The default marker size=1
168is shown in the top left corner. Marker sizes smaller than 1 can be
169specified. The marker size does not refer to any coordinate systems, it is an
170absolute value. Therefore the marker size is not affected by any change
171in TPad's scale. A marker size equal to 1 correspond to 8 pixels.
172That is, a square marker with size 1 will be drawn with a side equal to 8
173pixels on the screen.
174
175The marker size of any class inheriting from `TAttMarker` can
176be changed using the method `SetMarkerSize` and retrieved using the
177method `GetMarkerSize`.
178
179Begin_Macro
180{
181 c = new TCanvas("c","Marker sizes",0,0,500,200);
182 TMarker marker;
183 marker.SetMarkerStyle(3);
184 Double_t x = 0;
185 Double_t dx = 1/6.0;
186 for (Int_t i=1; i<6; i++) {
187 x += dx;
188 marker.SetMarkerSize(i*0.2); marker.DrawMarker(x,.165);
189 marker.SetMarkerSize(i*0.8); marker.DrawMarker(x,.495);
190 marker.SetMarkerSize(i*1.0); marker.DrawMarker(x,.835);
191 }
192}
193End_Macro
194
195Note that the marker styles number 1 6 and 7 (the dots), cannot be scaled. They
196are meant to be very fast to draw and are always drawn with the same number of
197pixels; therefore `SetMarkerSize` does not apply on them. To have a
198"scalable dot" a filled circle should be used instead, i.e. the marker style
199number 20. By default (if `SetMarkerStyle` is not specified), the marker
200style used is 1. That's the most common one to draw scatter plots.
201*/
202
203////////////////////////////////////////////////////////////////////////////////
204/// TAttMarker default constructor.
205///
206/// Default text attributes are taking from the current style.
207
209{
210 if (!gStyle) {fMarkerColor=1; fMarkerStyle=1; fMarkerSize=1; return;}
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// TAttMarker normal constructor.
218///
219/// Text attributes are taking from the argument list
220/// - color : Marker Color Index
221/// - style : Marker style (from 1 to 30)
222/// - size : marker size (float)
223
225{
226 fMarkerColor = color;
227 fMarkerSize = msize;
229}
230
231////////////////////////////////////////////////////////////////////////////////
232/// TAttMarker destructor.
233
235{
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Copy this marker attributes to a new TAttMarker.
240
241void TAttMarker::Copy(TAttMarker &attmarker) const
242{
243 attmarker.fMarkerColor = fMarkerColor;
244 attmarker.fMarkerStyle = fMarkerStyle;
245 attmarker.fMarkerSize = fMarkerSize;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Internal helper function that returns the corresponding marker style with
250/// line width 1 for the given style.
251
253{
254 if (style <= 49)
255 return style;
256
257 switch ((style - 50) % 18) {
258 case 0:
259 return 2;
260 case 1:
261 return 3;
262 case 2:
263 return 5;
264 case 3:
265 return 24;
266 case 4:
267 return 25;
268 case 5:
269 return 26;
270 case 6:
271 return 27;
272 case 7:
273 return 28;
274 case 8:
275 return 30;
276 case 9:
277 return 32;
278 case 10:
279 return 35;
280 case 11:
281 return 36;
282 case 12:
283 return 37;
284 case 13:
285 return 38;
286 case 14:
287 return 40;
288 case 15:
289 return 42;
290 case 16:
291 return 44;
292 case 17:
293 return 46;
294 default:
295 return style;
296 }
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Internal helper function that returns the line width of the given marker
301/// style (0 = filled marker)
302
304{
305 if (style >= 50)
306 return ((style - 50) / 18) + 2;
307 else if (style == 2 || style == 3 || style == 4 || style == 5
308 || style == 24 || style == 25 || style == 26 || style == 27
309 || style == 28 || style == 30 || style == 31 || style == 32
310 || style == 35 || style == 36 || style == 37 || style == 38
311 || style == 40 || style == 42 || style == 44 || style == 46)
312 return 1;
313 else
314 return 0;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Change current marker attributes if necessary.
319
321{
322 if (!gPad) return;
323 if (!gPad->IsBatch()) {
324 gVirtualX->SetMarkerColor(fMarkerColor);
325 gVirtualX->SetMarkerSize (fMarkerSize);
326 gVirtualX->SetMarkerStyle(fMarkerStyle);
327 }
328
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Reset this marker attributes to the default values.
334
336{
337 fMarkerColor = 1;
338 fMarkerStyle = 1;
339 fMarkerSize = 1;
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Save line attributes as C++ statement(s) on output stream out.
344
345void TAttMarker::SaveMarkerAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef, Int_t sizdef)
346{
347 if (fMarkerColor != coldef) {
348 if (fMarkerColor > 228) {
350 out<<" "<<name<<"->SetMarkerColor(ci);" << std::endl;
351 } else
352 out<<" "<<name<<"->SetMarkerColor("<<fMarkerColor<<");"<<std::endl;
353 }
354 if (fMarkerStyle != stydef) {
355 out<<" "<<name<<"->SetMarkerStyle("<<fMarkerStyle<<");"<<std::endl;
356 }
357 if (fMarkerSize != sizdef) {
358 out<<" "<<name<<"->SetMarkerSize("<<fMarkerSize<<");"<<std::endl;
359 }
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Invoke the DialogCanvas Marker attributes.
364
366{
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Set a transparent marker color. malpha defines the percentage of
372/// the color opacity from 0. (fully transparent) to 1. (fully opaque).
373
375{
377}
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
char name[80]
Definition TGX11.cxx:110
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
#define gPad
#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.
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 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:2174
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2032
void SetAttMarkerPS(Color_t color, Style_t style, Size_t msize) override
Set postscript marker attributes.
Definition TPad.cxx:6094
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