X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctgraphics%2Fezplot.cpp;h=5a2ec69a34a2700a309722310ee61cc19bfb4e0c;hp=965ef102ed7d32052b6b03f7d10c1da768bea019;hb=fd1d136a94a6d20013f38d6a997bdfefad0f5e98;hpb=43e126a48511a7e6c4081ebe774be265dabc59ec diff --git a/libctgraphics/ezplot.cpp b/libctgraphics/ezplot.cpp index 965ef10..5a2ec69 100644 --- a/libctgraphics/ezplot.cpp +++ b/libctgraphics/ezplot.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.cpp,v 1.15 2000/09/09 09:31:12 kevin Exp $ +** $Id: ezplot.cpp,v 1.20 2000/12/20 20:08:48 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 @@ -32,12 +32,10 @@ int snprintf (char *, size_t, const char*, ...); // Defaults static const double TICKRATIO = 0.4; // ratio of minor to major tick lengths static const int MAXNUMFMT = 15; // maximum length of a numeric format -static const double DEF_CHARHEIGHT = (1./43.); //size of characters in NDC -static const double DEF_CHARWIDTH = (1./80.); // size of characters in NDC static const int DEF_CURVE_CLR = C_RED; -EZPlotCurve::EZPlotCurve (const double* xData, const double* yData, int n, int color, int linestyle, int symbol, int symfreq, const string& legend) +EZPlotCurve::EZPlotCurve (const double* xData, const double* yData, int n, int color, int linestyle, int symbol, int symfreq, const std::string& legend) : x(NULL), y(NULL), m_sLegend (legend) { x = new double [n]; @@ -64,47 +62,52 @@ EZPlotCurve::~EZPlotCurve () void EZPlot::addCurve (const double *y, int n) { - double x [n]; + double* x = new double [n]; for (int i = 0; i < n; i++) x[i] = i; addCurve (x, y, n); + delete x; } void EZPlot::addCurve (const float *y, int n) { - double yDouble [n]; + double* yDouble = new double [n]; for (int i = 0; i < n; i++) yDouble[i] = y[i]; addCurve (yDouble, n); + delete yDouble; } void EZPlot::addCurve (const float x[], const double y[], int num) { - double dx [num]; + double* dx = new double [num]; for (int i = 0; i < num; i++) dx[i] = x[i]; addCurve (dx, y, num); + delete dx; } void EZPlot::addCurve (const double x[], const float y[], int num) { - double dy [num]; + double* dy = new double [num]; for (int i = 0; i < num; i++) dy[i] = y[i]; addCurve (x, dy, num); + + delete dy; } @@ -144,8 +147,8 @@ EZPlot::EZPlot (SGP& sgp) void EZPlot::initPlotSettings () { - charheight = DEF_CHARHEIGHT; - charwidth = DEF_CHARWIDTH; + charheight = rSGP.getCharHeight(); + charwidth = rSGP.getCharWidth(); c_xlabel = ""; c_ylabel = ""; @@ -338,12 +341,13 @@ EZPlot::plot () // calculate legend box boundaries int max_leg = 0; // longest legend in characters int num_leg = 0; // number of legend titles - for (EZPlotCurveConstIterator iterCurve = m_vecCurves.begin(); iterCurve != m_vecCurves.end(); iterCurve++) { - const EZPlotCurve& curve = **iterCurve; + for (EZPlotCurveConstIterator iterCurve2 = m_vecCurves.begin(); iterCurve2 != m_vecCurves.end(); iterCurve2++) { + const EZPlotCurve& curve = **iterCurve2; int nLegend = curve.m_sLegend.length(); if (nLegend > 0) { ++num_leg; - max_leg = max (max_leg, nLegend); + if (nLegend > max_leg) + nLegend = max_leg; } } @@ -521,8 +525,8 @@ EZPlot::plot () double symwidth = charwidth; double symheight = charheight; - for (EZPlotCurveIterator iterCurve = m_vecCurves.begin(); iterCurve != m_vecCurves.end(); iterCurve++) { - const EZPlotCurve& curve = **iterCurve; + for (EZPlotCurveIterator iterCurve3 = m_vecCurves.begin(); iterCurve3 != m_vecCurves.end(); iterCurve3++) { + const EZPlotCurve& curve = **iterCurve3; rSGP.setColor (curve.m_iColor); @@ -749,7 +753,7 @@ EZPlot::drawAxes() 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); - rSGP.setTextColor (clr_number, -1); + rSGP.setTextColor (clr_number, -1); rSGP.drawText (str); } } @@ -908,8 +912,10 @@ EZPlot::make_numfmt (char *fmtstr, int *fldwid, int *nfrac, double minval, doubl double delta = (maxval - minval) / nint; double absmin = fabs(minval); - double absmax = fabs(maxval); - double logt = log10( max(absmin, absmax) ); + double absmax = fabs(maxval); + if (absmin > absmax) + absmax = absmin; + double logt = log10( absmax ); if (fabs(logt) >= 6) { // use exponential format if (fabs(logt) > 99)