using System.Windows.Controls; using System.Windows.Markup; using System.Windows.Media; using System.Windows; using Microsoft.Research.DynamicDataDisplay.Charts; using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary; using System; namespace Microsoft.Research.DynamicDataDisplay { /// /// Represents a title of vertical axis. Can be placed from left or right of Plotter. /// public class VerticalAxisTitle : ContentControl, IPlotterElement { /// /// Initializes a new instance of the class. /// public VerticalAxisTitle() { ChangeLayoutTransform(); VerticalAlignment = VerticalAlignment.Center; FontSize = 16; } /// /// Initializes a new instance of the class. /// /// The content. public VerticalAxisTitle(object content) : this() { Content = content; } private void ChangeLayoutTransform() { if (placement == AxisPlacement.Left) LayoutTransform = new RotateTransform(-90); else LayoutTransform = new RotateTransform(90); } private Plotter plotter; public Plotter Plotter { get { return plotter; } } public void OnPlotterAttached(Plotter plotter) { this.plotter = plotter; var hostPanel = GetHostPanel(plotter); var index = GetInsertPosition(hostPanel); hostPanel.Children.Insert(index, this); } public void OnPlotterDetaching(Plotter plotter) { this.plotter = null; var hostPanel = GetHostPanel(plotter); hostPanel.Children.Remove(this); } private Panel GetHostPanel(Plotter plotter) { if (placement == AxisPlacement.Left) return plotter.LeftPanel; else return plotter.RightPanel; } private int GetInsertPosition(Panel panel) { if (panel == null) throw new ArgumentNullException("panel = null"); if (placement == AxisPlacement.Left) return 0; else return panel.Children.Count; } private AxisPlacement placement = AxisPlacement.Left; /// /// Gets or sets the placement of axis title. /// /// The placement. public AxisPlacement Placement { get { return placement; } set { if (value.IsBottomOrTop()) throw new ArgumentException(String.Format("VerticalAxisTitle only supports Left and Right values of AxisPlacement, you passed '{0}'", value), "Placement"); if (placement != value) { if (plotter != null) { var oldPanel = GetHostPanel(plotter); oldPanel.Children.Remove(this); } placement = value; ChangeLayoutTransform(); if (plotter != null) { var hostPanel = GetHostPanel(plotter); var index = GetInsertPosition(hostPanel); hostPanel.Children.Insert(index, this); } } } } } }