Index: trunk/SophyaPI/PIext/pihisto.cc
===================================================================
--- trunk/SophyaPI/PIext/pihisto.cc	(revision 3139)
+++ trunk/SophyaPI/PIext/pihisto.cc	(revision 3145)
@@ -12,6 +12,7 @@
 
 //------ Implementation classe P1DHistoWrapper
-P1DHistoWrapper::P1DHistoWrapper() 
-: mScale(1.) , mOff(0.) 
+P1DHistoWrapper::P1DHistoWrapper(int_4 asx)
+  :  P1DArrayAdapter(asx) , 
+     mScale(1.) , mOff(0.) , mRetFg(0)
 {
 }
@@ -44,4 +45,13 @@
       mOff = atof(opts.substr(8).c_str());
     }
+    else if(opts.substr(0,8) == "hbincont") {
+      mRetFg = 0;
+    }    
+    else if(opts.substr(0,8) == "hbinerr") {
+      mRetFg = 1;
+    }    
+    else if(opts.substr(0,8) == "hbinent") {
+      mRetFg = 2;
+    }    
     else {
       ndec--;
@@ -54,4 +64,17 @@
   if (rmdecopt)  opt = udopt;
   return(ndec);
+}
+
+int
+P1DHistoWrapper::OptionToString(vector<string> & opt) const
+{
+  char buff[64];
+  sprintf(buff, "hscale=%g", mScale);  opt.push_back(buff);
+  sprintf(buff, "hoffset=%g", mOff);  opt.push_back(buff);
+  if (mRetFg == 2) opt.push_back("hbinent");
+  else if (mRetFg == 1) opt.push_back("hbinerr");
+  else opt.push_back("hbincont");
+
+  return 1;
 }
 
@@ -75,5 +98,5 @@
 //	Constructeur. Si "ad == true", l'objet "histowp" est détruit par 
 //	le destructeur de l'objet "PIHisto"
-//	Note : "histowp" doit être créé par new
+//	Note : "histowp" doit être créé par new si ad==true
 //
 //--
@@ -85,13 +108,6 @@
   mAdDO = ad;     // Flag pour suppression automatique de mHistoWp
   stats=true;
-  // todraw = 0 draw scaled and offset value (default)
-  //        = 1 draw bin content
-  //        = 2 draw bin error (if exist)
-  //        = 3 draw number of entries in the bin (if exist)
-  todraw=0;
-  // error = -1 pas de barre d'erreur
-  //          1 barres d'erreurs,
-  //          0 barres d'erreurs automatiques (si markeur demande)
-  error=0;
+  pline=true;
+  error=false;
   filled=false;
   spoX=-0.01; spoY=-0.01;
@@ -108,17 +124,32 @@
 {
   if (!mHistoWp)  return;
+  if ( mHistoWp->NBins() < 1 ) {
+    SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), 0., 1.);
+  }
   double v,hmin,hmax;
-  hmin = 9.e39;
-  hmax = -9.e39;
-  for (int i=1; i<mHistoWp->NBins(); i++) {
-    v = DrawVal(i);
+  hmin = hmax = (*mHistoWp)(0);
+  for (int_4 i=1; i<mHistoWp->NBins(); i++) {
+    v = (*mHistoWp)(i);
     if(v<hmin) hmin = v;
     if(v>hmax) hmax = v;
   }
-  // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log
-  v = 0.1*(hmax-hmin);
-  hmin -= v;   hmax += v;
-
+  if ( isLogScaleY() ) {
+    if ( hmin >= 0.) {
+      if ( hmax <= hmin ) {
+	hmax = hmin*10.;
+	if (hmax <= 0.) hmax = 1.;
+	if (hmin <= 0.) hmin = hmax / 100.; 
+      }
+      else if ( (hmin == 0.) && (hmax > hmin) ) hmin = hmax/1.e6;
+      else hmin /= 1.1;
+    }
+    else if (hmax > 0.) hmax *= 1.1;
+  }
+  else {
+      v = 0.05*(hmax-hmin);
+      hmin -= v;   hmax += v;
+  }
   if(hmax<=hmin) hmax = hmin+1.;
+    
   SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax);
 }
@@ -134,8 +165,7 @@
   mHistoWp->Update();
 
-  bool oktrace=false;
   // Tracer d'une polyline si demandee
   bool drawpline=false;
