[165] | 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, float /*xmin*/, float /*ymin*/, float /*xmax*/, float /*ymax*/)
|
---|
| 41 | {
|
---|
| 42 | bool oktrace = false;
|
---|
| 43 | if (!mHisto) return;
|
---|
| 44 | if (mMrk != PI_NotDefMarker || mHisto->ClassId() == HProf::classId ) {
|
---|
| 45 | // Marqeurs definis OU HBProf => marqueurs+Erreurs si il y en a
|
---|
| 46 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
| 47 | float x1,y1, x2,y2;
|
---|
| 48 | float bw = mHisto->BinWidth();
|
---|
| 49 | for (int i=0; i<mHisto->NBins(); i++) {
|
---|
| 50 | if(mHisto->Error(i)>0.) {
|
---|
| 51 | // barres d'erreur verticales
|
---|
| 52 | x1 = x2 = mHisto->BinCenter(i);
|
---|
| 53 | y1 = (*mHisto)(i) - mHisto->Error(i);
|
---|
| 54 | y2 = (*mHisto)(i) + mHisto->Error(i);
|
---|
| 55 | g->DrawLine(x1,y1, x1, y2);
|
---|
| 56 | // limites de barres d'erreurs (horizontales)
|
---|
| 57 | x1 -= bw/3.; x2 += bw/3.;
|
---|
| 58 | g->DrawLine(x1,y1, x2, y1);
|
---|
| 59 | g->DrawLine(x1,y2, x2, y2);
|
---|
| 60 | }
|
---|
| 61 | // le marqueur
|
---|
| 62 | x1 = mHisto->BinCenter(i);
|
---|
| 63 | y1 = (*mHisto)(i);
|
---|
| 64 | g->DrawMarker(x1,y1);
|
---|
| 65 | }
|
---|
| 66 | oktrace = true;
|
---|
| 67 | }
|
---|
| 68 | if (mLAtt != PI_NotDefLineAtt) {
|
---|
| 69 | float x1,y1, x2, y2;
|
---|
| 70 | x1 = mHisto->BinLowEdge(0);
|
---|
| 71 | y1 = 0;
|
---|
| 72 | for (int i=0; i<mHisto->NBins(); i++) {
|
---|
| 73 | x2 = x1;
|
---|
| 74 | y2 = (*mHisto)(i);
|
---|
| 75 | g->DrawLine(x1,y1, x2, y2);
|
---|
| 76 | y1 = y2;
|
---|
| 77 | x2 = mHisto->BinHighEdge(i);
|
---|
| 78 | g->DrawLine(x1,y1, x2, y2);
|
---|
| 79 | x1 = x2;
|
---|
| 80 | }
|
---|
| 81 | y2 = 0; g->DrawLine(x1,y1, x2, y2);
|
---|
| 82 | oktrace = true;
|
---|
| 83 | }
|
---|
| 84 | if( !oktrace ) {
|
---|
| 85 | for(int i=0; i<mHisto->NBins(); i++) {
|
---|
| 86 | float left = mHisto->BinLowEdge(i);
|
---|
| 87 | float width = mHisto->BinWidth();
|
---|
| 88 | float bottom = 0;
|
---|
| 89 | float height = (*mHisto)(i);
|
---|
| 90 | g->DrawFBox(left,bottom,width,height);
|
---|
| 91 | g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | DrawStats(g);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void
|
---|
| 98 | PIHisto::DrawStats(PIGraphicUC* g)
|
---|
| 99 | {
|
---|
| 100 | if (!mHisto) return;
|
---|
| 101 | if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
|
---|
| 102 | float cellHeight = (YMax() - YMin()) * 0.05;
|
---|
| 103 | float cellWidth = (XMax() - XMin()) * 0.23;
|
---|
| 104 | g->DrawLine(XMax() - cellWidth, YMax(),
|
---|
| 105 | XMax() - cellWidth, YMax() - cellHeight);
|
---|
| 106 | g->DrawLine(XMax() - cellWidth, YMax() - cellHeight,
|
---|
| 107 | XMax() , YMax() - cellHeight);
|
---|
| 108 | char label[50];
|
---|
| 109 | sprintf(label, "N = %.6g", mHisto->NData());
|
---|
| 110 | g->SelFontSz((YMax() - YMin())/30);
|
---|
| 111 | g->DrawString(XMax() - cellWidth*0.9, YMax() - cellHeight*0.8, label);
|
---|
| 112 |
|
---|
| 113 | }
|
---|
| 114 |
|
---|