125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using ChartAndGraph;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using WI;
|
|
using static ChartAndGraph.BarChart;
|
|
using TMPro;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class UI_BarChart : UIBase
|
|
{
|
|
private BarChart barChart;
|
|
private UI_StackBar prefab_stackBar;
|
|
private UI_DateTime prefab_DateTime;
|
|
private RectTransform StackBarParent;
|
|
private RectTransform DateTimeParent;
|
|
|
|
private Dictionary<UI_StackBar, Vector3> stackBarPos = new();
|
|
public List<BarChartData> barChartDatas = new List<BarChartData>();
|
|
public UI_BarChartData barChartData;
|
|
public Vector2 labelOffset;
|
|
public override void AfterAwake()
|
|
{
|
|
prefab_stackBar = Resources.Load<UI_StackBar>("Prefabs/UI/PRF_UI_StackBar");
|
|
prefab_DateTime = Resources.Load<UI_DateTime>("Prefabs/UI/PRF_UI_DateTime");
|
|
barChart = GetComponentInChildren<BarChart>();
|
|
barChartData = GetComponentInChildren<UI_BarChartData>(true);
|
|
}
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(barChartData.rectTransform, Input.mousePosition))
|
|
return;
|
|
|
|
barChartData.SetActive(false);
|
|
}
|
|
}
|
|
public void SetChartData(List<BarChartData> barChartData)
|
|
{
|
|
this.barChartDatas.Clear();
|
|
barChart.DataSource.ClearGroups();
|
|
barChart.DataSource.ClearValues();
|
|
|
|
barChart.DataSource.AutomaticMaxValue = true;
|
|
|
|
for (int i = 0; i < barChartData.Count; i++)
|
|
{
|
|
barChart.DataSource.AddGroup(i.ToString());
|
|
barChart.DataSource.SetValue("TargetCycleTime", i.ToString(), barChartData[i].targetCycleTime);
|
|
barChart.DataSource.SetValue("CycleTime", i.ToString(), barChartData[i].cycleTime);
|
|
}
|
|
|
|
this.barChartDatas.AddRange(barChartData);
|
|
//GUI ´Ù ±×·ÁÁö±â Àü±îÁö ´ë±â
|
|
barChart.OnRedraw.AddListener(SetStackChartData);
|
|
}
|
|
private void SetStackChartData()
|
|
{
|
|
SetStackBarData();
|
|
SetChartLabels();
|
|
barChart.OnRedraw.RemoveAllListeners();
|
|
}
|
|
private void SetStackBarData()
|
|
{
|
|
ClearStackBar();
|
|
stackBarPos.Clear();
|
|
|
|
for (int i = 0; i < barChartDatas.Count; i++)
|
|
{
|
|
var stackBar = Instantiate(prefab_stackBar, StackBarParent);
|
|
barChart.GetBarTrackPosition("CycleTime", i.ToString(), out var topPosition);
|
|
var bottomPosition = new Vector3(topPosition.x, rectTransform.rect.height / 2, 0);
|
|
|
|
stackBar.SetStackBar(barChartDatas[i], topPosition, bottomPosition);
|
|
stackBar.onClickStackBar += OnClickStackBar;
|
|
stackBarPos.Add(stackBar, bottomPosition);
|
|
}
|
|
}
|
|
private void SetChartLabels()
|
|
{
|
|
ClearChartLabels();
|
|
|
|
for (int i = 0; i < barChartDatas.Count; i++)
|
|
{
|
|
barChart.GetBarTrackPosition("CycleTime", i.ToString(), out var topPosition);
|
|
barChart.GetBarTrackPosition("TargetCycleTime", i.ToString(), out var topTargetCycleTimePosition);
|
|
var bottomPositionX = (topPosition.x + topTargetCycleTimePosition.x) / 2f;
|
|
var bottomPositionY = DateTimeParent.transform.position.y;
|
|
|
|
var dateTime = Instantiate(prefab_DateTime, DateTimeParent);
|
|
dateTime.transform.position = new Vector3(bottomPositionX, bottomPositionY, 0);
|
|
dateTime.SetDateTime(barChartDatas[i]._time);
|
|
}
|
|
}
|
|
private void ClearStackBar()
|
|
{
|
|
if (StackBarParent.childCount <= 0)
|
|
return;
|
|
|
|
for (int i = 0; i < StackBarParent.childCount; i++)
|
|
{
|
|
Destroy(StackBarParent.transform.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
private void ClearChartLabels()
|
|
{
|
|
if (DateTimeParent.childCount <= 0)
|
|
return;
|
|
|
|
for(int i = 0; i < DateTimeParent.childCount; i++)
|
|
{
|
|
Destroy(DateTimeParent.transform.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
private void OnClickStackBar(UI_StackBar stackBar)
|
|
{
|
|
var originPos = stackBar.rectTransform.anchoredPosition;
|
|
var stackBarRightPos = originPos + new Vector2(stackBar.rectTransform.rect.width / 2f, 0f);
|
|
|
|
barChartData.SetData(stackBar.barChartData, stackBarRightPos);
|
|
}
|
|
}
|