r317: *** empty log message ***
[ctsim.git] / libctgraphics / ezplot.cpp
index 8c385e057cd6c73f46b4b4fd33e3d2852051b6d9..72f7e5149fbbfdbc9ff0ea53b4b5ed810db6e397 100644 (file)
@@ -6,7 +6,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ezplot.cpp,v 1.22 2000/12/25 21:54:26 kevin Exp $
+**  $Id: ezplot.cpp,v 1.25 2000/12/27 20:09:19 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
@@ -137,7 +137,22 @@ EZPlot::clearCurves ()
 EZPlot::EZPlot (SGP& sgp)
 : rSGP (sgp)
 {
-  initPlotSettings();
+    initKeywords();\r
+    m_pol.addSkipWord ("please");\r
+    m_pol.addSkipWord ("use");\r
+    m_pol.addSkipWord ("are");\r
+    m_pol.addSkipWord ("and");\r
+    m_pol.addSkipWord ("is");\r
+    m_pol.addSkipWord ("the");\r
+    m_pol.addSkipWord ("equals");\r
+    m_pol.addSkipChar ('=');\r
+    \r
+    m_pol.usefile (POL::P_USE_STR,"");\r
+    m_pol.set_inputline ("!eoc ,");\r
+    m_pol.reader ();\r
+    m_pol.closefile ();\r
+\r
+    initPlotSettings();
 }
 
 void
@@ -441,8 +456,8 @@ EZPlot::plot ()
   // adjust frame for title 
   title_row = ya_max;;\r
   if (c_title.length() > 0)
-    ya_max -= 2 * charheight;
-  
+    ya_max -= 2 * charheight;\r
+
   // calculate legend box boundaries 
   int max_leg = 0;                     // longest legend in characters 
   int num_leg = 0;                     // number of legend titles \r
@@ -521,12 +536,19 @@ EZPlot::plot ()
   
   // X-Label 
   if (c_xlabel.length() > 0)
-    ya_min += 2.0 * charheight;
+    ya_min += 1.5 * charheight;
   xlbl_row = xp_min;           // put x-label on bottom of plot frame 
   
   // Y-Label 
-  if (c_ylabel.length() > 0)
-    xa_min += 2.0 * charheight;        
+  if (c_ylabel.length() > 0) {\r
+    rSGP.setTextAngle (HALFPI);\r
+    rSGP.setTextSize (1.5 * charheight);\r
+    double xExtent, yExtent;\r
+    rSGP.getTextExtent (c_ylabel.c_str(), &xExtent, &yExtent);\r
+    rSGP.setTextSize (charheight);\r
+    xa_min += xExtent;\r
+    rSGP.setTextAngle (0.0);\r
+  }
   ylbl_col = xp_min;
   
   /*------------------------------*/
@@ -537,17 +559,19 @@ EZPlot::plot ()
   if (o_xaxis == NOAXIS || o_xtlabel == FALSE)
     xtl_ofs = 0.0;
   else if (o_xticks == BELOW)
-    xtl_ofs = -1.5 * charheight;
+    xtl_ofs = -0.5 * charheight;
   else if (o_xticks == ABOVE)
-    xtl_ofs = 1.5 * charheight;
+    xtl_ofs = 0.5 * charheight;
   
   if (o_yaxis == NOAXIS || o_ytlabel == FALSE)
     ytl_ofs = 0.0;
   else if (o_yticks == LEFT)
-    ytl_ofs = -(1 + y_fldwid) * charwidth;
+    ytl_ofs = -(2 + y_fldwid) * charwidth;
   else if (o_yticks == RIGHT)
     ytl_ofs = 1.5 * charwidth;
   
+  xa_max -= 0.7 * x_fldwid * charwidth; // make room for last x tick label\r
+\r
   xt_min = xa_min;
   yt_min = ya_min;
   xt_max = xa_max;
@@ -556,18 +580,18 @@ EZPlot::plot ()
   // see if need to shrink axis extents and/or tick extents 
   if (xtl_ofs != 0.0 && s_ycross == FALSE) {
     if (o_xticks == BELOW) {
-      ya_min += 2.5 * charheight;
+      ya_min += 1.5 * charheight;
       yt_min = ya_min;
     } else if (o_xticks == ABOVE) {
       ya_min += 0.0;
-      yt_min = ya_min + 2.5 * charheight;
+      yt_min = ya_min + 1.5 * charheight;
     }
   } else   // noaxis, no t-labels, or user set cross 
     yt_min = ya_min;
   
   if (ytl_ofs != 0.0 && s_xcross == FALSE) {
     if (o_yticks == LEFT) {
-      xa_min += (1 + y_fldwid) * charwidth;
+      xa_min += (2 + y_fldwid) * charwidth;
       xt_min = xa_min;
     } else if (o_yticks == RIGHT) {
       xa_min += 0.0;
@@ -575,7 +599,7 @@ EZPlot::plot ()
     }
   } else
     xt_min = xa_min;
-  
+
   // decrease size of graph, if necessary, to accommadate space 
   // between axis boundary and boundary of ticks 
   double x_added_ticks = 0; // number of tick spaces added to axis 
@@ -706,9 +730,9 @@ EZPlot::drawAxes()
   rSGP.setTextColor (1, -1);
   
   if (o_xticks == ABOVE)
-    xticklen = charheight;
+    xticklen = 0.5 * charheight;
   else if (o_xticks == BELOW)
-    xticklen = -charheight;
+    xticklen = -0.5 * charheight;
   
   if (o_yticks == RIGHT)
     yticklen = charwidth;
@@ -776,9 +800,11 @@ EZPlot::drawAxes()
         rSGP.lineAbs (xt_min + xn_tickinc * i, ya_min);
       }
     }
-    rSGP.moveAbs (xa_min + (xa_max-xa_min)/2 - c_xlabel.length()*charwidth * 1.5, xlbl_row +  charheight * 1.5);
     rSGP.setTextSize (charheight * 1.5);
-    rSGP.setTextColor (clr_label, -1);
+    rSGP.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);
     minorinc = xn_tickinc / (o_xminortick + 1);
@@ -842,19 +868,13 @@ EZPlot::drawAxes()
         rSGP.lineAbs (xa_min, y);
       }
     }\r
-#if 0\r
-    rSGP.moveAbs(.5,.5);\r
-    char s[128];\r
-    snprintf(s,sizeof(s),"%f, %f",charwidth, charheight);\r
-    rSGP.drawText(s);\r
-#endif\r
     rSGP.setTextAngle (HALFPI);
     rSGP.setTextSize (1.5 * charheight);
     rSGP.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);\r
-    rSGP.drawText (c_ylabel);
+    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);
     minorinc = yn_tickinc / (o_yminortick + 1);
@@ -881,8 +901,8 @@ EZPlot::drawAxes()
             axis_near = TRUE;
         }
         if (o_ytlabel == TRUE && axis_near == FALSE) {
-          snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i);
-          rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight);
+          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);
         }