void Add(string s, PenSave ps) { PenValue pv = Transform(ps); save[s] = ps; pens[s] = pv; }
void AddNew(IDictionary <string, object> d, double time) { currentTime = time; exists.Clear(); List <string> l = new List <string>(pens.Keys); foreach (string s in l) { if (!d.ContainsKey(s)) { pens.Remove(s); } } foreach (string s in d.Keys) { exists.Add(s); if (!pens.ContainsKey(s)) { continue; } PenValue pv = pens[s]; object o = d[s]; Func <object, double> conv = converters[s]; Get(pv, conv(o)); } add = AddExist; }
void AddExist(IDictionary <string, object> d, double time) { if (interval > 0) { double a = ((time - currentTime) / interval); double b = ((double)wNew / (double)bmp.Width); if (a < b) { return; } } currentTime = time; Graphics g = Graphics.FromImage(bmpNew); Clear(g, bmpNew.Width, bmpNew.Height); foreach (string s in pens.Keys) { PenValue pv = pens[s]; if (pv.pen == null) { continue; } int x1 = pv.x; if (!converters.ContainsKey(s)) { continue; } Func <object, double> conv = converters[s]; int y = Get(pv, conv(d[s])); g.DrawLine(pv.pen, 0, x1, wNew, y); } DrawControl(); }
int Get(PenValue pv, double d) { double x = (pv.max - d) * pv.scale * invertedHeight; int y = (int)x; pv.x = y; return(y); }
PenValue Transform(PenSave ps) { PenValue pv = new PenValue(); pv.pen = new Pen(ps.color); pv.min = ps.min; pv.max = ps.max; pv.scale = 1 / (ps.max - ps.min); return(pv); }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="info">Serialization info</param> /// <param name="context">Streaming context</param> protected DictionaryPerformer(SerializationInfo info, StreamingContext context) { save = SerializationPerformer.GetObject <Dictionary <string, PenSave> >(info, "Pens"); foreach (string s in save.Keys) { PenSave ps = save[s]; PenValue pv = Transform(ps); pens[s] = pv; } init(); }
/// <summary> /// Sets series to active /// </summary> /// <param name="s">Series name</param> /// <param name="active">True if active and facle otherwise</param> void SetAcive(string s, bool active) { if (active & save.ContainsKey(s)) { return; } if (!active & !save.ContainsKey(s)) { return; } if (!active) { save.Remove(s); pens.Remove(s); return; } PenSave ps = new PenSave(); ps.color = Color.White; PenValue pv = Transform(ps); save[s] = ps; pens[s] = pv; }