PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Isolines/AdditionalLinesRenderer.cs

#
C# | 87 lines | 69 code | 17 blank | 1 comment | 11 complexity | 4f6883a253cec65a67d21d6c29615a7a 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.Media;
  6. using System.Windows;
  7. using System.Windows.Data;
  8. using System.Diagnostics;
  9. namespace Microsoft.Research.DynamicDataDisplay.Charts.Isolines
  10. {
  11. public class AdditionalLinesRenderer : IsolineRenderer
  12. {
  13. protected override void CreateUIRepresentation()
  14. {
  15. InvalidateVisual();
  16. }
  17. protected override void OnPlotterAttached()
  18. {
  19. base.OnPlotterAttached();
  20. FrameworkElement parent = (FrameworkElement)Parent;
  21. var renderer = (FrameworkElement)parent.FindName("PART_IsolineRenderer");
  22. Binding contentBoundsBinding = new Binding { Path = new PropertyPath("(0)", Viewport2D.ContentBoundsProperty), Source = renderer };
  23. SetBinding(Viewport2D.ContentBoundsProperty, contentBoundsBinding);
  24. SetBinding(ViewportPanel.ViewportBoundsProperty, contentBoundsBinding);
  25. Plotter2D.Viewport.EndPanning += Viewport_EndPanning;
  26. Plotter2D.Viewport.PropertyChanged += Viewport_PropertyChanged;
  27. }
  28. void Viewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
  29. {
  30. if (e.PropertyName == "Visible")
  31. {
  32. if (Plotter2D.Viewport.PanningState == Viewport2DPanningState.NotPanning)
  33. InvalidateVisual();
  34. }
  35. }
  36. protected override void OnPlotterDetaching()
  37. {
  38. Plotter2D.Viewport.EndPanning -= Viewport_EndPanning;
  39. Plotter2D.Viewport.PropertyChanged -= Viewport_PropertyChanged;
  40. base.OnPlotterDetaching();
  41. }
  42. private void Viewport_EndPanning(object sender, EventArgs e)
  43. {
  44. InvalidateVisual();
  45. }
  46. protected override void OnRender(DrawingContext drawingContext)
  47. {
  48. if (Plotter2D == null) return;
  49. if (DataSource == null) return;
  50. var collection = (IsolineCollection)Parent.GetValue(IsolineCollectionProperty);
  51. if (collection == null) return;
  52. var bounds = ViewportPanel.GetViewportBounds(this);
  53. if (bounds.IsEmpty) return;
  54. var dc = drawingContext;
  55. var strokeThickness = StrokeThickness;
  56. var transform = Plotter2D.Transform.WithRects(bounds, new Rect(RenderSize));
  57. //dc.DrawRectangle(null, new Pen(Brushes.Green, 2), new Rect(RenderSize));
  58. var additionalLevels = GetAdditionalLevels(collection);
  59. IsolineBuilder.DataSource = DataSource;
  60. var additionalIsolineCollections = additionalLevels.Select(level =>
  61. {
  62. return IsolineBuilder.BuildIsoline(level);
  63. });
  64. foreach (var additionalCollection in additionalIsolineCollections)
  65. {
  66. RenderIsolineCollection(dc, strokeThickness, additionalCollection, transform);
  67. }
  68. }
  69. }
  70. }