aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/Components/YAxisLegends.cs
blob: d5f5b6d54cfb5e7ee0b537ab157c565dbed7a32a (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
using RealTimeGraphEx.Components.ComponentsItems;
using RealTimeGraphEx.FastGraphs;
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;
using System.Windows.Shapes;

namespace RealTimeGraphEx.Components
{
    public class YAxisLegends : ComponentBase
    {
        public DataTemplate LegendTemplate
        {
            get { return (DataTemplate)GetValue(LegendTemplateProperty); }
            set { SetValue(LegendTemplateProperty, value); }
        }
        public static readonly DependencyProperty LegendTemplateProperty =
            DependencyProperty.Register("LegendTemplate", typeof(DataTemplate), typeof(YAxisLegends), new PropertyMetadata(null));


        public YAxisLegends()
        {
            Location = ComponentLocationEnum.Right;
            Width = 30;
        }

        public override void Render(RealTimeGraphExBase graph, bool animate = false)
        {
            var multiGraph = graph as RealTimeGraphExMultiBase;

            if (multiGraph == null)
            {
                throw new InvalidCastException("The YAxisLegends component can only be used with multi series graphs.");
            }

            if (multiGraph.Controller == null) return;

            WrapPanel stack = new WrapPanel() { Orientation = Orientation.Vertical };
            this.Content = stack;

            for (int i = 0; i < multiGraph.Controller.DataSeriesCollection.Count; i++)
            {
                YAxisLegend legend = new YAxisLegend();

                legend.Content = multiGraph.Controller.DataSeriesCollection[i];

                if (LegendTemplate != null)
                {
                    legend.ContentTemplate = LegendTemplate;
                }

                stack.Children.Add(legend);
            }
        }
    }
}