-  if(GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) drawpline=true;
+  if (pline) drawpline=true;
   // Tracer des marqueurs si demande ou si HProf
   bool drawmarker=false;
@@ -143,24 +173,18 @@
   // Tracer des erreurs ?
   bool drawerr=false;
-  if(error==0) {  // Gestion automatique des erreurs
-    // Trace les erreurs si marqueurs demandes
-    if(drawmarker) drawerr=true;
-  }
-  else if(error>0) drawerr=true;
-  else if(error<0) drawerr=false;
+  if (error) drawerr = true;
   // Fill de l'histo ?
   bool drawfill=false;
   if(filled) drawfill=true; else drawfill=false;
-  // Et aussi si on ne demande ni ligne ni marqueur ?
-  if( !drawmarker && !drawpline && !drawerr ) drawfill=true;
+  // Et aussi si on ne demande ni ligne ni marqueur ni erreur ni fill ?
+  if( !drawmarker && !drawfill && !drawerr ) drawpline=true;
 
   // Remplissage des bins avec la couleur courante (trace en premier)
   if(drawfill) {
-    oktrace = true;
     for(int i=0; i<mHistoWp->NBins(); i++) {
       double left   = mHistoWp->BinLowEdge(i);
       double width  = mHistoWp->BinWidth();
       double bottom = 0;
-      double height = DrawVal(i);
+      double height = (*mHistoWp)(i);
       g->DrawFBox(left,bottom,width,height);
     }
@@ -169,8 +193,8 @@
   // Trace des marqeurs
   if(drawmarker) {
-    double x1,y1; oktrace = true;
+    double x1,y1; 
     for(int i=0; i<mHistoWp->NBins(); i++) {
       x1 = mHistoWp->BinCenter(i);
-      y1 = DrawVal(i);
+      y1 = (*mHistoWp)(i);
       g->DrawMarker(x1,y1);
     }
@@ -180,5 +204,5 @@
   if(drawerr) {
     if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
-    double x1,x2,y1,y2;  oktrace = true;
+    double x1,x2,y1,y2;  
     double bw = mHistoWp->BinWidth();
     for(int i=0; i<mHistoWp->NBins(); i++) {
@@ -186,6 +210,6 @@
         // barres d'erreur verticales
         x1 = x2 = mHistoWp->BinCenter(i);
-        y1 = DrawVal(i) - mHistoWp->Error(i);
-        y2 = DrawVal(i) + mHistoWp->Error(i);
+        y1 = (*mHistoWp)(i) - mHistoWp->Error(i);
+        y2 = (*mHistoWp)(i) + mHistoWp->Error(i);
         g->DrawLine(x1,y1, x1, y2);
         // limites de barres d'erreurs (horizontales)
@@ -199,4 +223,5 @@
   // Trace de la ligne continue si demandee
   if(drawpline) {
+    if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
     PIGrCoord* x1 = new PIGrCoord[2*mHistoWp->NBins()+2];
     PIGrCoord* y1 = new PIGrCoord[2*mHistoWp->NBins()+2];
@@ -208,5 +233,5 @@
     for(int i=0; i<mHistoWp->NBins(); i++) {
       x1[npt] = mHistoWp->BinLowEdge(i);
-      y1[npt] = DrawVal(i);
+      y1[npt] = (*mHistoWp)(i);
       npt++;
       x1[npt] = (double)x1[npt-1] + dx;
@@ -219,5 +244,4 @@
     g->DrawPolygon(x1,y1,npt,false);
     delete [] x1; delete [] y1;
-    oktrace = true;
   }
 
@@ -243,9 +267,12 @@
     else if(  opts=="nsta"   || opts=="nstat"
            || opts=="nostat" || opts=="nostats") stats=false;
-    else if(opts=="err") error=1;
-    else if(opts=="noerr" || opts=="nerr") error=-1;
-    else if(opts=="autoerr") error=0;
-    else if(opts=="fill") filled=true;
+    else if(opts=="err") error=true;
+    else if(opts=="noerr" || opts=="nerr") error=false;
+    // $CHECK$CMV  : on desactive pline si fill ? 
+    else if(opts=="fill") { filled=true; pline=false; }  
     else if(opts=="nofill" || opts=="nfill") filled=false;
+    // $CHECK$CMV  : on desactive fill si pline ? 
+    else if(opts=="pline") { pline=true; filled=false; }
+    else if(opts=="nopline") pline=false;
     else if(opts.substr(0,11) == "statposoff=") {
       float xo=0., yo=0.;
@@ -253,8 +280,4 @@
       spoX=xo; spoY=yo;
     }
-    else if(opts.substr(0,6) == "draw=v") todraw = 1;
-    else if(opts.substr(0,6) == "draw=e") todraw = 2;
-    else if(opts.substr(0,6) == "draw=n") todraw = 3;
-    else if(opts.substr(0,5) == "draw=" ) todraw = 0;
     else {
       ndec--;
@@ -281,16 +304,13 @@
  PIDrawer::OptionToString(opt);
 
- if(stats) opt.push_back("stat"); else opt.push_back("nstat");
- if(error==-1) opt.push_back("noerr");
-   else if(error==0) opt.push_back("autoerr");
-     else if(error==1) opt.push_back("err");
+ if(stats) opt.push_back("stat"); else opt.push_back("nostat");
+ if(error) opt.push_back("err");  else opt.push_back("noerr");
  if(filled) opt.push_back("fill"); else opt.push_back("nofill");
- if(todraw==1) opt.push_back("draw=v");
-   else if(todraw==2) opt.push_back("draw=e");
-     else if(todraw==3) opt.push_back("draw=n");
+ if(pline) opt.push_back("pline"); else opt.push_back("nopline");
 
  char str[256]; sprintf(str,"statposoff=%g,%g",spoX,spoY);
  opt.push_back(str);
 
+ mHistoWp->OptionToString(opt);
  return 1;
 }
@@ -300,19 +320,19 @@
 {
 info += " ---- PIHisto options help info : \n" ;
-info += "  draw=v: draw bin content\n";
-info += "      =e: draw bin error (if exist)\n";
-info += "      =n: draw number of entries in the bin (if exist)\n";
-info += "      default: draw scaled and offset value (default)\n";
-info += "  sta,stat,stats:            activate   statistic display\n";
-info += "  nsta,nstat,nostat,nostats: deactivate statistic display\n";
-info += "  err / noerr,nerr : draw, do not draw error bars\n";
-info += "  autoerr : draw error bars if Marker drawing requested\n";
-info += "  fill / nofill,nfill : fill, do not fill bars with selected color\n";
-info += "  statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
-info += "       as a fraction of total size \n";
+info += " sta,stat,stats:            activate   statistic display\n";
+info += " nsta,nstat,nostat,nostats: deactivate statistic display\n";
+info += " pline/nopline: display/do not display as polyline (def= pline) \n";
+info += " err/noerr,nerr: draw/do not draw error bars (def= noerr) \n";
+info += " fill/nofill,nfill: fill/do not fill histo (def= nofill) \n";
+info += " - Use marker attribute (marker=...) to draw markers \n"; 
+info += " statposoff=OffsetX,OffsetY : Position offset for Stats drawing \n";
+info += "      as a fraction of total size \n";
 info += " ---- HistoWrapper options : \n" ;
-info += "  hscale=value  : multiplicative factor (in Y) \n" ;
-info += "  hoffset=value : additive coefficient  (in Y) \n" ;
-info += "  hs1 : set hscale=1 hoffset=0  (default) \n" ;
+info += " hbincont: select bin content as Y value for display (default) \n";
+info += " hbinerr: select bin error as Y value for display \n";
+info += " hbinent: select bin entries as Y value for display \n";
+info += " hscale=value : multiplicative factor for Y value \n" ;
+info += " hoffset=value : additive coefficient for Y value \n" ;
+info += " hs1: set hscale=1 hoffset=0  (default) \n" ;
 // On recupere ensuite la chaine info de la classe de base
 PIDrawer::GetOptionsHelpInfo(info);
@@ -335,5 +355,5 @@
   if (nlig < 1) return;
 
-  double cellHeight = (nlig+0.6) * cH;
+  double cellHeight = nlig*1.2 * cH;
 
   int idxll = 0;
@@ -383,5 +403,5 @@
  for(int i=0; i<mHistoWp->NBins(); i++) {
    double xp=mHistoWp->BinCenter(i);
-   double yp=DrawVal(i);
+   double yp=(*mHistoWp)(i);
    xp = (xp-x)/(XMax()-XMin())/0.5;
    yp = (yp-y)/(YMax()-YMin())/0.5;
