Changeset 2542 in Sophya
- Timestamp:
- May 25, 2004, 2:35:30 PM (21 years ago)
- Location:
- trunk/SophyaPI/PI
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PI/pibargraph.cc
r2535 r2542 33 33 34 34 /* --Methode-- */ 35 PIBarGraph::PIBarGraph( )35 PIBarGraph::PIBarGraph(bool horiz, bool fill) 36 36 : PIDrawer() 37 37 { 38 idMin = 0.; idMax = 1.; 38 39 mMin = 0.; mMax = 1.; 39 aColIdx = 0; 40 //DEL aColIdx = 0; 41 fgFill = fill; 42 fgHoriz = horiz; 43 fillFrac = 0.5; 40 44 } 41 45 … … 46 50 47 51 /* --Methode-- */ 48 int PIBarGraph::AddBar(double val_, PIColors col_)52 int PIBarGraph::AddBar(double id_, double val_, string const& lab_, PIColors col_) 49 53 { 50 54 struct _bgdata bgd; 55 bgd.id = id_; 51 56 bgd.val = val_; 57 bgd.lab = lab_; 52 58 bgd.col = col_; 53 if (mBars.size() == 0) { mMin = mMax = val_; }59 if (mBars.size() == 0) { mMin = mMax = val_; idMin = idMax = id_; } 54 60 else { 55 61 if (val_ < mMin) mMin = val_; 56 62 if (val_ > mMax) mMax = val_; 63 if (id_ < idMin) idMin = id_; 64 if (id_ > idMax) idMax = id_; 57 65 } 58 66 mBars.push_back(bgd); … … 63 71 int PIBarGraph::AddBar(double val) 64 72 { 65 #define NACOL_ 8 66 PIColors autocol[NACOL_] = { PI_Red, PI_Blue, 67 PI_Yellow, PI_Orange, PI_Magenta, 68 PI_Cyan, PI_NavyBlue, PI_Green }; 69 int rc = AddBar(val, autocol[aColIdx]); 70 aColIdx = (aColIdx+1)%NACOL_; 71 return rc; 73 string lab = ""; 74 double id = mBars.size()+0.5; 75 return AddBar(id, val, lab, PI_NotDefColor); 76 } 77 78 79 static inline void swap_ifhoriz(double& a, double& b) 80 { 81 double tmp = a; 82 a = b; b = a; 72 83 } 73 84 … … 77 88 if (mBars.size() < 1) return; 78 89 double xmin, xmax, ymin, ymax; 79 xmin = 0.; xmax = mBars.size()+0.5; 90 xmin = idMin-fillFrac*(idMax-idMin)/mBars.size(); 91 xmax = idMax+fillFrac*(idMax-idMin)/mBars.size(); 80 92 if (mMin*mMax >= 0.) { 81 93 ymin = 0.; ymax = mMax*1.1; … … 83 95 else { 84 96 ymin = mMin*1.1; ymax = mMax*1.1; 97 } 98 if (fgHoriz) { 99 swap_ifhoriz(xmin, ymin); 100 swap_ifhoriz(xmax, ymax); 85 101 } 86 102 PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax); … … 90 106 } 91 107 108 static inline void swap_ifhoriz_g(PIGrCoord& a, PIGrCoord& b) 109 { 110 PIGrCoord tmp = a; 111 a = b; b = a; 112 } 92 113 93 114 /* --Methode-- */ … … 96 117 if (mBars.size() < 1) return; 97 118 PIGrCoord x,y,dx,dy; 119 double larg = fillFrac*(idMax-idMin)/mBars.size(); 98 120 for(unsigned int k=0; k<mBars.size(); k++) { 99 x = k+0.5; dx = 0.5;121 x = mBars[k].id-0.5*larg; dx = larg; 100 122 y = 0.; dy = mBars[k].val; 101 g->SelForeground(mBars[k].col); 102 g->DrawFBox(x,y,dx,dy); 123 if (mBars[k].col != PI_NotDefColor) g->SelForeground(mBars[k].col); 124 if (fgHoriz) { 125 swap_ifhoriz_g(x, y); 126 swap_ifhoriz_g(dx, dy); 127 } 128 if (fgFill) g->DrawFBox(x,y,dx,dy); 129 else { 130 g->DrawBox(x,y,dx,dy); 131 if ( mBars[k].lab.length() > 0 ) { 132 x = mBars[k].id; 133 y = 0.5*mBars[k].val; 134 if (fgHoriz) 135 g->DrawString(y, x, mBars[k].lab.c_str(), 136 PI_VerticalCenter|PI_HorizontalCenter|PI_TextDirectionHorizontal); 137 else 138 g->DrawString(x, y, mBars[k].lab.c_str(), 139 PI_VerticalCenter|PI_HorizontalCenter|PI_TextDirectionVerticalUp); 140 } 141 } 103 142 } 104 143 } -
trunk/SophyaPI/PI/pibargraph.h
r2535 r2542 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // Module PI : Peida Interactive PIBarGraph 3 // Drawer Y=f(X) E.Aubourg,R. Ansari 20043 // BarGraph drawer pairs(X_i,Y_i) - R. Ansari 2004 4 4 // (C) LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA 5 5 … … 17 17 class PIBarGraph : public PIDrawer { 18 18 public: 19 PIBarGraph( );19 PIBarGraph(bool horiz=false, bool fill=true); 20 20 virtual ~PIBarGraph(); 21 21 22 int AddBar(double val, PIColors col);22 int AddBar(double id, double val, string const& lab, PIColors col); 23 23 int AddBar(double val); 24 24 … … 30 30 31 31 protected: 32 struct _bgdata { double val; PIColors col; };32 struct _bgdata { double id,val; string lab; PIColors col; }; 33 33 vector<struct _bgdata> mBars; 34 34 double mMin, mMax; 35 int aColIdx; 36 }; 35 double idMin, idMax; 36 bool fgFill, fgHoriz; 37 double fillFrac; 38 }; 37 39 38 40
Note:
See TracChangeset
for help on using the changeset viewer.