| [223] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include "pihisto.h" | 
|---|
|  | 3 | #include "hisprof.h" | 
|---|
|  | 4 |  | 
|---|
|  | 5 | PIHisto::PIHisto(Histo* histo, bool ad) | 
|---|
|  | 6 | : PIDrawer(), mHisto(histo) | 
|---|
|  | 7 | { | 
|---|
|  | 8 | mAdDO = ad;     // Flag pour suppression automatique de mHisto | 
|---|
|  | 9 | } | 
|---|
|  | 10 |  | 
|---|
|  | 11 | PIHisto::~PIHisto() | 
|---|
|  | 12 | { | 
|---|
|  | 13 | if (mAdDO) delete mHisto; | 
|---|
|  | 14 | } | 
|---|
|  | 15 |  | 
|---|
|  | 16 | void | 
|---|
|  | 17 | PIHisto::UpdateLimits() | 
|---|
|  | 18 | { | 
|---|
|  | 19 | if (!mHisto)  return; | 
|---|
|  | 20 | float hmin = mHisto->VMin(); | 
|---|
|  | 21 | float hmax = mHisto->VMax()+0.2*(mHisto->VMax()-mHisto->VMin()); | 
|---|
|  | 22 | // si HBProf min,max calcules en tenant compte des erreurs | 
|---|
|  | 23 | if( mHisto->ClassId() == HProf::classId ) { | 
|---|
|  | 24 | float v1,v2; | 
|---|
|  | 25 | for (int i=1; i<mHisto->NBins(); i++) { | 
|---|
|  | 26 | v1 = (*mHisto)(i) - mHisto->Error(i); | 
|---|
|  | 27 | v2 = (*mHisto)(i) + mHisto->Error(i); | 
|---|
|  | 28 | if(v1<hmin) hmin = v1; | 
|---|
|  | 29 | if(v2>hmax) hmax = v2; | 
|---|
|  | 30 | } | 
|---|
|  | 31 | v1 = 0.1*(hmax-hmin); | 
|---|
|  | 32 | hmin -= v1;   hmax += v1; | 
|---|
|  | 33 | } | 
|---|
|  | 34 | if(hmax<=hmin) hmax += 1.; | 
|---|
|  | 35 | SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax); | 
|---|
|  | 36 | SetAxesFlags(kBoxAxes | kExtTicks | kLabels); | 
|---|
|  | 37 | } | 
|---|
|  | 38 |  | 
|---|
|  | 39 | void | 
|---|
|  | 40 | PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/) | 
|---|
|  | 41 | { | 
|---|
|  | 42 | bool oktrace = false; | 
|---|
|  | 43 | if (!mHisto)  return; | 
|---|
|  | 44 |  | 
|---|
|  | 45 | if (mMrk != PI_NotDefMarker || mHisto->ClassId() == HProf::classId ) { | 
|---|
|  | 46 | // Marqeurs definis OU HBProf => marqueurs+Erreurs si il y en a | 
|---|
|  | 47 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine); | 
|---|
|  | 48 | double x1,y1, x2,y2; | 
|---|
|  | 49 | double bw = mHisto->BinWidth(); | 
|---|
|  | 50 | for (int i=0; i<mHisto->NBins(); i++) { | 
|---|
|  | 51 | if(mHisto->Error(i)>0.) { | 
|---|
|  | 52 | // barres d'erreur verticales | 
|---|
|  | 53 | x1 = x2 = mHisto->BinCenter(i); | 
|---|
|  | 54 | y1 = (*mHisto)(i) - mHisto->Error(i); | 
|---|
|  | 55 | y2 = (*mHisto)(i) + mHisto->Error(i); | 
|---|
|  | 56 | g->DrawLine(x1,y1, x1, y2); | 
|---|
|  | 57 | // limites de barres d'erreurs (horizontales) | 
|---|
|  | 58 | x1 -= bw/3.;  x2 += bw/3.; | 
|---|
|  | 59 | g->DrawLine(x1,y1, x2, y1); | 
|---|
|  | 60 | g->DrawLine(x1,y2, x2, y2); | 
|---|
|  | 61 | } | 
|---|
|  | 62 | // le marqueur | 
|---|
|  | 63 | x1 = mHisto->BinCenter(i); | 
|---|
|  | 64 | y1 = (*mHisto)(i); | 
|---|
|  | 65 | g->DrawMarker(x1,y1); | 
|---|
|  | 66 | } | 
|---|
|  | 67 | oktrace = true; | 
|---|
|  | 68 | } | 
|---|
|  | 69 | if (mLAtt != PI_NotDefLineAtt) { | 
|---|
|  | 70 | double x1,y1, x2, y2; | 
|---|
|  | 71 | x1 = mHisto->BinLowEdge(0); | 
|---|
|  | 72 | y1 = 0; | 
|---|
|  | 73 | for (int i=0; i<mHisto->NBins(); i++) { | 
|---|
|  | 74 | x2 = x1; | 
|---|
|  | 75 | y2 = (*mHisto)(i); | 
|---|
|  | 76 | g->DrawLine(x1,y1, x2, y2); | 
|---|
|  | 77 | y1 = y2; | 
|---|
|  | 78 | x2 = mHisto->BinHighEdge(i); | 
|---|
|  | 79 | g->DrawLine(x1,y1, x2, y2); | 
|---|
|  | 80 | x1 = x2; | 
|---|
|  | 81 | } | 
|---|
|  | 82 | y2 = 0; g->DrawLine(x1,y1, x2, y2); | 
|---|
|  | 83 | oktrace = true; | 
|---|
|  | 84 | } | 
|---|
|  | 85 | if( !oktrace ) { | 
|---|
|  | 86 | for(int i=0; i<mHisto->NBins(); i++) { | 
|---|
|  | 87 | double left   = mHisto->BinLowEdge(i); | 
|---|
|  | 88 | double width  = mHisto->BinWidth(); | 
|---|
|  | 89 | double bottom = 0; | 
|---|
|  | 90 | double height = (*mHisto)(i); | 
|---|
|  | 91 | g->DrawFBox(left,bottom,width,height); | 
|---|
|  | 92 | g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne... | 
|---|
|  | 93 | } | 
|---|
|  | 94 | } | 
|---|
|  | 95 | // A faire a la fin - DrawStats change l'attribut de ligne | 
|---|
|  | 96 | DrawStats(g); | 
|---|
|  | 97 | } | 
|---|
|  | 98 |  | 
|---|
|  | 99 | void | 
|---|
|  | 100 | PIHisto::DrawStats(PIGraphicUC* g) | 
|---|
|  | 101 | { | 
|---|
|  | 102 | if (!mHisto) return; | 
|---|
|  | 103 | //  if (mLAtt == PI_NotDefLineAtt)  g->SelLine(PI_ThinLine); | 
|---|
|  | 104 | g->SelLine(PI_ThinLine); | 
|---|
|  | 105 | double cellHeight = (YMax() - YMin()) * 0.05; | 
|---|
|  | 106 | double cellWidth  = (XMax() - XMin()) * 0.23; | 
|---|
|  | 107 | g->DrawLine(XMax() - cellWidth, YMax(), | 
|---|
|  | 108 | XMax() - cellWidth, YMax() - cellHeight); | 
|---|
|  | 109 | g->DrawLine(XMax() - cellWidth, YMax() - cellHeight, | 
|---|
|  | 110 | XMax()            , YMax() - cellHeight); | 
|---|
|  | 111 | char label[50]; | 
|---|
|  | 112 | sprintf(label, "N = %.6g", mHisto->NData()); | 
|---|
|  | 113 | g->SelFontSz((YMax() - YMin())/30); | 
|---|
|  | 114 | g->DrawString(XMax() - cellWidth*0.9, YMax() - cellHeight*0.8, label); | 
|---|
|  | 115 |  | 
|---|
|  | 116 | } | 
|---|
|  | 117 |  | 
|---|