15 #include <TPolyLine.h>
19 #include "../CommonXAxis.h"
33 std::cout <<
"Entry CandleStock::GetValues()" << std::endl;
36 values.push_back( fopen ); values.push_back( fhigh ); values.push_back( flow ); values.push_back( fclose );
47 std::vector < std::string > vec_str_text;
48 std::string text_str0, text_str1, indic_str;
54 text_str1 = indic_str +
" open="+ Utils::toString<float>(values[0]) +
" high="+ Utils::toString<float>(values[1])+
55 " low="+Utils::toString<float>(values[2])+
" close="+ Utils::toString<float>(values[3]);
59 vec_str_text.push_back( text_str0 );
60 vec_str_text.push_back( text_str1 );
67 void CandleStock::SetValues(
unsigned int , std::vector<double> values,
double xmin,
double xmax, time_t date,
unsigned int )
115 Int_t pxl, pyl, pxt, pyt;
117 Int_t px1 = gPad->XtoAbsPixel(
fxmin);
118 Int_t py1 = gPad->YtoAbsPixel(
fopen);
119 Int_t px2 = gPad->XtoAbsPixel(
fxmax);
120 Int_t py2 = gPad->YtoAbsPixel(
fclose);
126 if (px1 < px2) {pxl = px1; pxt = px2;}
127 else {pxl = px2; pxt = px1;}
128 if (py1 < py2) {pyl = py1; pyt = py2;}
129 else {pyl = py2; pyt = py1;}
132 if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) {
177 #ifdef DEBUG_OBJSTOCK
178 std::cout <<
"Entry CandleStock::distancetoPoint " << std::endl;
184 for (
unsigned int y = 0; y<4; y++ ) {
186 distance = TMath::Abs( py - gPad->YtoAbsPixel( dtab_py[y] ));
187 if ( distance < dist ) {
194 std::cout <<
"Exit CandleStock::distancetoPoint dist py " << dist <<
" " << yvalue << std::endl;
211 line.SetLineColor(3);
215 line.SetLineColor(2);
220 line.PaintLine ( xmiddle,
flow, xmiddle,
fhigh );
252 std::vector<float>
values;
253 values.push_back(
fvalue );
259 #ifdef DEBUG_OBJSTOCK
260 std::cout <<
"BarStock::MakeStringForStatusBar " << std::endl;
262 std::vector < std::string > vec_str_text;
263 std::string text_str0, text_str1, indic_str;
264 std::vector<float>
values;
269 text_str1 = indic_str +
" ="+ Utils::toString<float>(values[0]);
273 vec_str_text.push_back( text_str0 );
274 vec_str_text.push_back( text_str1 );
286 std::vector<float>
values;
295 double xmin,
double xmax, time_t date,
unsigned int opt_value )
305 fvalue = (Double_t) values[opt_value];
319 Int_t pxl, pyl, pxt, pyt;
322 Int_t px1 = gPad->XtoAbsPixel(
fxmin);
334 py1 = gPad->YtoAbsPixel(0.);
337 Int_t px2 = gPad->XtoAbsPixel(
fxmax );
338 Int_t py2 = gPad->YtoAbsPixel(
fvalue );
347 if (px1 < px2) {pxl = px1; pxt = px2;}
348 else {pxl = px2; pxt = px1;}
349 if (py1 < py2) {pyl = py1; pyt = py2;}
350 else {pyl = py2; pyt = py1;}
355 if ( (px >= pxl && px <= pxt) && (py >= pyl && py <= pyt) ) {
357 std::cout <<
" BarStock::DtP return 0 " << std::endl;
366 #ifdef DEBUG_OBJSTOCK
367 std::cout <<
"Entry Bar::DistancetoPoint " << std::endl;
368 std::cout <<
"py " << py << std::endl;
372 return TMath::Abs ( py - gPad->YtoAbsPixel(
fvalue) );
382 Double_t fvalue2 =
fvalue;
389 ymin = gPad->GetUymin();
411 #ifdef DEBUG_OBJSTOCK
412 std::cout <<
"Entry Constructor PStockLine size " << size << std::endl;
418 for ( UInt_t i = 0; i < size; i++ ) {
426 #ifdef DEBUG_OBJSTOCK
427 std::cout <<
"Entry Constructor PStockLine size " << size << std::endl;
433 for ( UInt_t i = 0; i < size; i++ ) {
443 float coeff, origin, extra_y;
449 coeff = ( y1 - y0 ) / ( x1 - x0 );
450 origin = y0 - coeff * x0;
453 extra_y = coeff * gPad->AbsPixeltoX( px ) + origin;
460 #ifdef DEBUG_OBJSTOCK
461 std::cout <<
"Entry PStockLine::GetValues px/py, &date " << px <<
" " << py << std::endl;
465 std::vector<float>
values;
473 std::cout <<
"date " << date <<
" bin " << bin <<
" bin2 " << bin2 << std::endl;
492 float value_pt =
ExtrapolateYPad ( px, bin, bin2, value_pt0, value_pt1 );
495 values.push_back ( value_pt );
503 #ifdef DEBUG_OBJSTOCK
504 std::cout <<
" PStockLine::MakeStringForStatusBar " << std::endl;
505 std::cout <<
" px, py" << px <<
" " << py << std::endl;
509 std::string text_str0, text_str1;
510 std::vector<std::string> vec_string;
512 std::vector<float>
values;
518 text_str1 =
GetNameObject() +
" = " + Utils::toString<float>( values[0] );
520 vec_string.push_back( text_str0 );
521 vec_string.push_back( text_str1 );
528 #ifdef DEBUG_OBJSTOCK
529 std::cout <<
"\n\tPStockLine::GetExtrema size plvalues " <<
plvalues.size() << std::endl;
531 std::vector<Double_t>::const_iterator it, it2;
533 Double_t value, value_min, value_max;
537 for ( it =
plvalues.begin(); it != it2; ++it ) {
540 if ( value < value_min ) value_min = value;
541 if ( value > value_max ) value_max = value;
556 Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value )
558 #ifdef DEBUG_OBJSTOCK
559 std::cout <<
"Entry PStockLine::SetValues opt_value " << opt_value <<
" values[opt] " << values[opt_value] << std::endl;
562 plvalues.push_back( values[ opt_value ]);
564 fx.push_back ( ( xmin + xmax ) / 2.0f );
567 dates.push_back ( date );
572 #ifdef DEBUG_OBJSTOCK
573 std::cout <<
"PStockLine::Resize add_data new size " << new_size << std::endl;
574 std::cout <<
"old size " <<
plvalues.size() << std::endl;
577 fx.resize ( new_size );
588 #ifdef DEBUG_OBJSTOCK
589 std::cout <<
"PStockLine::ClearObjectStock()" << std::endl;
596 #ifdef DEBUG_OBJSTOCK
597 std::cout <<
"after clear plvalues.size() " <<
plvalues.size() << std::endl;
598 std::cout <<
"fx.size() " <<
fx.size() << std::endl;
606 #ifdef DEBUG_OBJSTOCK
607 std::cout <<
"Entry PStockLine::DistancetoPrimitive" << std::endl;
619 for (i = 0; i <
fx.size(); i++) {
620 pxp = gPad->XtoAbsPixel(gPad->XtoPad(
fx[i]));
621 pyp = gPad->YtoAbsPixel(gPad->YtoPad(
plvalues[i]));
622 d = TMath::Abs(pxp-px) + TMath::Abs(pyp-py);
623 if (d < distance) distance = d;
627 for (i=0;i<
fx.size()-1;i++) {
630 d = DistancetoLine(px, py,
fx[i], gPad->YtoPad(
plvalues[i]),
632 if (d < distance) distance = d;
641 #ifdef DEBUG_OBJSTOCK
642 std::cout <<
"Entry PStockLine::distancetoPoint " << std::endl;
643 std::cout <<
"Get input bin " << bin <<
"value at bin " <<
plvalues[bin] << std::endl;
646 return TMath::Abs( gPad->YtoAbsPixel(
plvalues[bin] ) - py );
660 #ifdef DEBUG_OBJSTOCK
661 std::cout <<
"Entry PStockLine::Paint() " << std::endl;
662 std::cout <<
"fx.size() " <<
fx.size() << std::endl;
663 std::cout <<
"GetLineColor " << GetLineColor() << std::endl;
664 std::cout <<
"kPaint" <<
ToPaint() << std::endl;
667 TPolyLine TPLine (
fx.size());
668 TPLine.SetLineColor ( GetLineColor() );
670 for ( UInt_t i=0; i<
fx.size(); i++ ) {
674 if ( TPLine.GetN() >= 2 ) {
677 #ifdef DEBUG_OBJSTOCK
679 std::cout <<
"TPLine too short do not Paint it" << std::endl;
689 #ifdef DEBUG_OBJSTOCK
690 std::cout <<
" PStockLine::SetObjectStock " << std::endl;
697 std::vector<type_value_data>
values;
698 std::vector<double> values_intern;
701 unsigned int xfirst, xlast;
703 unsigned int size_data = ldata->
GetSize();
705 ComputeBinRange( ldata, fcommon_xaxis_th, Hparam_stock, xfirst, xlast, shift_left );
713 for (
unsigned int bin = xlast ;bin >= xfirst; bin --) {
718 xmin = fcommon_xaxis_th->
GetXAxis()->GetBinLowEdge(bin);
719 xmax = fcommon_xaxis_th->
GetXAxis()->GetBinUpEdge(bin);
725 std::copy ( values.begin(), values.end(), values_intern.begin() );
729 SetValues ( size_data - bin + shift_left, values, xmin, xmax,
739 #ifdef DEBUG_OBJSTOCK
740 std::cout <<
"Entry Constructor CollectionObjectStock size " << size << std::endl;
741 std::cout <<
"name_contained " << name_contained << std::endl;
743 std::cout <<
"ref0 " << ref0 << std::endl;
749 #ifdef DEBUG_OBJSTOCK
750 std::cout <<
"Destructor CollectionObjectStock" << std::endl;
753 for (
unsigned int i = 0; i <
vec_object.size(); i ++ ) {
765 #ifdef DEBUG_OBJSTOCK
766 std::cout <<
"Entry CollectionObjectStock::SetParent " << std::endl;
768 for (
unsigned i=0; i <
vec_object.size(); ++i )
787 #ifdef DEBUG_OBJSTOCK
788 std::cout <<
" Entry CollectionObjectStock::AddToVecObject " << std::endl;
796 #ifdef DEBUG_OBJSTOCK
797 std::cout <<
" Entry CollectionObjectStock::Resize " << std::endl;
799 for (
unsigned int i = 0; i <
vec_object.size(); i++ )
805 #ifdef DEBUG_OBJSTOCK
806 std::cout <<
" Entry CollectionObjectStock::GetExtrema " << std::endl;
815 for (
unsigned int i = 0; i <
vec_object.size(); i++ ) {
817 if ( lmin < tmin ) tmin = lmin;
818 if ( lmax > tmax ) tmax = lmax;
825 double xmin,
double xmax, time_t date,
unsigned int )
827 #ifdef DEBUG_OBJSTOCK
828 std::cout <<
"CollectionObjectStock::SetValues " << std::endl;
829 std::cout <<
"vec_object.size() " <<
vec_object.size() << std::endl;
830 std::cout <<
"values[0] " << values[0] << std::endl;
833 std::vector<double> single_value(1);
835 for (
unsigned int i= 0; i <
vec_object.size(); i++ ) {
837 single_value[0] = values[i];
838 std::cout <<
"single_value " << single_value[0] << std::endl;
840 vec_object[i]->SetValues( bin, single_value, xmin, xmax, date );
847 #ifdef DEBUG_OBJSTOCK
848 std::cout <<
" Entry CollectionObjectStock::ClearObjectStock vec_object.size() " <<
vec_object.size() << std::endl;
850 for (
unsigned int i = 0; i <
vec_object.size(); i++ ) {
858 #ifdef DEBUG_OBJSTOCK
859 std::cout <<
" Entry CollectionObjectStock::DistancetoPrimitive " << std::endl;
863 Int_t dist_objstock = 9999;
868 for (
unsigned int i = 0; i <
vec_object.size(); i++ ) {
871 dist_objstock =
vec_object[i]->DistancetoPrimitive( px, py, &tmp_object );
874 if ( dist_objstock <= dist ) {
875 dist = dist_objstock;
884 #ifdef DEBUG_OBJSTOCK
885 std::cout <<
" aggregate return dist " << dist << std::endl;
886 std::cout <<
" aggregate obj " << *obj << std::endl;
894 #ifdef DEBUG_OBJSTOCK
895 std::cout <<
"Entry CollectionObjectStock::Paint size " <<
vec_object.size() << std::endl;
897 for (
unsigned int i = 0; i <
vec_object.size(); i++ ) {
913 #ifdef DEBUG_OBJSTOCK
914 std::cout <<
"Entry CollectionObjectStock::SetObjectStock vec_object.size() " <<
vec_object.size() << std::endl;
919 std::vector<type_value_data>
values;
921 std::vector<double> values_intern;
934 unsigned int xfirst, xlast;
936 unsigned int size_data = ldata->
GetSize();
943 ComputeBinRange( ldata, fcommon_xaxis_th, Hparam_stock, xfirst, xlast, shift_left );
946 for (
unsigned int bin = xlast ;bin >= xfirst; bin-- ) {
953 xmin = fcommon_xaxis_th->
GetXAxis()->GetBinLowEdge(bin);
954 xmax = fcommon_xaxis_th->
GetXAxis()->GetBinUpEdge(bin);
957 xmin += (xmax-xmin)*0.1;
958 xmax -= (xmax-xmin)*0.1;
961 std::copy ( values.begin(), values.end(), values_intern.begin() );
963 SetValues( size_data - bin + shift_left, values_intern, xmin, xmax,
double GetXPadFromBin(int bin)
Xvalue of the bin center, called by PStockLine to Extrapolate values.
int DistancetoPoint(int, int py, double &yvalue, int) const
called by THStock for anchoring.
virtual int DistancetoPoint(int, int, double &yvalue, int bin=-1) const
called by THStock for anchoring.
virtual time_t GetDate() const
virtual void GetExtrema(double &min, double &max) const
virtual void ClearObjectStock()
Call ClearObject on every objects contained in the collection.
virtual void GetExtrema(double &min, double &max) const
override abstract base function
virtual ~CollectionObjectStock()
virtual void ClearObjectStock()
different from Candle/Bar, delete the PstockLine.
virtual void Paint(const Option_t *="")
Paint the object.
Derive from TH1 will draw the graph.
virtual void Paint(const Option_t *="")
Paint the objet, to overide.
std::vector< float > GetValues(int px, int py, time_t &date) const
protected version, used by MakeStringForStatusBar difficult to extrapolate..., need optional bin2 ...
virtual void AddToVecObject(AbstractObjectStock *obj)
for all indicators, size and if update need to resize
virtual void SetObjectStock(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock)
called by , here need to send the correct ldata, but cannot split ldata so need to set up manually ...
ClassImp(CanvasStock) CanvasStock
virtual bool ToPaint() const
virtual std::string GetNameObject() const
pure-virtual access
CommonXAxis * GetCommonXAxis()
virtual void GetExtrema(double &min, double &max) const
overide base class
std::vector< time_t > dates
easy if date is here, still extrapolate data
std::vector< AbstractObjectStock * > vec_object
slight difference with ListObjectStock, here pointer to object, not object
Define concrete classes for ObjectStock.
Hparam_stock_t Hparam_stock
virtual std::string GetNameObject() const
virtual std::string GetNameObject() const
pure-virtual access
Define a base class for drawing indicator only, they are sorted in ListDataStock object.
Int_t GetBinFromPixel(Int_t px, Int_t &total_bin) const
called by ObjectStock, for StatusBar
void ComputeBinRange(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock, unsigned int &xfirst, unsigned int &xlast, int &shift_left)
set up bin first/ last.
virtual void GetExtrema(double &min, double &max) const
override the Abstract base class
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock **obj)
Define the template ListObjectStock<T> in a separate header.
virtual void SetObjectStock(ListDataStockBase *ldata, CommonXAxis *fcommon_xaxis_th, Hparam_stock_t &Hparam_stock)
used for from the listdata
virtual void Paint(const Option_t *="")
realize the painting, not setting the values
virtual std::vector< type_value_data > GetValues() const =0
Return the value(s) in a vector.
virtual Int_t DistancetoPoint(int px, int py, double &yvalue, int bin=-1) const
specific, called only by ListDataStock do not use bin, but follow the hierarchy pixel better return a...
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
virtual time_t GetDate() const
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
float ExtrapolateYPad(int px, int bin0, int bin1, float x0, float x1) const
std::vector< float > GetValues() const
return the 4 values of a candle use fby MakeStringForStatus and GetExtrema
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py, AbstractObjectStock **)
always called from ListObjectStock, aadd **pointer to overide abstract base, but not used ...
virtual int DistancetoPrimitive(int px, int py, AbstractObjectStock **obj)
used for selection of object, for const need attention to the pointer
virtual void SetValues(UInt_t, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
implementeation of pure virtual in Abstract, need double here
virtual int DistancetoPrimitive(int px, int py, AbstractObjectStock **)
used for selection of object, for const need attention to the pointer
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
virtual void SetParent(THStock *thstock)
different from AbstractObjectStock, broadcast to all, needed ? could set to himself as well ...
virtual unsigned int GetSize() const =0
Return the size of the vector.
virtual std::vector< std::string > MakeStringForStatusBar(int px, int py) const
create the string for the StatusBar
Abstract base class for the ListDataStock, for storing base pointers in vectors.
std::vector< double > fx
x coordinates, middle of the bin for painting
time_t GetDate() const
Get the date data member.
virtual const DataStock & NoChronologicAt(const unsigned int offset) const =0
Get nth element in a non chronological order.
virtual void Paint(const Option_t *="")
Paint one candle.
virtual void SetValues(UInt_t bin, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
Set the values .
Define an abstract base class for all objects to be painted in a THStock.
std::vector< double > plvalues
virtual void Resize(unsigned int new_size)
std::vector< float > GetValues() const
return 1 one value in a vector used by MakeStringForStatus and GetExtrema
virtual void SetValues(UInt_t bin, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)
virtual void Resize(unsigned int new_size)
virtual void SetValues(UInt_t bin, std::vector< double > values, Double_t xmin, Double_t xmax, time_t date, UInt_t opt_value=0)