r318: *** empty log message ***
[ctsim.git] / libctgraphics / ezplot.cpp
index 72f7e5149fbbfdbc9ff0ea53b4b5ed810db6e397..e4537f01cd47d3e3861ef725e777811c68a74720 100644 (file)
@@ -6,7 +6,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ezplot.cpp,v 1.25 2000/12/27 20:09:19 kevin Exp $
+**  $Id: ezplot.cpp,v 1.26 2000/12/29 15:45:06 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -134,8 +134,7 @@ EZPlot::clearCurves ()
 }
 
 
-EZPlot::EZPlot (SGP& sgp)
-: rSGP (sgp)
+EZPlot::EZPlot ()
 {
     initKeywords();\r
     m_pol.addSkipWord ("please");\r
@@ -158,10 +157,8 @@ EZPlot::EZPlot (SGP& sgp)
 void
 EZPlot::initPlotSettings ()
 {
-  charheight = rSGP.getCharHeight();
-  charwidth = rSGP.getCharWidth();
-\r
   m_iCurrentCurve = -1;\r
+  m_pSGP = NULL;\r
 
   c_xlabel = "";
   c_ylabel =  "";
@@ -340,17 +337,19 @@ EZPlot::getLegend (unsigned int iCurve) const
 */
 
 void
-EZPlot::plot ()
+EZPlot::plot (SGP* pSGP)
 {\r
   if (m_vecCurves.size() <= 0)
     return;
-  
-  rSGP.setWindow (0., 0., 1., 1.);
+  \r
+  m_pSGP = pSGP;\r
+
+  m_pSGP->setWindow (0., 0., 1., 1.);
   
   if (s_textsize == TRUE)
-    rSGP.setTextPointSize (v_textsize);\r
-  charheight = rSGP.getCharHeight();
-  charwidth = rSGP.getCharWidth();
+    m_pSGP->setTextPointSize (v_textsize);\r
+  charheight = m_pSGP->getCharHeight();
+  charwidth = m_pSGP->getCharWidth();
  
   const EZPlotCurve& firstCurve = *m_vecCurves[0];\r
   double xmin = firstCurve.x[0];   // extent of curves in world coord
@@ -457,6 +456,8 @@ EZPlot::plot ()
   title_row = ya_max;;\r
   if (c_title.length() > 0)
     ya_max -= 2 * charheight;\r
+  else\r
+    ya_max -= 0.7 * charheight;  // allow room for yaxis ticklabel\r
 
   // calculate legend box boundaries 
   int max_leg = 0;                     // longest legend in characters 
@@ -493,8 +494,8 @@ EZPlot::plot ()
     
     yl_min = yl_max - leg_height;
     
-    rSGP.setColor (clr_legend);
-    rSGP.drawRect (xl_min, yl_min, xl_max, yl_max);
+    m_pSGP->setColor (clr_legend);
+    m_pSGP->drawRect (xl_min, yl_min, xl_max, yl_max);
     
     int iLegend = 0;                   // current legend position \r
     for (iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
@@ -506,21 +507,21 @@ EZPlot::plot ()
       double xmax = xl_max - 1.0 * charwidth;
       double y = yl_max - (2.0 + iLegend * 3) * charheight;
       
-      rSGP.moveAbs (xmin, y + 0.5 * charheight);\r
-      rSGP.drawText (pstrLegend->c_str());
-      rSGP.setColor (getColor (iCurve));\r
+      m_pSGP->moveAbs (xmin, y + 0.5 * charheight);\r
+      m_pSGP->drawText (pstrLegend->c_str());
+      m_pSGP->setColor (getColor (iCurve));\r
       int iLS = getLinestyle (iCurve);
       if (iLS != SGP::LS_NOLINE) {
-        rSGP.setLineStyle (iLS);
-        rSGP.moveAbs (xmin, y);
-        rSGP.lineAbs (xmax, y);
+        m_pSGP->setLineStyle (iLS);
+        m_pSGP->moveAbs (xmin, y);
+        m_pSGP->lineAbs (xmax, y);
       }\r
       int iSymbol = getSymbol (iCurve);
       if (iSymbol > 0) {
         double xinc = (xmax - xmin) / (5 - 1);
-        rSGP.setLineStyle (SGP::LS_SOLID);
+        m_pSGP->setLineStyle (SGP::LS_SOLID);
         for (int j = 0; j < 5; j++) {
-          rSGP.moveAbs (xmin + j * xinc, y);
+          m_pSGP->moveAbs (xmin + j * xinc, y);
           symbol(iSymbol, 0.5 * charwidth, 0.5 * charheight);
         }
       }
@@ -541,13 +542,13 @@ EZPlot::plot ()
   
   // Y-Label 
   if (c_ylabel.length() > 0) {\r
-    rSGP.setTextAngle (HALFPI);\r
-    rSGP.setTextSize (1.5 * charheight);\r
+    m_pSGP->setTextAngle (HALFPI);\r
+    m_pSGP->setTextSize (1.5 * charheight);\r
     double xExtent, yExtent;\r
-    rSGP.getTextExtent (c_ylabel.c_str(), &xExtent, &yExtent);\r
-    rSGP.setTextSize (charheight);\r
+    m_pSGP->getTextExtent (c_ylabel.c_str(), &xExtent, &yExtent);\r
+    m_pSGP->setTextSize (charheight);\r
     xa_min += xExtent;\r
-    rSGP.setTextAngle (0.0);\r
+    m_pSGP->setTextAngle (0.0);\r
   }
   ylbl_col = xp_min;
   
@@ -650,7 +651,7 @@ EZPlot::plot ()
   
   // PLOT CURVES 
   
-  rSGP.setLineStyle (SGP::LS_SOLID);
+  m_pSGP->setLineStyle (SGP::LS_SOLID);
   drawAxes();
   
   // size of symbol in NDC 
@@ -663,12 +664,12 @@ EZPlot::plot ()
   for (iCurve = 0; iCurve < m_vecCurves.size(); iCurve++) {
     const EZPlotCurve* const pCurve = m_vecCurves [iCurve];
     \r
-    rSGP.setColor (getColor (iCurve));\r
+    m_pSGP->setColor (getColor (iCurve));\r
     int iSym = getSymbol (iCurve);\r
     int iLS = getLinestyle (iCurve);\r
 \r
     if (iLS != SGP::LS_NOLINE) {
-      rSGP.setLineStyle (iLS);
+      m_pSGP->setLineStyle (iLS);
       double x1 = convertWorldToNDC_X (pCurve->x[0]);
       double y1 = convertWorldToNDC_Y (pCurve->y[0]);\r
       for (int i = 1; i < pCurve->m_iPointCount; i++) {
@@ -677,8 +678,8 @@ EZPlot::plot ()
         double x2Clip = x2;\r
         double y2Clip = y2;\r
         if (clip_rect (x1, y1, x2Clip, y2Clip, clipRect)) {\r
-          rSGP.moveAbs (x1, y1);\r
-          rSGP.lineAbs (x2Clip, y2Clip);\r
+          m_pSGP->moveAbs (x1, y1);\r
+          m_pSGP->lineAbs (x2Clip, y2Clip);\r
         }\r
         x1 = x2;\r
         y1 = y2;\r
@@ -686,17 +687,17 @@ EZPlot::plot ()
     }
     if (iSym > 0) {\r
       int iSymFreq = getSymbolFreq (iCurve);
-      rSGP.setLineStyle (SGP::LS_SOLID);
+      m_pSGP->setLineStyle (SGP::LS_SOLID);
       double x = convertWorldToNDC_X (pCurve->x[0]);
       double y = convertWorldToNDC_Y (pCurve->y[0]);
-      rSGP.moveAbs (x, y);
+      m_pSGP->moveAbs (x, y);
       symbol (iSym, symwidth, symheight);
       for (int i = 1; i < pCurve->m_iPointCount; i++)
         if (i % iSymFreq == 0 || i == pCurve->m_iPointCount - 1) {
           x = convertWorldToNDC_X (pCurve->x[i]);
           y = convertWorldToNDC_Y (pCurve->y[i]);\r
           if (y >= ygn_min && y <= ygn_max) {
-            rSGP.moveAbs (x, y);
+            m_pSGP->moveAbs (x, y);
             symbol (iSym, symwidth, symheight);\r
           }
         }
@@ -726,8 +727,8 @@ EZPlot::drawAxes()
   char str[256];
   char *numstr;
   
-  rSGP.setTextSize (charheight);
-  rSGP.setTextColor (1, -1);
+  m_pSGP->setTextSize (charheight);
+  m_pSGP->setTextColor (1, -1);
   
   if (o_xticks == ABOVE)
     xticklen = 0.5 * charheight;
@@ -741,21 +742,21 @@ EZPlot::drawAxes()
   
   if (c_title.length() > 0) {
     double wText, hText;
-    rSGP.setTextSize (charheight * 2.0);
-    rSGP.getTextExtent (c_title.c_str(), &wText, &hText);
-    rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - wText/2, title_row);
-    rSGP.setTextColor (clr_title, -1);
-    rSGP.drawText (c_title);
-    rSGP.setTextSize (charheight);
+    m_pSGP->setTextSize (charheight * 2.0);
+    m_pSGP->getTextExtent (c_title.c_str(), &wText, &hText);
+    m_pSGP->moveAbs (xa_min + (xa_max-xa_min)/2 - wText/2, title_row);
+    m_pSGP->setTextColor (clr_title, -1);
+    m_pSGP->drawText (c_title);
+    m_pSGP->setTextSize (charheight);
   }
   
   if (o_grid == TRUE || o_box == TRUE) {
-    rSGP.setColor (clr_axis);
-    rSGP.moveAbs (xa_min, ya_min);
-    rSGP.lineAbs (xa_max, ya_min);
-    rSGP.lineAbs (xa_max, ya_max);
-    rSGP.lineAbs (xa_min, ya_max);
-    rSGP.lineAbs (xa_min, ya_min);
+    m_pSGP->setColor (clr_axis);
+    m_pSGP->moveAbs (xa_min, ya_min);
+    m_pSGP->lineAbs (xa_max, ya_min);
+    m_pSGP->lineAbs (xa_max, ya_max);
+    m_pSGP->lineAbs (xa_min, ya_max);
+    m_pSGP->lineAbs (xa_min, ya_min);
   }
   
   // calculate position of axes 
@@ -781,44 +782,44 @@ EZPlot::drawAxes()
   if (o_xaxis == LINEAR) {
     // draw axis line 
     
-    rSGP.setColor (clr_axis);
+    m_pSGP->setColor (clr_axis);
     if (o_tag && !o_grid && !o_box && s_xcross) {
-      rSGP.moveAbs (xa_min, xaxispos - charheight);
-      rSGP.lineAbs (xa_min, xaxispos + charheight);
+      m_pSGP->moveAbs (xa_min, xaxispos - charheight);
+      m_pSGP->lineAbs (xa_min, xaxispos + charheight);
     }
-    rSGP.moveAbs (xa_min, xaxispos);
-    rSGP.lineAbs (xa_max, xaxispos);
+    m_pSGP->moveAbs (xa_min, xaxispos);
+    m_pSGP->lineAbs (xa_max, xaxispos);
     if (o_tag && !o_grid && !o_box) {
-      rSGP.moveAbs (xa_max, xaxispos - charheight);
-      rSGP.lineAbs (xa_max, xaxispos + charheight);
+      m_pSGP->moveAbs (xa_max, xaxispos - charheight);
+      m_pSGP->lineAbs (xa_max, xaxispos + charheight);
     }
     
     if (o_grid == TRUE) {
-      rSGP.setColor (clr_grid);
+      m_pSGP->setColor (clr_grid);
       for (i = 0; i <= x_nint; i++) {
-        rSGP.moveAbs (xt_min + xn_tickinc * i, ya_max);
-        rSGP.lineAbs (xt_min + xn_tickinc * i, ya_min);
+        m_pSGP->moveAbs (xt_min + xn_tickinc * i, ya_max);
+        m_pSGP->lineAbs (xt_min + xn_tickinc * i, ya_min);
       }
     }
-    rSGP.setTextSize (charheight * 1.5);
-    rSGP.setTextColor (clr_label, -1);\r
+    m_pSGP->setTextSize (charheight * 1.5);
+    m_pSGP->setTextColor (clr_label, -1);\r
     double wText, hText;\r
-    rSGP.getTextExtent (c_xlabel.c_str(), &wText, &hText);
-    rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - wText / 2, xlbl_row +  charheight * 1.5);\r
-    rSGP.drawText (c_xlabel);
-    rSGP.setTextSize (charheight);
+    m_pSGP->getTextExtent (c_xlabel.c_str(), &wText, &hText);
+    m_pSGP->moveAbs (xa_min + (xa_max-xa_min)/2 - wText / 2, xlbl_row +  charheight * 1.5);\r
+    m_pSGP->drawText (c_xlabel);
+    m_pSGP->setTextSize (charheight);
     minorinc = xn_tickinc / (o_xminortick + 1);
     
     for (i = 0; i <= x_nint; i++) {
       x = xt_min + xn_tickinc * i;
-      rSGP.setColor (clr_axis);
-      rSGP.moveAbs (x, xaxispos);
-      rSGP.lineAbs (x, xaxispos + xticklen);
+      m_pSGP->setColor (clr_axis);
+      m_pSGP->moveAbs (x, xaxispos);
+      m_pSGP->lineAbs (x, xaxispos + xticklen);
       if (i != x_nint)
         for (j = 1; j <= o_xminortick; j++) {
           x2 = x + minorinc * j;
-          rSGP.moveAbs (x2, xaxispos);
-          rSGP.lineAbs (x2, xaxispos + TICKRATIO * xticklen);
+          m_pSGP->moveAbs (x2, xaxispos);
+          m_pSGP->lineAbs (x2, xaxispos + TICKRATIO * xticklen);
         }
         axis_near = FALSE;
         if (xaxispos + xtl_ofs > ya_min && o_yaxis != NOAXIS) {
@@ -834,9 +835,9 @@ EZPlot::drawAxes()
         if (o_xtlabel == TRUE && axis_near == FALSE) {
           snprintf (str, sizeof(str), x_numfmt, xgw_min + xw_tickinc * i);
           numstr = str_skip_head (str, " ");
-          rSGP.moveAbs (x-strlen(numstr)*charwidth/2, xaxispos + xtl_ofs);
-          rSGP.setTextColor (clr_number, -1);
-          rSGP.drawText (numstr);
+          m_pSGP->moveAbs (x-strlen(numstr)*charwidth/2, xaxispos + xtl_ofs);
+          m_pSGP->setTextColor (clr_number, -1);
+          m_pSGP->drawText (numstr);
         }
     }
   }            // X - Axis 
@@ -848,47 +849,47 @@ EZPlot::drawAxes()
   
   if (o_yaxis == LINEAR) {
     
-    rSGP.setColor (clr_axis);
+    m_pSGP->setColor (clr_axis);
     if (o_tag && !o_grid && !o_box && s_ycross) {
-      rSGP.moveAbs (yaxispos - charwidth, ya_min);
-      rSGP.lineAbs (yaxispos + charwidth, ya_min);
+      m_pSGP->moveAbs (yaxispos - charwidth, ya_min);
+      m_pSGP->lineAbs (yaxispos + charwidth, ya_min);
     }
-    rSGP.moveAbs (yaxispos, ya_min);
-    rSGP.lineAbs (yaxispos, ya_max);
+    m_pSGP->moveAbs (yaxispos, ya_min);
+    m_pSGP->lineAbs (yaxispos, ya_max);
     if (o_tag && !o_grid && !o_box) {
-      rSGP.moveAbs (yaxispos - charwidth, ya_max);
-      rSGP.lineAbs (yaxispos + charwidth, ya_max);
+      m_pSGP->moveAbs (yaxispos - charwidth, ya_max);
+      m_pSGP->lineAbs (yaxispos + charwidth, ya_max);
     }
     
     if (o_grid == TRUE) {
-      rSGP.setColor (clr_grid);
+      m_pSGP->setColor (clr_grid);
       for (i = 0; i <= y_nint; i++) {
         y = yt_min + yn_tickinc * i;
-        rSGP.moveAbs (xa_max, y);
-        rSGP.lineAbs (xa_min, y);
+        m_pSGP->moveAbs (xa_max, y);
+        m_pSGP->lineAbs (xa_min, y);
       }
     }\r
-    rSGP.setTextAngle (HALFPI);
-    rSGP.setTextSize (1.5 * charheight);
-    rSGP.setTextColor (clr_label, -1);\r
+    m_pSGP->setTextAngle (HALFPI);
+    m_pSGP->setTextSize (1.5 * charheight);
+    m_pSGP->setTextColor (clr_label, -1);\r
     double xExtent, yExtent;\r
-    rSGP.getTextExtent (c_ylabel.c_str(), &xExtent, &yExtent);\r
-    rSGP.moveAbs (ylbl_col, ya_min + (ya_max-ya_min)/2 - yExtent / 2);\r
-    rSGP.drawText (c_ylabel);\r
-    rSGP.setTextAngle (0.0);
-    rSGP.setTextSize (charheight);
+    m_pSGP->getTextExtent (c_ylabel.c_str(), &xExtent, &yExtent);\r
+    m_pSGP->moveAbs (ylbl_col, ya_min + (ya_max-ya_min)/2 - yExtent / 2);\r
+    m_pSGP->drawText (c_ylabel);\r
+    m_pSGP->setTextAngle (0.0);
+    m_pSGP->setTextSize (charheight);
     minorinc = yn_tickinc / (o_yminortick + 1);
     
     for (i = 0; i <= y_nint; i++) {
       y = yt_min + yn_tickinc * i;
-      rSGP.setColor (clr_axis);
-      rSGP.moveAbs (yaxispos, y);
-      rSGP.lineAbs (yaxispos + yticklen, y);
+      m_pSGP->setColor (clr_axis);
+      m_pSGP->moveAbs (yaxispos, y);
+      m_pSGP->lineAbs (yaxispos + yticklen, y);
       if (i != y_nint)
         for (j = 1; j <= o_yminortick; j++) {
           y2 = y + minorinc * j;
-          rSGP.moveAbs (yaxispos, y2);
-          rSGP.lineAbs (yaxispos + TICKRATIO * yticklen, y2);
+          m_pSGP->moveAbs (yaxispos, y2);
+          m_pSGP->lineAbs (yaxispos + TICKRATIO * yticklen, y2);
         }
         axis_near = FALSE;
         if (yaxispos + ytl_ofs > xa_min && o_xaxis != NOAXIS) {
@@ -902,9 +903,9 @@ EZPlot::drawAxes()
         }
         if (o_ytlabel == TRUE && axis_near == FALSE) {
           snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i);\r
-          rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight);\r
-          rSGP.setTextColor (clr_number, -1);\r
-          rSGP.drawText (str);
+          m_pSGP->moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight);\r
+          m_pSGP->setTextColor (clr_number, -1);\r
+          m_pSGP->drawText (str);
         }
     }
   }            // Y - Axis
@@ -918,34 +919,34 @@ EZPlot::symbol (int sym, double symwidth, double symheight)
     return;
   
   if (sym == SB_CROSS) {
-    rSGP.moveRel (-0.5 * symwidth, -0.5 * symheight);
-    rSGP.lineRel (symwidth, symheight);
-    rSGP.moveRel (-symwidth, 0.0);
-    rSGP.lineRel (symwidth, -symheight);
-    rSGP.moveRel (-0.5 * symwidth, 0.5 * symheight);
+    m_pSGP->moveRel (-0.5 * symwidth, -0.5 * symheight);
+    m_pSGP->lineRel (symwidth, symheight);
+    m_pSGP->moveRel (-symwidth, 0.0);
+    m_pSGP->lineRel (symwidth, -symheight);
+    m_pSGP->moveRel (-0.5 * symwidth, 0.5 * symheight);
   } else if (sym == SB_PLUS) {
-    rSGP.moveRel (-0.5 * symwidth, 0.0);
-    rSGP.lineRel (symwidth, 0.0);
-    rSGP.moveRel (-0.5 * symwidth, -0.5 * symheight);
-    rSGP.lineRel (0.0, symheight);
-    rSGP.moveRel (0.0, -0.5 * symheight);
+    m_pSGP->moveRel (-0.5 * symwidth, 0.0);
+    m_pSGP->lineRel (symwidth, 0.0);
+    m_pSGP->moveRel (-0.5 * symwidth, -0.5 * symheight);
+    m_pSGP->lineRel (0.0, symheight);
+    m_pSGP->moveRel (0.0, -0.5 * symheight);
   } else if (sym == SB_BOX) {
-    rSGP.moveRel (-0.5 * symwidth, -0.5 * symheight);
-    rSGP.lineRel (symwidth, 0.0);
-    rSGP.lineRel (0.0, symheight);
-    rSGP.lineRel (-symwidth, 0.0);
-    rSGP.lineRel (0.0, -symheight);
-    rSGP.moveRel (0.5 * symwidth, 0.5 * symheight);
+    m_pSGP->moveRel (-0.5 * symwidth, -0.5 * symheight);
+    m_pSGP->lineRel (symwidth, 0.0);
+    m_pSGP->lineRel (0.0, symheight);
+    m_pSGP->lineRel (-symwidth, 0.0);
+    m_pSGP->lineRel (0.0, -symheight);
+    m_pSGP->moveRel (0.5 * symwidth, 0.5 * symheight);
   } else if (sym == SB_CIRCLE) {
-    rSGP.drawCircle (symwidth);
+    m_pSGP->drawCircle (symwidth);
   } else if (sym == SB_ERRORBAR) {
-    rSGP.moveRel (-0.5 * symwidth, 0.5 * symheight);
-    rSGP.lineRel (symwidth, 0.0);
-    rSGP.moveRel (-0.5 * symwidth, 0.0);
-    rSGP.lineRel (0.0, -symheight);
-    rSGP.moveRel (-0.5 * symwidth, 0.0);
-    rSGP.lineRel (symwidth, 0.0);
-    rSGP.moveRel (-0.5 * symwidth, 0.5 * symheight);
+    m_pSGP->moveRel (-0.5 * symwidth, 0.5 * symheight);
+    m_pSGP->lineRel (symwidth, 0.0);
+    m_pSGP->moveRel (-0.5 * symwidth, 0.0);
+    m_pSGP->lineRel (0.0, -symheight);
+    m_pSGP->moveRel (-0.5 * symwidth, 0.0);
+    m_pSGP->lineRel (symwidth, 0.0);
+    m_pSGP->moveRel (-0.5 * symwidth, 0.5 * symheight);
   }
 }