43 xVal (
double (_xVal)),
48 double XVal ()
const {
return xVal;}
49 double YVal ()
const {
return yVal;}
77 vector<PlotPoint> points;
105 return xVal < right.xVal;
134 points.push_back (PlotPoint (_xVal, _yVal));
151 maxPointsPlotedInASeries (0),
152 numOfDefaultColorsUsed (0),
174 for (
kkuint32 x = 0; x < series.size (); x++)
189 if ((_seriesIDX < 0) || (_seriesIDX >= series.size ()))
192 <<
"*** ERROR *** Chart::AddAValue" << std::endl
193 <<
" Invalid SeriesIDX[" << _seriesIDX <<
"]" << std::endl
194 <<
" Only [" << series.size () <<
"] series defined." << std::endl
199 series[_seriesIDX]->AddAValue (_xVal, _yVal);
201 if (series[_seriesIDX]->Size () > maxPointsPlotedInASeries)
202 maxPointsPlotedInASeries = series[_seriesIDX]->Size ();
205 if (_xVal < minXValue)
208 if (_xVal > maxXValue)
211 if (_yVal < minYValue)
214 if (_yVal > maxYValue)
247 series.push_back (
new Series (_name, defaultColors[numOfDefaultColorsUsed % numOfDefinedDefaultColors]));
248 numOfDefaultColorsUsed++;
257 series.push_back (
new Series (_name, _color));
267 xLabels.push_back (XLabel (_xVal, _name));
293 chartWidth = maxPointsPlotedInASeries * 10;
295 if (chartWidth > 1000)
298 chartHeight = chartWidth;
300 if (chartHeight > 500)
308 yRange = maxYValue - minYValue;
309 xRange = maxXValue - minXValue;
311 yScale = (
double)chartHeight / yRange;
312 xScale = (
double)chartWidth / xRange;
323 double sigTensPlace = floor (log10 (yRange));
325 sigTensPlace = pow (10.0, sigTensPlace);
327 yIncrement = floor (yRange / sigTensPlace) * sigTensPlace;
331 if (numOfYIncremets < 2)
333 yIncrement = yIncrement / 4.0;
335 else if (numOfYIncremets < 5)
337 yIncrement = yIncrement / 2.0;
339 else if (numOfYIncremets > 7)
341 yIncrement = yIncrement * 2.0;
343 else if (numOfYIncremets > 13)
345 yIncrement = yIncrement * 4.0;
348 yMin = floor (minYValue / yIncrement) * yIncrement;
349 yMax = ceil (maxYValue / yIncrement) * yIncrement;
351 yRange = yMax - yMin;
352 yScale = (
double)chartHeight / yRange;
356 kkint32 height = chartHeight + 2 * yOffset;
357 kkint32 width = chartWidth + 2 * xOffset;
359 RasterPtr chart =
new Raster (height
, width
, true);
363 chart
->DrawLine (yOffset
, xOffset
, yOffset + chartHeight
, xOffset
, axisColor
);
364 chart
->DrawLine (yOffset
, xOffset
, yOffset
, xOffset + chartWidth
, axisColor
);
371 double y = yMin + yIncrement;
384 if ((yMin < 0.0) && (yMax > 0.0))
396 if ((xMin < 0.0) && (xMax > 0.0))
411 for (
kkuint32 seriesIDX = 0; seriesIDX < series.size (); seriesIDX++)
415 if (s->points.size () == 0)
422 for (
kkuint32 plotIDX = 1; plotIDX < s->points.size (); plotIDX++)
429 RasterCoordinates (point)
, 456 for (
kkuint32 x = 0; x < xLabels.size (); x++)
458 if (xLabels[x].XVal () == xVal)
472 Series& s = *(series[seriesIDX]);
475 for (pIDX = 0; pIDX <= s.points.size (); pIDX++)
477 if (s.points[pIDX].XVal () == xVal)
478 return &s.points[pIDX];
489 ofstream o (_fileName.Str ());
493 <<
"*** ERROR *** Chart::Save, Error Opening file[" << _fileName <<
"]." << std::endl
501 for (
kkuint32 seriesIDX = 0; seriesIDX < series.size (); seriesIDX++)
504 for (
kkuint32 plotIDX = 0; plotIDX < s->points.size (); plotIDX++)
507 if (LookUpXLableIDX (p
.XVal ()) < 0)
511 # ifdef USE_SECURE_FUNCS
512 sprintf_s (buff,
sizeof (buff),
"%g", p.XVal ());
514 sprintf (buff,
"%g", p.XVal ());
517 xLabels.push_back (XLabel (p.XVal (), buff));
524 std::sort (xLabels.begin (), xLabels.end ());
529 o <<
"Title" <<
"\t" << title << std::endl;
530 o <<
"MinAndMaxXValues:" <<
"\t" << minXValue <<
"\t" << maxXValue << std::endl;
531 o <<
"MinAndMaxYValues:" <<
"\t" << minYValue <<
"\t" << maxYValue << std::endl;
533 o <<
"MaxPointsPlottedInASeries" <<
"\t" << maxPointsPlotedInASeries << std::endl;
544 o <<
"XLabel" <<
"\t" <<
"XValue";
547 o <<
"\t" << series[seriesIDX]->name;
557 for (x = 0; x < xLabels.size (); x++)
559 XLabel& xLabel = xLabels[x];
564 o << xLabel.Name () <<
"\t" << xVal;
PixelValue(const PixelValue &pixelValue)
void AddAValue(float _xVal, float _yVal)
void DrawLine(kkint32 bpRow, kkint32 bpCol, kkint32 epRow, kkint32 epCol, PixelValue pixelVal)
void DefineASeries(KKStr _name, PixelValue _color)
void DefineAXLabel(float _xVal, KKStr _name)
void Save(KKStr _fileName)
PlotPoint(kkint32 _xVal, kkint32 _yVal)
static PixelValue defaultColors[]
A class that is used by to represent a single image in memory.
unsigned __int32 kkuint32
void AddAValue(kkuint32 _seriesIDX, float _xVal, float _yVal)
void DefineASeries(KKStr _name)
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
void DrawDot(const Point &point, const PixelValue &color, kkint32 size)
Series(KKStr _name, PixelValue _color)
KKStr(const KKStr &str)
Copy Constructor.
PixelValue(uchar _r, uchar _g, uchar _b)
Constructs a 'PixelValue' instance using the provided values for the color components.
void SaveImage(const Raster &image, const KKStr &imageFileName)
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
XLabel(double _xVal, KKStr _name)
Raster(kkint32 _height, kkint32 _width, bool _color)
Constructs a blank image with given dimensions.
bool operator<(const XLabel &right) const
Point(kkint32 _row, kkint32 _col)
friend std::ostream & operator<<(std::ostream &os, const Matrix &matrix)
void DrawLine(const Point &beginPoint, const Point &endPoint, const PixelValue &pixelVal)
static const kkint32 numOfDefinedDefaultColors
vector< SeriesPtr > SeriesList
PlotPoint(double _xVal, double _yVal)
Used to Create chart's from defined series of data.
Used by the Raster Class to represent the contents of one pixel.
void SaveAsImage(KKStr _fileName)