r557: no message
[ctsim.git] / libctgraphics / ezplot.cpp
index 260d5badbc68b295c84a7f4b7bbc169526614bf4..ed1ca233d26ef8e8c02e967e78717935a77b64bd 100644 (file)
@@ -4,9 +4,9 @@
 **    EZPLOT                                   
 **
 **  This is part of the CTSim program
-**  Copyright (C) 1983-2000 Kevin Rosenberg
+**  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: ezplot.cpp,v 1.27 2001/01/02 09:58:11 kevin Exp $
+**  $Id: ezplot.cpp,v 1.31 2001/02/20 04:48:45 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
@@ -36,14 +36,12 @@ static const int DEF_CURVE_CLR = C_RED;
 
 
 EZPlotCurve::EZPlotCurve (const double* xData, const double* yData, int n)
-: x(NULL), y(NULL)
+: x(new double[n]), y(new double[n])
 {
-  x = new double [n];
-  y = new double [n];
-  
-  int copyCount = n * sizeof(double);
-  memcpy (x, xData, copyCount);
-  memcpy (y, yData, copyCount);
+  for (int i = 0; i < n; i++) {
+    x[i] = xData[i];
+    y[i] = yData[i];
+  }
   
   m_iPointCount = n;
 }
@@ -94,7 +92,7 @@ EZPlot::addCurve (const float x[], const double y[], int num)
 }
 
 void
-EZPlot::addCurve (const double x[], const float y[], int num)
+EZPlot::addCurve (const double* const x, const float* const y, int num)
 {
   double* dy = new double [num];
   
@@ -108,7 +106,7 @@ EZPlot::addCurve (const double x[], const float y[], int num)
 
 
 void
-EZPlot::addCurve (const double x[], const double y[], int num)
+EZPlot::addCurve (const double* const x, const double* const y, int num)
 {
   if (num < 1)
     return;
@@ -723,18 +721,20 @@ EZPlot::plot (SGP* pSGP)
   if (o_yaxis == NOAXIS || o_ytlabel == FALSE)
     ytl_ofs = 0.0;
   else if (o_yticks == LEFT) {
-    double xExtent, yExtent;
+    double xExtentMin, xExtentMax, yExtent;
     char s[1024];
-    snprintf (s, sizeof(s), y_numfmt, 0);
-    m_pSGP->getTextExtent (s, &xExtent, &yExtent);
-    ytl_ofs = -2.0 * charwidth - xExtent;
+    snprintf (s, sizeof(s), y_numfmt, ymin);
+    m_pSGP->getTextExtent (s, &xExtentMin, &yExtent);
+    snprintf (s, sizeof(s), y_numfmt, ymax);
+    m_pSGP->getTextExtent (s, &xExtentMax, &yExtent);
+    if (xExtentMin > xExtentMax)
+      xExtentMax = xExtentMin;
+    ytl_ofs = -xExtentMax;
   } else if (o_yticks == RIGHT)
     ytl_ofs = 1.5 * charwidth;
   
   xa_max -= 0.7 * x_fldwid * charwidth; // make room for last x tick label
 
-
-
   xt_min = xa_min;
   yt_min = ya_min;
   xt_max = xa_max;
@@ -754,11 +754,11 @@ EZPlot::plot (SGP* pSGP)
   
   if (ytl_ofs != 0.0 && s_xcross == FALSE) {
     if (o_yticks == LEFT) {
-      xa_min += (2 + y_fldwid) * charwidth;
+      xa_min += 2*charwidth - ytl_ofs; // (2 + y_fldwid) * charwidth;
       xt_min = xa_min;
     } else if (o_yticks == RIGHT) {
       xa_min += 0.0;
-      xt_min = xa_min + ytl_ofs + y_fldwid * charwidth;
+      xt_min = xa_min + ytl_ofs; // + y_fldwid * charwidth;
     }
   } else
     xt_min = xa_min;
@@ -886,8 +886,7 @@ EZPlot::plot (SGP* pSGP)
           }
         }
     }
-  }
-  
+  }  
 }