124 lines
3.4 KiB
C#
124 lines
3.4 KiB
C#
using ChartAndGraph;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using WI;
|
|
using TMPro;
|
|
using static ChartAndGraph.GraphChartBase;
|
|
|
|
public class UI_GraphChart : UIBase, IPointerClickHandler
|
|
{
|
|
public GraphChart Graph;
|
|
//public UI_DateTime prf_dateTime;
|
|
//public RectTransform Content_DateTime;
|
|
|
|
public UI_GraphChartData chartDetailData;
|
|
private TextMeshProUGUI GraphName;
|
|
|
|
public string graphName;
|
|
|
|
public bool isMainChart;
|
|
public Action<string> onClickChart;
|
|
|
|
private List<float> graphChartData = new List<float>();
|
|
private List<string> graphDateTimeData = new List<string>();
|
|
|
|
private TextMeshProUGUI MinValue;
|
|
private TextMeshProUGUI MaxValue;
|
|
private TextMeshProUGUI AveValue;
|
|
|
|
private float min;
|
|
private float max;
|
|
private float ave;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
Graph = GetComponentInChildren<GraphChart>();
|
|
//prf_dateTime = Resources.Load<UI_DateTime>("Prefabs/UI/PRF_UI_DateTime");
|
|
chartDetailData = GetComponentInChildren<UI_GraphChartData>(true);
|
|
}
|
|
public void Update()
|
|
{
|
|
if (!isMainChart)
|
|
return;
|
|
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(chartDetailData.rectTransform, Input.mousePosition))
|
|
{
|
|
Debug.Log("¹þ¾î³²");
|
|
return;
|
|
}
|
|
|
|
|
|
chartDetailData.SetActive(false);
|
|
}
|
|
}
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
if (!isMainChart)
|
|
{
|
|
onClickChart?.Invoke(graphName);
|
|
}
|
|
}
|
|
|
|
public void OnClickItem(GraphEventArgs args)
|
|
{
|
|
chartDetailData.SetData(graphName, graphChartData[args.Index], graphDateTimeData[args.Index], args.Position);
|
|
}
|
|
|
|
//public void SetChartLabels(List<string> labels)
|
|
//{
|
|
// for (int i = 0; i < labels.Count; i++)
|
|
// {
|
|
// var date = Instantiate(prf_dateTime, Content_DateTime);
|
|
// date.SetDateTime(labels[i]);
|
|
// }
|
|
//}
|
|
public void SetChartData(string graphName, GraphChartData graphData)
|
|
{
|
|
this.graphName = graphName;
|
|
|
|
min = graphData.chartData.Min();
|
|
max = graphData.chartData.Max();
|
|
ave = graphData.chartData.Average();
|
|
|
|
AveValue.SetText(DecimalPointCalculate(ave));
|
|
|
|
graphChartData.Clear();
|
|
graphDateTimeData.Clear();
|
|
|
|
if (isMainChart)
|
|
{
|
|
MinValue.SetText(DecimalPointCalculate(min));
|
|
MaxValue.SetText(DecimalPointCalculate(max));
|
|
}
|
|
else
|
|
{
|
|
GraphName.SetText(this.graphName);
|
|
}
|
|
|
|
Graph.DataSource.VerticalViewSize = max * 2f;
|
|
Graph.DataSource.ClearCategory("WorkConditionsData");
|
|
Graph.DataSource.StartBatch();
|
|
|
|
for (int i = 0; i < graphData.chartData.Count; i++)
|
|
{
|
|
Graph.DataSource.AddPointToCategory("WorkConditionsData", i, graphData.chartData[i]);
|
|
graphChartData.Add(graphData.chartData[i]);
|
|
graphDateTimeData.Add(graphData.timeData[i]);
|
|
}
|
|
Graph.DataSource.EndBatch();
|
|
}
|
|
private string DecimalPointCalculate(float value)
|
|
{
|
|
var floatValue = Mathf.Round(value * 10f) / 10f;
|
|
|
|
return floatValue.ToString();
|
|
}
|
|
|
|
}
|