using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace FusionCharts.WebParts
{
///
/// Represents an array of plots to graph
///
public class Plots
{
///
/// xValues stored in an array that contains string
///
private List _xArray = new List();
///
/// yValues stored in an array of arrays of doubles
/// _yArray[5][1] = 5th data point added, 2nd series
///
private List> _yArray = new List>();
///
/// Counts for yvalues - only used in group stats
/// yctValues stored in an array of arrays of doubles
/// _yctArray[5][1] = 5th data point added, 2nd series, #data elements
///
private List> _yctArray = new List>();
///
/// Number of y values per data point
/// which is the same thing as number of series being plotted
///
private int _nSeries;
///
/// Constructor
///
/// number of y values per data point
public Plots(int nseries)
{
_nSeries = nseries;
}
///
/// Adds a new plot
///
/// a string for xValue
/// array of yValues
public void Add(string x, List yvalues)
{
CheckPoint(x, yvalues, "Plots.Add");
_xArray.Add(x);
_yArray.Add(yvalues);
}
///
/// Adds a new plot
///
/// a string for xValue
/// array of yValues
/// array of counts of yValues
public void AddWithCounts(string x, List yvalues, List yctvalues)
{
CheckPoint(x, yvalues, "Plots.Add");
CheckPoint(x, yctvalues, "Plots.Add");
_xArray.Add(x);
_yArray.Add(yvalues);
_yctArray.Add(yctvalues);
}
private void CheckPoint(string x, List yvalues, string method)
{
if (yvalues.Count != _nSeries)
{
throw new Exception(string.Format(
"{0}: Wrong number data points ({1} should be {2}) for x value {3}"
, method
, yvalues.Count
, _nSeries
, IfNull(x, "")
));
}
}
private static string IfNull(string x, string defval)
{
return x == null ? defval : x;
}
///
/// Gets an x value based on its position in the array
///
///
///
public string GetX(int pos)
{
return _xArray[pos].ToString();
}
///
/// Gets an y value based on its position in the array
///
///
///
public List GetY(int pos)
{
string x = _xArray[pos];
List yvalues = _yArray[pos];
CheckPoint(x, yvalues, "Plots.GetY");
return yvalues;
}
///
/// Gets an yct value based on its position in the array
///
///
///
public List GetYct(int pos)
{
string x = _xArray[pos];
List yctvalues = _yctArray[pos];
CheckPoint(x, yctvalues, "Plots.GetYct");
return yctvalues;
}
///
/// Returns true of the x value exists. Returns false if not.
///
///
///
public bool Contains(string x)
{
return _xArray.Contains(x);
}
///
/// Gets the index (position) of a element x
///
///
/// -1 if the elements is not present in the array
public int XIndexOf(string x)
{
if (_xArray.Contains(x)) return _xArray.IndexOf(x);
return -1;
}
///
/// Returns the number of elements in the array
///
///
public int Count()
{
return _xArray.Count;
}
}
}