PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/Samples/Simple/DynamicPointAddSample/Window1.xaml.cs

#
C# | 71 lines | 54 code | 9 blank | 8 comment | 1 complexity | 4197e49c476fd97de85eb7f41ca558af 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.Windows.Threading;
  15. using System.Collections.ObjectModel;
  16. using Microsoft.Research.DynamicDataDisplay;
  17. using Microsoft.Research.DynamicDataDisplay.DataSources;
  18. namespace DynamicPointAddSample
  19. {
  20. /// <summary>
  21. /// Interaction logic for Window1.xaml
  22. /// </summary>
  23. public partial class Window1 : Window
  24. {
  25. public Window1()
  26. {
  27. InitializeComponent();
  28. Loaded += new RoutedEventHandler(Window1_Loaded);
  29. }
  30. private DispatcherTimer timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(4) };
  31. private ObservableCollection<Point> data = new ObservableCollection<Point>();
  32. private int x = 0;
  33. private Random rnd = new Random();
  34. private void Window1_Loaded(object sender, RoutedEventArgs e)
  35. {
  36. // initial collection content
  37. for (int i = 0; i < 10000; i++)
  38. {
  39. AddNextPoint();
  40. }
  41. // switching off approximate content bounds' comparison, as this can cause improper behavior.
  42. plotter.Viewport.UseApproximateContentBoundsComparison = false;
  43. // adding line chart to plotter
  44. var line = plotter.AddLineGraph(data.AsDataSource());
  45. // again switching off approximate content bounds' comparison - now in coercion method of Viewport2D.ContentBounds attached dependency property.
  46. Viewport2D.SetUsesApproximateContentBoundsComparison(line, false);
  47. // simulating data being received from external source on each timer tick
  48. timer.Tick += new EventHandler(timer_Tick);
  49. timer.Start();
  50. }
  51. void timer_Tick(object sender, EventArgs e)
  52. {
  53. AddNextPoint();
  54. plotter.FitToView();
  55. }
  56. private void AddNextPoint()
  57. {
  58. Point p = new Point { X = x++, Y = rnd.NextDouble() };
  59. data.Add(p);
  60. }
  61. }
  62. }