16 #include "Riostream.h"
27 #include "../src_cpp/ListDataStock.h"
37 #include "TPainter3dAlgorithms.h"
58 #ifdef DEBUG_HISTPAINTER
59 std::cout <<
"For test Constructor THistPainterStock" << std::endl;
66 #ifdef DEBUG_HISTPAINTER
67 std::cout <<
"For test Destructor THistPainterStock" << std::endl;
79 Int_t nch = strlen(choptin);
81 strncpy (chopt,choptin,128);
83 Hoption_stock.Axis = Hoption_stock.Bar = Hoption_stock.Curve = Hoption_stock.Error = 0;
84 Hoption_stock.Hist = Hoption_stock.Line = Hoption_stock.Mark = Hoption_stock.Fill = 0;
85 Hoption_stock.Same = Hoption_stock.Func = Hoption_stock.Plus = Hoption_stock.Scat = 0;
86 Hoption_stock.Star = Hoption_stock.Arrow = Hoption_stock.Box = Hoption_stock.Text = 0;
87 Hoption_stock.Char = Hoption_stock.Color = Hoption_stock.Contour = Hoption_stock.Logx = 0;
88 Hoption_stock.Logy = Hoption_stock.Logz = Hoption_stock.Lego = Hoption_stock.Surf = 0;
89 Hoption_stock.Off = Hoption_stock.Tri = Hoption_stock.Proj = Hoption_stock.AxisPos = 0;
90 Hoption_stock.Spec = Hoption_stock.Pie = 0;
94 Hoption_stock.Candle = 0;
99 Hoption_stock.List = 0;
100 Hoption_stock.Zscale = 0;
101 Hoption_stock.FrontBox = 1;
102 Hoption_stock.BackBox = 1;
103 Hoption_stock.System = kCARTESIAN;
105 Hoption_stock.HighRes = 0;
108 Hoption_stock.Zero = 0;
139 l = strstr(chopt,
"GL");
143 l = strstr(chopt,
"X+");
145 Hoption_stock.AxisPos = 10;
148 l = strstr(chopt,
"Y+");
150 Hoption_stock.AxisPos += 1;
153 if((Hoption_stock.AxisPos == 10 || Hoption_stock.AxisPos == 1) && (nch == 2)) Hoption_stock.Hist = 1;
154 if(Hoption_stock.AxisPos == 11 && nch == 4) Hoption_stock.Hist = 1;
156 l = strstr(chopt,
"SAMES");
158 if (nch == 5) Hoption_stock.Hist = 1;
159 Hoption_stock.Same = 2;
162 l = strstr(chopt,
"SAME");
164 if (nch == 4) Hoption_stock.Hist = 1;
165 Hoption_stock.Same = 1;
169 l = strstr(chopt,
"BAR");
171 Hoption_stock.Hist = 0;
172 Hoption_stock.Bar = 10; strncpy(l,
" ",3);
173 if (l[3] ==
'1') { Hoption_stock.Bar = 11; l[3] =
' '; }
174 if (l[3] ==
'2') { Hoption_stock.Bar = 12; l[3] =
' '; }
175 if (l[3] ==
'3') { Hoption_stock.Bar = 13; l[3] =
' '; }
176 if (l[3] ==
'4') { Hoption_stock.Bar = 14; l[3] =
' '; }
180 l = strstr(chopt,
"+-");
if (l) { Hoption_stock.Plus = 2; strncpy(l,
" ",2); }
181 l = strstr(chopt,
"-+");
if (l) { Hoption_stock.Plus = 2; strncpy(l,
" ",2); }
183 l = strstr(chopt,
"HIST");
if (l) { Hoption_stock.Hist = 2; strncpy(l,
" ",4); Hoption_stock.Func = 0; Hoption_stock.Error = 0;}
184 l = strstr(chopt,
"AXIS");
if (l) { Hoption_stock.Axis = 1; strncpy(l,
" ",4); }
185 l = strstr(chopt,
"AXIG");
if (l) { Hoption_stock.Axis = 2; strncpy(l,
" ",4); }
186 l = strstr(chopt,
"TEXT");
189 if (sscanf(&l[4],
"%d",&angle) > 0) {
190 if (angle < 0) angle=0;
191 if (angle > 90) angle=90;
192 Hoption_stock.Text = 1000+angle;
194 Hoption_stock.Text = 1;
197 Hoption_stock.Scat = 0;
223 if (strstr(chopt,
"A")) Hoption_stock.Axis = -1;
224 if (strstr(chopt,
"B")) Hoption_stock.Bar = 1;
276 Hoption_stock.Logx = gPad->GetLogx();
277 Hoption_stock.Logy = gPad->GetLogy();
278 Hoption_stock.Logz = gPad->GetLogz();
307 #ifdef DEBUG_HISTPAINTER
308 std::cout <<
"Entry Paint Frame, is Hoption_stock.Same " << Hoption_stock.Same << std::endl;
312 if (Hoption_stock.Same) {
313 #ifdef DEBUG_HISTPAINTER
314 std::cout <<
"Entry Paint Frame, is Hoption_stock.Same true" << std::endl;
341 #ifdef DEBUG_HISTPAINTER
342 std::cout <<
"Entry RecalculateRange Proj=" << Hoption_stock.Proj << std::endl;
344 if (Hoption_stock.Same)
return;
352 Double_t dx = xmax-xmin;
353 Double_t dy = ymax-ymin;
354 Double_t dxr = dx/(1 - gPad->GetLeftMargin() - gPad->GetRightMargin());
355 Double_t dyr = dy/(1 - gPad->GetBottomMargin() - gPad->GetTopMargin());
359 gPad->Range(xmin - dxr*gPad->GetLeftMargin(),
360 ymin - dyr*gPad->GetBottomMargin(),
361 xmax + dxr*gPad->GetRightMargin(),
362 ymax + dyr*gPad->GetTopMargin());
363 gPad->RangeAxis( xmin, ymin, xmax, ymax );
370 #ifdef DEBUG_HISTPAINTER
371 std::cout <<
"\n\t Entry PaintTitle()" << std::endl;
378 if (Hoption_stock.Same)
return;
379 if (fH->TestBit(TH1::kNoTitle))
return;
381 Int_t nt = strlen(fH->GetTitle());
382 TPaveText *title = 0;
384 TIter next(gPad->GetListOfPrimitives());
385 while ((obj = next())) {
386 if (!obj->InheritsFrom(TPaveText::Class()))
continue;
387 title = (TPaveText*)obj;
388 if (strcmp(title->GetName(),
"title")) {title = 0;
continue;}
391 if (nt == 0 || gStyle->GetOptTitle() <= 0) {
392 if (title)
delete title;
397 Double_t ht = gStyle->GetTitleH();
398 Double_t wt = gStyle->GetTitleW();
403 if ( ((
THStock*)fH)->GetSizeTitle() != 0. ) {
406 ht = 1.05*((
THStock*)fH)->GetSizeTitle();
411 if (ht <= 0) ht = 1.05 * gStyle->GetTitleFontSize();
412 if (ht <= 0) ht = 0.05;
418 l.SetTitle(fH->GetTitle());
421 ht = TMath::Max(ht, 2.0*l.GetYsize()/(gPad->GetY2() - gPad->GetY1()));
422 Double_t wndc = l.GetXsize()/(gPad->GetX2() - gPad->GetX1());
423 wt = TMath::Min(0.7, 0.02+wndc);
426 TText *t0 = (TText*)title->GetLine(0);
429 if (!strcmp(t0->GetTitle(),fH->GetTitle()))
return;
430 t0->SetTitle(fH->GetTitle());
431 if (wt > 0) title->SetX2NDC(title->GetX1NDC()+wt);
440 Int_t talh = gStyle->GetTitleAlign()/10;
441 if (talh < 1) talh = 1;
if (talh > 3) talh = 3;
442 Int_t talv = gStyle->GetTitleAlign()%10;
443 if (talv < 1) talv = 1;
if (talv > 3) talv = 3;
445 xpos = gStyle->GetTitleX();
446 ypos = gStyle->GetTitleY();
447 if (talh == 2) xpos = xpos-wt/2.;
448 if (talh == 3) xpos = xpos-wt;
449 if (talv == 2) ypos = ypos+ht/2.;
450 if (talv == 1) ypos = ypos+ht;
455 TPaveText *ptitle =
new TPaveText(xpos, ypos-ht, xpos+wt, ypos,
"blNDC");
460 ptitle->SetFillColor(gStyle->GetTitleFillColor());
461 ptitle->SetFillStyle(gStyle->GetTitleStyle());
462 ptitle->SetName(
"title");
463 ptitle->SetBorderSize(gStyle->GetTitleBorderSize());
464 ptitle->SetTextColor(gStyle->GetTitleTextColor());
465 ptitle->SetTextFont(gStyle->GetTitleFont(
""));
468 if (gStyle->GetTitleFont(
"")%10 > 2) {
470 std::cout <<
"Test condition font " << std::endl;
471 ptitle->SetTextSize(gStyle->GetTitleFontSize());
486 ptitle->AddText(fH->GetTitle());
488 ptitle->SetBit(kCanDelete);
510 #ifdef DEBUG_HISTPAINTER
511 std::cout <<
"Entry THistPainterStock::PaintInit latest version " << std::endl;
513 std::cout <<
" this = " <<
this << std::endl;
518 Int_t size_data_axis;
519 Int_t size_data_listd;
521 Int_t shift_futur, shift_left;
523 Double_t bigp = TMath::Power( 10, 32 );
524 Double_t ymax = -bigp;
525 Double_t ymin = bigp;
528 fXaxis = ( (
THStock *)fH )->GetCommonXAxis()->GetXAxis();
531 size_data_axis = fXaxis->GetNbins();
536 if ( ldata ==
nullptr ) {
537 std::cout <<
"THsitPainterStock::PaintInit Error ldata is null " << std::endl;
542 size_data_listd = ldata->
GetSize();
544 #ifdef DEBUG_HISTPAINTER
545 std::cout <<
"size_data_axis = fXaxis->GetNbins() " << size_data_axis << std::endl;
546 std::cout <<
"size_data_listd " << size_data_listd << std::endl;
597 shift_futur = ( (
THStock *)fH )-> GetCommonXAxis() -> GetShift();
614 shift_left = size_data_axis - size_data_listd - shift_futur;
616 #ifdef DEBUG_HISTPAINTER
626 if ( shift_futur > 0 ) {
628 #ifdef DEBUG_HISTPAINTER
629 std::cout <<
"Take min between Hparam.xlast " <<
Hparam_stock.
xlast << std::endl;
630 std::cout <<
"and size_data_listd + shift_left " << size_data_listd + shift_left << std::endl;
631 std::cout <<
"shift_futur > 0, Took Min for xlast " <<
Hparam_stock.
xlast << std::endl;
640 #ifdef DEBUG_HISTPAINTER
648 #ifdef DEBUG_HISTPAINTER
649 std::cout <<
"All Hparam_stock set up ? " << std::endl;
651 std::cout <<
" Look for maximum, minimum " << std::endl;
660 #ifdef DEBUG_HISTPAINTER
661 std::cout <<
"Before GetObjectExtrema " << std::endl;
665 ((
THStock *)fH)->GetObjectExtrema( ymin, ymax );
667 #ifdef DEBUG_HISTPAINTER
668 std::cout <<
" After GetObjectExtrema ymin " << ymin <<
" ymax " << ymax << std::endl;
678 #ifdef DEBUG_HISTPAINTER
681 std::cout <<
"Exit THistPainterStock::PaintInit()\n" << std::endl;
695 #ifdef DEBUG_HISTPAINTER
696 std::cout <<
"\n\tEntry THistPainterStock::PaintAxis " << std::endl;
700 if (Hoption_stock.Same && Hoption_stock.Axis <= 0)
return;
707 static char chopt[10] =
"";
712 Int_t ndiv, ndivx, ndivy, nx1, nx2, ndivsave;
714 Double_t umin, umax, uminsave, umaxsave;
715 Short_t xAxisPos = Hoption_stock.AxisPos/10;
716 Short_t yAxisPos = Hoption_stock.AxisPos - 10*xAxisPos;
718 Double_t axmin = gPad->GetUxmin();
719 Double_t axmax = gPad->GetUxmax();
720 Double_t aymin = gPad->GetUymin();
721 Double_t aymax = gPad->GetUymax();
733 ndivy = fYaxis->GetNdivisions();
735 axis.ImportAxisAttributes(fYaxis);
738 strcat(chopt,
"SDH");
739 if (ndivy < 0) strcat(chopt,
"N");
740 if (gPad->GetGridy()) {
741 gridl = (axmax-axmin)/(gPad->GetX2() - gPad->GetX1());
746 if (Hoption_stock.Logy) {
748 ndiv = TMath::Abs(ndivy);
754 umin = TMath::Power(10,aymin);
755 umax = TMath::Power(10,aymax);
759 ndiv = TMath::Abs(ndivy);
771 if (fYaxis->GetTimeDisplay()) {
772 std::cout <<
"Paint Display " << std::endl;
774 if (strlen(fYaxis->GetTimeFormatOnly()) == 0) {
780 Double_t yAxisXPos1, yAxisXPos2;
796 axis.SetOption(chopt);
802 if (Hoption_stock.Same && Hoption_stock.Axis) {
803 axis.SetLabelSize(0.);
807 axis.PaintAxis(yAxisXPos1, aymin,
809 umin, umax, ndiv, chopt, gridl, drawGridOnly);
812 if (gPad->GetTicky()) {
813 if (gPad->GetTicky() < 2) {
815 axis.SetTickSize(-fYaxis->GetTickLength());
820 if ((cw=strstr(chopt,
"W"))) *cw=
'z';
822 axis.PaintAxis(yAxisXPos2, aymin, yAxisXPos2, aymax,
823 uminsave, umaxsave, ndivsave, chopt, gridl, drawGridOnly);
829 if (Hoption_stock.Axis == -1)
return;
833 ndivx = fXaxis->GetNdivisions();
838 nx1 = TMath::Max(1, ndivx%100);
839 ndivx = 100*nx2 + Int_t(Float_t(nx1)*gPad->GetAbsWNDC());
841 axis.SetTextAngle(0);
842 axis.ImportAxisAttributes(fXaxis);
845 strcat(chopt,
"SDH");
846 if (ndivx < 0) strcat(chopt,
"N");
847 if (gPad->GetGridx()) {
848 gridl = (aymax-aymin)/(gPad->GetY2() - gPad->GetY1());
853 if (Hoption_stock.Logx) {
855 ndiv = TMath::Abs(ndivx);
861 umin = TMath::Power(10,axmin);
862 umax = TMath::Power(10,axmax);
866 ndiv = TMath::Abs(ndivx);
878 if (fXaxis->GetTimeDisplay()) {
880 if (strlen(fXaxis->GetTimeFormatOnly()) == 0) {
885 Double_t xAxisYPos1, xAxisYPos2;
900 axis.SetOption(chopt);
906 if (Hoption_stock.Same && Hoption_stock.Axis) {
907 axis.SetLabelSize(0.);
920 axis.PaintAxis(axmin, xAxisYPos1, axmax, xAxisYPos1,
921 umin, umax, ndiv, chopt, gridl, drawGridOnly);
924 if (gPad->GetTickx()) {
926 cw=strstr(chopt,
"-");
932 if (gPad->GetTickx() < 2) strcat(chopt,
"U");
933 if ((cw=strstr(chopt,
"W"))) *cw=
'z';
935 axis.PaintAxis(axmin, xAxisYPos2, axmax, xAxisYPos2,
936 uminsave, umaxsave, ndivsave, chopt, gridl, drawGridOnly);
939 #ifdef DEBUG_HISTPAINTER
940 std::cout <<
"Exit PaintAxis" << std::endl;
954 #ifdef DEBUG_HISTPAINTER
955 std::cout <<
"\n\t Entry Paint in THistPainterStock" << std::endl;
957 std::cout <<
"will paint fH->GetName() " << fH->GetName() << std::endl;
962 if (fH->GetBuffer()) fH->BufferEmpty(-1);
964 gPad->SetVertical(kTRUE);
968 std::cout <<
"Return from THistPainterStock::Paint because MakeChopt returned false" << std::endl;
975 if (Hoption_stock.Same)
976 std::cout <<
"Option SAME" << std::endl;
977 else if (Hoption_stock.Axis == -1)
978 std::cout <<
"Option A" << std::endl;
979 #ifdef DEBUG_HISTPAINTER
981 std::cout <<
"No Option, default" << std::endl;
990 std::cout <<
"\n\tPaintInit return 0, IMPOSSIBLE \n" << std::endl;
1010 #ifdef DEBUG_HISTPAINTER
1011 std::cout <<
"Hoption_stock.Axis " << Hoption_stock.Axis << std::endl;
1014 Bool_t gridx = gPad->GetGridx();
1015 Bool_t gridy = gPad->GetGridy();
1016 if (Hoption_stock.Axis > 0) {
1017 if (Hoption_stock.Axis > 1)
1020 if (gridx) gPad->SetGridx(0);
1021 if (gridy) gPad->SetGridy(0);
1023 if (gridx) gPad->SetGridx(1);
1024 if (gridy) gPad->SetGridy(1);
1026 if (Hoption_stock.Same ==1) Hoption_stock.Same = 2;
1032 if (gridx) gPad->SetGridx(0);
1033 if (gridy) gPad->SetGridy(0);
1035 if (gridx) gPad->SetGridx(1);
1036 if (gridy) gPad->SetGridy(1);
1043 ((
THStock *)fH)->PaintObjectStock();
1063 if ( ( Hoption_stock.Axis < 0 ) || ( Hoption_stock.Same ) ) {
1064 #ifdef DEBUG_HISTPAINTER
1065 std::cout <<
"option Axis or SAME return " << std::endl;
1071 char tmp_date[30]=
"";
1072 char tmp_date_opt[15]=
"";
1073 char memo_opt[15]=
"";
1076 Int_t frequence,count=0;
1085 #ifdef DEBUG_HISTPAINTER
1086 std::cout <<
"SetLabelAxis " << std::endl;
1087 std::cout <<
" ldata " << ldata << std::endl;
1088 std::cout <<
" ETime " << tmscl << std::endl;
1089 std::cout <<
" size_data " << size_data << std::endl;
1091 std::cout <<
" name " << ldata->
GetName() << std::endl;
1095 if ( size_data > 8 )
1096 frequence = ( size_data+4 )/8;
1116 strftime(tmp_date,25,
"%d",&date_tm);
1117 strftime( tmp_date_opt, 25,
"-%m", &date_tm);
1123 strftime(tmp_date,25,
"%H:%M",&date_tm);
1124 strftime( tmp_date_opt, 25,
"-%d", &date_tm);
1128 strftime(tmp_date,25,
"%m",&date_tm);
1129 strftime( tmp_date_opt, 25,
"%y", &date_tm);
1132 strftime(tmp_date,25,
"%H",&date_tm);
1135 strftime(tmp_date,25,
"%y",&date_tm);
1138 if ( strcmp( memo_opt, tmp_date_opt ) ) {
1141 if (count % frequence == 0 ) {
1142 strcpy ( memo_opt, tmp_date_opt );
1143 strcat( tmp_date, tmp_date_opt );
1150 if (count % frequence == 0 ) {
1151 fXaxis->SetBinLabel(bin,tmp_date);
1154 else fXaxis->SetBinLabel(bin,
"");
1171 #ifdef DEBUG_HISTPAINTER
1172 std::cout <<
"Entry THistPainterStock::DistancetoPrimitive " << std::endl;
1175 const Int_t kMaxDiff = 7;
1176 Int_t puxmin = gPad->XtoAbsPixel(gPad->GetUxmin());
1177 Int_t puymin = gPad->YtoAbsPixel(gPad->GetUymin());
1178 Int_t puxmax = gPad->XtoAbsPixel(gPad->GetUxmax());
1179 Int_t puymax = gPad->YtoAbsPixel(gPad->GetUymax());
1180 Int_t yxaxis, dyaxis,xyaxis, dxaxis;
1182 TString doption = gPad->GetPadPointer()->GetDrawOption();
1187 if (doption.Contains(
"same")) dsame = kTRUE;
1189 dyaxis = Int_t(2*(puymin-puymax)*fYaxis->GetLabelSize());
1190 if (doption.Contains(
"y+")) {
1191 xyaxis = puxmax + Int_t((puxmax-puxmin)*fYaxis->GetLabelOffset());
1192 if (px <= xyaxis+dyaxis && px >= xyaxis && py >puymax && py < puymin) {
1194 if (gPad->IsVertical()) gPad->SetSelected(fYaxis);
1195 else gPad->SetSelected(fXaxis);
1200 xyaxis = puxmin - Int_t((puxmax-puxmin)*fYaxis->GetLabelOffset());
1201 if (px >= xyaxis-dyaxis && px <= xyaxis && py >puymax && py < puymin) {
1203 if (gPad->IsVertical()) gPad->SetSelected(fYaxis);
1204 else gPad->SetSelected(fXaxis);
1210 dxaxis = Int_t((puymin-puymax)*fXaxis->GetLabelSize());
1211 if (doption.Contains(
"x+")) {
1212 yxaxis = puymax - Int_t((puymin-puymax)*fXaxis->GetLabelOffset());
1213 if (py >= yxaxis-dxaxis && py <= yxaxis && px <puxmax && px > puxmin) {
1215 if (gPad->IsVertical()) gPad->SetSelected(fXaxis);
1216 else gPad->SetSelected(fYaxis);
1221 yxaxis = puymin + Int_t((puymin-puymax)*fXaxis->GetLabelOffset());
1222 if (yxaxis < puymin) yxaxis = puymin;
1223 if (py <= yxaxis+dxaxis && py >= yxaxis && px <puxmax && px > puxmin) {
1225 if (gPad->IsVertical()) gPad->SetSelected(fXaxis);
1226 else gPad->SetSelected(fYaxis);
1239 Int_t dist_stock = ((
THStock*) fH)->DistancetoPrimitive( px, py, &(obj_stock) );
1243 if ( dist_stock <= dist ) {
1246 if ( dist < kMaxDiff ) {
1248 #ifdef DEBUG_HISTPAINTER
1249 std::cout <<
"select an ObjectStock " << obj_stock->ClassName() << std::endl;
1253 gPad->SetSelected(obj_stock);
1258 #ifdef DEBUG_HISTPAINTER
1259 std:cout <<
"After gPad->SeSelected, reutrn dist " << dist << std::endl;
1266 #ifdef DEBUG_HISTPAINTER
1267 std::cout <<
"Exit THistPainterStock::DistancetoPrimitive, no selection return previous curdist dist= " << dist << std::endl;
1275 std::cout <<
"\n\tPrintInfo THistPainterStock " << std::endl;
1281 std::cout <<
"\t Exit THistPainterStock::PrintInfo\n" << std::endl;
Derive from TH1 will draw the graph.
virtual void RecalculateRange()
virtual ~THistPainterStock()
Seems present because of ExecuteEvent not overloaded by CanvasStock CanvasStock contains Pad...
Define concrete classes for ObjectStock.
Hparam_stock_t Hparam_stock
virtual void PaintAxis(Bool_t drawGridOnly=kFALSE)
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
virtual Int_t MakeChopt(Option_t *choptin)
virtual const DataStock & ChronologicAt(const unsigned int offset) const =0
Get the nth element in a chronological order.
Overload TPad Because ExecuteEvent not overloaded by CanvasStock.
virtual void Paint(Option_t *option="")
struct tm GetDateTm() const
Get a tm structure of the date.
virtual unsigned int GetSize() const =0
Return the size of the vector.
Derive a specific painter for THStock.
std::string GetName() const
Abstract base class for the ListDataStock, for storing base pointers in vectors.
virtual Int_t PaintInit()
setup minimum/ maximum of the frame Called by Paint()
virtual void PaintTitle()
virtual ETime GetTimeScale() const
ClassImp(THistPainterStock) Hoption_stock_t Hoption_stock
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Check distance to TAxis, broadcast to THStock, and select the object.
virtual void PaintFrame()