This commit is contained in:
xyy
2026-04-03 22:01:27 +08:00
parent 27780b99f3
commit 003b46546a
2 changed files with 62 additions and 24 deletions

View File

@@ -114,16 +114,28 @@ namespace MembranePoreTester.ViewModels
flow = Math.Round(ConvertFlowByMode(rawFlow), 2);
}
if (pressure <= 0 || flow <= 0)
return;
CurrentFlow = flow;
// 3. 直接新增一行(不查找相同压力)
var newPoint = new Models.DataPoint
// 3. 查找是否已有相同压力点(按两位小数匹配),有则更新对应流量,否则新增
var existing = Record.DataPoints.FirstOrDefault(p => Math.Abs(p.Pressure - pressure) < 0.001);
if (existing != null)
{
Pressure = pressure,
WetFlow = TestMode.Contains("湿膜") ? flow : 0,
DryFlow = TestMode.Contains("干膜") ? flow : 0
};
Record.DataPoints.Add(newPoint);
if (TestMode != null && TestMode.Contains("湿膜"))
existing.WetFlow = flow;
else
existing.DryFlow = flow;
}
else
{
var newPoint = new Models.DataPoint
{
Pressure = Math.Round(pressure, 2),
WetFlow = TestMode != null && TestMode.Contains("湿膜") ? flow : 0,
DryFlow = TestMode != null && TestMode.Contains("干膜") ? flow : 0
};
Record.DataPoints.Add(newPoint);
}
// 4. 刷新曲线
UpdatePlot();
@@ -732,7 +744,14 @@ namespace MembranePoreTester.ViewModels
public string TestMode
{
get => _testMode;
set => SetProperty(ref _testMode, value);
set
{
if (SetProperty(ref _testMode, value))
{
// 切换测试模式时刷新曲线显示(显示对应模式的历史数据)
UpdatePlot();
}
}
}
@@ -785,6 +804,9 @@ namespace MembranePoreTester.ViewModels
TitleFontWeight = 1
};
// 让线条更平滑使用线性插值OxyPlot 默认即可),同时关闭区域填充等
model.DefaultColors = new[] { OxyColors.Blue, OxyColors.Red };
// 添加坐标轴
@@ -799,41 +821,56 @@ namespace MembranePoreTester.ViewModels
{
Position = AxisPosition.Left,
Title = "流量 (L/min)",
TitleFontSize = 12
TitleFontSize = 12,
Minimum = 0, // 从0开始绘制避免覆盖整个Y轴
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot
});
// 湿膜流量 - 使用更清晰的标题
var wetSeries = new LineSeries
{
Title = "湿膜流量 (Wet Flow)",
Title = "湿膜流量 (Wet Flow)",
Color = OxyColors.Blue,
MarkerType = MarkerType.Circle,
MarkerSize = 4,
MarkerStroke = OxyColors.Blue,
MarkerFill = OxyColors.Blue,
StrokeThickness = 2
MarkerType = MarkerType.None,
StrokeThickness = 1
};
// 干膜流量 - 使用更清晰的标题
var drySeries = new LineSeries
{
Title = "干膜流量 (Dry Flow)",
Title = "干膜流量 (Dry Flow)",
Color = OxyColors.Red,
MarkerType = MarkerType.Triangle,
MarkerSize = 5,
MarkerStroke = OxyColors.Red,
MarkerFill = OxyColors.Red,
StrokeThickness = 2
MarkerType = MarkerType.None,
StrokeThickness = 1
};
// 始终按记录填充两个序列(保留历史数据),但只在当前测试模式下将对应序列添加到图表
foreach (var dp in sorted)
{
wetSeries.Points.Add(new OxyPlot.DataPoint(dp.Pressure, dp.WetFlow));
drySeries.Points.Add(new OxyPlot.DataPoint(dp.Pressure, dp.DryFlow));
}
model.Series.Add(wetSeries);
model.Series.Add(drySeries);
// 根据当前 TestMode 决定显示哪条曲线,切换回另一种模式时其历史数据会从 Record 恢复并显示
if (TestMode != null && TestMode.Contains("湿膜"))
{
if (wetSeries.Points.Count > 0)
model.Series.Add(wetSeries);
}
else if (TestMode != null && TestMode.Contains("干膜"))
{
if (drySeries.Points.Count > 0)
model.Series.Add(drySeries);
}
else
{
// 如果没有明确模式,默认显示两条曲线(适用于同时显示的情况)
if (wetSeries.Points.Count > 0)
model.Series.Add(wetSeries);
if (drySeries.Points.Count > 0)
model.Series.Add(drySeries);
}
lock (_plotLock)
{