// using System.Collections.Generic; // using TMPro; // using UnityEngine; // using UnityEngine.UI; // /// // /// 用于绘制BFI和血流指数折线图的组件 // /// // public class ChartComponent : MonoBehaviour // { // [Header("图表设置")] // public RectTransform chartArea; // public LineRenderer lineRenderer; // public TextMeshProUGUI valueLabel; // public TextMeshProUGUI titleLabel; // public Color lineColor = Color.green; // public float lineWidth = 2f; // [Header("数据设置")] // public int maxDataPoints = 50; // public float minValue = 0f; // public float maxValue = 100f; // public string unit = ""; // private List dataPoints = new List(); // private Vector3[] linePoints; // void Awake() // { // if (lineRenderer == null) // { // lineRenderer = GetComponent(); // if (lineRenderer == null) // { // var obj = new GameObject("LineRenderer"); // obj.transform.SetParent(transform); // lineRenderer = obj.AddComponent(); // } // } // // 设置LineRenderer属性 // lineRenderer.material = new Material(Shader.Find("Sprites/Default")); // // lineRenderer.color = lineColor; // lineRenderer.startWidth = lineWidth; // lineRenderer.endWidth = lineWidth; // lineRenderer.useWorldSpace = false; // lineRenderer.sortingOrder = 1; // linePoints = new Vector3[maxDataPoints]; // } // /// // /// 添加数据点 // /// // public void AddDataPoint(float value) // { // dataPoints.Add(value); // // 保持最大数据点数量 // if (dataPoints.Count > maxDataPoints) // { // dataPoints.RemoveAt(0); // } // UpdateChart(); // UpdateValueLabel(value); // } // /// // /// 更新图表显示 // /// // private void UpdateChart() // { // if (dataPoints.Count < 2) return; // var rect = chartArea.rect; // var width = rect.width; // var height = rect.height; // lineRenderer.positionCount = dataPoints.Count; // for (int i = 0; i < dataPoints.Count; i++) // { // float x = (float)i / (maxDataPoints - 1) * width - width / 2; // float y = Mathf.Lerp(-height / 2, height / 2, // Mathf.InverseLerp(minValue, maxValue, dataPoints[i])); // linePoints[i] = new Vector3(x, y, 0); // } // lineRenderer.SetPositions(linePoints); // } // /// // /// 更新数值标签 // /// // private void UpdateValueLabel(float value) // { // if (valueLabel != null) // { // valueLabel.text = value.ToString("F1") + unit; // } // } // /// // /// 设置图表标题 // /// // public void SetTitle(string title) // { // if (titleLabel != null) // { // titleLabel.text = title; // } // } // /// // /// 清空数据 // /// // public void ClearData() // { // dataPoints.Clear(); // lineRenderer.positionCount = 0; // } // }