Changeset 1932 in Sophya
- Timestamp:
- Mar 13, 2002, 9:27:31 PM (24 years ago)
- Location:
- trunk/SophyaPI/PI
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PI/piaxestools.cc
r1916 r1932 194 194 char buff[128]; 195 195 if (curscdwdg != NULL) { 196 string format,dum; 196 197 PIScDrawWdg* scd = curscdwdg; 197 sprintf(buff, "%g %g", scd->XMin(), scd->XMax()); 198 PIDrawer::BonFormatAxes(scd->XMin(),scd->XMax(),-1.,format,0,2); 199 dum = format; dum += " "; dum += format; 200 sprintf(buff,dum.c_str(),scd->XMin(),scd->XMax()); 198 201 mText[0]->SetText(buff); 199 sprintf(buff, "%g %g", scd->YMin(), scd->YMax()); 202 PIDrawer::BonFormatAxes(scd->YMin(),scd->YMax(),-1.,format,0,2); 203 sprintf(buff,dum.c_str(),scd->YMin(),scd->YMax()); 200 204 mText[1]->SetText(buff); 201 205 int xa, ya; -
trunk/SophyaPI/PI/pidrawer.cc
r1930 r1932 383 383 if (flags & kLabels) { 384 384 if (!aYdir) 385 DrawHLabels(g, -xMajTickLen* 8, xFirstMajTick, xMajTickStep,0);385 DrawHLabels(g, -xMajTickLen*5, xFirstMajTick, xMajTickStep,0); 386 386 else 387 DrawHLabels(g, xMajTickLen* 8, xFirstMajTick, xMajTickStep,0);387 DrawHLabels(g, xMajTickLen*5, xFirstMajTick, xMajTickStep,0); 388 388 if (!aXdir) 389 389 DrawVLabels(g, -yMajTickLen*2, yFirstMajTick, yMajTickStep,1); … … 441 441 if (flags & kLabels) { 442 442 if (!aYdir) { 443 DrawHLabels(g, g->DeltaUCY(yMin, -xMajTickLen* 8), xFirstMajTick, xMajTickStep,0);444 DrawHLabels(g, g->DeltaUCY(yMax, xMajTickLen*2), xFirstMajTick, xMajTickStep,0);443 DrawHLabels(g, g->DeltaUCY(yMin, -xMajTickLen*5), xFirstMajTick, xMajTickStep,0); 444 //DrawHLabels(g, g->DeltaUCY(yMax, xMajTickLen*2), xFirstMajTick, xMajTickStep,0); 445 445 } 446 446 else { 447 DrawHLabels(g, g->DeltaUCY(yMin, -xMajTickLen*2), xFirstMajTick, xMajTickStep,0);448 DrawHLabels(g, g->DeltaUCY(yMax, xMajTickLen* 8), xFirstMajTick, xMajTickStep,0);447 //DrawHLabels(g, g->DeltaUCY(yMin, -xMajTickLen*2), xFirstMajTick, xMajTickStep,0); 448 DrawHLabels(g, g->DeltaUCY(yMax, xMajTickLen*5), xFirstMajTick, xMajTickStep,0); 449 449 } 450 450 if (!aXdir) { 451 451 DrawVLabels(g, g->DeltaUCX(xMin, -yMajTickLen*2), yFirstMajTick, yMajTickStep,1); 452 DrawVLabels(g, g->DeltaUCX(xMax, yMajTickLen*2), yFirstMajTick, yMajTickStep,-1);452 //DrawVLabels(g, g->DeltaUCX(xMax, yMajTickLen*2), yFirstMajTick, yMajTickStep,-1); 453 453 } 454 454 else { 455 DrawVLabels(g, g->DeltaUCX(xMin, -yMajTickLen*2), yFirstMajTick, yMajTickStep,-1);455 //DrawVLabels(g, g->DeltaUCX(xMin, -yMajTickLen*2), yFirstMajTick, yMajTickStep,-1); 456 456 DrawVLabels(g, g->DeltaUCX(xMax, yMajTickLen*2), yFirstMajTick, yMajTickStep,1); 457 457 } … … 495 495 PIDrawer::DrawHLabels(PIGraphicUC* g, double y, double xBeg, double xStep, int just) 496 496 { 497 double fsz = xMajTickLen*4.; 498 if(axesAFSz) g->SelFontSz(fsz); 499 500 // Choix du bon format pour les labels des axes; 501 char label[64]; string format; 502 int npuiss = BonFormatAxes(xBeg,xMax,xStep,format,2,1); 503 double fac = 1.; 504 505 if(npuiss!=0) { 506 fac = pow(10.,(double)npuiss); 507 sprintf(label,"10^%d",npuiss); 508 double largeur = g->CalcStringWidth(label); 509 double xm = (aXdir)? xMin+largeur: xMax-largeur; 510 double ym = (aYdir)? yMax+2.5*fsz: yMin-2.5*fsz; 511 g->DrawString(xm,ym,label); 512 } 513 497 514 double xOffset = 0; 498 int kk; 499 500 if (axesAFSz) 501 g->SelFontSz(xMajTickLen*4.); // Passage de x3. a x4. - Reza Janvier 2002 515 double xlastlabelfin = xBeg - 2.*(xMax-xBeg); 516 for(double x=xBeg; x<=xMax+xStep/10.; x+=xStep) { 517 //Attention erreur d'arrondi x->0 (on code 5.1698e-26 au lieu de 0) 518 double xx = (fabs(x/xStep)<1.e-5) ? 0.: x; 519 sprintf(label,format.c_str(),xx/fac); 520 for(int kk=0;kk<64;kk++) if(label[kk]==' ') {label[kk]='\0'; break;} 521 double largeur = g->CalcStringWidth(label); 522 if(just==1) xOffset=-largeur; else if(just==0) xOffset=-largeur/2; 523 if(aXdir) xOffset = -xOffset; 524 if(x+xOffset > xlastlabelfin) { 525 g->DrawString(g->DeltaUCX(x,xOffset),y,label); 526 xlastlabelfin = x + xOffset + 1.1*largeur; 527 } 528 } 529 } 530 531 void 532 PIDrawer::DrawVLabels(PIGraphicUC* g, double x, double yBeg, double yStep, int just) 533 { 534 double fsz = xMajTickLen*4.; 535 if(axesAFSz) g->SelFontSz(fsz); 502 536 503 537 // Choix du bon format pour les labels des axes; 504 string format; 505 BonFormatAxes(xBeg,xMax,xStep,format,1); 506 507 double xlastlabelfin = xBeg - 2.*(xMax-xBeg); 508 for (double x=xBeg; x<=xMax+xStep/10.; x += xStep) { 509 // Attention aux erreurs d'arrondi quand x->0 510 // car on code 5.1698e-26 au lieu de 0 511 double xx = (fabs(x/xStep)<1.e-5) ? 0.: x; 512 char label[64]; sprintf(label,format.c_str(), xx); 513 for(kk=0;kk<64;kk++) if(label[kk]==' ') {label[kk]='\0'; break;} 514 double largeur = g->CalcStringWidth(label); 515 if(just == 1) xOffset = -largeur; 516 else if(just == 0) xOffset = -largeur/2; 517 else xOffset = 0; 518 if(aXdir) xOffset = -xOffset; 519 if( x+xOffset > xlastlabelfin ) { 520 g->DrawString(g->DeltaUCX(x,xOffset), y, label); 521 xlastlabelfin = x + xOffset + 1.1*largeur; 522 } 538 char label[64]; string format; 539 int npuiss = BonFormatAxes(yBeg,yMax,yStep,format,2,1); 540 double fac = 1.; 541 542 if(npuiss!=0) { 543 fac = pow(10.,(double)npuiss); 544 sprintf(label,"10^%d",npuiss); 545 double largeur = g->CalcStringWidth(label); 546 double xm = (aXdir)? xMax+largeur: xMin-largeur; 547 double ym = (aYdir)? yMin-1.5*fsz: yMax+1.5*fsz; 548 g->DrawString(xm,ym,label); 523 549 } 524 } 525 526 void 527 PIDrawer::DrawVLabels(PIGraphicUC* g, double x, double yBeg, double yStep, int just) 528 { 550 529 551 double xOffset = 0; 530 531 if (axesAFSz)532 g->SelFontSz(xMajTickLen*4.); // Passage de x3. a x4. - Reza Janvier 2002533 534 // Choix du bon format pour les labels des axes;535 string format;536 BonFormatAxes(yBeg,yMax,yStep,format,1);537 538 552 for (double y=yBeg; y<=yMax; y += yStep) { 539 553 double yy = (fabs(y/yStep)<1.e-5) ? 0.: y; 540 char label[64]; sprintf(label,format.c_str(),yy);554 sprintf(label,format.c_str(),yy/fac); 541 555 for(int kk=0;kk<64;kk++) if(label[kk]==' ') {label[kk]='\0'; break;} 542 556 double largeur = g->CalcStringWidth(label); 543 if (just == 1) 544 xOffset = -largeur; 545 else if (just == 0) 546 xOffset = -largeur/2; 547 else 548 xOffset = 0; 557 if (just==1) xOffset=-largeur; else if(just==0) xOffset=-largeur/2; 549 558 if (aXdir) xOffset = -xOffset; 550 559 g->DrawString(g->DeltaUCX(x, xOffset), y, label); … … 568 577 } 569 578 579 /////////////////////////////////////////////////////////////////////////// 570 580 /* --Methode-Static-- */ 571 581 void PIDrawer::BestTicks(double xmin,double xmax,int nticks … … 608 618 /* --Methode-Static-- */ 609 619 int PIDrawer::BonFormatAxes(double xmin,double xmax,double xstep 610 ,string& format,int add_digit)620 ,string& format,int typf,int add_digit) 611 621 // *** Calcul format optimal pour ecrire les labels numeriques des axes: 612 // - Les axes vont de "xmin" a "xmax". 613 // - On veut un intervalle "xstep" entre les ticks. 614 // - Le programme retourne le format dans le "string format" 615 // - add_digit: nombre de digit a ajouter au nombre de digit minimum. 616 // Return: "ndig" nombre de digits necessaires pour distinguer 617 // les valeurs xmin+k*dx (<=xmax) 622 // ---- Input 623 // . xmin,xmax : limites du plot sur l'axe considere. 624 // . xstep : distance entre les ticks. 625 // . add_digit : nombre de digits a ajouter au nombre de digits minimum. 626 // . typf : type de format en sortie 627 // 0 : format optimum %-nn.mme ou %-nn.mmf selon valeurs 628 // 1 : format %-nn.mme 629 // 2 : format %-nn.mmf pour imprimer x/10^npuiss 630 // tel que x/10^npuiss soit entre 0 et 10 631 // ---- Output 632 // . format : le format d'impression 633 // ---- Return: 634 // Si typ=0 ou 1 635 // "ndig" : nombre de digits necessaires pour distinguer 636 // les valeurs xmin+k*dx (<=xmax) 637 // Si typ=2 638 // "npuiss" : tel que x/10^npuiss soit entre 0 et 10 639 // Dans ce cas le format est celui qui imprime x/10^npuiss 618 640 { 619 641 format = "%-5g"; // format par default 620 if(xmin>=xmax) return -1;642 if(xmin>=xmax) {if(typf==2) return 0; else return -1;} 621 643 622 644 if(xstep<=0. || xstep>xmax-xmin) xstep = xmax-xmin; … … 625 647 if(axmin>axmax) swap(axmin,axmax); 626 648 double l10amax = log10(axmax), l10xstep = log10(xstep); 627 628 //printf("BonFormatAxes: xmin=%-21.14e xmax=%-21.14e\n",xmin,xmax);629 //printf(" xstep=%-21.14e log10(xstep)=%g\n",xstep,l10xstep);630 //printf(" axmax=%-21.14e log10(axmax)=%g diff=%g\n"631 // ,axmax,l10amax,l10amax-l10xstep);632 633 // Nombre de digits necessaires pour ecrire amax et xstep634 649 int il10amax = int(floor(l10amax)); 650 651 // choix du type de format 652 char ftype = 'e'; 653 int npuiss = 0; 654 if(typf==2) { 655 npuiss = il10amax; 656 if(npuiss<-300 || npuiss>300) { 657 ftype='e'; npuiss=0; 658 } else { 659 // On recalcule les valeurs de decision pour axmax/10^npuiss, xstep/10^npuiss 660 l10amax -= (double)npuiss; l10xstep -= (double)npuiss; 661 il10amax = int(floor(l10amax)); 662 ftype = 'f'; 663 } 664 } else if(typf==1) { 665 ftype='e'; 666 } else { 667 ftype='e'; 668 // On evite d'ecrire +a.bbbe+ccc -> format %f 669 // Ex: 1.2345e+2 -> 123.45 / -1.2345e+2 -> -123.45 670 // 1.2345e-1 -> 0.12345 / -1.2345e-1 -> -0.12345 671 if(axmin>=1e-4 && axmax<1e4) ftype='f'; 672 } 673 674 //printf("BonFormatAxes[npuiss=%d]: xmin=%-21.14e xmax=%-21.14e\n",npuiss,xmin,xmax); 675 //printf(" xstep=%-21.14e log10(xstep/10^%d)=%g\n",xstep,npuiss,l10xstep); 676 //printf(" axmax=%-21.14e log10(axmax/10^%d)=%g diff=%g\n" 677 // ,axmax,npuiss,l10amax,l10amax-l10xstep); 678 679 // Nombre de digits necessaires pour ecrire axmax et xstep 635 680 int ndig = il10amax - int(floor(l10xstep)); 636 if(ndig<0) ndig *= -1; 637 ndig += 1; 681 if(ndig<0) ndig *= -1; ndig += 1; 638 682 //printf("ndig=%d",ndig); 639 683 … … 644 688 // Calcul du bon format 645 689 char str[16]; 646 if(axmin>=1e-4 && axmax<1e4) { 647 // On evite d'ecrire +a.bbbe+ccc -> format %f 648 // Ex: 1.2345e+2 -> 123.45 / -1.2345e+2 -> -123.45 649 // 1.2345e-1 -> 0.12345 / -1.2345e-1 -> -0.12345 650 // Calcul du format %-nn.mmf 690 if(ftype=='f') { // Calcul du format %-nn.mmf 651 691 int mm=-1, nn; 652 692 if(il10amax<0) { // +0.12345 +0.0012345 +0.0012345 ... … … 658 698 if(mm<0.) mm=0; if(nn<mm+3) nn=mm+3; 659 699 sprintf(str,"%%-%d.%df",nn,mm); 660 } else { 661 // Calcul du nombre "nn" devant le format %-nn.mme 700 } else if(ftype=='e') { // Calcul du format %-nn.mme 662 701 // +d.<--ddd-->e+123 663 // 1 2 34567 664 // nn = ndig+7 mm = ndig-1 702 // 1 2 34567 ==> nn=ndig+7 mm=ndig-1 665 703 sprintf(str,"%%-%d.%de",ndig+7,ndig-1); 666 704 } … … 669 707 //printf("format=[%s]\n",format.c_str()); 670 708 709 if(typf==2) return npuiss; 671 710 return ndig; 672 711 } 673 -
trunk/SophyaPI/PI/pidrawer.h
r1930 r1932 104 104 // Calcul du format optimal pour les axes 105 105 static int BonFormatAxes(double xmin,double xmax,double xstep 106 ,string& format,int add_digit=0);106 ,string& format,int typf=0,int add_digit=0); 107 107 108 108 // Les objets/methodes suivants devraient etre protected … … 164 164 }; 165 165 166 167 168 166 #endif -
trunk/SophyaPI/PI/piscdrawwdg.cc
r1930 r1932 610 610 double xm = (fabs(xmax)>fabs(xmin)) ? fabs(xmax): fabs(xmin); 611 611 double dx = fabs(xmax-xmin)/500.; 612 PIDrawer::BonFormatAxes(xm,xm+dx,dx,format, 1);612 PIDrawer::BonFormatAxes(xm,xm+dx,dx,format,0,1); 613 613 return format; 614 614 }
Note:
See TracChangeset
for help on using the changeset viewer.