Няма описание
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarkLineHelper.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. namespace XCharts.Runtime
  3. {
  4. internal static class MarkLineHelper
  5. {
  6. public static string GetFormatterContent(Serie serie, MarkLineData data)
  7. {
  8. var serieLabel = data.label;
  9. var numericFormatter = serieLabel.numericFormatter;
  10. if (string.IsNullOrEmpty(serieLabel.formatter))
  11. {
  12. var content = ChartCached.NumberToStr(data.runtimeValue, numericFormatter);
  13. return serieLabel.formatterFunction == null? content:
  14. serieLabel.formatterFunction(data.index, data.runtimeValue, null, content);
  15. }
  16. else
  17. {
  18. var content = serieLabel.formatter;
  19. FormatterHelper.ReplaceSerieLabelContent(ref content, numericFormatter, serie.dataCount, data.runtimeValue,
  20. 0, serie.serieName, data.name, data.name, Color.clear, null);
  21. return serieLabel.formatterFunction == null? content:
  22. serieLabel.formatterFunction(data.index, data.runtimeValue, null, content);
  23. }
  24. }
  25. public static Vector3 GetLabelPosition(MarkLineData data)
  26. {
  27. if (!data.label.show) return Vector3.zero;
  28. var dir = (data.runtimeEndPosition - data.runtimeStartPosition).normalized;
  29. var horizontal = Mathf.Abs(Vector3.Dot(dir, Vector3.right)) == 1;
  30. var labelWidth = data.runtimeLabel == null ? 50 : data.runtimeLabel.GetTextWidth();
  31. var labelHeight = data.runtimeLabel == null ? 20 : data.runtimeLabel.GetTextHeight();
  32. switch (data.label.position)
  33. {
  34. case LabelStyle.Position.Start:
  35. if (data.runtimeStartPosition == Vector3.zero) return Vector3.zero;
  36. if (horizontal) return data.runtimeStartPosition + data.label.offset + labelWidth / 2 * Vector3.left;
  37. else return data.runtimeStartPosition + data.label.offset + labelHeight / 2 * Vector3.down;
  38. case LabelStyle.Position.Middle:
  39. if (data.runtimeCurrentEndPosition == Vector3.zero) return Vector3.zero;
  40. var center = (data.runtimeStartPosition + data.runtimeCurrentEndPosition) / 2;
  41. if (horizontal) return center + data.label.offset + labelHeight / 2 * Vector3.up;
  42. else return center + data.label.offset + labelWidth / 2 * Vector3.right;
  43. default:
  44. if (data.runtimeCurrentEndPosition == Vector3.zero) return Vector3.zero;
  45. if (horizontal) return data.runtimeCurrentEndPosition + data.label.offset + labelWidth / 2 * Vector3.right;
  46. else return data.runtimeCurrentEndPosition + data.label.offset + labelHeight / 2 * Vector3.up;
  47. }
  48. }
  49. }
  50. }