PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/Xbap/DynamicDataDisplay.Xbap.Samples/Demos/v04/Markers/StockMarkersPage.xaml.cs

#
C# | 97 lines | 73 code | 15 blank | 9 comment | 3 complexity | 37e79681cce9215e578f30e68f9cb98a MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Collections.ObjectModel;
  15. using Microsoft.Research.DynamicDataDisplay;
  16. namespace NewMarkersSample.Pages
  17. {
  18. /// <summary>
  19. /// Interaction logic for StockMarkersPage.xaml
  20. /// </summary>
  21. public partial class StockMarkersPage : Page
  22. {
  23. public StockMarkersPage()
  24. {
  25. InitializeComponent();
  26. }
  27. private readonly ObservableCollection<StockInfo> stockData = new ObservableCollection<StockInfo>();
  28. private Random rnd = new Random();
  29. private void Page_Loaded(object sender, RoutedEventArgs e)
  30. {
  31. // making both plotters' viewport connected
  32. plotter.Viewport.SetBinding(Viewport2D.VisibleProperty, new Binding("Visible") { Source = plotter2.Viewport, Mode = BindingMode.TwoWay });
  33. DateTime now = DateTime.Now;
  34. dateAxis.SetConversion(1000, now, 1010, now.AddDays(10));
  35. dateAxis2.SetConversion(1000, now, 1010, now.AddDays(10));
  36. // setting visible region in terms of <DateTime, double> rectangle, not usual <double, double> one.
  37. var genericPlotter = plotter.GetGenericPlotter<DateTime, double>();
  38. genericPlotter.ViewportRect = new GenericRect<DateTime, double>(DateTime.Now.AddDays(-2), -2.5, DateTime.Now.AddDays(60), 2.5);
  39. // initialialize stock data
  40. const int count = 35;
  41. for (int i = 0; i < count; i++)
  42. {
  43. stockData.Add(CreateNewStockInfo());
  44. }
  45. // this will make charts to display data,
  46. // as they are inside window, and their DataContext properties will change as Window's DataContext changes.
  47. // This happens because DataContextProperty inherits its value from parent in LogicalTree.
  48. DataContext = stockData;
  49. }
  50. private int daysCounter = 0;
  51. private StockInfo CreateNewStockInfo()
  52. {
  53. double open;
  54. if (stockData.Count == 0)
  55. {
  56. open = rnd.NextDouble();
  57. }
  58. else
  59. {
  60. open = stockData[stockData.Count - 1].Close;
  61. }
  62. double close = rnd.NextDouble();
  63. double low = Math.Min(open, close) - rnd.NextDouble();
  64. double high = Math.Max(open, close) + rnd.NextDouble();
  65. DateTime time = DateTime.Now.Date.AddDays(daysCounter++);
  66. StockInfo info = new StockInfo { Open = open, Close = close, High = high, Low = low, Time = time };
  67. return info;
  68. }
  69. private void addStockInfo_Click(object sender, RoutedEventArgs e)
  70. {
  71. stockData.Add(CreateNewStockInfo());
  72. }
  73. }
  74. public sealed class StockInfo
  75. {
  76. public double Open { get; set; }
  77. public double Close { get; set; }
  78. public double High { get; set; }
  79. public double Low { get; set; }
  80. public DateTime Time { get; set; }
  81. }
  82. }