작업 시간 분석 UI 기능 개발
This commit is contained in:
@@ -1,18 +1,43 @@
|
||||
using ChartAndGraph;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using WI;
|
||||
using static ChartAndGraph.BarChart;
|
||||
|
||||
public class UI_BarChart : UIBase
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
BarChart barChart;
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
public bool isCycleTimeChart;
|
||||
public List<BarChartData> barChartDatas = new List<BarChartData>();
|
||||
|
||||
public UI_BarChartData barChartData;
|
||||
public override void AfterAwake()
|
||||
{
|
||||
|
||||
barChart = GetComponentInChildren<BarChart>();
|
||||
barChartData = GetComponentInChildren<UI_BarChartData>(true);
|
||||
}
|
||||
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);
|
||||
barChartData.SetData(barChartDatas[index]);
|
||||
}
|
||||
}
|
||||
|
||||
68
Assets/WorkSpace/Personal/JYM/UI_BarChartData.cs
Normal file
68
Assets/WorkSpace/Personal/JYM/UI_BarChartData.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using WI;
|
||||
using UnityEngine.EventSystems;
|
||||
public class UI_BarChartData : UIBase
|
||||
{
|
||||
private TextMeshProUGUI CoolingTimeData;
|
||||
private TextMeshProUGUI HoldingPressureTimeData;
|
||||
private TextMeshProUGUI WeighingTimeData;
|
||||
private TextMeshProUGUI ETCData;
|
||||
|
||||
public TextMeshProUGUI DateTime;
|
||||
|
||||
public Vector3 offset;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
SetActive(false);
|
||||
}
|
||||
public void SetData(BarChartData data)
|
||||
{
|
||||
ShowUINextToClickedUI();
|
||||
|
||||
CoolingTimeData.SetText(ConvertFloatToString(data.coolingTime));
|
||||
HoldingPressureTimeData.SetText(ConvertFloatToString(data.holdingPressureTime));
|
||||
WeighingTimeData.SetText(ConvertFloatToString(data.weighingTime));
|
||||
ETCData.SetText(ConvertFloatToString(data.etc));
|
||||
|
||||
DateTime.SetText(data._time);
|
||||
}
|
||||
private string ConvertFloatToString(float value)
|
||||
{
|
||||
float truncatedFloat = Mathf.Floor(value * 100f) / 100f;
|
||||
return truncatedFloat.ToString();
|
||||
}
|
||||
|
||||
|
||||
void ShowUINextToClickedUI()
|
||||
{
|
||||
RectTransform parentRectTransform = rectTransform.parent.GetComponent<RectTransform>();
|
||||
|
||||
Vector2 localPoint;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, Input.mousePosition, null, out localPoint);
|
||||
|
||||
Vector2 parentSize = parentRectTransform.rect.size;
|
||||
Vector2 uiSize = rectTransform.rect.size;
|
||||
|
||||
float clampedX = Mathf.Clamp(localPoint.x + offset.x, -parentSize.x / 2 + uiSize.x / 2, parentSize.x / 2 - uiSize.x / 2);
|
||||
float clampedY = Mathf.Clamp(localPoint.y + offset.y, -parentSize.y / 2 + uiSize.y / 2, parentSize.y / 2 - uiSize.y / 2);
|
||||
|
||||
rectTransform.localPosition = new Vector2(clampedX, clampedY);
|
||||
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (EventSystem.current.currentSelectedGameObject != null)
|
||||
return;
|
||||
|
||||
SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/WorkSpace/Personal/JYM/UI_BarChartData.cs.meta
Normal file
11
Assets/WorkSpace/Personal/JYM/UI_BarChartData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98999ae4da220534a9f4db050ed06da1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,8 +12,8 @@ using static ChartAndGraph.GraphChartBase;
|
||||
public class UI_GraphChart : UIBase, IPointerClickHandler
|
||||
{
|
||||
public GraphChart Graph;
|
||||
public UI_DateTime prf_dateTime;
|
||||
public RectTransform Content_DateTime;
|
||||
//public UI_DateTime prf_dateTime;
|
||||
//public RectTransform Content_DateTime;
|
||||
|
||||
private UI_GraphChartData chartDetailData;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UI_GraphChart : UIBase, IPointerClickHandler
|
||||
public override void AfterAwake()
|
||||
{
|
||||
Graph = GetComponentInChildren<GraphChart>();
|
||||
prf_dateTime = Resources.Load<UI_DateTime>("Prefabs/UI/PRF_UI_DateTime");
|
||||
//prf_dateTime = Resources.Load<UI_DateTime>("Prefabs/UI/PRF_UI_DateTime");
|
||||
chartDetailData = FindSingle<UI_GraphChartData>();
|
||||
}
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
@@ -53,14 +53,14 @@ public class UI_GraphChart : UIBase, IPointerClickHandler
|
||||
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 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;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class WorkConditionsManager : MonoBehaviour, ISingle
|
||||
public List<float> originHumidityData = new();
|
||||
public List<float> originCycleTimeData = new();
|
||||
|
||||
public List<string> mainChartLabels = new List<string>();
|
||||
//public List<string> mainChartLabels = new List<string>();
|
||||
public List<string> originChartLabels = new List<string>();
|
||||
|
||||
public int targetCount;
|
||||
@@ -48,7 +48,7 @@ public class WorkConditionsManager : MonoBehaviour, ISingle
|
||||
public void SetGraphChartData(WorkConditionsData workConditionsData)
|
||||
{
|
||||
graphDatas.Clear();
|
||||
mainChartLabels.Clear();
|
||||
//mainChartLabels.Clear();
|
||||
|
||||
originPeakData.Clear();
|
||||
originTemperatureData.Clear();
|
||||
@@ -73,9 +73,9 @@ public class WorkConditionsManager : MonoBehaviour, ISingle
|
||||
graphDatas.Add("주변 습도", DownSampleToFixedCount(originHumidityData, originChartLabels, targetCount));
|
||||
graphDatas.Add("싸이클 타임", DownSampleToFixedCount(originCycleTimeData, originChartLabels, targetCount));
|
||||
|
||||
mainChartLabels.AddRange(DownSampleToFixedCount(originChartLabels, 5));
|
||||
//mainChartLabels.AddRange(DownSampleToFixedCount(originChartLabels, 5));
|
||||
|
||||
onSendChartLabels?.Invoke(mainChartLabels);
|
||||
//onSendChartLabels?.Invoke(mainChartLabels);
|
||||
onCompleteLoadData?.Invoke(workConditionsData);
|
||||
}
|
||||
private int ConvertStringToInt(string stringData)
|
||||
|
||||
80
Assets/WorkSpace/Personal/JYM/WorkTimeManager.cs
Normal file
80
Assets/WorkSpace/Personal/JYM/WorkTimeManager.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using WI;
|
||||
|
||||
[Serializable]
|
||||
public class BarChartData
|
||||
{
|
||||
public string _time;
|
||||
public string itemcd;
|
||||
public float cycleTime;
|
||||
public float targetCycleTime;
|
||||
public float coolingTime;
|
||||
public float holdingPressureTime;
|
||||
public float weighingTime;
|
||||
public float etc;
|
||||
}
|
||||
public class WorkTimeManager : MonoBehaviour, ISingle
|
||||
{
|
||||
public List<BarChartData> originDatas = new List<BarChartData>();
|
||||
public List<BarChartData> mainChartDatas = new List<BarChartData>();
|
||||
|
||||
public int targetCount;
|
||||
public Action<List<BarChartData>> onSendChartData;
|
||||
public void SetWorkTimeData(WorkTimeData workTimeData)
|
||||
{
|
||||
SetBarChartData(workTimeData);
|
||||
}
|
||||
private void SetBarChartData(WorkTimeData workTimeData)
|
||||
{
|
||||
originDatas.Clear();
|
||||
mainChartDatas.Clear();
|
||||
|
||||
foreach (var row in workTimeData.data.rows)
|
||||
{
|
||||
var data = new BarChartData();
|
||||
data._time = row._time;
|
||||
data.itemcd = row.ITEMCD;
|
||||
data.cycleTime = ConvertStringToFloat(row.C045);
|
||||
data.targetCycleTime = ConvertStringToFloat(row.CYCLETIME);
|
||||
data.coolingTime = ConvertStringToFloat(row.C046);
|
||||
data.holdingPressureTime = ConvertStringToFloat(row.C027);
|
||||
data.weighingTime = ConvertStringToFloat(row.C037);
|
||||
data.etc = data.cycleTime - (data.coolingTime + data.holdingPressureTime + data.weighingTime);
|
||||
|
||||
originDatas.Add(data);
|
||||
}
|
||||
|
||||
mainChartDatas.AddRange(DownSampleToFixedCount(originDatas, targetCount));
|
||||
|
||||
onSendChartData?.Invoke(mainChartDatas);
|
||||
}
|
||||
private float ConvertStringToFloat(string stringData)
|
||||
{
|
||||
float.TryParse(stringData, out var result);
|
||||
return result;
|
||||
}
|
||||
private List<BarChartData> DownSampleToFixedCount(List<BarChartData> originDatas, int targetCount)
|
||||
{
|
||||
var sampleData = new List<BarChartData>();
|
||||
|
||||
double interval = (double)originDatas.Count / targetCount;
|
||||
|
||||
if (originDatas.Count <= targetCount || targetCount <= 0)
|
||||
{
|
||||
return originDatas;
|
||||
}
|
||||
for (int i = 0; i < targetCount; i++)
|
||||
{
|
||||
int index = (int)Math.Round(i * interval);
|
||||
if (index >= originDatas.Count)
|
||||
{
|
||||
index = originDatas.Count - 1;
|
||||
}
|
||||
sampleData.Add(originDatas[index]);
|
||||
}
|
||||
return sampleData;
|
||||
}
|
||||
}
|
||||
11
Assets/WorkSpace/Personal/JYM/WorkTimeManager.cs.meta
Normal file
11
Assets/WorkSpace/Personal/JYM/WorkTimeManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b03079933dda160409973fae997d4a37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user