feat: 일반 라인 그래프 생성 추가

hhsung_work
HyungJune Kim 10 months ago
parent 4cbcc658b8
commit 41bff54c4f

@ -8,6 +8,7 @@ using OxyPlot;
using OxyPlot.Axes;
using OxyPlot.Series;
using SmartAquaViewer.DataAnalysis;
using static SmartAquaViewer.Model.Enums;
namespace SmartAquaViewer.ViewModel
{
@ -86,7 +87,70 @@ namespace SmartAquaViewer.ViewModel
Model.InvalidatePlot(true);
}
private static double? ResolveTankY(WaterQualityVO vo, string fieldName)
public void SetDefaultLineGraph(
List<WaterQualityVO> collection,
MonitorTab selectedTab,
FieldItem? xField, FieldItem? yField,
bool isMarker)
{
Model.Series.Clear();
Model.Axes.Clear();
var xAxis = new DateTimeAxis
{
Position = AxisPosition.Bottom,
Title = "시간",
StringFormat = "HH:mm:ss",
IntervalType = DateTimeIntervalType.Minutes,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot
};
var yAxis = new LinearAxis
{
Position = AxisPosition.Left,
Title = yField.Display,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot
};
Model.Axes.Add(xAxis);
Model.Axes.Add(yAxis);
var series = new LineSeries()
{
MarkerType = isMarker ? MarkerType.Circle : MarkerType.None,
MarkerSize = isMarker ? 3 : 0
};
foreach (var r in collection.OrderBy(r => r.RecordedTime))
{
if (selectedTab.Equals(MonitorTab.Filter))
{
var y = ResolveFilterY(r, yField.Name!);
if (!y.HasValue) continue;
series.Points.Add(new DataPoint(
DateTimeAxis.ToDouble(r.RecordedTime),
y.Value));
if (series.Points.Count > 0)
{
// 트래커 포맷: 시간, 수조, 지표, 값
series.TrackerFormatString =
$"시간: {{2:HH:mm}}\n{yField.Display}: {{4:0.###}}";
}
}
else if (selectedTab.Equals(MonitorTab.Sterilizer))
{
}
}
Model.Series.Add(series);
Model.InvalidatePlot(true);
}
private double? ResolveTankY(WaterQualityVO vo, string fieldName)
{
return fieldName switch
{
@ -98,5 +162,20 @@ namespace SmartAquaViewer.ViewModel
_ => null
};
}
private double? ResolveFilterY(WaterQualityVO vo, string fieldName)
{
return fieldName switch
{
"Filtering.SumpPH" => vo.Filtering.SumpPH,
"Filtering.SumpORP" => vo.Filtering.SumpORP,
"Filtering.SumpWaterLevel" => vo.Filtering.SumpWaterLevel,
"Filtering.SumpFlowRate" => vo.Filtering.SumpFlowRate,
"Filtering.SumpTemperature" => vo.Filtering.SumpTemperature,
"Filtering.FlowRate" => vo.Filtering.FlowRate,
"Filtering.HeatPumpTemperature" => vo.Filtering.HeatPumpTemperature,
_ => null
};
}
}
}

@ -249,12 +249,11 @@ namespace SmartAquaViewer.ViewModel
switch (SelectedGraphType)
{
case GraphType.LINE:
var xFieldLine = SelectedXField?.Name == "RecordedTime" ? SelectedXField : null;
var xField = SelectedXField?.Name == "RecordedTime" ? SelectedXField : null;
var yField = SelectedYField;
var isMarker = ShowMarkers;
GraphControlVM.SetTankLineGraph(
TankGroups, xFieldLine, yField, isMarker
);
if (SelectedTab.Equals(MonitorTab.Tank)) SetGraphData_Line_Tank(data, xField, yField, isMarker);
else GraphControlVM.SetDefaultLineGraph(WaterQualityList, SelectedTab, xField, yField, isMarker);
break;
case GraphType.BOX:
var xFieldBox = SelectedXField;
@ -273,13 +272,15 @@ namespace SmartAquaViewer.ViewModel
}
}
private void SetGraphData_Line_Tank(FieldItem? xField, FieldItem? yField, bool showMarkers, bool useSmoothing)
private void SetGraphData_Line_Tank(object data, FieldItem? xField, FieldItem? yField, bool showMarkers)
{
if (SelectedTab != MonitorTab.Tank) return;
if (xField?.Name != "RecordedTime" || yField == null) return;
if (SelectedWaterTanks.Count == 0) return;
var collection = data as Dictionary<int, ObservableCollection<WaterQualityVO>>;
GraphControlVM.SetTankLineGraph(collection, xField, yField, showMarkers);
}
private object SetGraphData()
@ -292,16 +293,8 @@ namespace SmartAquaViewer.ViewModel
data = SelectedWaterTanks;
break;
case MonitorTab.Filter:
data = WaterQualityList.ToDictionary(
x => x.RecordedTime,
x => x.Filtering
);
break;
case MonitorTab.Sterilizer:
data = WaterQualityList.ToDictionary(
x => x.RecordedTime,
x => x.Sterilizing
);
data = WaterQualityList;
break;
default:
break;

Loading…
Cancel
Save