void IGraphDrawing.DrawGraph(int graphId, List <int> samples, AdcSampleProfile profile) { var graph = new GraphPainter(visualSize).DrawGraph( samples, profile, ChooseColor(graphId), graphId); graphVisuals[graphId] = graph; RebuildChildren(); }
public DrawingVisual DrawGraph(List <int> samples, AdcSampleProfile profile, Color color, int graphId) { var drawingVisual = new DrawingVisual(); DrawingContext dc = drawingVisual.RenderOpen(); var graphBrush = new SolidColorBrush(color); var graphPen = new Pen(graphBrush, 2); string text = graphId.ToString(); var typeface = new Typeface("Arial"); double emSize = (graphH / 20); var ft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, emSize, graphBrush); dc.DrawText(ft, new Point(graphX + (ft.Width * graphId), graphY - ft.Height)); int numPoints = samples.Count(); if (numPoints > 1) { int profileH = (profile.MaxValue - profile.MinValue); double pointX = graphX; // number of line segments is number of points - 1 double pointStep = graphW / (numPoints - 1); var lastPoint = new Point(); foreach (var sample in samples) { double pointH = ((double)(sample - profile.MinValue) / profileH) * graphH; double pointY = graphY - pointH; var point = new Point(pointX, pointY); double pointRadius = graphPen.Thickness / 2; dc.DrawEllipse(graphBrush, graphPen, point, pointRadius, pointRadius); if (pointX > graphX) { dc.DrawLine(graphPen, lastPoint, point); } lastPoint = point; pointX += pointStep; } } dc.Close(); return(drawingVisual); }