// Classe traceur d histogramme 96-99 // C. Magneville , R. Ansari 2000-2007 // (C) CEA-DAPNIA LAL-IN2P3/CNRS #include #include #include #include #include #include "pihisto.h" //------ Implementation classe P1DHistoWrapper P1DHistoWrapper::P1DHistoWrapper() : mScale(1.) , mOff(0.) { } P1DHistoWrapper::~P1DHistoWrapper() { } int P1DHistoWrapper::GetStatInfoAsText(vector & /* text */ ) { return 0; } int P1DHistoWrapper::DecodeOptionString(vector & opt, bool rmdecopt) { if(opt.size() < 1) return(0); vector udopt; // On gardera ici les options non decodees unsigned int k = 0; int ndec = opt.size(); for( k=0; kNBins(); i++) { v = DrawVal(i); if(vhmax) hmax = v; } // REZA$CHECK : Modifier pour tenir compte si axe (Y) en log v = 0.1*(hmax-hmin); hmin -= v; hmax += v; if(hmax<=hmin) hmax = hmin+1.; SetLimits(mHistoWp->XMin(), mHistoWp->XMax(), hmin, hmax); } void PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/) { if (axesFlags != kAxesNone) DrawAxes(g); if (!mHistoWp) return; if (mHistoWp->NBins()<=0) return; mHistoWp->Update(); bool oktrace=false; // Tracer d'une polyline si demandee bool drawpline=false; if(GetGraphicAtt().GetLineAtt() != PI_NotDefLineAtt) drawpline=true; // Tracer des marqueurs si demande ou si HProf bool drawmarker=false; if (GetGraphicAtt().GetMarker() != PI_NotDefMarker) drawmarker = true; // 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; // 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; // Remplissage des bins avec la couleur courante (trace en premier) if(drawfill) { oktrace = true; for(int i=0; iNBins(); i++) { double left = mHistoWp->BinLowEdge(i); double width = mHistoWp->BinWidth(); double bottom = 0; double height = DrawVal(i); g->DrawFBox(left,bottom,width,height); } } // Trace des marqeurs if(drawmarker) { double x1,y1; oktrace = true; for(int i=0; iNBins(); i++) { x1 = mHistoWp->BinCenter(i); y1 = DrawVal(i); g->DrawMarker(x1,y1); } } // Trace des erreurs if(drawerr) { if(GetGraphicAtt().GetLineAtt()==PI_NotDefLineAtt) g->SelLine(PI_ThinLine); double x1,x2,y1,y2; oktrace = true; double bw = mHistoWp->BinWidth(); for(int i=0; iNBins(); i++) { if(mHistoWp->Error(i)>0.) { // barres d'erreur verticales x1 = x2 = mHistoWp->BinCenter(i); y1 = DrawVal(i) - mHistoWp->Error(i); y2 = DrawVal(i) + mHistoWp->Error(i); g->DrawLine(x1,y1, x1, y2); // limites de barres d'erreurs (horizontales) x1 -= bw/3.; x2 += bw/3.; g->DrawLine(x1,y1, x2, y1); g->DrawLine(x1,y2, x2, y2); } } } // Trace de la ligne continue si demandee if(drawpline) { PIGrCoord* x1 = new PIGrCoord[2*mHistoWp->NBins()+2]; PIGrCoord* y1 = new PIGrCoord[2*mHistoWp->NBins()+2]; double dx = mHistoWp->BinWidth(); int npt=0; x1[npt] = mHistoWp->BinLowEdge(0); y1[npt] = 0; npt++; for(int i=0; iNBins(); i++) { x1[npt] = mHistoWp->BinLowEdge(i); y1[npt] = DrawVal(i); npt++; x1[npt] = (double)x1[npt-1] + dx; y1[npt] = y1[npt-1]; npt++; } x1[npt] = x1[npt-1]; y1[npt] = 0; npt++; g->DrawPolygon(x1,y1,npt,false); delete [] x1; delete [] y1; oktrace = true; } // Trace/Ecriture des statistiques // A faire a la fin - DrawStats change l'attribut de ligne if(stats) DrawStats(g); } int PIHisto::DecodeOptionString(vector & opt, bool rmdecopt) { int optsz1 = opt.size(); if(optsz1<1) return(0); int ndec1 = PIDrawer::DecodeOptionString(opt, rmdecopt); if(optsz1-ndec1<1) return(ndec1); // si tout a ete decode vector udopt; // On gardera ici les options non decodees unsigned int k = 0; int ndec = opt.size(); for( k=0; kSelLine(PI_ThinLine); g->SelLine(PI_ThinLine); g->SelFontSz((YMax() - YMin())/30); // La hauteur de la cellule PIGrCoord a, d; double cH = (double)g->GetFontHeight(a,d); vector lines; int nlig = mHistoWp->GetStatInfoAsText(lines); if (nlig < 1) return; double cellHeight = (nlig+0.6) * cH; int idxll = 0; int kl; // on recherche la ligne la plus longue for(kl=1; kl lines[idxll].length() ) idxll = kl; double cellWidth = 1.1 * (double)g->CalcStringWidth(lines[idxll].c_str()); double ofpx = spoX*(XMax()-XMin()); double ofpy = spoY*(YMax()-YMin()); double xu, yu, cw; // Les limites du cadre xu = g->DeltaUCX(XMax(), -cellWidth); yu = g->DeltaUCY(YMax(), -cellHeight); double recw = XMax()-xu; double rech = YMax()-yu; xu += ofpx; yu += ofpy; g->DrawBox(xu, yu, recw, rech); // L'ecriture des labels (attention aux inversions possibles des axes!) cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth; xu = g->DeltaUCX(XMax(),cw); cw = (g->isAxeYDirUpDown()) ? -0.15*cH : -1.15*cH; yu = g->DeltaUCY(YMax(),cw); xu += ofpx; yu += ofpy; for(kl=0; klDrawString(xu, yu, lines[kl].c_str() ); cw += -1.15*cH; yu = g->DeltaUCY(YMax(),cw); yu += ofpy; } } /* --Methode-- */ double PIHisto::GetDistanceToPoint(double x, double y) { if (!mHistoWp) return 1.e+9; double dist = -1.e+18; for(int i=0; iNBins(); i++) { double xp=mHistoWp->BinCenter(i); double yp=DrawVal(i); xp = (xp-x)/(XMax()-XMin())/0.5; yp = (yp-y)/(YMax()-YMin())/0.5; xp = xp*xp+yp*yp; if(dist<0. || xp