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); } } } }