aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/Components/YAxisTicks.cs
blob: e340aac8a8e3e181819781184fa4ee0d5f6265ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using RealTimeGraphEx.Components.ComponentsItems;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace RealTimeGraphEx.Components
{
    public class YAxisTicks : ComponentBase
    {
        private Grid innerGrid;

        #region Constructors

        public YAxisTicks()
        {
            Width = 4;
            Location = ComponentLocationEnum.Left;
            this.SizeChanged += (x, y) => { Render(Graph); };
        }

        #endregion

        #region Properties

        public int SmallTicks
        {
            get { return (int)GetValue(SmallTicksProperty); }
            set { SetValue(SmallTicksProperty, value); }
        }
        public static readonly DependencyProperty SmallTicksProperty =
            DependencyProperty.Register("SmallTicks", typeof(int), typeof(YAxisTicks), new PropertyMetadata(20));

        public int BigTicks
        {
            get { return (int)GetValue(BigTicksProperty); }
            set { SetValue(BigTicksProperty, value); }
        }
        public static readonly DependencyProperty BigTicksProperty =
            DependencyProperty.Register("BigTicks", typeof(int), typeof(YAxisTicks), new PropertyMetadata(2));

        public DataTemplate SmallTickTemplate
        {
            get 
n>); } set { SetValue(SmallTickTemplateProperty, value); } } public static readonly DependencyProperty SmallTickTemplateProperty = DependencyProperty.Register("SmallTickTemplate", typeof(DataTemplate), typeof(YAxisTicks), new PropertyMetadata(null)); public DataTemplate BigTickTemplate { get { return (DataTemplate)GetValue(BigTickTemplateProperty); } set { SetValue(BigTickTemplateProperty, value); } } public static readonly DependencyProperty BigTickTemplateProperty = DependencyProperty.Register("BigTickTemplate", typeof(DataTemplate), typeof(YAxisTicks), new PropertyMetadata(null)); #endregion public override void Render(RealTimeGraphExBase graph, bool animate = false) { if (graph == null) return; if (SmallTicks < 2) return; if (innerGrid == null) { innerGrid = new Grid(); } double animationTime = animate ? 0.2 : 0; Grid grid = innerGrid; DoubleAnimation heightAnimation = new DoubleAnimation() { Duration = new Duration(TimeSpan.FromSeconds(animationTime)) }; heightAnimation.To = double.IsNaN(Graph.gridLinesAndImageWrapperGrid.Height) ? Graph.gridLinesAndImageWrapperGrid.ActualHeight : Graph.gridLinesAndImageWrapperGrid.Height; if (!double.IsNaN(grid.Height)) { grid.BeginAnimation(Grid.HeightProperty, heightAnimation); } else { grid.Height = Graph.gridLinesAndImageWrapperGrid.ActualHeight; } grid.VerticalAlignment = System.Windows.VerticalAlignment.Top; ThicknessAnimation marginAni = new ThicknessAnimation() { Duration = new Duration(TimeSpan.FromSeconds(animationTime)) }; marginAni.To = new Thickness(0, Graph.gridLinesAndImageWrapperGrid.Margin.Top, 0, 0); if (!double.IsNaN(grid.Height)) { grid.BeginAnimation(MarginProperty, marginAni); } else { grid.Margin = new Thickness(0, Graph.gridLinesAndImageWrapperGrid.Margin.Top, 0, 0); } double height = double.IsNaN(Graph.gridLinesAndImageWrapperGrid.Height) ? Graph.gridLinesAndImageWrapperGrid.ActualHeight : Graph.gridLinesAndImageWrapperGrid.Height; int smallTicks = (int)Math.Round((SmallTicks * (((height * 100) / Graph.gridMain.ActualHeight) / 100)), MidpointRounding.ToEven); this.Content = grid; this.ClipToBounds = true; grid.RowDefinitions.Clear(); grid.Children.Clear(); int bigTickCounter = BigTicks; for (int i = 0; i < smallTicks; i++) { RowDefinition rowTick = new RowDefinition(); rowTick.Height = new GridLength(1, GridUnitType.Star); grid.RowDefinitions.Add(rowTick); if (i == bigTickCounter) { YAxisBigTick bigTick = new YAxisBigTick(); bigTick.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; bigTick.VerticalAlignment = System.Windows.VerticalAlignment.Top; if (BigTickTemplate != null) { bigTick.ContentTemplate = BigTickTemplate; } bigTickCounter += BigTicks; grid.Children.Add(bigTick); Grid.SetRow(bigTick, i); } else { YAxisSmallTick smallTick = new YAxisSmallTick(); smallTick.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; smallTick.VerticalAlignment = System.Windows.VerticalAlignment.Top; if (SmallTickTemplate != null) { smallTick.ContentTemplate = SmallTickTemplate; } grid.Children.Add(smallTick); Grid.SetRow(smallTick, i); } } //Add last tick YAxisSmallTick lastTick = new YAxisSmallTick(); lastTick.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; lastTick.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; if (SmallTickTemplate != null) { lastTick.ContentTemplate = SmallTickTemplate; } grid.Children.Add(lastTick); Grid.SetRow(lastTick, smallTicks - 1); } protected override void OnGraphZoomComplete(Point transformOrigin, double scaleX, double scaleY) { Render(Graph, true); } protected override void OnGraphPanningComplete(Point translate) { if (innerGrid != null) { var renderBounds = Graph.GetGraphRenderBounds(); innerGrid.BeginAnimation(MarginProperty, null); innerGrid.Margin = new Thickness(0, Graph.gridLinesAndImageWrapperGrid.Margin.Top, 0, 0); } } } }