1 | using System.Windows.Controls;
|
---|
2 | using System.Windows.Markup;
|
---|
3 | using System.Windows.Media;
|
---|
4 | using System.Windows;
|
---|
5 | using Microsoft.Research.DynamicDataDisplay.Charts;
|
---|
6 | using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
|
---|
7 | using System;
|
---|
8 |
|
---|
9 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
10 | {
|
---|
11 | /// <summary>
|
---|
12 | /// Represents a title of vertical axis. Can be placed from left or right of Plotter.
|
---|
13 | /// </summary>
|
---|
14 | public class VerticalAxisTitle : ContentControl, IPlotterElement
|
---|
15 | {
|
---|
16 | /// <summary>
|
---|
17 | /// Initializes a new instance of the <see cref="VerticalAxisTitle"/> class.
|
---|
18 | /// </summary>
|
---|
19 | public VerticalAxisTitle()
|
---|
20 | {
|
---|
21 | ChangeLayoutTransform();
|
---|
22 | VerticalAlignment = VerticalAlignment.Center;
|
---|
23 | FontSize = 16;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /// <summary>
|
---|
27 | /// Initializes a new instance of the <see cref="VerticalAxisTitle"/> class.
|
---|
28 | /// </summary>
|
---|
29 | /// <param name="content">The content.</param>
|
---|
30 | public VerticalAxisTitle(object content)
|
---|
31 | : this()
|
---|
32 | {
|
---|
33 | Content = content;
|
---|
34 | }
|
---|
35 |
|
---|
36 | private void ChangeLayoutTransform()
|
---|
37 | {
|
---|
38 | if (placement == AxisPlacement.Left)
|
---|
39 | LayoutTransform = new RotateTransform(-90);
|
---|
40 | else
|
---|
41 | LayoutTransform = new RotateTransform(90);
|
---|
42 | }
|
---|
43 |
|
---|
44 | private Plotter plotter;
|
---|
45 | public Plotter Plotter
|
---|
46 | {
|
---|
47 | get { return plotter; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void OnPlotterAttached(Plotter plotter)
|
---|
51 | {
|
---|
52 | this.plotter = plotter;
|
---|
53 |
|
---|
54 | var hostPanel = GetHostPanel(plotter);
|
---|
55 | var index = GetInsertPosition(hostPanel);
|
---|
56 |
|
---|
57 | hostPanel.Children.Insert(index, this);
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void OnPlotterDetaching(Plotter plotter)
|
---|
61 | {
|
---|
62 | this.plotter = null;
|
---|
63 |
|
---|
64 | var hostPanel = GetHostPanel(plotter);
|
---|
65 |
|
---|
66 | hostPanel.Children.Remove(this);
|
---|
67 | }
|
---|
68 |
|
---|
69 | private Panel GetHostPanel(Plotter plotter)
|
---|
70 | {
|
---|
71 | if (placement == AxisPlacement.Left)
|
---|
72 | return plotter.LeftPanel;
|
---|
73 | else
|
---|
74 | return plotter.RightPanel;
|
---|
75 | }
|
---|
76 |
|
---|
77 | private int GetInsertPosition(Panel panel)
|
---|
78 | {
|
---|
79 | if (panel == null)
|
---|
80 | throw new ArgumentNullException("panel = null");
|
---|
81 |
|
---|
82 | if (placement == AxisPlacement.Left)
|
---|
83 | return 0;
|
---|
84 | else
|
---|
85 | return panel.Children.Count;
|
---|
86 | }
|
---|
87 |
|
---|
88 | private AxisPlacement placement = AxisPlacement.Left;
|
---|
89 | /// <summary>
|
---|
90 | /// Gets or sets the placement of axis title.
|
---|
91 | /// </summary>
|
---|
92 | /// <value>The placement.</value>
|
---|
93 | public AxisPlacement Placement
|
---|
94 | {
|
---|
95 | get { return placement; }
|
---|
96 | set
|
---|
97 | {
|
---|
98 | if (value.IsBottomOrTop())
|
---|
99 | throw new ArgumentException(String.Format("VerticalAxisTitle only supports Left and Right values of AxisPlacement, you passed '{0}'", value), "Placement");
|
---|
100 |
|
---|
101 | if (placement != value)
|
---|
102 | {
|
---|
103 | if (plotter != null)
|
---|
104 | {
|
---|
105 | var oldPanel = GetHostPanel(plotter);
|
---|
106 | oldPanel.Children.Remove(this);
|
---|
107 | }
|
---|
108 |
|
---|
109 | placement = value;
|
---|
110 |
|
---|
111 | ChangeLayoutTransform();
|
---|
112 |
|
---|
113 | if (plotter != null)
|
---|
114 | {
|
---|
115 | var hostPanel = GetHostPanel(plotter);
|
---|
116 | var index = GetInsertPosition(hostPanel);
|
---|
117 | hostPanel.Children.Insert(index, this);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 | } |
---|