Skip to content

Instantly share code, notes, and snippets.

@Buildstarted
Created August 12, 2011 22:19
Show Gist options
  • Save Buildstarted/1143127 to your computer and use it in GitHub Desktop.
Save Buildstarted/1143127 to your computer and use it in GitHub Desktop.
Data hold for graphing data
public namespace Graphing {
public class Graph<TX, TY> {
private readonly List<GraphData<TX, TY>> _data;
public Graph() {
_data = new List<GraphData<TX, TY>>();
}
public GraphData<TX, TY> this[int index] {
get { return _data[index]; }
}
public void Add(GraphData<TX, TY> graph ) {
this._data.Add(graph);
}
public void Add(Dictionary<TX, TY> dictionary ) {
this._data.Add(new GraphData<TX, TY>(dictionary));
}
public TX MaxX { get { return _data.Max(f => f.MaxX); } }
public TY MaxY { get { return _data.Max(f => f.MaxY); } }
public TX MinX { get { return _data.Min(f => f.MinX); } }
public TY MinY { get { return _data.Min(f => f.MinY); } }
}
public class GraphData<TX, TY> : IEnumerable<KeyValuePair<TX, TY>> {
private readonly Dictionary<TX, TY> _data;
public Color Color { get; set; }
public GraphType GraphType { get; set; }
public GraphData() {
_data = new Dictionary<TX, TY>();
}
public GraphData(Dictionary<TX, TY> dictionary) {
_data = dictionary;
}
public TY MaxY { get { return _data.Values.Max(); } }
public TY MinY { get { return _data.Values.Min(); } }
public TX MaxX { get { return _data.Keys.Max(); } }
public TX MinX { get { return _data.Keys.Min(); } }
public void Add(TX x, TY y) {
_data.Add(x, y);
}
public Dictionary<TX, TY> Data {
get { return _data; }
}
public IEnumerator<KeyValuePair<TX, TY>> GetEnumerator() {
return _data.AsEnumerable().GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return _data.AsEnumerable().GetEnumerator();
}
}
public enum GraphType {
Bar,
Line,
Pie
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment