Legend.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using Veldrid.Common.Plot;
  8. namespace Veldrid.Common.Legend
  9. {
  10. public class Legend : BaseVeldridRender
  11. {
  12. MutiText text;
  13. public Legend(VeldridContent control) : base(control)
  14. {
  15. text = new MutiText(control,true,true);
  16. }
  17. internal override void DisposeResources()
  18. {
  19. base.DisposeResources();
  20. text?.DisposeResources();
  21. }
  22. internal override void CreateResources()
  23. {
  24. base.CreateResources();
  25. text.CreateResources();
  26. text.FontSize = 14;
  27. }
  28. public SeriesInfo[] SeriesInfos = new SeriesInfo[0];
  29. internal override void DrawData()
  30. {
  31. base.DrawData();
  32. if (SeriesInfos == null
  33. || SeriesInfos.Length == 0 ) return;
  34. var count = SeriesInfos.Where(x => x.Visibily && x.Color.A > 0).ToArray();
  35. if(text.TextInfos.Length!= count.Length)
  36. {
  37. text.TextInfos = Enumerable.Range(0, count.Length).Select(x => new TextInfo()).ToArray();
  38. }
  39. for (int i = 0; i < count.Length; i++)
  40. {
  41. text.TextInfos[i].Text = "—— " + count[i].Name;
  42. text.TextInfos[i].Color = count[i].Color;
  43. text.TextInfos[i].Visibily = count[i].Visibily;
  44. text.TextInfos[i].VerticalAlignment = VerticalAlignment.Top;
  45. text.TextInfos[i].HorizontalAlignment = HorizontalAlignment.Right;
  46. text.TextInfos[i].Local = new PointF(Range.MaxX - 400, Range.MaxY - 300 - 500 * i);
  47. }
  48. text.Draw();
  49. }
  50. }
  51. }