65 lines
2.1 KiB
C#
65 lines
2.1 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 stackBar;
|
|
|
|
public List<BarChartData> barChartDatas = new List<BarChartData>();
|
|
public UI_BarChartData barChartData;
|
|
private bool isClickChart;
|
|
public override void AfterAwake()
|
|
{
|
|
barChart = GetComponentInChildren<BarChart>();
|
|
stackBar = GetComponentInChildren<UI_StackBar>(true);
|
|
barChartData = GetComponentInChildren<UI_BarChartData>(true);
|
|
}
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(barChartData.rectTransform, Input.mousePosition))
|
|
return;
|
|
|
|
if (RectTransformUtility.RectangleContainsScreenPoint(stackBar.rectTransform, Input.mousePosition))
|
|
return;
|
|
|
|
stackBar.SetActive(false);
|
|
barChartData.SetActive(false);
|
|
}
|
|
}
|
|
public void SetChartData(List<BarChartData> barChartData)
|
|
{
|
|
this.barChartDatas.Clear();
|
|
barChart.DataSource.ClearGroups();
|
|
|
|
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);
|
|
}
|
|
|
|
public void OnClickItem(BarEventArgs arg)
|
|
{
|
|
int.TryParse(arg.Group, out var index);
|
|
barChart.GetBarTrackPosition("CycleTime", index.ToString(), out var topPosition);
|
|
barChartData.SetData(barChartDatas[index], topPosition);
|
|
|
|
var bottomPosition = new Vector3(topPosition.x, rectTransform.rect.height / 2, 0);
|
|
stackBar.SetStackBar(barChartDatas[index], topPosition, bottomPosition);
|
|
}
|
|
}
|