Changeset 3145 in Sophya for trunk/SophyaPI/PIext/pihisto.cc
- Timestamp:
- Jan 18, 2007, 5:33:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/pihisto.cc
r3139 r3145 12 12 13 13 //------ Implementation classe P1DHistoWrapper 14 P1DHistoWrapper::P1DHistoWrapper() 15 : mScale(1.) , mOff(0.) 14 P1DHistoWrapper::P1DHistoWrapper(int_4 asx) 15 : P1DArrayAdapter(asx) , 16 mScale(1.) , mOff(0.) , mRetFg(0) 16 17 { 17 18 } … … 44 45 mOff = atof(opts.substr(8).c_str()); 45 46 } 47 else if(opts.substr(0,8) == "hbincont") { 48 mRetFg = 0; 49 } 50 else if(opts.substr(0,8) == "hbinerr") { 51 mRetFg = 1; 52 } 53 else if(opts.substr(0,8) == "hbinent") { 54 mRetFg = 2; 55 } 46 56 else { 47 57 ndec--; … … 54 64 if (rmdecopt) opt = udopt; 55 65 return(ndec); 66 } 67 68 int 69 P1DHistoWrapper::OptionToString(vector<string> & opt) const 70 { 71 char buff[64]; 72 sprintf(buff, "hscale=%g", mScale); opt.push_back(buff); 73 sprintf(buff, "hoffset=%g", mOff); opt.push_back(buff); 74 if (mRetFg == 2) opt.push_back("hbinent"); 75 else if (mRetFg == 1) opt.push_back("hbinerr"); 76 else opt.push_back("hbincont"); 77 78 return 1; 56 79 } 57 80 … … 75 98 // Constructeur. Si "ad == true", l'objet "histowp" est détruit par 76 99 // le destructeur de l'objet "PIHisto" 77 // Note : "histowp" doit être créé par new 100 // Note : "histowp" doit être créé par new si ad==true 78 101 // 79 102 //-- … … 85 108 mAdDO = ad; // Flag pour suppression automatique de mHistoWp 86 109 stats=true; 87 // todraw = 0 draw scaled and offset value (default) 88 // = 1 draw bin content 89 // = 2 draw bin error (if exist) 90 // = 3 draw number of entries in the bin (if exist) 91 todraw=0; 92 // error = -1 pas de barre d'erreur 93 // 1 barres d'erreurs, 94 // 0 barres d'erreurs automatiques (si markeur demande) 95 error=0; 110 pline=true; 111 error=false; 96 112 filled=false; 97 113 spoX=-0.01; spoY=-0.01; … … 108 124 { 109 125 if (!mHistoWp) return; 126 if ( mHistoWp->NBins() < 1 ) { 127 SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), 0., 1.); 128 } 110 129 double v,hmin,hmax; 111 hmin = 9.e39; 112 hmax = -9.e39; 113 for (int i=1; i<mHistoWp->NBins(); i++) { 114 v = DrawVal(i); 130 hmin = hmax = (*mHistoWp)(0); 131 for (int_4 i=1; i<mHistoWp->NBins(); i++) { 132 v = (*mHistoWp)(i); 115 133 if(v<hmin) hmin = v; 116 134 if(v>hmax) hmax = v; 117 135 } 118 // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log 119 v = 0.1*(hmax-hmin); 120 hmin -= v; hmax += v; 121 136 if ( isLogScaleY() ) { 137 if ( hmin >= 0.) { 138 if ( hmax <= hmin ) { 139 hmax = hmin*10.; 140 if (hmax <= 0.) hmax = 1.; 141 if (hmin <= 0.) hmin = hmax / 100.; 142 } 143 else if ( (hmin == 0.) && (hmax > hmin) ) hmin = hmax/1.e6; 144 else hmin /= 1.1; 145 } 146 else if (hmax > 0.) hmax *= 1.1; 147 } 148 else { 149 v = 0.05*(hmax-hmin); 150 hmin -= v; hmax += v; 151 } 122 152 if(hmax<=hmin) hmax = hmin+1.; 153 123 154 SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax); 124 155 } … … 134 165 mHistoWp->Update(); 135 166 136 bool oktrace=false;137 167 // Tracer d'une polyline si demandee 138 168 bool drawpline=false; 139 if (GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) drawpline=true;169 if (pline) drawpline=true; 140 170 // Tracer des marqueurs si demande ou si HProf 141 171 bool drawmarker=false; … … 143 173 // Tracer des erreurs ? 144 174 bool drawerr=false; 145 if(error==0) { // Gestion automatique des erreurs 146 // Trace les erreurs si marqueurs demandes 147 if(drawmarker) drawerr=true; 148 } 149 else if(error>0) drawerr=true; 150 else if(error<0) drawerr=false; 175 if (error) drawerr = true; 151 176 // Fill de l'histo ? 152 177 bool drawfill=false; 153 178 if(filled) drawfill=true; else drawfill=false; 154 // Et aussi si on ne demande ni ligne ni marqueur ?155 if( !drawmarker && !draw pline && !drawerr ) drawfill=true;179 // Et aussi si on ne demande ni ligne ni marqueur ni erreur ni fill ? 180 if( !drawmarker && !drawfill && !drawerr ) drawpline=true; 156 181 157 182 // Remplissage des bins avec la couleur courante (trace en premier) 158 183 if(drawfill) { 159 oktrace = true;160 184 for(int i=0; i<mHistoWp->NBins(); i++) { 161 185 double left = mHistoWp->BinLowEdge(i); 162 186 double width = mHistoWp->BinWidth(); 163 187 double bottom = 0; 164 double height = DrawVal(i);188 double height = (*mHistoWp)(i); 165 189 g->DrawFBox(left,bottom,width,height); 166 190 } … … 169 193 // Trace des marqeurs 170 194 if(drawmarker) { 171 double x1,y1; oktrace = true;195 double x1,y1; 172 196 for(int i=0; i<mHistoWp->NBins(); i++) { 173 197 x1 = mHistoWp->BinCenter(i); 174 y1 = DrawVal(i);198 y1 = (*mHistoWp)(i); 175 199 g->DrawMarker(x1,y1); 176 200 } … … 180 204 if(drawerr) { 181 205 if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 182 double x1,x2,y1,y2; oktrace = true;206 double x1,x2,y1,y2; 183 207 double bw = mHistoWp->BinWidth(); 184 208 for(int i=0; i<mHistoWp->NBins(); i++) { … … 186 210 // barres d'erreur verticales 187 211 x1 = x2 = mHistoWp->BinCenter(i); 188 y1 = DrawVal(i) - mHistoWp->Error(i);189 y2 = DrawVal(i) + mHistoWp->Error(i);212 y1 = (*mHistoWp)(i) - mHistoWp->Error(i); 213 y2 = (*mHistoWp)(i) + mHistoWp->Error(i); 190 214 g->DrawLine(x1,y1, x1, y2); 191 215 // limites de barres d'erreurs (horizontales) … … 199 223 // Trace de la ligne continue si demandee 200 224 if(drawpline) { 225 if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine); 201 226 PIGrCoord* x1 = new PIGrCoord[2*mHistoWp->NBins()+2]; 202 227 PIGrCoord* y1 = new PIGrCoord[2*mHistoWp->NBins()+2]; … … 208 233 for(int i=0; i<mHistoWp->NBins(); i++) { 209 234 x1[npt] = mHistoWp->BinLowEdge(i); 210 y1[npt] = DrawVal(i);235 y1[npt] = (*mHistoWp)(i); 211 236 npt++; 212 237 x1[npt] = (double)x1[npt-1] + dx; … … 219 244 g->DrawPolygon(x1,y1,npt,false); 220 245 delete [] x1; delete [] y1; 221 oktrace = true;222 246 } 223 247 … … 243 267 else if( opts=="nsta" || opts=="nstat" 244 268 || opts=="nostat" || opts=="nostats") stats=false; 245 else if(opts=="err") error= 1;246 else if(opts=="noerr" || opts=="nerr") error= -1;247 else if(opts=="autoerr") error=0;248 else if(opts=="fill") filled=true;269 else if(opts=="err") error=true; 270 else if(opts=="noerr" || opts=="nerr") error=false; 271 // $CHECK$CMV : on desactive pline si fill ? 272 else if(opts=="fill") { filled=true; pline=false; } 249 273 else if(opts=="nofill" || opts=="nfill") filled=false; 274 // $CHECK$CMV : on desactive fill si pline ? 275 else if(opts=="pline") { pline=true; filled=false; } 276 else if(opts=="nopline") pline=false; 250 277 else if(opts.substr(0,11) == "statposoff=") { 251 278 float xo=0., yo=0.; … … 253 280 spoX=xo; spoY=yo; 254 281 } 255 else if(opts.substr(0,6) == "draw=v") todraw = 1;256 else if(opts.substr(0,6) == "draw=e") todraw = 2;257 else if(opts.substr(0,6) == "draw=n") todraw = 3;258 else if(opts.substr(0,5) == "draw=" ) todraw = 0;259 282 else { 260 283 ndec--; … … 281 304 PIDrawer::OptionToString(opt); 282 305 283 if(stats) opt.push_back("stat"); else opt.push_back("nstat"); 284 if(error==-1) opt.push_back("noerr"); 285 else if(error==0) opt.push_back("autoerr"); 286 else if(error==1) opt.push_back("err"); 306 if(stats) opt.push_back("stat"); else opt.push_back("nostat"); 307 if(error) opt.push_back("err"); else opt.push_back("noerr"); 287 308 if(filled) opt.push_back("fill"); else opt.push_back("nofill"); 288 if(todraw==1) opt.push_back("draw=v"); 289 else if(todraw==2) opt.push_back("draw=e"); 290 else if(todraw==3) opt.push_back("draw=n"); 309 if(pline) opt.push_back("pline"); else opt.push_back("nopline"); 291 310 292 311 char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY); 293 312 opt.push_back(str); 294 313 314 mHistoWp->OptionToString(opt); 295 315 return 1; 296 316 } … … 300 320 { 301 321 info += " ---- PIHisto options help info : \n" ; 302 info += " draw=v: draw bin content\n"; 303 info += " =e: draw bin error (if exist)\n"; 304 info += " =n: draw number of entries in the bin (if exist)\n"; 305 info += " default: draw scaled and offset value (default)\n"; 306 info += " sta,stat,stats: activate statistic display\n"; 307 info += " nsta,nstat,nostat,nostats: deactivate statistic display\n"; 308 info += " err / noerr,nerr : draw, do not draw error bars\n"; 309 info += " autoerr : draw error bars if Marker drawing requested\n"; 310 info += " fill / nofill,nfill : fill, do not fill bars with selected color\n"; 311 info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n"; 312 info += " as a fraction of total size \n"; 322 info += " sta,stat,stats: activate statistic display\n"; 323 info += " nsta,nstat,nostat,nostats: deactivate statistic display\n"; 324 info += " pline/nopline: display/do not display as polyline (def= pline) \n"; 325 info += " err/noerr,nerr: draw/do not draw error bars (def= noerr) \n"; 326 info += " fill/nofill,nfill: fill/do not fill histo (def= nofill) \n"; 327 info += " - Use marker attribute (marker=...) to draw markers \n"; 328 info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n"; 329 info += " as a fraction of total size \n"; 313 330 info += " ---- HistoWrapper options : \n" ; 314 info += " hscale=value : multiplicative factor (in Y) \n" ; 315 info += " hoffset=value : additive coefficient (in Y) \n" ; 316 info += " hs1 : set hscale=1 hoffset=0 (default) \n" ; 331 info += " hbincont: select bin content as Y value for display (default) \n"; 332 info += " hbinerr: select bin error as Y value for display \n"; 333 info += " hbinent: select bin entries as Y value for display \n"; 334 info += " hscale=value : multiplicative factor for Y value \n" ; 335 info += " hoffset=value : additive coefficient for Y value \n" ; 336 info += " hs1: set hscale=1 hoffset=0 (default) \n" ; 317 337 // On recupere ensuite la chaine info de la classe de base 318 338 PIDrawer::GetOptionsHelpInfo(info); … … 335 355 if (nlig < 1) return; 336 356 337 double cellHeight = (nlig+0.6)* cH;357 double cellHeight = nlig*1.2 * cH; 338 358 339 359 int idxll = 0; … … 383 403 for(int i=0; i<mHistoWp->NBins(); i++) { 384 404 double xp=mHistoWp->BinCenter(i); 385 double yp= DrawVal(i);405 double yp=(*mHistoWp)(i); 386 406 xp = (xp-x)/(XMax()-XMin())/0.5; 387 407 yp = (yp-y)/(YMax()-YMin())/0.5;
Note:
See TracChangeset
for help on using the changeset viewer.