source: Sophya/trunk/SophyaPI/PIext/pihisto.cc@ 1645

Last change on this file since 1645 was 1645, checked in by cmv, 24 years ago

Correc. bug display Statis si axes inverses cmv 24/08/2001

File size: 4.8 KB
RevLine 
[544]1// Classe traceur d histogramme 96-99
2// CEA-DAPNIA LAL-IN2P3/CNRS
3
[165]4#include <stdio.h>
[295]5#include <typeinfo>
6
[165]7#include "pihisto.h"
8#include "hisprof.h"
9
[544]10//++
11// Class PIHisto
12// Lib PIext
13// include pihisto.h
14//
15// Classe traceur d'objet histogramme (classe *Histo*)
16//--
17//++
18// Links Parents
19// PIDrawer
20//--
21//++
22// Titre Constructeur, méthodes
23//--
24//++
25// PIHisto(Histo* histo, bool ad=false)
26// Constructeur. Si "ad == true", l'objet "histo" est détruit par
27// le destructeur de l'objet "PIHisto"
28// Note : "histo" doit être créé par new
29//
30// void SetStats(bool fg=true)
31// Active/ désactive l'indication des statistiques d'histogramme
32//--
33
34
[165]35PIHisto::PIHisto(Histo* histo, bool ad)
36: PIDrawer(), mHisto(histo)
37{
38 mAdDO = ad; // Flag pour suppression automatique de mHisto
[544]39 SetStats(true);
[165]40}
41
42PIHisto::~PIHisto()
43{
44 if (mAdDO) delete mHisto;
45}
46
47void
48PIHisto::UpdateLimits()
49{
50 if (!mHisto) return;
51 float hmin = mHisto->VMin();
52 float hmax = mHisto->VMax()+0.2*(mHisto->VMax()-mHisto->VMin());
53 // si HBProf min,max calcules en tenant compte des erreurs
[295]54 if( typeid(*mHisto) == typeid(HProf) ) {
[165]55 float v1,v2;
56 for (int i=1; i<mHisto->NBins(); i++) {
57 v1 = (*mHisto)(i) - mHisto->Error(i);
58 v2 = (*mHisto)(i) + mHisto->Error(i);
59 if(v1<hmin) hmin = v1;
60 if(v2>hmax) hmax = v2;
61 }
62 v1 = 0.1*(hmax-hmin);
63 hmin -= v1; hmax += v1;
64 }
65 if(hmax<=hmin) hmax += 1.;
66 SetLimits(mHisto->XMin(), mHisto->XMax(), hmin, hmax);
[548]67// SetAxesFlags(kBoxAxes | kExtTicks | kLabels); NE PAS faire Reza 11/99
[165]68}
69
70void
[205]71PIHisto::Draw(PIGraphicUC* g, double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
[165]72{
[548]73 if (axesFlags != kAxesNone) DrawAxes(g);
74
[165]75 bool oktrace = false;
76 if (!mHisto) return;
[203]77
[1057]78 if(mMrk != PI_NotDefMarker || (typeid(*mHisto) == typeid(HProf)) ) {
79 // Marqeurs definis OU HProf => marqueurs+Erreurs si il y en a
[1090]80 mHisto->UpdateHisto(); // pour le cas ou c'est un HProf
[1057]81 if(mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
[205]82 double x1,y1, x2,y2;
83 double bw = mHisto->BinWidth();
[1057]84 for(int i=0; i<mHisto->NBins(); i++) {
[165]85 if(mHisto->Error(i)>0.) {
86 // barres d'erreur verticales
87 x1 = x2 = mHisto->BinCenter(i);
88 y1 = (*mHisto)(i) - mHisto->Error(i);
89 y2 = (*mHisto)(i) + mHisto->Error(i);
90 g->DrawLine(x1,y1, x1, y2);
91 // limites de barres d'erreurs (horizontales)
92 x1 -= bw/3.; x2 += bw/3.;
93 g->DrawLine(x1,y1, x2, y1);
94 g->DrawLine(x1,y2, x2, y2);
95 }
96 // le marqueur
97 x1 = mHisto->BinCenter(i);
98 y1 = (*mHisto)(i);
99 g->DrawMarker(x1,y1);
100 }
101 oktrace = true;
102 }
[1057]103 if(mLAtt != PI_NotDefLineAtt) {
[205]104 double x1,y1, x2, y2;
[165]105 x1 = mHisto->BinLowEdge(0);
106 y1 = 0;
[1057]107 for(int i=0; i<mHisto->NBins(); i++) {
[165]108 x2 = x1;
109 y2 = (*mHisto)(i);
110 g->DrawLine(x1,y1, x2, y2);
111 y1 = y2;
112 x2 = mHisto->BinHighEdge(i);
113 g->DrawLine(x1,y1, x2, y2);
114 x1 = x2;
115 }
116 y2 = 0; g->DrawLine(x1,y1, x2, y2);
117 oktrace = true;
118 }
119 if( !oktrace ) {
120 for(int i=0; i<mHisto->NBins(); i++) {
[205]121 double left = mHisto->BinLowEdge(i);
122 double width = mHisto->BinWidth();
123 double bottom = 0;
124 double height = (*mHisto)(i);
[165]125 g->DrawFBox(left,bottom,width,height);
126 g->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
127 }
128 }
[203]129 // A faire a la fin - DrawStats change l'attribut de ligne
[1057]130 if(stats) DrawStats(g);
[165]131}
132
133void
134PIHisto::DrawStats(PIGraphicUC* g)
135{
136 if (!mHisto) return;
[203]137 // if (mLAtt == PI_NotDefLineAtt) g->SelLine(PI_ThinLine);
138 g->SelLine(PI_ThinLine);
[1644]139 g->SelFontSz((YMax() - YMin())/30, mFAtt);
140
141 // La hauteur de la cellule
[544]142 PIGrCoord a, d;
143 double cH = (double)g->GetFontHeight(a,d);
[1645]144 double cellHeight = 3.6 * cH;
[1644]145
146 // Les labels et leurs longueurs -> largeur de la cellule
[1645]147 char *label, label1[64], label2[64], label3[64];
148 sprintf(label1, "N= %-g",mHisto->NData());
149 sprintf(label2, "m= %-g",mHisto->Mean());
150 sprintf(label3, "s= %-g",mHisto->Sigma());
[1644]151 label = label1;
152 if(strlen(label)<strlen(label2)) label = label2;
153 if(strlen(label)<strlen(label3)) label = label3;
154 double cellWidth = 1.1 * (double)g->CalcStringWidth(label);
155
[1645]156 double xu, yu, cw;
[1644]157 // Les limites du cadre
[1645]158 xu = g->DeltaUCX(XMax(), -cellWidth);
159 yu = g->DeltaUCY(YMax(), -cellHeight);
160 g->DrawLine(xu,YMax(),xu,yu);
161 g->DrawLine(xu,yu,XMax(),yu);
[1644]162
[1645]163 // L'ecriture des labels (attention aux inversions possibles des axes!)
164 cw = (g->isAxeXDirRtoL()) ? -0.05*cellWidth : -0.95*cellWidth;
165 xu = g->DeltaUCX(XMax(),cw);
166
167 cw = (g->isAxeYDirUpDown()) ? -0.15*cH : -1.15*cH;
168 yu = g->DeltaUCY(YMax(),cw);
169 g->DrawString(xu, yu,label1);
170 cw += -1.15*cH;
171 yu = g->DeltaUCY(YMax(),cw);
172 g->DrawString(xu, yu,label2);
173 cw += -1.15*cH;
174 yu = g->DeltaUCY(YMax(),cw);
175 g->DrawString(xu, yu,label3);
[165]176
177}
Note: See TracBrowser for help on using the repository browser.