Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

sxy_chart.cpp

Go to the documentation of this file.
00001 // =======================================================================
00002 
00003 char *chart_cpp = "$Id: sxy_chart.cpp,v 1.9 2003/04/25 20:21:43 clinio Exp $";
00004 
00005 // =======================================================================
00006 
00007 #include <float.h>
00008 #include <assert.h>
00009 
00010 extern "C" {
00011 #include <iup.h>
00012 #include <cd.h>
00013 #include <cdiup.h>
00014 }
00015 
00016 #include "sxy_chart.h"
00017 #include "sxy_curve.h"
00018 #include "sxy_utils.h"
00019 
00020 #define MAX_AREAS   32
00021 #define MAX_CURVES  64
00022 #define MAX_AXIS    10
00023 
00024 // =======================================================================
00025 
00026 // .......................................................................
00027 
00030 SXYChart::SXYChart(SXYGraph* gra, double nxmin, double nymin, 
00031 double nxmax, double nymax) {
00032   xmulstep = 1;
00033   ymulstep = 1;
00034 
00035   graph = gra;
00036   assert(graph != NULL);
00037 
00038   xy_xgrid = NULL;
00039   xy_ygrid = NULL;
00040 
00041   areas_vector = new SXYVector<SXYArea*>(MAX_AREAS, NULL);
00042   curves_vector = new SXYVector<SXYCurve*>(MAX_CURVES, NULL);
00043   xaxes_vector = new SXYVector<SXYAxis*>(MAX_AXIS, NULL);
00044   yaxes_vector = new SXYVector<SXYAxis*>(MAX_AXIS, NULL);
00045 
00046   assert(areas_vector);
00047   assert(curves_vector);
00048   assert(xaxes_vector);
00049   assert(yaxes_vector);
00050 
00051   int ref_font_size = SXYChart::getFontSizeReference();
00052 
00053   /* Criação do título XY */
00054   xy_title = new XYRasterText("Título",
00055         XYCoordinate((double)0.5), XYCoordinate((double)0.98),
00056         XY_DARK_BLUE, ref_font_size+4,
00057         XYRasterText::helvetica, XYRasterText::bold,
00058         XYRasterText::north, XYRasterText::horizontal);
00059 
00060   /* Criação do subtítulo XY */
00061   xy_subtitle = new XYRasterText("Subtítulo",
00062         XYCoordinate((double)0.5), XYCoordinate((double)0.95),
00063         XY_BLUE, ref_font_size+2, XYRasterText::helvetica,
00064         XYRasterText::plain, XYRasterText::north, 
00065         XYRasterText::horizontal);
00066 
00067   assert(xy_title);
00068   assert(xy_subtitle);
00069 
00070   /* Criação dos eixos */
00071   xy_xgrid = new XYGrid(1., 100., 0., XY_DARK_GRAY, XYObject::dotted, 0.0, 1.);
00072   xy_ygrid = new XYGrid(1., 100., 0., XY_DARK_GRAY, XYObject::dotted, 90.0, 1.);
00073   assert(xy_xgrid);
00074   assert(xy_ygrid);
00075 
00076   /* Criação da legenda */
00077   int leg_nlines = 1;
00078   int leg_ncols = 1; 
00079   xy_legend = new XYLegend( 
00080         XYCoordinate((double)0.5), 
00081         XYCoordinate((double)0.15), 
00082         leg_nlines, leg_ncols, xytrue, xytrue);
00083   assert(xy_legend);
00084   xy_legend->frameColor(XY_BLACK);
00085   xy_legend->backgroundColor(XY_WHITE);
00086 
00087   /* Verificação do tamanho e posição do gráfico XY no canvas */
00088   double nw = fabs(nxmax - nxmin);
00089   double nh = fabs(nymax - nymin);
00090   double px = nxmin;
00091   double py = nymin;
00092 
00093   /* Criação do gráfico XY */
00094   cdCanvas *cdcnv = graph->getCdCanvas();
00095   assert(cdcnv);
00096   xy_graph = new XYCartesian(cdcnv, px, py, nw, nh, xy_xgrid, xy_ygrid);
00097   assert(xy_graph);
00098 
00099   setGridType( HORIZONTAL_GRID, LINEAR_GRID );
00100   setGridType( VERTICAL_GRID, LINEAR_GRID );
00101 
00102   /* Inserção dos objetos XY no gráfico */
00103   xy_graph->insert( xy_title );
00104   xy_graph->insert( xy_subtitle );
00105   xy_graph->legend( xy_legend );
00106 
00107   /* Ajuste de atributos default */
00108   xy_graph->backgroundColor( XY_GRAY );
00109   xy_graph->calcMaskArea();
00110   xy_graph->maskAreaColor( XY_WHITE );
00111   xy_graph->distortion( xytrue );
00112   xy_graph->doubleBuffering( xytrue );
00113 }
00114 
00115 // .......................................................................
00116 
00118 SXYChart::~SXYChart() {
00119   if (areas_vector) delete areas_vector;
00120   areas_vector = NULL;
00121 
00122   if (curves_vector) delete curves_vector;
00123   curves_vector = NULL;
00124 
00125   if (xaxes_vector) delete xaxes_vector;
00126   xaxes_vector = NULL;
00127 
00128   if (yaxes_vector) delete yaxes_vector;
00129   yaxes_vector = NULL;
00130 
00131   if (xy_title) delete xy_title; 
00132   xy_title = NULL;
00133 
00134   if (xy_subtitle) delete xy_subtitle; 
00135   xy_subtitle = NULL;
00136 
00137   if (xy_xgrid) delete xy_xgrid; 
00138   xy_xgrid = NULL;
00139 
00140   if (xy_ygrid) delete xy_ygrid; 
00141   xy_ygrid = NULL;
00142 
00143   if (xy_legend) delete xy_legend; 
00144   xy_legend = NULL;
00145 
00146   // Estamos com algum problema no XY...
00147   // delete xy_graph;  
00148   xy_graph = NULL;
00149 }
00150 
00151 
00152 // .......................................................................
00153 
00154 long int SXYChart::getMainColor( void ) {
00155   return xy_graph->maskAreaColor();
00156 }
00157 
00158 // .......................................................................
00159 
00160 void SXYChart::setMainColor( long int color ) {
00161   xy_graph->maskAreaColor( color );
00162 }
00163 
00164 // .......................................................................
00165 
00166 long int SXYChart::getGridColor( void ) {
00167   return xy_xgrid->color();
00168 }
00169 
00170 // .......................................................................
00171 
00172 void SXYChart::setGridColor( long int color ) {
00173   xy_xgrid->color( color );
00174   xy_ygrid->color( color );
00175 }
00176 
00177 // .......................................................................
00178 
00179 long int SXYChart::getBackgroundColor( void ) {
00180   return xy_graph->backgroundColor();
00181 }
00182 
00183 // .......................................................................
00184 
00185 void SXYChart::setBackgroundColor( long int color ) {
00186   xy_graph->backgroundColor( color );
00187 }
00188 
00189 // .......................................................................
00190 
00191 void SXYChart::getLegendRelativePosition(double& x, double& y) {
00192    double px, py;
00193    xy_legend->position(&px,&py);
00194    x = px; y = py;
00195 }
00196 
00197 // .......................................................................
00198 
00199 void SXYChart::setLegendRelativePosition(double x, double y) {
00200    xy_legend->position(x,y);
00201 }
00202 
00203 // .......................................................................
00204 
00205 void SXYChart::setLegendVisibility(unsigned int flag) {
00206    xy_legend->visible( flag ? xytrue : xyfalse );
00207 }
00208 
00209 // .......................................................................
00210 
00211 unsigned int SXYChart::getLegendVisibility(void) {
00212    return xy_legend->visible() ? 1 : 0;
00213 }
00214 
00215 // .......................................................................
00216 
00217 XYRasterText* SXYChart::getXyTitle(void) {
00218    return xy_title;
00219 }
00220 
00221 // .......................................................................
00222 
00223 XYRasterText* SXYChart::getXySubTitle(void) {
00224    return xy_subtitle;
00225 }
00226 
00227 // .......................................................................
00228 
00229 XYLegend* SXYChart::getXyLegend(void) {
00230    return xy_legend;
00231 }
00232 
00233 // .......................................................................
00234 
00235 SXYGraph* SXYChart::getGraph(void) {
00236   return graph;
00237 }
00238 
00239 // .......................................................................
00240 
00241 void SXYChart::repaintChart(cdCanvas* cnv, SXYGraphDoubleBufferMode mode) {
00242   /* Redesenho do gráfico */
00243   xybool db = (mode == WITH_DOUBLE_BUFFER ? xytrue : xyfalse);
00244   xy_graph->setCdCanvas(cnv);
00245   rebuildMaskArea();
00246   xy_graph->doubleBuffering(db);
00247   xy_graph->clear();
00248   xy_graph->draw();
00249 }
00250 
00251 // .......................................................................
00252 
00253 void SXYChart::rebuildMaskArea(void) {
00254   assert(xy_graph);
00255   xy_graph->calcMaskArea();
00256 }
00257 
00258 // .......................................................................
00259 
00260 SXYArea* SXYChart::getArea(unsigned int a) {
00261    assert(areas_vector);
00262    return areas_vector->getElement(a);
00263 }
00264 // .......................................................................
00265 
00266 unsigned int SXYChart::getNumAreas(void) {
00267    if (areas_vector == NULL) return 0;
00268    return areas_vector->getLength();
00269 }
00270 
00271 // .......................................................................
00272 
00273 void SXYChart::insertArea(SXYArea* area) {
00274    assert(areas_vector);
00275    areas_vector->insertElement(area);
00276 }
00277 
00278 // .......................................................................
00279 
00280 void SXYChart::removeArea(SXYArea* area) {
00281    assert(areas_vector);
00282    areas_vector->removeElement(area);
00283 }
00284 
00285 // .......................................................................
00286 
00287 SXYCurve* SXYChart::getCurve(unsigned int c) {
00288    assert(curves_vector);
00289    return curves_vector->getElement(c);
00290 }
00291 // .......................................................................
00292 
00293 unsigned int SXYChart::getNumCurves(void) {
00294    if (curves_vector == NULL) return 0;
00295    return curves_vector->getLength();
00296 }
00297 
00298 // .......................................................................
00299 
00300 void SXYChart::insertCurve(SXYCurve* curve) {
00301    assert(curves_vector);
00302    curves_vector->insertElement(curve);
00303    assert(xy_legend);
00304    xy_legend->lines(getNumCurves());
00305 }
00306 
00307 // .......................................................................
00308 
00309 void SXYChart::removeCurve(SXYCurve* curve) {
00310    assert(curves_vector);
00311    curves_vector->removeElement(curve);
00312    assert(xy_legend);
00313    xy_legend->lines(getNumCurves());
00314 }
00315 
00316 // .......................................................................
00317 
00318 SXYAxis* SXYChart::getAxis(SXYAxisOrientation orientation, unsigned int a) {
00319    if (orientation == HORIZONTAL_AXIS) {
00320       assert(xaxes_vector);
00321       return xaxes_vector->getElement(a);
00322    } 
00323    else {
00324       assert(yaxes_vector);
00325       return yaxes_vector->getElement(a);
00326    }
00327 }
00328 // .......................................................................
00329 
00330 unsigned int SXYChart::getNumAxes(SXYAxisOrientation orientation) {
00331    if (orientation == HORIZONTAL_AXIS) {
00332       assert(xaxes_vector);
00333       return xaxes_vector->getLength();
00334    } 
00335    else {
00336       assert(yaxes_vector);
00337       return yaxes_vector->getLength();
00338    }
00339 }
00340 
00341 // .......................................................................
00342 
00343 void SXYChart::insertAxis(SXYAxisOrientation orientation, SXYAxis* axis) {
00344    if (orientation == HORIZONTAL_AXIS) {
00345       assert(xaxes_vector);
00346       xaxes_vector->insertElement(axis);
00347    } 
00348    else {
00349       assert(yaxes_vector);
00350       yaxes_vector->insertElement(axis);
00351    }
00352 }
00353 
00354 // .......................................................................
00355 
00356 void SXYChart::removeAxis(SXYAxisOrientation orientation, SXYAxis* axis) {
00357    if (orientation == HORIZONTAL_AXIS) {
00358       assert(xaxes_vector);
00359       xaxes_vector->removeElement(axis);
00360    } 
00361    else {
00362       assert(yaxes_vector);
00363       yaxes_vector->removeElement(axis);
00364    }
00365 }
00366 
00367 // .......................................................................
00368 
00369 char* SXYChart::getTitle(void) {
00370   assert(xy_title);
00371   return xy_title->text();
00372 }
00373 
00374 // .......................................................................
00375 
00376 char* SXYChart::getSubTitle(void) {
00377   assert(xy_subtitle);
00378   return xy_subtitle->text();
00379 }
00380 
00381 // .......................................................................
00382 
00383 void SXYChart::setTitle(char* txt) {
00384    xy_title->text( (const char*)txt );
00385 }
00386 
00387 // .......................................................................
00388 
00389 void SXYChart::setSubTitle(char* txt) {
00390    xy_subtitle->text( (const char*)txt );
00391 }
00392 
00393 // .......................................................................
00394 
00395 XYCartesian* SXYChart::getXyGraph(void) {
00396    return xy_graph;
00397 }
00398 
00399 // .......................................................................
00400 
00401 int SXYChart::getFontSizeReference(void) {
00402    return 8;
00403 }
00404 
00405 // .......................................................................
00406 
00407 long int SXYChart::getTitleColor(void) {
00408    assert(xy_title);
00409    return xy_title->color();
00410 }
00411 
00412 // .......................................................................
00413 
00414 long int SXYChart::getSubTitleColor(void) {
00415    assert(xy_subtitle);
00416    return xy_subtitle->color();
00417 }
00418 
00419 // .......................................................................
00420 
00421 void SXYChart::setGridType(SXYGridOrientation orientation, SXYGridType type) {
00422   if ( orientation == HORIZONTAL_GRID ) {
00423      if (xy_xgrid != NULL) { delete xy_xgrid; xy_xgrid = NULL; }
00424 
00425      if (type == LOG_GRID) {
00426         xy_xgrid = new XYGridLog(1., 100., 1., XY_DARK_GRAY, 
00427               XYObject::dotted, 0.0, 1.);
00428         xy_xgrid->min(.1); xy_xgrid->max(10.); xy_xgrid->step(.5);
00429      }
00430      else if ( type == LINEAR_GRID ) {
00431         xy_xgrid = new XYGrid(0., 100., 0., XY_DARK_GRAY, 
00432               XYObject::dotted, 0.0, 1.);
00433         xy_xgrid->min(0.); xy_xgrid->max(100.); xy_xgrid->step(10.);
00434      }
00435      else {
00436         assert(0);
00437      }
00438      assert( xy_xgrid );
00439      xy_xgrid->visible( xytrue );
00440      xy_graph->setGridH( xy_xgrid );
00441      xgrid_type = type;
00442   }
00443   else if (orientation == VERTICAL_GRID ) {
00444      if (xy_ygrid != NULL) { delete xy_ygrid; xy_ygrid = NULL; }
00445 
00446      if (type == LOG_GRID) {
00447         xy_ygrid = new XYGridLog(1., 100., 1., XY_DARK_GRAY, 
00448               XYObject::dotted, 90.0, 1.);
00449         xy_ygrid->min(.1); xy_ygrid->max(10.); xy_ygrid->step(.5);
00450      }
00451      else if ( type == LINEAR_GRID ) {
00452         xy_ygrid = new XYGrid(0., 100., 0., XY_DARK_GRAY, 
00453               XYObject::dotted, 90.0, 1.);
00454         xy_ygrid->min(0.); xy_ygrid->max(100.); xy_ygrid->step(10.);
00455      }
00456      else {
00457         assert(0);
00458      }
00459      assert( xy_ygrid );
00460      xy_ygrid->visible( xytrue );
00461      xy_graph->setGridV( xy_ygrid );
00462      ygrid_type = type;
00463   }
00464   else {
00465      assert(0);
00466   }
00467 }
00468 
00469 // .......................................................................
00470 
00471 void SXYChart::setGridPosition(SXYGridOrientation orientation,
00472 double xp, double yp) {
00473   if (orientation == HORIZONTAL_GRID) {
00474      assert(xy_xgrid);
00475      xy_xgrid->position(xp, yp);
00476   }
00477   else {
00478      assert(xy_ygrid);
00479      xy_ygrid->position(xp, yp);
00480   }
00481 }
00482 
00483 // .......................................................................
00484 
00485 void SXYChart::setGridDirection(SXYGridOrientation orientation,
00486 SXYGridDirection direction) {
00487   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00488   assert(xygr);
00489   double ang = 45.0;
00490   if (orientation == HORIZONTAL_GRID) {
00491      if (direction == NORMAL_GRID) {
00492        ang = 0.0;
00493        xygr->leftTick(xyfalse);
00494     }
00495     else {
00496        ang = 180.0;
00497        xygr->leftTick(xyfalse);
00498     }
00499   }
00500   else {
00501     if (direction == NORMAL_GRID) {
00502        xygr->leftTick(xytrue);
00503        ang = 90.0;
00504     }
00505     else {
00506        ang = 270.0;
00507        xygr->leftTick(xytrue);
00508     }
00509   }
00510   xygr->rotation(ang);
00511 }
00512 
00513 // .......................................................................
00514 
00515 SXYGridDirection SXYChart::getGridDirection(SXYGridOrientation orientation) {
00516   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00517   assert(xygr);
00518   if (orientation == HORIZONTAL_GRID) {
00519      double ang = xygr->rotation();
00520      return ang == 0.0 ? NORMAL_GRID : INVERTED_GRID;
00521   }
00522   else {
00523      double ang = xygr->rotation();
00524      return ang == 90.0 ? NORMAL_GRID : INVERTED_GRID;
00525   }
00526 }
00527 
00528 // .......................................................................
00529 
00530 SXYGridType SXYChart::getGridType(SXYGridOrientation orientation) {
00531   return orientation == HORIZONTAL_GRID ? xgrid_type : ygrid_type;
00532 }
00533 
00534 // .......................................................................
00535 
00536 unsigned int SXYChart::getGridVisibility(SXYGridOrientation orientation) {
00537   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00538   assert(xygr);
00539   return xygr->visible() == xytrue ? 1 : 0;
00540 }
00541 
00542 // .......................................................................
00543 
00544 void SXYChart::getGridScales(SXYGridOrientation orientation,
00545 double& min, double& max) {
00546   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00547   assert(xygr);
00548   min = xygr->min();
00549   max = xygr->max();
00550 }
00551 
00552 // .......................................................................
00553 
00554 double SXYChart::getGridStep(SXYGridOrientation orientation) {
00555   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00556   assert(xygr);
00557   return xygr->step();
00558 }
00559 
00560 // .......................................................................
00561 
00562 void SXYChart::setTitleColor(long int col) {
00563    assert(xy_title);
00564    xy_title->color(col);
00565 }
00566 
00567 // .......................................................................
00568 
00569 void SXYChart::setSubTitleColor(long int col) {
00570    assert(xy_subtitle);
00571    xy_subtitle->color(col);
00572 }
00573 
00574 // .......................................................................
00575 
00576 void SXYChart::setGridVisibility(SXYGridOrientation orientation, 
00577 unsigned int flag) {
00578   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00579   assert(xygr);
00580   xygr->visible(flag ? xytrue : xyfalse);
00581 }
00582 
00583 // .......................................................................
00584 
00585 double SXYChart::getGridAutoMultipleStep(SXYGridOrientation orientation ) {
00586   double mst = orientation == HORIZONTAL_GRID ? xmulstep : ymulstep;
00587   return mst; 
00588 }
00589 
00590 // .......................................................................
00591 
00592 void SXYChart::setGridAutoMultipleStep(SXYGridOrientation orientation, 
00593 double mulstep ) {
00594   if (orientation == HORIZONTAL_GRID) xmulstep = mulstep;
00595   else ymulstep = mulstep;
00596 }
00597 
00598 // .......................................................................
00599 
00600 void SXYChart::setGridScales(SXYGridOrientation orientation, 
00601 double min, double max) {
00602   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00603   assert(xygr);
00604   xygr->min(min);
00605   xygr->max(max);
00606 }
00607 
00608 // .......................................................................
00609 
00610 void SXYChart::tryGridAdjust(void) {
00611   SXYAxis* xax = getAxis(HORIZONTAL_AXIS, 0);
00612   double xmin, xmax; 
00613   xax->getScales(xmin, xmax);
00614   double xstep = xax->getStep();
00615   setGridScales(HORIZONTAL_GRID, xmin, xmax);
00616   setGridStep(HORIZONTAL_GRID, xstep*xmulstep);
00617   setGridDirection(HORIZONTAL_GRID, (SXYGridDirection)xax->getDirection());
00618 
00619   SXYAxis* yax = getAxis(VERTICAL_AXIS, 0);
00620   double ymin, ymax; 
00621   yax->getScales(ymin, ymax);
00622   double ystep = yax->getStep();
00623   setGridScales(VERTICAL_GRID, ymin, ymax);
00624   setGridStep(VERTICAL_GRID, ystep*ymulstep);
00625   setGridDirection(VERTICAL_GRID, (SXYGridDirection)yax->getDirection());
00626 }
00627 
00628 // .......................................................................
00629 
00630 void SXYChart::setZoom(double xratio, double yratio) {
00631   unsigned int nxaxes = getNumAxes(HORIZONTAL_AXIS);
00632   for (unsigned int ix = 0; ix < nxaxes; ix++) {
00633     SXYAxis* xax = getAxis(HORIZONTAL_AXIS, ix);
00634     xax->setZoom(xratio);
00635   }
00636   unsigned int nyaxes = getNumAxes(VERTICAL_AXIS);
00637   for (unsigned int iy = 0; iy < nyaxes; iy++) {
00638     SXYAxis* yax = getAxis(VERTICAL_AXIS, iy);
00639     yax->setZoom(yratio);
00640   }
00641   tryGridAdjust();
00642 }
00643 
00644 // .......................................................................
00645 
00646 void SXYChart::setGridSize(SXYGridOrientation orientation, double size) {
00647   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00648   assert(xygr);
00649   xygr->size(size);
00650 }
00651 
00652 // .......................................................................
00653 
00654 void SXYChart::setGridStep(SXYGridOrientation orientation, double val) {
00655   XYGrid* xygr = orientation == HORIZONTAL_GRID ? xy_xgrid : xy_ygrid;
00656   assert(xygr);
00657   xygr->step(val);
00658 }
00659 
00660 // .......................................................................
00661 
00666 void SXYChart::fitScale(SXYAxisOrientation orientation) {
00667   unsigned int naxis = getNumAxes(orientation);
00668   for( unsigned int i = 0; i < naxis; i++ ) {
00669     double xmin = FLT_MAX, xmax = -FLT_MAX, ymin = FLT_MAX, ymax = -FLT_MAX;
00670     SXYAxis *axis = getAxis(orientation, i);
00671     unsigned int ncurves = getNumCurvesWithAxis(axis, orientation);
00672 
00673     /* Se não houver curvas, não é necessário mais testar nada. */
00674     if (ncurves == 0) continue;
00675 
00676     /* Loop sobre todas as curvas */
00677     for (unsigned int j = 0; j < ncurves; j++) {
00678       double xi, xa, yi, ya;
00679       SXYCurve *curve = getCurveFromAxis(j, axis, orientation);
00680       curve->getLimits(xi, xa, yi, ya);
00681       if (xi < xmin) xmin = xi;
00682       if (xa > xmax) xmax = xa;
00683       if (yi < ymin) ymin = yi;
00684       if (ya > ymax) ymax = ya;
00685     }
00686 
00687     /* Cálculos dos ajustes finais das escalas */
00688     //SXYUtil::calcMinMax(xmin, xmax, ymin, ymax);
00689     if (orientation == HORIZONTAL_AXIS) {
00690        if (axis->getType() == LINEAR_AXIS) SXYUtil::calcZoomOut(xmin, xmax);
00691        axis->setScales(xmin, xmax);
00692     }
00693     else {
00694        if (axis->getType() == LINEAR_AXIS) SXYUtil::calcZoomOut(ymin, ymax);
00695        axis->setScales(ymin, ymax);
00696     }
00697     axis->tryScalesAdjust();
00698     tryGridAdjust();
00699   }
00700 }
00701 
00702 // .......................................................................
00703 
00704 void SXYChart::setAllAxis(SXYAxisOrientation orientation, 
00705 double vmin, double vmax) {
00706   unsigned int naxis = getNumAxes(orientation);
00707   for( unsigned int i = 0; i < naxis; i++ ) {
00708     SXYAxis *axis = getAxis(orientation, i);
00709     axis->setScales(vmin, vmax);
00710     axis->tryScalesAdjust();
00711     tryGridAdjust();
00712   }
00713 }
00714 
00715 // .......................................................................
00716 
00717 SXYCurve* SXYChart::getCurveFromAxis(int n, SXYAxis *axis, 
00718 SXYAxisOrientation orientation) {
00719   int found = 0;
00720   for (unsigned int i = 0; i < getNumCurves(); i++) {
00721     SXYAxis *a = NULL;
00722     SXYCurve *curve = getCurve(i);
00723 
00724     if (orientation == HORIZONTAL_AXIS) a = curve->getHorizontalAxis();
00725     else a = curve->getVerticalAxis();
00726 
00727     if (a == axis) {
00728       if (found == n) return curve;
00729       else found++;
00730     }
00731   }
00732   return NULL;
00733 }
00734 
00735 // .......................................................................
00736 
00737 unsigned int SXYChart::getNumCurvesWithAxis(SXYAxis* axis, 
00738 SXYAxisOrientation orientation) {
00739   unsigned int ncurves = getNumCurves();
00740   int tot = 0;
00741   assert(axis);
00742 
00743   for (unsigned int c = 0; c < ncurves; c++) {
00744     SXYAxis *a = NULL;
00745     SXYCurve *curve = getCurve(c);
00746 
00747     if (orientation == HORIZONTAL_AXIS) a = curve->getHorizontalAxis();
00748     else a = curve->getVerticalAxis();
00749 
00750     if (a == axis) tot++;
00751   }
00752 
00753   return tot;
00754 }
00755 
00756 // .......................................................................
00757 
00758 void SXYChart::setLayoutFrom(SXYChart* other) {
00759    setTitle( other->getTitle() );
00760    setSubTitle( other->getSubTitle() );
00761    setTitleColor( other->getTitleColor() );
00762    setSubTitleColor( other->getSubTitleColor() );
00763                
00764    setBackgroundColor( other->getBackgroundColor() );
00765    setGridColor( other->getGridColor() );
00766    setMainColor( other->getMainColor() );
00767 
00768    double px, py;
00769    other->getLegendRelativePosition(px, py);
00770    setLegendRelativePosition(px, py);
00771 }
00772 
00773 
00774 // .......................................................................
00775 
00776 

SXY
Tecgraf / PUC-Rio - Computer Graphics Technology Group