forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TGaxis.cxx
2612 lines (2320 loc) · 91 KB
/
TGaxis.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/graf:$Id$
// Author: Rene Brun, Olivier Couet 12/12/94
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "Riostream.h"
#include "TROOT.h"
#include "TGaxis.h"
#include "TAxisModLab.h"
#include "TVirtualPad.h"
#include "TVirtualX.h"
#include "TLine.h"
#include "TLatex.h"
#include "TStyle.h"
#include "TF1.h"
#include "TAxis.h"
#include "THashList.h"
#include "TObjString.h"
#include "TObject.h"
#include "TMath.h"
#include "THLimitsFinder.h"
#include "TColor.h"
#include "TClass.h"
#include "TTimeStamp.h"
#include "TSystem.h"
#include "TTimeStamp.h"
Int_t TGaxis::fgMaxDigits = 5;
Float_t TGaxis::fXAxisExpXOffset = 0.; //Exponent X offset for the X axis
Float_t TGaxis::fXAxisExpYOffset = 0.; //Exponent Y offset for the X axis
Float_t TGaxis::fYAxisExpXOffset = 0.; //Exponent X offset for the Y axis
Float_t TGaxis::fYAxisExpYOffset = 0.; //Exponent Y offset for the Y axis
const Int_t kHori = BIT(9); //defined in TPad
ClassImp(TGaxis);
/** \class TGaxis
\ingroup BasicGraphics
The axis painter class.
Instances of this class are generated by the histograms and graphs painting
classes when `TAxis` are drawn. `TGaxis` is the "painter class" of
`TAxis`. Therefore it is mainly used via `TAxis`, even if is some
occasion it can be used directly to draw an axis which is not part of a graph
or an instance. For instance to draw an extra scale on a plot.
- [Basic definition](#GA00)
- [Definition with a function](#GA01)
- [Logarithmic axis](#GA02)
- [Blank axis](#GA03)
- [Tick marks' orientation](#GA04)
- [Tick marks' size](#GA05)
- [Labels' positionning](#GA06)
- [Labels' orientation](#GA07)
- [Labels' position on tick marks](#GA08)
- [Labels' format](#GA09)
- [Alphanumeric labels](#GA10)
- [Changing axis labels](#GA10a)
- [Number of divisions optimisation](#GA11)
- [Maximum Number of Digits for the axis labels](#GA12)
- [Optional grid](#GA13)
- [Time axis](#GA14)
## <a name="GA00"></a> Basic definition
A `TGaxis` is defined the following way:
~~~ {.cpp}
TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
Double_t wmin, Double_t wmax, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
~~~
Where:
- xmin : X origin coordinate in user's coordinates space.
- xmax : X end axis coordinate in user's coordinates space.
- ymin : Y origin coordinate in user's coordinates space.
- ymax : Y end axis coordinate in user's coordinates space.
- wmin : Lowest value for the tick mark labels written on the axis.
- wmax : Highest value for the tick mark labels written on the axis.
- ndiv : Number of divisions.
- ndiv=N1 + 100*N2 + 10000*N3
- N1=number of 1st divisions.
- N2=number of 2nd divisions.
- N3=number of 3rd divisions. e.g.:
- ndiv=0 --> no tick marks.
- ndiv=2 --> 2 divisions, one tick mark in the middle of the axis.
- chopt : Drawing options (see below).
- gridlength: grid length on main tick marks.
The example below generates various kind of axis.
Begin_Macro(source)
{
TCanvas *c1 = new TCanvas("c1","Examples of TGaxis",10,10,700,500);
c1->Range(-10,-1,10,1);
TGaxis *axis1 = new TGaxis(-4.5,-0.2,5.5,-0.2,-6,8,510,"");
axis1->SetName("axis1");
axis1->Draw();
TGaxis *axis2 = new TGaxis(-4.5,0.2,5.5,0.2,0.001,10000,510,"G");
axis2->SetName("axis2");
axis2->Draw();
TGaxis *axis3 = new TGaxis(-9,-0.8,-9,0.8,-8,8,50510,"");
axis3->SetName("axis3");
axis3->Draw();
TGaxis *axis4 = new TGaxis(-7,-0.8,-7,0.8,1,10000,50510,"G");
axis4->SetName("axis4");
axis4->Draw();
TGaxis *axis5 = new TGaxis(-4.5,-0.6,5.5,-0.6,1.2,1.32,80506,"-+");
axis5->SetName("axis5");
axis5->SetLabelSize(0.03);
axis5->SetTextFont(72);
axis5->SetLabelOffset(0.025);
axis5->Draw();
TGaxis *axis6 = new TGaxis(-4.5,0.6,5.5,0.6,100,900,50510,"-");
axis6->SetName("axis6");
axis6->Draw();
TGaxis *axis7 = new TGaxis(8,-0.8,8,0.8,0,9000,50510,"+L");
axis7->SetName("axis7");
axis7->SetLabelOffset(0.01);
axis7->Draw();
//one can make axis going top->bottom. However because of a long standing
//problem, the two x values should not be equal
TGaxis *axis8 = new TGaxis(6.5,0.8,6.499,-0.8,0,90,50510,"-");
axis8->SetName("axis8");
axis8->Draw();
}
End_Macro
## <a name="GA01"></a> Definition with a function
Instead of the wmin,wmax arguments of the normal definition, the
name of a `TF1` function can be specified. This function will be used to
map the user coordinates to the axis values and ticks.
A `TGaxis` is defined the following way:
~~~ {.cpp}
TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
const char *func, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
~~~
Where:
- xmin : X origin coordinate in user's coordinates space.
- xmax : X end axis coordinate in user's coordinates space.
- ymin : Y origin coordinate in user's coordinates space.
- ymax : Y end axis coordinate in user's coordinates space.
- func : function defining axis labels and tick marks.
- ndiv : Number of divisions.
- ndiv=N1 + 100*N2 + 10000*N3
- N1=number of 1st divisions.
- N2=number of 2nd divisions.
- N3=number of 3rd divisions. e.g.:
- ndiv=0 --> no tick marks.
- ndiv=2 --> 2 divisions, one tick mark in the middle of the axis.
- chopt : Drawing options (see below).
- gridlength: grid length on main tick marks.
Examples:
Begin_Macro(source)
{
TCanvas *c2 = new TCanvas("c2","c2",10,10,700,500);
gPad->DrawFrame(0.,-2.,10.,2);
TF1 *f1=new TF1("f1","-x",-10,10);
TGaxis *A1 = new TGaxis(0,2,10,2,"f1",510,"-");
A1->SetTitle("axis with decreasing values");
A1->Draw();
TF1 *f2=new TF1("f2","exp(x)",0,2);
TGaxis *A2 = new TGaxis(1,1,9,1,"f2");
A2->SetTitle("exponential axis");
A2->SetLabelSize(0.03);
A2->SetTitleSize(0.03);
A2->SetTitleOffset(1.2);
A2->Draw();
TF1 *f3=new TF1("f3","log10(x)",1,1000);
TGaxis *A3 = new TGaxis(2,-2,2,0,"f3",505,"G");
A3->SetTitle("logarithmic axis");
A3->SetLabelSize(0.03);
A3->SetTitleSize(0.03);
A3->SetTitleOffset(0.); // Axis title automatically placed
A3->Draw();
}
End_Macro
## <a name="GA02"></a> Logarithmic axis
By default axis are linear. To define a `TGaxis` as logarithmic, it is
enough to create it with the option `"G"`.
When plotting an histogram or a graph the logarithmic scale can be set using:
- `gPad->SetLogx(1);` set the logarithmic scale on the X axis
- `gPad->SetLogy(1);` set the logarithmic scale on the Y axis
When the `SetMoreLogLabels()` method is called more labels are drawn
when in logarithmic scale and there is a small number of decades (less than 3).
## <a name="GA03"></a> Blank axis
To draw only the axis tick marks without the axis body, it is enough to specify
the option `"B"`. It useful to superpose axis.
## <a name="GA04"></a> Tick marks' orientation
By default tick marks are drawn on the positive side of the axis, except for
vertical axis for which the default is negative. The `chop` parameter
allows to control the tick marks orientation:
- `chopt = "+"`: tick marks are drawn on Positive side. (default)
- `chopt ="-"`: tick mark are drawn on the negative side.
- `chopt = "+-"`: tick marks are drawn on both sides of the axis.
- `chopt = "U"`: Unlabelled axis, default is labeled.
## <a name="GA05"></a> Tick marks' size
By default, tick marks have a length equal to 3 per cent of the axis length.
When the option "S" is specified, the length of the tick marks is equal to
`fTickSize*axis_length`, where `fTickSize` may be set via
`TGaxis::SetTickSize`.
When plotting an histogram `h` the tick marks size can be changed using:
- `h->GetXaxis()->SetTickLength(0.02);` set the tick length for the X axis
- `gStyle->SetTickLength(0.02,"x");` set the tick length for the X axis
of all histograms drawn after this instruction.
A good way to remove tick marks on an axis is to set the tick length to 0:
`h->GetXaxis()->SetTickLength(0.);`
## <a name="GA06"></a> Labels' positionning
Labels are normally drawn on side opposite to tick marks. However the option
`"="` allows to draw them on the same side. The distance between the labels and
the axis body can be changed with `SetLabelOffset`.
## <a name="GA07"></a> Labels' orientation
By default axis labels are drawn parallel to the axis. However if the axis is vertical
then are drawn perpendicular to the axis.
## <a name="GA08"></a> Labels' position on tick marks
By default axis labels are centered on tick marks. However, for vertical axis,
they are right adjusted. The `chop` parameter allows to control the labels'
position on tick marks:
- `chopt = "R"`: labels are Right adjusted on tick mark.(default is centered)
- `chopt = "L"`: labels are Left adjusted on tick mark.
- `chopt = "C"`: labels are Centered on tick mark.
- `chopt = "M"`: In the Middle of the divisions.
## <a name="GA09"></a> Labels' format
Blank characters are stripped, and then the label is correctly aligned. the dot,
if last character of the string, is also stripped, unless the option `"."`
(a dot, or period) is specified. if `SetDecimals(kTRUE)` has been called
all labels have the same number of decimals after the `"."`
The same is true if `gStyle->SetStripDecimals(kFALSE)` has been called.
In the following, we have some parameters, like tick marks length and characters
height (in percentage of the length of the axis (user's coordinates))
The default values are as follows:
- Primary tick marks: 3.0 %
- Secondary tick marks: 1.5 %
- Third order tick marks: .75 %
- Characters height for labels: 4%
- Labels offset: 1.0 %
By default, an exponent of the form 10^N is used when the label values are either
all very small or very large. One can disable the exponent by calling
`axis.SetNoExponent(kTRUE)`.
`TGaxis::SetExponentOffset(Float_t xoff, Float_t yoff, Option_t *axis)` is
static function to set X and Y offset of the axis 10^n notation. It is in % of
the pad size. It can be negative. `axis` specifies which axis
(`"x"` or/and `"y"`), default is `"x"` if `axis = "xz"`
set the two axes
## <a name="GA10"></a> Alphanumeric labels
Axis labels can be any alphanumeric character strings. Such axis can be produced
only with histograms because the labels'definition is stored in `TAxis`.
The following example demonstrates how to create such labels.
Begin_Macro(source)
../../../tutorials/hist/hlabels2.C
End_Macro
Because the alphanumeric labels are usually longer that the numeric labels, their
size is by default equal to `0.66666 * the_numeric_labels_size`.
## <a name="GA10a"></a> Changing axis labels
\since **ROOT version 6.07/07:**
After an axis has been created, TGaxis::ChangeLabel allows to define new text
attributes for a given label. A fine tuning of the labels can be done. All the
attributes can be changed as well as the text label itself.
When plotting an histogram or a graph the labels can be changed like in the
following example which shows a way to produce \f$\pi\f$-axis :
Begin_Macro(source)
{
Double_t pi = TMath::Pi();
TF1* f = new TF1("f","TMath::Cos(x/TMath::Pi())", -pi, pi);
TH1* h = f->GetHistogram();
TAxis* a = h->GetXaxis();
a->SetNdivisions(-502);
a->ChangeLabel(1,-1,-1,-1,-1,-1,"-#pi");
a->ChangeLabel(-1,-1,-1,-1,-1,-1,"#pi");
f->Draw();
}
End_Macro
## <a name="GA11"></a> Number of divisions optimisation
By default the number of divisions on axis is optimised to show a coherent
labelling of the main tick marks. The number of division (`ndiv`) is a
composite integer given by:
` ndiv = N1 + 100*N2 + 10000*N3`
- `N1` = number of 1st divisions.
- `N2` = number of 2nd divisions.
- `N3` = number of 3rd divisions.
by default the value of `N1`, `N2` and `N3` are maximum
values. After optimisation the real number of divisions will be smaller or
equal to these value. If one wants to bypass the optimisation, the option `"N"`
should be given when the `TGaxis` is created. The option `"I"`
also act on the number of division as it will force an integer labelling of
the axis.
On an histogram pointer `h` the number of divisions can be set in different ways:.
- Directly on the histogram. The following will set the number of division
to 510 on the X axis of `h`. To avoid optimization the number of divisions
should be negative (ie: -510);
~~~ {.cpp}
h->SetNdivisions(510, "X");
~~~
- On the axis itself:
~~~ {.cpp}
h->GetXaxis()->SetNdivisions(510, kTRUE);
~~~
The first parameter is the number of division. If it is negative of if the
second parameter is kFALSE then the number of divisions is not optimised.
And other signature is also allowed:
~~~ {.cpp}
h->GetXaxis()->SetNdivisions(10, 5, 0, kTRUE);
~~~
## <a name="GA12"></a> Maximum Number of Digits for the axis labels
The static function `TGaxis::SetMaxDigits` sets the maximum number of
digits permitted for the axis labels above which the notation with 10^N is used.
For example, to accept 6 digits number like 900000 on an axis call
`TGaxis::SetMaxDigits(6)`. The default value is 5.
`fgMaxDigits` must be greater than 0.
## <a name="GA13"></a> Optional grid
The option `"W"` allows to draw a grid on the primary tick marks. In case
of a log axis, the grid is only drawn for the primary tick marks if the number
of secondary and tertiary divisions is 0. `SetGridLength()` allows to define
the length of the grid.
When plotting an histogram or a graph the grid can be set ON or OFF using:
- `gPad->SetGridy(1);` set the grid on the X axis
- `gPad->SetGridx(1);` set the grid on the Y axis
- `gPad->SetGrid(1,1);` set the grid on both axis.
## <a name="GA14"></a> Time axis
Axis labels may be considered as times, plotted in a defined time format.
The format is set with `SetTimeFormat()`.
The `TGaxis` minimum (`wmin`) and maximum (`wmax`) values
are considered as two time values in seconds.
The time axis will be spread around the time offset value (set with
`SetTimeOffset()`). Actually it will go from `TimeOffset+wmin` to
`TimeOffset+wmax`
Usually time axis are created automatically via histograms, but one may also
want to draw a time axis outside an "histogram context". This can be done
thanks to the option `"T"` of `TGaxis`.
Begin_Macro(source)
{
c1 = new TCanvas("c1","Examples of TGaxis",10,10,700,100);
c1->Range(-10,-1,10,1);
TGaxis *axis = new TGaxis(-8,0.,8,0.,-100000,150000,2405,"tS");
axis->SetLabelSize(0.3);
axis->SetTickSize(0.2);
TDatime da(2003,02,28,12,00,00);
axis->SetTimeOffset(da.Convert());
axis->SetTimeFormat("%d-%m-%Y");
axis->Draw();
return c1;
}
End_Macro
The following example compares what the system time function `gmtime`
and `localtime` give with what gives `TGaxis`. It can be used
as referenced test to check if the time option of `TGaxis` is working properly.
Begin_Macro(source)
../../../tutorials/graphs/timeonaxis3.C
End_Macro
The following macro illustrates the use, with histograms axis, of the time mode on the axis
with different time intervals and time formats.
Begin_Macro(source)
../../../tutorials/graphs/timeonaxis.C
End_Macro
An other example showing how to define the time offset as 2003, January 1st
using histograms axis.
Begin_Macro(source)
../../../tutorials/graphs/timeonaxis2.C
End_Macro
*/
////////////////////////////////////////////////////////////////////////////////
/// TGaxis default constructor.
TGaxis::TGaxis(): TLine(), TAttText(11,0,1,62,0.040)
{
fGridLength = 0.;
fLabelOffset = 0.005;
fLabelSize = 0.040;
fLabelFont = 62;
fLabelColor = 1;
fTickSize = 0.030;
fTitleOffset = 1;
fTitleSize = fLabelSize;
fChopt = "";
fName = "";
fTitle = "";
fTimeFormat = "";
fFunctionName= "";
fFunction = 0;
fAxis = 0;
fNdiv = 0;
fNModLabs = 0;
fModLabs = 0;
fWmin = 0.;
fWmax = 0.;
}
////////////////////////////////////////////////////////////////////////////////
/// TGaxis normal constructor.
TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
Double_t wmin, Double_t wmax, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
: TLine(xmin,ymin,xmax,ymax), TAttText(11,0,1,62,0.040)
{
fWmin = wmin;
fWmax = wmax;
fNdiv = ndiv;
fNModLabs = 0;
fModLabs = 0;
fGridLength = gridlength;
fLabelOffset = 0.005;
fLabelSize = 0.040;
fLabelFont = 62;
fLabelColor = 1;
fTickSize = 0.030;
fTitleOffset = 1;
fTitleSize = fLabelSize;
fChopt = chopt;
fName = "";
fTitle = "";
fTimeFormat = "";
fFunctionName= "";
fFunction = 0;
fAxis = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor with a `TF1` to map axis values.
TGaxis::TGaxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
const char *funcname, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
: TLine(xmin,ymin,xmax,ymax), TAttText(11,0,1,62,0.040)
{
fFunction = (TF1*)gROOT->GetFunction(funcname);
if (!fFunction) {
Error("TGaxis", "calling constructor with an unknown function: %s", funcname);
fWmin = 0;
fWmax = 1;
} else {
fWmin = fFunction->GetXmin();
fWmax = fFunction->GetXmax();
}
fFunctionName= funcname;
fNdiv = ndiv;
fNModLabs = 0;
fModLabs = 0;
fGridLength = gridlength;
fLabelOffset = 0.005;
fLabelSize = 0.040;
fLabelFont = 62;
fLabelColor = 1;
fTickSize = 0.030;
fTitleOffset = 1;
fTitleSize = fLabelSize;
fChopt = chopt;
fName = "";
fTitle = "";
fTimeFormat = "";
fAxis = 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Copy constructor.
TGaxis::TGaxis(const TGaxis& ax) :
TLine(ax),
TAttText(ax),
fWmin(ax.fWmin),
fWmax(ax.fWmax),
fGridLength(ax.fGridLength),
fTickSize(ax.fTickSize),
fLabelOffset(ax.fLabelOffset),
fLabelSize(ax.fLabelSize),
fTitleOffset(ax.fTitleOffset),
fTitleSize(ax.fTitleSize),
fNdiv(ax.fNdiv),
fLabelColor(ax.fLabelColor),
fLabelFont(ax.fLabelFont),
fNModLabs(ax.fNModLabs),
fChopt(ax.fChopt),
fName(ax.fName),
fTitle(ax.fTitle),
fTimeFormat(ax.fTimeFormat),
fFunctionName(ax.fFunctionName),
fFunction(ax.fFunction),
fAxis(ax.fAxis),
fModLabs(ax.fModLabs)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Assignment operator.
TGaxis& TGaxis::operator=(const TGaxis& ax)
{
if(this!=&ax) {
TLine::operator=(ax);
TAttText::operator=(ax);
fWmin=ax.fWmin;
fWmax=ax.fWmax;
fGridLength=ax.fGridLength;
fTickSize=ax.fTickSize;
fLabelOffset=ax.fLabelOffset;
fLabelSize=ax.fLabelSize;
fTitleOffset=ax.fTitleOffset;
fTitleSize=ax.fTitleSize;
fNdiv=ax.fNdiv;
fModLabs=ax.fModLabs;
fLabelColor=ax.fLabelColor;
fLabelFont=ax.fLabelFont;
fChopt=ax.fChopt;
fName=ax.fName;
fTitle=ax.fTitle;
fTimeFormat=ax.fTimeFormat;
fFunctionName=ax.fFunctionName;
fFunction=ax.fFunction;
fAxis=ax.fAxis;
fNModLabs=ax.fNModLabs;
}
return *this;
}
////////////////////////////////////////////////////////////////////////////////
/// TGaxis default destructor.
TGaxis::~TGaxis()
{
}
////////////////////////////////////////////////////////////////////////////////
/// If center = kTRUE axis labels are centered in the center of the bin.
/// The default is to center on the primary tick marks.
/// This option does not make sense if there are more bins than tick marks.
void TGaxis::CenterLabels(Bool_t center)
{
if (center) SetBit(TAxis::kCenterLabels);
else ResetBit(TAxis::kCenterLabels);
}
////////////////////////////////////////////////////////////////////////////////
/// If center = kTRUE axis title will be centered. The default is right adjusted.
void TGaxis::CenterTitle(Bool_t center)
{
if (center) SetBit(TAxis::kCenterTitle);
else ResetBit(TAxis::kCenterTitle);
}
////////////////////////////////////////////////////////////////////////////////
/// Draw this axis with new attributes.
void TGaxis::DrawAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
Double_t wmin, Double_t wmax, Int_t ndiv, Option_t *chopt,
Double_t gridlength)
{
TGaxis *newaxis = new TGaxis(xmin,ymin,xmax,ymax,wmin,wmax,ndiv,chopt,gridlength);
newaxis->SetLineColor(fLineColor);
newaxis->SetLineWidth(fLineWidth);
newaxis->SetLineStyle(fLineStyle);
newaxis->SetTextAlign(fTextAlign);
newaxis->SetTextAngle(fTextAngle);
newaxis->SetTextColor(fTextColor);
newaxis->SetTextFont(fTextFont);
newaxis->SetTextSize(fTextSize);
newaxis->SetTitleSize(fTitleSize);
newaxis->SetTitleOffset(fTitleOffset);
newaxis->SetLabelFont(fLabelFont);
newaxis->SetLabelColor(fLabelColor);
newaxis->SetLabelSize(fLabelSize);
newaxis->SetLabelOffset(fLabelOffset);
newaxis->SetTickSize(fTickSize);
newaxis->SetBit(kCanDelete);
newaxis->SetTitle(GetTitle());
newaxis->SetBit(TAxis::kCenterTitle,TestBit(TAxis::kCenterTitle));
newaxis->AppendPad();
}
////////////////////////////////////////////////////////////////////////////////
/// Static function returning fgMaxDigits (See SetMaxDigits).
Int_t TGaxis::GetMaxDigits()
{
return fgMaxDigits;
}
////////////////////////////////////////////////////////////////////////////////
/// Internal method to import TAxis attributes to this TGaxis.
void TGaxis::ImportAxisAttributes(TAxis *axis)
{
fAxis = axis;
SetLineColor(axis->GetAxisColor());
SetTextColor(axis->GetTitleColor());
SetTextFont(axis->GetTitleFont());
SetLabelColor(axis->GetLabelColor());
SetLabelFont(axis->GetLabelFont());
SetLabelSize(axis->GetLabelSize());
SetLabelOffset(axis->GetLabelOffset());
SetTickSize(axis->GetTickLength());
SetTitle(axis->GetTitle());
SetTitleOffset(axis->GetTitleOffset());
SetTitleSize(axis->GetTitleSize());
SetBit(TAxis::kCenterTitle, axis->TestBit(TAxis::kCenterTitle));
SetBit(TAxis::kCenterLabels, axis->TestBit(TAxis::kCenterLabels));
SetBit(TAxis::kRotateTitle, axis->TestBit(TAxis::kRotateTitle));
SetBit(TAxis::kNoExponent, axis->TestBit(TAxis::kNoExponent));
SetBit(TAxis::kTickPlus, axis->TestBit(TAxis::kTickPlus));
SetBit(TAxis::kTickMinus, axis->TestBit(TAxis::kTickMinus));
SetBit(TAxis::kMoreLogLabels, axis->TestBit(TAxis::kMoreLogLabels));
if (axis->GetDecimals()) SetBit(TAxis::kDecimals); //the bit is in TAxis::fAxis2
SetTimeFormat(axis->GetTimeFormat());
}
////////////////////////////////////////////////////////////////////////////////
/// Draw this axis with its current attributes.
void TGaxis::Paint(Option_t *)
{
Double_t wmin = fWmin;
Double_t wmax = fWmax;
Int_t ndiv = fNdiv;
// following code required to support toggle of lin/log scales
Double_t x1 = gPad->XtoPad(fX1);
Double_t y1 = gPad->YtoPad(fY1);
Double_t x2 = gPad->XtoPad(fX2);
Double_t y2 = gPad->YtoPad(fY2);
PaintAxis(x1,y1,x2,y2,wmin,wmax,ndiv,fChopt.Data(),fGridLength);
}
////////////////////////////////////////////////////////////////////////////////
/// Control function to draw an axis.
/// Original authors: O.Couet C.E.Vandoni N.Cremel-Somon.
/// Modified and converted to C++ class by Rene Brun.
void TGaxis::PaintAxis(Double_t xmin, Double_t ymin, Double_t xmax, Double_t ymax,
Double_t &wmin, Double_t &wmax, Int_t &ndiv, Option_t *chopt,
Double_t gridlength, Bool_t drawGridOnly)
{
const char *where = "PaintAxis";
Double_t alfa, beta, ratio1, ratio2, grid_side;
Double_t axis_lengthN = 0;
Double_t axis_length0 = 0;
Double_t axis_length1 = 0;
Double_t axis_length;
Double_t atick[3];
Double_t tick_side;
Double_t charheight;
Double_t phil, phi, sinphi, cosphi, asinphi, acosphi;
Double_t binLow = 0., binLow2 = 0., binLow3 = 0.;
Double_t binHigh = 0., binHigh2 = 0., binHigh3 = 0.;
Double_t binWidth = 0., binWidth2 = 0., binWidth3 = 0.;
Double_t xpl1, xpl2, ypl1, ypl2;
Double_t xtick = 0;
Double_t xtick0, xtick1, dxtick=0;
Double_t ytick, ytick0, ytick1;
Double_t wlabel, dwlabel;
Double_t xfactor, yfactor;
Double_t xlabel, ylabel, dxlabel;
Double_t xone, xtwo;
Double_t rlab;
Double_t x0, x1, y0, y1, xx0, xx1, yy0, yy1;
xx0 = xx1 = yy0 = yy1 = 0;
Double_t xxmin, xxmax, yymin, yymax;
xxmin = xxmax = yymin = yymax = 0;
Double_t xlside, xmside;
Double_t ww, af, rne;
Double_t xx, yy;
Double_t xmnlog, x00, x11, h2, h2sav, axmul, y;
Float_t chupxvsav, chupyvsav;
Double_t rtxw, rtyw;
Int_t nlabels, nticks, nticks0, nticks1;
Int_t i, j, k, l, decade, ltick;
Int_t mside, lside;
Int_t nexe = 0;
Int_t lnlen = 0;
Int_t iexe, if1, if2, na, nf, ih1, ih2, nbinin, nch, kmod;
Int_t optionLog,optionBlank,optionVert,optionPlus,optionMinus,optionUnlab,optionPara;
Int_t optionDown,optionRight,optionLeft,optionCent,optionEqual,optionDecimals=0,optionDot;
Int_t optionY,optionText,optionGrid,optionSize,optionNoopt,optionInt,optionM,optionUp,optionX;
Int_t optionTime;
Int_t first=0,last=0,labelnumber;
Int_t xalign, yalign;
Int_t nn1, nn2, nn3, n1a, n2a, n3a, nb2, nb3;
Int_t nbins=10, n1aold, nn1old;
n1aold = nn1old = 0;
Int_t ndyn;
Int_t nhilab = 0;
Int_t idn;
Bool_t flexe = 0;
Bool_t flexpo,flexne;
char *label;
char *chtemp;
char *coded;
char chlabel[256];
char kchtemp[256];
char chcoded[8];
TLine *linegrid;
TString timeformat;
TString typolabel;
time_t timelabel;
Double_t timed, wTimeIni;
struct tm* utctis;
Double_t rangeOffset = 0;
Double_t epsilon = 1e-5;
const Double_t kPI = TMath::Pi();
Double_t rwmi = wmin;
Double_t rwma = wmax;
chtemp = &kchtemp[0];
label = &chlabel[0];
linegrid = 0;
fFunction = (TF1*)gROOT->GetFunction(fFunctionName.Data());
Bool_t noExponent = TestBit(TAxis::kNoExponent);
// If moreLogLabels = kTRUE more Log Intermediate Labels are drawn.
Bool_t moreLogLabels = TestBit(TAxis::kMoreLogLabels);
// the following parameters correspond to the pad range in NDC
// and the user's coordinates in the pad
Double_t padh = gPad->GetWh()*gPad->GetAbsHNDC();
Double_t rwxmin = gPad->GetX1();
Double_t rwxmax = gPad->GetX2();
Double_t rwymin = gPad->GetY1();
Double_t rwymax = gPad->GetY2();
if(strchr(chopt,'G')) optionLog = 1; else optionLog = 0;
if(strchr(chopt,'B')) optionBlank= 1; else optionBlank= 0;
if(strchr(chopt,'V')) optionVert = 1; else optionVert = 0;
if(strchr(chopt,'+')) optionPlus = 1; else optionPlus = 0;
if(strchr(chopt,'-')) optionMinus= 1; else optionMinus= 0;
if(strchr(chopt,'U')) optionUnlab= 1; else optionUnlab= 0;
if(strchr(chopt,'P')) optionPara = 1; else optionPara = 0;
if(strchr(chopt,'O')) optionDown = 1; else optionDown = 0;
if(strchr(chopt,'R')) optionRight= 1; else optionRight= 0;
if(strchr(chopt,'L')) optionLeft = 1; else optionLeft = 0;
if(strchr(chopt,'C')) optionCent = 1; else optionCent = 0;
if(strchr(chopt,'=')) optionEqual= 1; else optionEqual= 0;
if(strchr(chopt,'Y')) optionY = 1; else optionY = 0;
if(strchr(chopt,'T')) optionText = 1; else optionText = 0;
if(strchr(chopt,'W')) optionGrid = 1; else optionGrid = 0;
if(strchr(chopt,'S')) optionSize = 1; else optionSize = 0;
if(strchr(chopt,'N')) optionNoopt= 1; else optionNoopt= 0;
if(strchr(chopt,'I')) optionInt = 1; else optionInt = 0;
if(strchr(chopt,'M')) optionM = 1; else optionM = 0;
if(strchr(chopt,'0')) optionUp = 1; else optionUp = 0;
if(strchr(chopt,'X')) optionX = 1; else optionX = 0;
if(strchr(chopt,'t')) optionTime = 1; else optionTime = 0;
if(strchr(chopt,'.')) optionDot = 1; else optionDot = 0;
if (TestBit(TAxis::kTickPlus)) optionPlus = 2;
if (TestBit(TAxis::kTickMinus)) optionMinus = 2;
if (TestBit(TAxis::kCenterLabels)) optionM = 1;
if (TestBit(TAxis::kDecimals)) optionDecimals = 1;
if (!gStyle->GetStripDecimals()) optionDecimals = 1;
if (fAxis) {
if (fAxis->GetLabels()) {
optionM = 1;
optionText = 1;
ndiv = fAxis->GetLast()-fAxis->GetFirst()+1;
}
TList *ml = fAxis->GetModifiedLabels();
if (ml) {
fModLabs = ml;
fNModLabs = fModLabs->GetSize();
} else {
fModLabs = 0;
fNModLabs = 0;
}
}
if (ndiv < 0) {
Error(where, "Invalid number of divisions: %d",ndiv);
return;
}
// Set the grid length
if (optionGrid) {
if (gridlength == 0) gridlength = 0.8;
linegrid = new TLine();
linegrid->SetLineColor(gStyle->GetGridColor());
if (linegrid->GetLineColor() == 0) linegrid->SetLineColor(GetLineColor());
linegrid->SetLineStyle(gStyle->GetGridStyle());
linegrid->SetLineWidth(gStyle->GetGridWidth());
}
// No labels if the axis label offset is big.
// In that case the labels are not visible anyway.
if (GetLabelOffset() > 1.1 ) optionUnlab = 1;
// Determine time format
Int_t idF = fTimeFormat.Index("%F");
if (idF>=0) {
timeformat = fTimeFormat(0,idF);
} else {
timeformat = fTimeFormat;
}
//GMT option
if (fTimeFormat.Index("GMT")>=0) optionTime =2;
// Determine the time offset and correct for time offset not being integer.
Double_t timeoffset =0;
if (optionTime) {
if (idF>=0) {
Int_t lnF = fTimeFormat.Length();
TString stringtimeoffset = fTimeFormat(idF+2,lnF);
Int_t year, mm, dd, hh, mi, ss;
if (sscanf(stringtimeoffset.Data(), "%d-%d-%d %d:%d:%d", &year, &mm, &dd, &hh, &mi, &ss) == 6) {
//Get time offset in seconds since EPOCH:
struct tm tp;
tp.tm_year = year-1900;
tp.tm_mon = mm-1;
tp.tm_mday = dd;
tp.tm_hour = hh;
tp.tm_min = mi;
tp.tm_sec = ss;
tp.tm_isdst = 0; //no DST for UTC (and forced to 0 in MktimeFromUTC function)
timeoffset = TTimeStamp::MktimeFromUTC(&tp);
// Add the time offset's decimal part if it is there
Int_t ids = stringtimeoffset.Index("s");
if (ids >= 0) {
Float_t dp;
Int_t lns = stringtimeoffset.Length();
TString sdp = stringtimeoffset(ids+1,lns);
sscanf(sdp.Data(),"%g",&dp);
timeoffset += dp;
}
} else {
Error(where, "Time offset has not the right format");
}
} else {
timeoffset = gStyle->GetTimeOffset();
}
wmin += timeoffset - (int)(timeoffset);
wmax += timeoffset - (int)(timeoffset);
// correct for time offset at a good limit (min, hour, day, month, year)
struct tm* tp0;
time_t timetp = (time_t)((Long_t)(timeoffset));
Double_t range = wmax - wmin;
Long_t rangeBase = 60;
if (range>60) rangeBase = 60*20; // minutes
if (range>3600) rangeBase = 3600*20; // hours
if (range>86400) rangeBase = 86400*20; // days
if (range>2419200) rangeBase = 31556736; // months (average # days)
rangeOffset = (Double_t) ((Long_t)(timeoffset)%rangeBase);
if (range>31536000) {
tp0 = gmtime(&timetp);
tp0->tm_mon = 0;
tp0->tm_mday = 1;
tp0->tm_hour = 0;
tp0->tm_min = 0;
tp0->tm_sec = 0;
tp0->tm_isdst = 1; // daylight saving time is on.
rangeBase = (timetp-mktime(tp0)); // years
rangeOffset = (Double_t) (rangeBase);
}
wmax += rangeOffset;
wmin += rangeOffset;
}
// Determine number of divisions 1, 2 and 3
n1a = ndiv%100;
n2a = (ndiv%10000 - n1a)/100;
n3a = ndiv/10000;
nn3 = TMath::Max(n3a,1);
nn2 = TMath::Max(n2a,1)*nn3;
nn1 = TMath::Max(n1a,1)*nn2+1;
nticks= nn1;
// Axis bining optimisation is ignored if:
// - the first and the last label are equal
// - the number of divisions is 0
// - less than 1 primary division is requested
// - logarithmic scale is requested
if (wmin == wmax || ndiv == 0 || n1a <= 1 || optionLog) {
optionNoopt = 1;
optionInt = 0;
}
// Axis bining optimisation
if ( (wmax-wmin) < 1 && optionInt) {
Error(where, "option I not available");
optionInt = 0;
}
if (!optionNoopt || optionInt ) {
// Primary divisions optimisation
// When integer labelling is required, Optimize is invoked first
// and only if the result is not an integer labelling, AdjustBinSize is invoked.
THLimitsFinder::Optimize(wmin,wmax,n1a,binLow,binHigh,nbins,binWidth,fChopt.Data());