작업 조건 분석 수정
This commit is contained in:
@@ -12,19 +12,22 @@ using static ChartAndGraph.GraphChartBase;
|
||||
public class UI_GraphChart : UIBase, IPointerClickHandler
|
||||
{
|
||||
public GraphChart Graph;
|
||||
//public UI_DateTime prf_dateTime;
|
||||
//public RectTransform Content_DateTime;
|
||||
private UI_DateTime prf_dateTime;
|
||||
private RectTransform Content_DateTime;
|
||||
|
||||
public UI_GraphChartData chartDetailData;
|
||||
private TextMeshProUGUI GraphName;
|
||||
|
||||
public string graphName;
|
||||
|
||||
public int targetCount;
|
||||
public int startIndex;
|
||||
public float offsetY;
|
||||
public bool isMainChart;
|
||||
public Action<string> onClickChart;
|
||||
|
||||
private List<float> graphChartData = new List<float>();
|
||||
private List<string> graphDateTimeData = new List<string>();
|
||||
private Dictionary<int, Vector3> labelPos = new();
|
||||
|
||||
private TextMeshProUGUI MinValue;
|
||||
private TextMeshProUGUI MaxValue;
|
||||
@@ -37,7 +40,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 = GetComponentInChildren<UI_GraphChartData>(true);
|
||||
}
|
||||
public void Update()
|
||||
@@ -67,38 +70,13 @@ 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 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();
|
||||
@@ -110,6 +88,95 @@ public class UI_GraphChart : UIBase, IPointerClickHandler
|
||||
graphDateTimeData.Add(graphData.timeData[i]);
|
||||
}
|
||||
Graph.DataSource.EndBatch();
|
||||
|
||||
SetDataValue(graphData);
|
||||
|
||||
if (isMainChart)
|
||||
{
|
||||
Graph.OnRedraw.AddListener(SetChartLabels);
|
||||
}
|
||||
}
|
||||
private void SetDataValue(GraphChartData graphData)
|
||||
{
|
||||
min = graphData.chartData.Min();
|
||||
max = graphData.chartData.Max();
|
||||
ave = graphData.chartData.Average();
|
||||
|
||||
AveValue.SetText(DecimalPointCalculate(ave));
|
||||
|
||||
if (isMainChart)
|
||||
{
|
||||
MinValue.SetText(DecimalPointCalculate(min));
|
||||
MaxValue.SetText(DecimalPointCalculate(max));
|
||||
}
|
||||
else
|
||||
{
|
||||
GraphName.SetText(this.graphName);
|
||||
}
|
||||
}
|
||||
private void SetChartLabels()
|
||||
{
|
||||
ClearLabels();
|
||||
this.labelPos.Clear();
|
||||
|
||||
for (int i = 0; i < graphChartData.Count; i++)
|
||||
{
|
||||
Graph.PointToWorldSpace(out var worldSpace, i, graphChartData[i], "WorkConditionsData");
|
||||
this.labelPos.Add(i, worldSpace);
|
||||
}
|
||||
var labelPos = DownSampleToFixedCount(this.labelPos, targetCount, startIndex);
|
||||
|
||||
foreach(var index in labelPos.Keys)
|
||||
{
|
||||
var date = Instantiate(prf_dateTime, Content_DateTime);
|
||||
date.transform.position = new Vector3(labelPos[index].x, offsetY, 0);
|
||||
date.SetDateTime(graphDateTimeData[index]);
|
||||
}
|
||||
}
|
||||
private void ClearLabels()
|
||||
{
|
||||
if (Content_DateTime.childCount <= 0)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < Content_DateTime.childCount; i++)
|
||||
{
|
||||
Destroy(Content_DateTime.transform.GetChild(i).gameObject);
|
||||
}
|
||||
}
|
||||
private Dictionary<int, Vector3> DownSampleToFixedCount(Dictionary<int, Vector3> labelPos, int targetCount, int startIndex)
|
||||
{
|
||||
Dictionary<int, Vector3> sampledData = new Dictionary<int, Vector3>();
|
||||
|
||||
if (labelPos.Count <= targetCount || targetCount <= 0)
|
||||
return new Dictionary<int, Vector3>(labelPos);
|
||||
|
||||
if (startIndex < 0)
|
||||
startIndex = 0;
|
||||
|
||||
List<int> keys = labelPos.Keys.OrderBy(k => k).ToList();
|
||||
int totalCount = keys.Count;
|
||||
|
||||
if (startIndex >= totalCount)
|
||||
startIndex = totalCount - 1;
|
||||
|
||||
int availableCount = totalCount - startIndex;
|
||||
double interval = (double)(availableCount - 1) / (targetCount - 1);
|
||||
|
||||
for (int i = 0; i < targetCount; i++)
|
||||
{
|
||||
int indexInKeys = (int)Math.Round(startIndex + i * interval);
|
||||
if (i == targetCount - 1)
|
||||
indexInKeys = totalCount - 1;
|
||||
|
||||
if (indexInKeys >= totalCount)
|
||||
indexInKeys = totalCount - 1;
|
||||
|
||||
int key = keys[indexInKeys];
|
||||
|
||||
if (!sampledData.ContainsKey(key))
|
||||
sampledData.Add(key, labelPos[key]);
|
||||
}
|
||||
return sampledData;
|
||||
}
|
||||
private string DecimalPointCalculate(float value)
|
||||
{
|
||||
@@ -117,5 +184,4 @@ public class UI_GraphChart : UIBase, IPointerClickHandler
|
||||
|
||||
return floatValue.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -127,25 +127,4 @@ public class WorkConditionsManager : MonoBehaviour, ISingle
|
||||
}
|
||||
return new GraphChartData(sampleGraph);
|
||||
}
|
||||
private List<string> DownSampleToFixedCount(List<string> dateTime, int targetCount)
|
||||
{
|
||||
List<string> sampledData = new List<string>();
|
||||
|
||||
double interval = (double)dateTime.Count / targetCount;
|
||||
|
||||
if (dateTime.Count <= targetCount || targetCount <= 0)
|
||||
{
|
||||
return new List<string>(dateTime);
|
||||
}
|
||||
for (int i = 0; i < targetCount; i++)
|
||||
{
|
||||
int index = (int)Math.Round(i * interval);
|
||||
if (index >= dateTime.Count)
|
||||
{
|
||||
index = dateTime.Count - 1;
|
||||
}
|
||||
sampledData.Add(dateTime[index]);
|
||||
}
|
||||
return sampledData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user