Changeset 2542 in Sophya


Ignore:
Timestamp:
May 25, 2004, 2:35:30 PM (21 years ago)
Author:
ansari
Message:

Suite codage drawer PIBarGraph - Reza 25 Mai 2004

Location:
trunk/SophyaPI/PI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/pibargraph.cc

    r2535 r2542  
    3333
    3434/* --Methode-- */
    35 PIBarGraph::PIBarGraph()
     35PIBarGraph::PIBarGraph(bool horiz, bool fill)
    3636    : PIDrawer()
    3737{
     38  idMin = 0.; idMax = 1.;
    3839  mMin = 0.; mMax = 1.;
    39   aColIdx = 0;
     40  //DEL  aColIdx = 0;
     41  fgFill = fill;
     42  fgHoriz = horiz;
     43  fillFrac = 0.5;
    4044}
    4145
     
    4650
    4751/* --Methode-- */
    48 int PIBarGraph::AddBar(double val_, PIColors col_)
     52int PIBarGraph::AddBar(double id_, double val_, string const& lab_, PIColors col_)
    4953{
    5054  struct _bgdata bgd;
     55  bgd.id = id_;
    5156  bgd.val = val_;
     57  bgd.lab = lab_;
    5258  bgd.col = col_;
    53   if (mBars.size() == 0) { mMin = mMax = val_; }
     59  if (mBars.size() == 0) { mMin = mMax = val_; idMin = idMax = id_; }
    5460  else {
    5561    if (val_ < mMin)  mMin = val_;
    5662    if (val_ > mMax)  mMax = val_;
     63    if (id_ < idMin)  idMin = id_;
     64    if (id_ > idMax)  idMax = id_;
    5765  }
    5866  mBars.push_back(bgd);
     
    6371int PIBarGraph::AddBar(double val)
    6472{
    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
     79static inline void swap_ifhoriz(double& a, double& b)
     80{
     81  double tmp = a;
     82  a = b;  b = a;
    7283}
    7384
     
    7788  if (mBars.size() < 1)  return;
    7889  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();
    8092  if (mMin*mMax >= 0.) {
    8193    ymin = 0.; ymax = mMax*1.1;
     
    8395  else {
    8496    ymin = mMin*1.1;  ymax = mMax*1.1;
     97  }
     98  if (fgHoriz) {
     99    swap_ifhoriz(xmin, ymin);
     100    swap_ifhoriz(xmax, ymax);
    85101  }
    86102  PIAxes::ReSizeMinMax(isLogScaleX(),xmin,xmax);
     
    90106}
    91107
     108static inline void swap_ifhoriz_g(PIGrCoord& a, PIGrCoord& b)
     109{
     110  PIGrCoord tmp = a;
     111  a = b;  b = a;
     112}
    92113
    93114/* --Methode-- */
     
    96117  if (mBars.size() < 1) return;
    97118  PIGrCoord x,y,dx,dy;
     119  double larg = fillFrac*(idMax-idMin)/mBars.size();
    98120  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;
    100122    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    }
    103142  }
    104143}
  • trunk/SophyaPI/PI/pibargraph.h

    r2535 r2542  
    11// This may look like C code, but it is really -*- C++ -*-
    22// Module PI : Peida Interactive  PIBarGraph
    3 // Drawer Y=f(X)      E.Aubourg, R. Ansari  2004
     3// BarGraph drawer pairs(X_i,Y_i) -    R. Ansari  2004
    44// (C) LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
    55
     
    1717class PIBarGraph : public PIDrawer {
    1818public:
    19                      PIBarGraph();
     19                     PIBarGraph(bool horiz=false, bool fill=true);
    2020  virtual            ~PIBarGraph();
    2121
    22   int                AddBar(double val, PIColors col);
     22  int                AddBar(double id, double val, string const& lab, PIColors col);
    2323  int                AddBar(double val);
    2424 
     
    3030
    3131protected:
    32   struct _bgdata { double val; PIColors col; };
     32  struct _bgdata { double id,val; string lab; PIColors col; };
    3333  vector<struct _bgdata> mBars;
    3434  double mMin, mMax;
    35   int aColIdx;
    36 };
     35  double idMin, idMax;
     36  bool fgFill, fgHoriz;
     37  double fillFrac;
     38 };
    3739
    3840
Note: See TracChangeset for help on using the changeset viewer.