[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows.Controls;
|
---|
| 6 | using System.Windows;
|
---|
| 7 |
|
---|
| 8 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
| 9 | {
|
---|
| 10 | public abstract class InjectedPlotterBase : ChartPlotter, IPlotterElement
|
---|
| 11 | {
|
---|
| 12 | /// <summary>
|
---|
| 13 | /// Initializes a new instance of the <see cref="InjectedPlotterBase"/> class.
|
---|
| 14 | /// </summary>
|
---|
| 15 | public InjectedPlotterBase()
|
---|
| 16 | : base(PlotterLoadMode.Empty)
|
---|
| 17 | {
|
---|
| 18 | ViewportPanel = new Canvas();
|
---|
| 19 |
|
---|
| 20 | Viewport = new InjectedViewport2D(ViewportPanel, this) { CoerceVisibleFunc = CoerceVisible };
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | protected abstract DataRect CoerceVisible(DataRect newVisible, DataRect baseVisible);
|
---|
| 24 |
|
---|
| 25 | protected void CoerceVisible()
|
---|
| 26 | {
|
---|
| 27 | Viewport.CoerceValue(Viewport2D.VisibleProperty);
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | private void OuterViewport_PropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
|
---|
| 31 | {
|
---|
| 32 | OuterViewport_PropertyChanged(e);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | protected virtual void OuterViewport_PropertyChanged(ExtendedPropertyChangedEventArgs e)
|
---|
| 36 | {
|
---|
| 37 | CoerceVisible();
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | protected override void OnChildAdded(IPlotterElement child)
|
---|
| 41 | {
|
---|
| 42 | base.OnChildAdded(child);
|
---|
| 43 |
|
---|
| 44 | if (plotter != null && !plotter.Children.Contains(child))
|
---|
| 45 | {
|
---|
| 46 | plotter.PerformChildChecks = false;
|
---|
| 47 | plotter.Children.Add(child);
|
---|
| 48 | plotter.PerformChildChecks = true;
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void OnChildRemoving(IPlotterElement child)
|
---|
| 53 | {
|
---|
| 54 | base.OnChildRemoving(child);
|
---|
| 55 |
|
---|
| 56 | if (plotter != null && plotter.Children.Contains(child))
|
---|
| 57 | {
|
---|
| 58 | plotter.PerformChildChecks = false;
|
---|
| 59 | plotter.Children.Remove(child);
|
---|
| 60 | plotter.PerformChildChecks = true;
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | #region Properties
|
---|
| 65 |
|
---|
| 66 | #region ConjunctionMode property
|
---|
| 67 |
|
---|
| 68 | /// <summary>
|
---|
| 69 | /// Gets or sets the conjunction mode - the way of how inner plotter calculates its Visible rect in dependence of outer plotter's Visible.
|
---|
| 70 | /// This is a DependencyProperty.
|
---|
| 71 | /// </summary>
|
---|
| 72 | /// <value>The conjunction mode.</value>
|
---|
| 73 | public ViewportConjunctionMode ConjunctionMode
|
---|
| 74 | {
|
---|
| 75 | get { return (ViewportConjunctionMode)GetValue(ConjunctionModeProperty); }
|
---|
| 76 | set { SetValue(ConjunctionModeProperty, value); }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | public static readonly DependencyProperty ConjunctionModeProperty = DependencyProperty.Register(
|
---|
| 80 | "ConjunctionMode",
|
---|
| 81 | typeof(ViewportConjunctionMode),
|
---|
| 82 | typeof(InjectedPlotterBase),
|
---|
| 83 | new FrameworkPropertyMetadata(ViewportConjunctionMode.XY, OnConjunctionModeReplaced));
|
---|
| 84 |
|
---|
| 85 | private static void OnConjunctionModeReplaced(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
---|
| 86 | {
|
---|
| 87 | InjectedPlotterBase owner = (InjectedPlotterBase)d;
|
---|
| 88 | owner.OnConjunctionModeChanged();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | protected abstract void OnConjunctionModeChanged();
|
---|
| 92 |
|
---|
| 93 | #endregion
|
---|
| 94 | #endregion
|
---|
| 95 |
|
---|
| 96 | #region IPlotterElement methods
|
---|
| 97 |
|
---|
| 98 | public virtual void OnPlotterAttached(Plotter plotter)
|
---|
| 99 | {
|
---|
| 100 | this.plotter = (Plotter2D)plotter;
|
---|
| 101 | this.plotter.Viewport.PropertyChanged += OuterViewport_PropertyChanged;
|
---|
| 102 |
|
---|
| 103 | plotter.CentralGrid.Children.Add(ViewportPanel);
|
---|
| 104 |
|
---|
| 105 | HeaderPanel = plotter.HeaderPanel;
|
---|
| 106 | FooterPanel = plotter.FooterPanel;
|
---|
| 107 |
|
---|
| 108 | LeftPanel = plotter.LeftPanel;
|
---|
| 109 | BottomPanel = plotter.BottomPanel;
|
---|
| 110 | RightPanel = plotter.RightPanel;
|
---|
| 111 | TopPanel = plotter.BottomPanel;
|
---|
| 112 |
|
---|
| 113 | MainCanvas = plotter.MainCanvas;
|
---|
| 114 | CentralGrid = plotter.CentralGrid;
|
---|
| 115 | MainGrid = plotter.MainGrid;
|
---|
| 116 | ParallelCanvas = plotter.ParallelCanvas;
|
---|
| 117 |
|
---|
| 118 | OnLoaded();
|
---|
| 119 | ExecuteWaitingChildrenAdditions();
|
---|
| 120 | AddAllChildrenToParentPlotter();
|
---|
| 121 | CoerceVisible();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | private void AddAllChildrenToParentPlotter()
|
---|
| 125 | {
|
---|
| 126 | plotter.PerformChildChecks = false;
|
---|
| 127 | foreach (var child in Children)
|
---|
| 128 | {
|
---|
| 129 | if (plotter.Children.Contains(child))
|
---|
| 130 | continue;
|
---|
| 131 |
|
---|
| 132 | plotter.Children.Add(child);
|
---|
| 133 | }
|
---|
| 134 | plotter.PerformChildChecks = true;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 | protected override bool IsLoadedInternal
|
---|
| 138 | {
|
---|
| 139 | get
|
---|
| 140 | {
|
---|
| 141 | return plotter != null;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | public virtual void OnPlotterDetaching(Plotter plotter)
|
---|
| 146 | {
|
---|
| 147 | plotter.CentralGrid.Children.Remove(ViewportPanel);
|
---|
| 148 | this.plotter.Viewport.PropertyChanged -= OuterViewport_PropertyChanged;
|
---|
| 149 | RemoveAllChildrenFromParentPlotter();
|
---|
| 150 |
|
---|
| 151 | this.plotter = null;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | private void RemoveAllChildrenFromParentPlotter()
|
---|
| 155 | {
|
---|
| 156 | plotter.PerformChildChecks = false;
|
---|
| 157 | foreach (var child in Children)
|
---|
| 158 | {
|
---|
| 159 | plotter.Children.Remove(child);
|
---|
| 160 | }
|
---|
| 161 | plotter.PerformChildChecks = true;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | private Plotter2D plotter;
|
---|
| 165 | public Plotter2D Plotter
|
---|
| 166 | {
|
---|
| 167 | get { return plotter; }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | Plotter IPlotterElement.Plotter
|
---|
| 171 | {
|
---|
| 172 | get { return plotter; }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | #endregion
|
---|
| 176 |
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | }
|
---|