public AnalyticsView() { InitializeComponent(); returnGraph.DataContext = this; Mediator.Instance.PortfolioChanged += (s, e) => { HistoricalAnalyticSeries.Clear(); HistoricalPointSeries.Clear(); returnGraph.Children.Clear(); HistoricalAnalyticSeries = e.AnalyticList.ToList(); if (HistoricalAnalyticSeries.Count > 0) { DrawGraph(); } }; }
private void DrawGraph() { double wxmin = -5; double wxmax = 65; //Convert.ToDouble(HistoricalAnalyticSeries.Count()); double wymin = -30; //Convert.ToDouble(HistoricalAnalyticSeries.Min().CalculatedAnalytic) -5; double wymax = 30; //Convert.ToDouble(HistoricalAnalyticSeries.Max().CalculatedAnalytic) + 5; const double xstep = 5; const double ystep = 10; const double dmargin = 10; double dxmin = dmargin; double dxmax = returnGraph.Width - dmargin; double dymin = dmargin; double dymax = returnGraph.Height - dmargin; // Prepare the transformation matrices. PrepareTransformations( wxmin, wxmax, wymin, wymax, dxmin, dxmax, dymax, dymin); // Get the tic mark lengths. Point p0 = DtoW(new Point(0, 0)); Point p1 = DtoW(new Point(5, 5)); double xtic = p1.X - p0.X; double ytic = p1.Y - p0.Y; // Make the X axis. GeometryGroup xaxis_geom = new GeometryGroup(); p0 = new Point(wxmin, 0); p1 = new Point(wxmax, 0); xaxis_geom.Children.Add(new LineGeometry(WtoD(p0), WtoD(p1))); Path xaxis_path = new Path(); xaxis_path.StrokeThickness = 1; xaxis_path.Stroke = Brushes.Black; xaxis_path.Data = xaxis_geom; returnGraph.Children.Add(xaxis_path); // Make the Y axis. GeometryGroup yaxis_geom = new GeometryGroup(); p0 = new Point(0, wymin); p1 = new Point(0, wymax); xaxis_geom.Children.Add(new LineGeometry(WtoD(p0), WtoD(p1))); for (double y = -50; y <= wymax; y += ystep) { // Add the tic mark. Point tic0 = WtoD(new Point(-xtic, y)); Point tic1 = WtoD(new Point(xtic, y)); xaxis_geom.Children.Add(new LineGeometry(tic0, tic1)); // Label the tic mark's Y coordinate. DrawText(returnGraph, y.ToString(), new Point(tic0.X - 10, tic0.Y), 12, HorizontalAlignment.Center, VerticalAlignment.Center); } Path yaxis_path = new Path(); yaxis_path.StrokeThickness = 1; yaxis_path.Stroke = Brushes.Black; yaxis_path.Data = yaxis_geom; returnGraph.Children.Add(yaxis_path); //Build Graph for (int i = 0; i < HistoricalAnalyticSeries.Count(); i++) { Point p = new Point(i, Convert.ToDouble(HistoricalAnalyticSeries[i].CalculatedAnalytic)); HistoricalPointSeries.Add(WtoD(p)); } Polyline polyline = new Polyline(); polyline.StrokeThickness = 1; polyline.Stroke = Brushes.DarkOrange; polyline.Points = HistoricalPointSeries; returnGraph.Children.Add(polyline); }