using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using Veldrid.Common.Plot; namespace Veldrid.Common.Legend { public class Legend : BaseVeldridRender { MutiText text; public Legend(VeldridContent control) : base(control) { text = new MutiText(control,true,true); } internal override void DisposeResources() { base.DisposeResources(); text?.DisposeResources(); } internal override void CreateResources() { base.CreateResources(); text.CreateResources(); text.FontSize = 14; } public SeriesInfo[] SeriesInfos = new SeriesInfo[0]; internal override void DrawData() { base.DrawData(); if (SeriesInfos == null || SeriesInfos.Length == 0 ) return; var count = SeriesInfos.Where(x => x.Visibily && x.Color.A > 0).ToArray(); if(text.TextInfos.Length!= count.Length) { text.TextInfos = Enumerable.Range(0, count.Length).Select(x => new TextInfo()).ToArray(); } for (int i = 0; i < count.Length; i++) { text.TextInfos[i].Text = "—— " + count[i].Name; text.TextInfos[i].Color = count[i].Color; text.TextInfos[i].Visibily = count[i].Visibily; text.TextInfos[i].VerticalAlignment = VerticalAlignment.Top; text.TextInfos[i].HorizontalAlignment = HorizontalAlignment.Right; text.TextInfos[i].Local = new PointF(Range.MaxX - 400, Range.MaxY - 300 - 500 * i); } text.Draw(); } } }