00001
00002
00003 char *simple_graph_cpp = "$Id: sxy_graph_simple.cpp,v 1.8 2003/01/17 17:43:13 clinio Exp $";
00004
00005
00006
00007 extern "C" {
00008 #include <iup.h>
00009 #include <cd.h>
00010 #include <cdiup.h>
00011 }
00012
00013 #include "sxy_graph_simple.h"
00014 #include "sxy_graph.h"
00015 #include "sxy_chart.h"
00016 #include "sxy_curve.h"
00017 #include "sxy_axis.h"
00018
00019
00020
00021
00022
00025 SXYSimpleGraph::SXYSimpleGraph(Ihandle* iupcnv, SXYSimpleGraphType sgtype) :
00026 SXYGraph(iupcnv) {
00027 type = sgtype;
00028 }
00029
00030
00031
00032 void SXYSimpleGraph::remountGraph(void) {
00033 int nchts = getNumCharts();
00034 SXYVector<SXYCurve*> *transfered_curves = NULL;
00035 SXYChart* old_cht = NULL;
00036 SXYAxis* old_xax = NULL;
00037 SXYAxis* old_yax = NULL;
00038
00039 assert (nchts == 0 || nchts == 1);
00040 if (nchts == 1) {
00041 old_cht = getTheChart();
00042 assert(old_cht);
00043 assert(old_cht->getNumAxes(HORIZONTAL_AXIS) == 1);
00044 assert(old_cht->getNumAxes(VERTICAL_AXIS) == 1);
00045 old_xax = old_cht->getAxis(HORIZONTAL_AXIS, 0);
00046 old_yax = old_cht->getAxis(VERTICAL_AXIS, 0);
00047 assert (old_xax != NULL && old_yax != NULL);
00048
00049 int ntransf = old_cht->getNumCurves();
00050 if (ntransf > 0) {
00051 transfered_curves = new SXYVector<SXYCurve*>(ntransf, NULL);
00052 for (int c = 0; c < ntransf; c++)
00053 transfered_curves->insertElement(old_cht->getCurve(c));
00054 }
00055
00056 old_cht->removeAxis(HORIZONTAL_AXIS, old_xax);
00057 old_cht->removeAxis(VERTICAL_AXIS, old_yax);
00058 removeChart(old_cht);
00059 }
00060
00061 SXYChart* cht = new SXYChart(this, 0.0, 0.0, 1.0, 1.0);
00062 insertChart(cht);
00063
00064 SXYAxisType xaxtype, yaxtype;
00065 inferAxisType(&xaxtype, &yaxtype);
00066
00067 SXYAxis* xax = new SXYAxis(cht, HORIZONTAL_AXIS, xaxtype, 0.1, 0.1, 0.8);
00068 cht->insertAxis(HORIZONTAL_AXIS, xax);
00069
00070 SXYAxis* yax = new SXYAxis(cht, VERTICAL_AXIS, yaxtype, 0.1, 0.1, 0.8);
00071 cht->insertAxis(VERTICAL_AXIS, yax);
00072
00073 SXYGridType xgrtype, ygrtype;
00074 inferGridType(&xgrtype, &ygrtype);
00075 cht->setGridType(HORIZONTAL_GRID, xgrtype);
00076 cht->setGridType(VERTICAL_GRID, ygrtype);
00077 cht->tryGridAdjust();
00078
00079 if (nchts == 1) {
00080 int ntransf = transfered_curves->getLength();
00081 for (int c = 0; c < ntransf; c++)
00082 (transfered_curves->getElement(c))->setAxis(xax,yax);
00083 delete transfered_curves;
00084
00085 xax->setLayoutFrom(old_xax);
00086 yax->setLayoutFrom(old_yax);
00087 cht->setLayoutFrom(old_cht);
00088
00089 delete old_xax;
00090 delete old_yax;
00091 delete old_cht;
00092 }
00093 }
00094
00095
00096
00097 void SXYSimpleGraph::inferGridType(SXYGridType* xtype, SXYGridType* ytype) {
00098 *xtype = LINEAR_GRID;
00099 *ytype = LINEAR_GRID;
00100
00101 SXYAxis* xax = getHorizontalAxis();
00102 SXYAxis* yax = getVerticalAxis();
00103 assert(xax && yax);
00104
00105 if (xax->getType() == LOG_AXIS) *xtype = LOG_GRID;
00106 if (yax->getType() == LOG_AXIS) *ytype = LOG_GRID;
00107 }
00108
00109
00110
00111 void SXYSimpleGraph::inferAxisType(SXYAxisType* xtype, SXYAxisType* ytype) {
00112 SXYSimpleGraphType graph_type = getType();
00113
00114 *xtype = LINEAR_AXIS;
00115 if (graph_type == LOG_SIMPLE_GRAPH) {
00116 *xtype = LOG_AXIS;
00117 }
00118 else if (graph_type == TIME_LINEAR_SIMPLE_GRAPH ||
00119 graph_type == TIME_LOG_SIMPLE_GRAPH) {
00120 *xtype = TIME_AXIS;
00121 }
00122
00123 *ytype = LINEAR_AXIS;
00124 if (graph_type == LOG_SIMPLE_GRAPH ||
00125 graph_type == SEMILOG_SIMPLE_GRAPH ||
00126 graph_type == TIME_LOG_SIMPLE_GRAPH) {
00127 *ytype = LOG_AXIS;
00128 }
00129 }
00130
00131
00132
00134 SXYSimpleGraph::~SXYSimpleGraph() {
00135 assert (getNumCharts() == 1);
00136
00137 SXYChart* cht = getTheChart();
00138 assert(cht);
00139
00140 assert(cht->getNumAxes(HORIZONTAL_AXIS) == 1);
00141 assert(cht->getNumAxes(VERTICAL_AXIS) == 1);
00142
00143 SXYAxis* xax = getHorizontalAxis();
00144 SXYAxis* yax = getVerticalAxis();
00145 assert(xax && yax);
00146
00147 delete xax;
00148 delete yax;
00149 delete cht;
00150 }
00151
00152
00153
00154 void SXYSimpleGraph::getScales(double& xmin, double& xmax,
00155 double& ymin, double& ymax) {
00156 SXYAxis* xax = getHorizontalAxis();
00157 SXYAxis* yax = getVerticalAxis();
00158 assert(xax && yax);
00159 xax->getScales(xmin, xmax);
00160 yax->getScales(ymin, ymax);
00161 }
00162
00163
00164
00165 void SXYSimpleGraph::getAxesSteps(double& sx, double& sy) {
00166 SXYAxis* xax = getHorizontalAxis();
00167 SXYAxis* yax = getVerticalAxis();
00168 assert(xax && yax);
00169 sx = xax->getStep();
00170 sy = yax->getStep();
00171 }
00172
00173
00174
00175 void SXYSimpleGraph::setAxesSteps(double sx, double sy) {
00176 SXYAxis* xax = getHorizontalAxis();
00177 SXYAxis* yax = getVerticalAxis();
00178 assert(xax && yax);
00179 xax->setStep(sx);
00180 yax->setStep(sy);
00181 }
00182
00183
00184
00185 void SXYSimpleGraph::setScales(double xmin, double xmax,
00186 double ymin, double ymax) {
00187 SXYAxis* xax = getHorizontalAxis();
00188 SXYAxis* yax = getVerticalAxis();
00189 assert(xax && yax);
00190 xax->setScales(xmin, xmax);
00191 yax->setScales(ymin, ymax);
00192 SXYChart* cht = getTheChart();
00193 assert(cht);
00194 cht->tryGridAdjust();
00195 }
00196
00197
00198
00199 void SXYSimpleGraph::fitHorizontalScale(void) {
00200 fitScales(INDIVIDUAL_X);
00201 adaptGrid(getHorizontalAxis());
00202 }
00203
00204
00205
00206 void SXYSimpleGraph::fitVerticalScale(void) {
00207 fitScales(INDIVIDUAL_Y);
00208 adaptGrid(getVerticalAxis());
00209 }
00210
00211
00212
00213 void SXYSimpleGraph::fitAllScales(void) {
00214 fitScales(INDIVIDUAL_X);
00215 fitScales(INDIVIDUAL_Y);
00216 adaptGrid(getHorizontalAxis());
00217 adaptGrid(getVerticalAxis());
00218 }
00219
00220
00221
00222 void SXYSimpleGraph::getGridScales(double& xmin, double& xmax,
00223 double& ymin, double& ymax ) {
00224 SXYChart* cht = getTheChart();
00225 assert(cht);
00226 cht->getGridScales(HORIZONTAL_GRID, xmin, xmax);
00227 cht->getGridScales(VERTICAL_GRID, ymin, ymax);
00228 }
00229
00230
00231
00232 void SXYSimpleGraph::setGridScales(double xmin, double xmax,
00233 double ymin, double ymax) {
00234 SXYChart* cht = getTheChart();
00235 assert(cht);
00236 cht->setGridScales(HORIZONTAL_GRID, xmin, xmax);
00237 cht->setGridScales(VERTICAL_GRID, ymin, ymax);
00238 }
00239
00240
00241
00242 void SXYSimpleGraph::getGridsSteps(double& sx, double& sy) {
00243 SXYChart* cht = getTheChart();
00244 assert(cht);
00245 sx = cht->getGridStep(HORIZONTAL_GRID);
00246 sy = cht->getGridStep(VERTICAL_GRID);
00247 }
00248
00249
00250
00251 void SXYSimpleGraph::setGridsSteps(double sx, double sy) {
00252 SXYChart* cht = getTheChart();
00253 assert(cht);
00254 cht->setGridStep(HORIZONTAL_GRID, sx);
00255 cht->setGridStep(VERTICAL_GRID, sy);
00256 }
00257
00258
00259
00260 void SXYSimpleGraph::getGridsAutoMultipleSteps(double& smx, double& smy) {
00261 SXYChart* cht = getTheChart();
00262 assert(cht);
00263 smx = cht->getGridAutoMultipleStep(HORIZONTAL_GRID);
00264 smy = cht->getGridAutoMultipleStep(VERTICAL_GRID);
00265 }
00266
00267
00268
00269 void SXYSimpleGraph::setGridsAutoMultipleSteps(double smx, double smy) {
00270 SXYChart* cht = getTheChart();
00271 assert(cht);
00272 cht->setGridAutoMultipleStep(HORIZONTAL_GRID, smx);
00273 cht->setGridAutoMultipleStep(VERTICAL_GRID, smy);
00274 }
00275
00276
00277
00278 void SXYSimpleGraph::adaptGrid( SXYAxis* ax ) {
00279 SXYGridOrientation or = ax->getOrientation() == HORIZONTAL_AXIS ?
00280 HORIZONTAL_GRID : VERTICAL_GRID;
00281 double x, y;
00282 ax->getPosition(x, y);
00283 double mn, mx;
00284 ax->getScales(mn, mx);
00285
00286 SXYChart* cht = getTheChart();
00287 assert(cht);
00288 cht->setGridPosition(or, x, y);
00289 cht->setGridDirection(or, (SXYGridDirection) ax->getDirection() );
00290 cht->setGridScales(or, mn, mx);
00291 cht->setGridSize(or, ax->getSize());
00292 }
00293
00294
00295
00296 void SXYSimpleGraph::setHorizontalAxisDirection(SXYAxisDirection direction) {
00297 SXYAxis* ax = getHorizontalAxis();
00298 assert(ax);
00299 ax->setDirection(direction);
00300 adaptGrid(ax);
00301 }
00302
00303
00304
00305 void SXYSimpleGraph::setHorizontalAxisPosition(double xp, double yp) {
00306 SXYAxis* ax = getHorizontalAxis();
00307 assert(ax);
00308 ax->setPosition(xp, yp);
00309 adaptGrid(ax);
00310 }
00311
00312
00313
00314 void SXYSimpleGraph::setVerticalAxisPosition(double xp, double yp) {
00315 SXYAxis* ax = getVerticalAxis();
00316 assert(ax);
00317 ax->setPosition(xp, yp);
00318 adaptGrid(ax);
00319 }
00320
00321
00322
00323 void SXYSimpleGraph::setVerticalAxisDirection(SXYAxisDirection direction) {
00324 SXYAxis* ax = getVerticalAxis();
00325 assert(ax);
00326 ax->setDirection(direction);
00327 adaptGrid(ax);
00328 }
00329
00330
00331
00332 SXYAxisDirection SXYSimpleGraph::getHorizontalAxisDirection(void) {
00333 SXYAxis* ax = getHorizontalAxis();
00334 assert(ax);
00335 return ax->getDirection();
00336 }
00337
00338
00339
00340 SXYAxisDirection SXYSimpleGraph::getVerticalAxisDirection(void) {
00341 SXYAxis* ax = getVerticalAxis();
00342 assert(ax);
00343 return ax->getDirection();
00344 }
00345
00346
00347
00348 void SXYSimpleGraph::setTheTitle(char* title) {
00349 SXYChart* cht = getTheChart();
00350 assert(cht);
00351 cht->setTitle(title);
00352 }
00353
00354
00355
00356 char* SXYSimpleGraph::getTheTitle(void) {
00357 SXYChart* cht = getTheChart();
00358 assert(cht);
00359 return cht->getTitle();
00360 }
00361
00362
00363
00364 void SXYSimpleGraph::setTheSubTitle(char* title) {
00365 SXYChart* cht = getTheChart();
00366 assert(cht);
00367 cht->setSubTitle(title);
00368 }
00369
00370
00371
00372 char* SXYSimpleGraph::getTheSubTitle(void) {
00373 SXYChart* cht = getTheChart();
00374 assert(cht);
00375 return cht->getSubTitle();
00376 }
00377
00378
00379
00380
00381 void SXYSimpleGraph::setHorizontalAxisTitle(char* title) {
00382 SXYAxis* ax = getHorizontalAxis();
00383 assert(ax);
00384 ax->setTitle(title);
00385 }
00386
00387
00388
00389 void SXYSimpleGraph::setVerticalAxisTitle(char* title) {
00390 SXYAxis* ax = getVerticalAxis();
00391 assert(ax);
00392 ax->setTitle(title);
00393 }
00394
00395
00396
00397
00398 char* SXYSimpleGraph::getHorizontalAxisTitle(void) {
00399 SXYAxis* ax = getHorizontalAxis();
00400 assert(ax);
00401 return ax->getTitle();
00402 }
00403
00404
00405
00406 char* SXYSimpleGraph::getVerticalAxisTitle(void) {
00407 SXYAxis* ax = getVerticalAxis();
00408 assert(ax);
00409 return ax->getTitle();
00410 }
00411
00412
00413
00414 void SXYSimpleGraph::setType(SXYSimpleGraphType sgtype) {
00415 type = sgtype;
00416 remountGraph();
00417 }
00418
00419
00420
00421 SXYSimpleGraphType SXYSimpleGraph::getType(void) {
00422 return type;
00423 }
00424
00425
00426
00427 SXYChart* SXYSimpleGraph::getTheChart(void) {
00428 return getChart(0);
00429 }
00430
00431
00432
00433 SXYAxis* SXYSimpleGraph::getVerticalAxis(void) {
00434 SXYChart* cht = getTheChart();
00435 return cht->getAxis(VERTICAL_AXIS, 0);
00436 }
00437
00438
00439
00440 SXYAxis* SXYSimpleGraph::getHorizontalAxis(void) {
00441 SXYChart* cht = getTheChart();
00442 return cht->getAxis(HORIZONTAL_AXIS, 0);
00443 }
00444
00445
00446
00447 void SXYSimpleGraph::attachCurve(SXYCurve* curve) {
00448 SXYAxis* xax = getHorizontalAxis();
00449 SXYAxis* yax = getVerticalAxis();
00450 assert(xax && yax);
00451 curve->setAxis(xax, yax);
00452 }
00453
00454
00455
00456 void SXYSimpleGraph::detachCurve(SXYCurve* curve) {
00457 curve->unsetAxis();
00458 }
00459
00460
00461
00462 void SXYSimpleGraph::revertHorizontalAxis(void) {
00463 SXYAxis* ax = getHorizontalAxis();
00464 assert(ax);
00465 double x, y;
00466 ax->getPosition(x, y);
00467 ax->setPosition(1.0-x, y);
00468 SXYAxisDirection dir = ax->getDirection() == INVERTED_AXIS ?
00469 NORMAL_AXIS : INVERTED_AXIS;
00470 ax->setDirection(dir);
00471 }
00472
00473
00474
00475 void SXYSimpleGraph::revertVerticalAxis(void) {
00476 SXYAxis* ax = getVerticalAxis();
00477 assert(ax);
00478 double x, y;
00479 ax->getPosition(x, y);
00480 ax->setPosition(x, 1.0-y);
00481 SXYAxisDirection dir = ax->getDirection() == INVERTED_AXIS ?
00482 NORMAL_AXIS : INVERTED_AXIS;
00483 ax->setDirection(dir);
00484 }
00485
00486
00487
00488 void SXYSimpleGraph::setVerticalAxisSize(double size) {
00489 SXYAxis* ax = getVerticalAxis();
00490 assert(ax);
00491 ax->setSize(size);
00492 }
00493
00494
00495
00496 double SXYSimpleGraph::getVerticalAxisSize(void) {
00497 SXYAxis* ax = getVerticalAxis();
00498 assert(ax);
00499 return ax->getSize();
00500 }
00501
00502
00503
00504 void SXYSimpleGraph::setHorizontalAxisSize(double size) {
00505 SXYAxis* ax = getHorizontalAxis();
00506 assert(ax);
00507 ax->setSize(size);
00508 }
00509
00510
00511
00512 double SXYSimpleGraph::getHorizontalAxisSize(void) {
00513 SXYAxis* ax = getHorizontalAxis();
00514 assert(ax);
00515 return ax->getSize();
00516 }
00517
00518
00519
00520 void SXYSimpleGraph::setAxesLayout(SXYSimpleGraphLayout new_layout) {
00521 switch(new_layout) {
00522 case HALF_CROSS_LAYOUT: {
00523 setHorizontalAxisPosition(0.1,0.5);
00524 setVerticalAxisPosition(0.5,0.1);
00525 setHorizontalAxisDirection(NORMAL_AXIS);
00526 setVerticalAxisDirection(NORMAL_AXIS);
00527 setHorizontalAxisSize(0.8);
00528 setVerticalAxisSize(0.8);
00529 break;
00530 }
00531 case QUARTER_CROSS_LAYOUT: {
00532 setHorizontalAxisPosition(0.1,0.25);
00533 setVerticalAxisPosition(0.25,0.1);
00534 setHorizontalAxisDirection(NORMAL_AXIS);
00535 setVerticalAxisDirection(NORMAL_AXIS);
00536 setHorizontalAxisSize(0.8);
00537 setVerticalAxisSize(0.8);
00538 break;
00539 }
00540 case DEPTH_LAYOUT: {
00541 setHorizontalAxisPosition(0.1,0.9);
00542 setVerticalAxisPosition(0.1,0.9);
00543 setHorizontalAxisDirection(NORMAL_AXIS);
00544 setVerticalAxisDirection(INVERTED_AXIS);
00545 setHorizontalAxisSize(0.8);
00546 setVerticalAxisSize(0.8);
00547 break;
00548 }
00549 case TYPICAL_LAYOUT: {
00550 setHorizontalAxisPosition(0.1,0.1);
00551 setVerticalAxisPosition(0.1,0.1);
00552 setHorizontalAxisDirection(NORMAL_AXIS);
00553 setVerticalAxisDirection(NORMAL_AXIS);
00554 setHorizontalAxisSize(0.8);
00555 setVerticalAxisSize(0.8);
00556 break;
00557 }
00558 }
00559 }
00560
00561
00562