[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows.Controls.Primitives;
|
---|
| 6 | using System.Windows.Controls;
|
---|
| 7 | using System.Windows;
|
---|
| 8 | using Microsoft.Research.DynamicDataDisplay.Charts;
|
---|
| 9 | using Microsoft.Research.DynamicDataDisplay.Common;
|
---|
| 10 |
|
---|
| 11 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
| 12 | {
|
---|
| 13 | public abstract class PlotterScrollBar : IPlotterElement
|
---|
| 14 | {
|
---|
| 15 | protected PlotterScrollBar()
|
---|
| 16 | {
|
---|
| 17 | scrollBar.Scroll += OnScroll;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | private void OnScroll(object sender, ScrollEventArgs e)
|
---|
| 21 | {
|
---|
| 22 | DataRect visible = plotter.Viewport.Visible;
|
---|
| 23 | visible = CreateVisibleRect(visible, scrollBar.Value);
|
---|
| 24 | plotter.Viewport.Visible = visible;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | private readonly ScrollBar scrollBar = new ScrollBar();
|
---|
| 28 | protected ScrollBar ScrollBar
|
---|
| 29 | {
|
---|
| 30 | get { return scrollBar; }
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | private Plotter2D plotter;
|
---|
| 34 | protected Plotter2D Plotter
|
---|
| 35 | {
|
---|
| 36 | get { return plotter; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | private void OnViewportPropertyChanged(object sender, ExtendedPropertyChangedEventArgs e)
|
---|
| 40 | {
|
---|
| 41 | if (e.PropertyName == "Visible" || e.PropertyName == "Output")
|
---|
| 42 | {
|
---|
| 43 | UpdateScrollBar((Viewport2D)sender);
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | #region IPlotterElement Members
|
---|
| 48 |
|
---|
| 49 | void IPlotterElement.OnPlotterAttached(Plotter plotter)
|
---|
| 50 | {
|
---|
| 51 | GetHostPanel(plotter).Children.Add(scrollBar);
|
---|
| 52 |
|
---|
| 53 | Plotter2D plotter2d = (Plotter2D)plotter;
|
---|
| 54 | this.plotter = plotter2d;
|
---|
| 55 | var viewport = plotter2d.Viewport;
|
---|
| 56 | viewport.PropertyChanged += OnViewportPropertyChanged;
|
---|
| 57 | viewport.DomainChanged += OnViewportDomainChanged;
|
---|
| 58 |
|
---|
| 59 | UpdateScrollBar(viewport);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | protected abstract void UpdateScrollBar(Viewport2D viewport);
|
---|
| 63 |
|
---|
| 64 | protected virtual void SetValue(Range<double> visibleRange, Range<double> domainRange)
|
---|
| 65 | {
|
---|
| 66 | scrollBar.Value = visibleRange.Min;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private void OnViewportDomainChanged(object sender, EventArgs e)
|
---|
| 70 | {
|
---|
| 71 | UpdateScrollBar((Viewport2D)sender);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | protected abstract DataRect CreateVisibleRect(DataRect rect, double value);
|
---|
| 75 | protected abstract Panel GetHostPanel(Plotter plotter);
|
---|
| 76 |
|
---|
| 77 | void IPlotterElement.OnPlotterDetaching(Plotter plotter)
|
---|
| 78 | {
|
---|
| 79 | this.plotter.Viewport.PropertyChanged -= OnViewportPropertyChanged;
|
---|
| 80 | this.plotter.Viewport.DomainChanged -= OnViewportDomainChanged;
|
---|
| 81 |
|
---|
| 82 | GetHostPanel(plotter).Children.Remove(scrollBar);
|
---|
| 83 |
|
---|
| 84 | UpdateScrollBar(null);
|
---|
| 85 |
|
---|
| 86 | this.plotter = null;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | Plotter IPlotterElement.Plotter
|
---|
| 90 | {
|
---|
| 91 | get { return plotter; }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | #endregion
|
---|
| 95 | }
|
---|
| 96 | }
|
---|