更新睡眠报告散点图

This commit is contained in:
wyf
2025-08-22 10:17:55 +08:00
parent f21f75d5e4
commit c432212870
8 changed files with 82 additions and 65 deletions

View File

@@ -152,6 +152,16 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
), ),
], ],
), ),
Text(
(widget.data['range']?.toString().trim().isNotEmpty ??
false)
? "参考范围".tr + "" + widget.data['range'].toString()
: "参考范围".tr + "" + "未知数据".tr,
style: TextStyle(
color: stringToColor("#C8CBD2"),
fontSize: 26.rpx,
),
),
SizedBox( SizedBox(
height: 81.rpx, height: 81.rpx,
), ),

View File

@@ -589,19 +589,7 @@ class _MinePageState extends State<MinePage> {
); );
Get.toNamed("/loginPage"); Get.toNamed("/loginPage");
} else { } else {
// TopSlideNotification.show(
// context,
// text: "待开发.提示".tr,
// textColor:
// themeController.currentColor.sc2,
// );
// Get.toNamed("/newSleepReportPage",
// arguments: {
// 'date': DateTime.now()
// .millisecondsSinceEpoch,
// "mac": 'aaaaaaeeeeeq',
// 'type': 1
// });
} }
}, },
child: Container( child: Container(

View File

@@ -549,6 +549,7 @@ class _NewHomePageState extends State<NewHomePage> {
'date': DateTime.now() 'date': DateTime.now()
.millisecondsSinceEpoch, .millisecondsSinceEpoch,
'person_show': false, 'person_show': false,
'reportPadding': false,
}, },
); );
} }
@@ -652,6 +653,8 @@ class _NewHomePageState extends State<NewHomePage> {
// 'backgroundColor':stringToColor("#003058"), // 'backgroundColor':stringToColor("#003058"),
'person_show': 'person_show':
false, false,
'reportPadding':
false,
}, },
); );
}, },

View File

@@ -5,29 +5,24 @@ import 'package:vbvs_app/common/util/MyUtils.dart';
class ScatterPlotChart extends StatelessWidget { class ScatterPlotChart extends StatelessWidget {
final List<ScatterSpot> points; final List<ScatterSpot> points;
final int xMax; final double xMin;
final int yMax; final double xMax;
final double yMin;
final double yMax;
final Color pointColor; final Color pointColor;
final int divisions;
ScatterPlotChart({ ScatterPlotChart({
required this.points, required this.points,
required this.xMin,
required this.xMax, required this.xMax,
required this.yMin,
required this.yMax, required this.yMax,
required this.pointColor, required this.pointColor,
required this.divisions,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// 计算向上取整后的最大值 const double interval = 400; // 默认间隔
// double xMaxCeil = (xMax / divisions).ceil() * divisions.toDouble();
double temp = (xMax / divisions).ceil().toDouble(); // 计算向上取整后的每个分区的最大值
double xMaxCeil = (((temp / 100).ceil()) * 100 * (divisions))
.toDouble(); // 向百取整并乘以 divisions
double tempy = (yMax / divisions).ceil().toDouble(); // 计算向上取整后的每个分区的最大值
double yMaxCeil =
(((tempy / 100).ceil()) * 100 * (divisions)).toDouble();
return SizedBox( return SizedBox(
child: ScatterChart( child: ScatterChart(
@@ -35,18 +30,20 @@ class ScatterPlotChart extends StatelessWidget {
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
gridData: FlGridData( gridData: FlGridData(
show: true, show: true,
horizontalInterval: yMaxCeil / divisions, horizontalInterval: interval,
verticalInterval: xMaxCeil / divisions, verticalInterval: interval,
getDrawingHorizontalLine: (value) { getDrawingHorizontalLine: (value) {
return FlLine( return FlLine(
color: themeController.currentColor.sc4, // 设置网格线颜色 color: themeController.currentColor.sc4,
strokeWidth: 0.5, strokeWidth: 1.rpx,
dashArray: [5, 5], // 设置虚线 [实线长度, 空白长度]
); );
}, },
getDrawingVerticalLine: (value) { getDrawingVerticalLine: (value) {
return FlLine( return FlLine(
color: themeController.currentColor.sc4, // 设置网格线颜色 color: themeController.currentColor.sc4,
strokeWidth: 0.5, strokeWidth: 1.rpx,
dashArray: [5, 5], // 设置虚线
); );
}, },
), ),
@@ -55,10 +52,14 @@ class ScatterPlotChart extends StatelessWidget {
leftTitles: AxisTitles( leftTitles: AxisTitles(
sideTitles: SideTitles( sideTitles: SideTitles(
showTitles: true, showTitles: true,
reservedSize: 60.rpx, // 给 y 轴标签更多空间 reservedSize: 70.rpx,
interval: 400, // 强制 400 一个刻度
getTitlesWidget: (double value, TitleMeta meta) { getTitlesWidget: (double value, TitleMeta meta) {
// 只显示 400 的倍数
if (value % 400 != 0) return Container();
return Padding( return Padding(
padding: EdgeInsets.only(right: 14.rpx), // 右侧加间距 padding: EdgeInsets.only(right: 14.rpx),
child: Text( child: Text(
value.toStringAsFixed(0), value.toStringAsFixed(0),
style: TextStyle( style: TextStyle(
@@ -67,7 +68,7 @@ class ScatterPlotChart extends StatelessWidget {
), ),
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center, // 右对齐 textAlign: TextAlign.center,
), ),
); );
}, },
@@ -77,17 +78,17 @@ class ScatterPlotChart extends StatelessWidget {
sideTitles: SideTitles( sideTitles: SideTitles(
showTitles: true, showTitles: true,
getTitlesWidget: (double value, TitleMeta meta) { getTitlesWidget: (double value, TitleMeta meta) {
// 只显示 400 的倍数
if (value % 400 != 0) return Container();
return Text( return Text(
value.toStringAsFixed(0), value.toStringAsFixed(0),
style: TextStyle( style: TextStyle(
fontSize: 18.rpx, fontSize: 18.rpx,
color: themeController.currentColor.sc4, color: themeController.currentColor.sc4,
), ),
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center, // 右对齐
); );
}, },
interval: 400, // 强制间隔 400
), ),
), ),
rightTitles: AxisTitles( rightTitles: AxisTitles(
@@ -104,21 +105,20 @@ class ScatterPlotChart extends StatelessWidget {
width: 0.5, width: 0.5,
), ),
), ),
// 修改散点的大小和颜色
scatterSpots: points.map((point) { scatterSpots: points.map((point) {
return ScatterSpot( return ScatterSpot(
point.x, // x 坐标 point.x,
point.y, // y 坐标 point.y,
dotPainter: FlDotCirclePainter( dotPainter: FlDotCirclePainter(
radius: 3.rpx, // 自定义大小 radius: 3.rpx,
color: pointColor, // 自定义颜色 color: pointColor,
), ),
); );
}).toList(), }).toList(),
minX: 0, minX: xMin,
maxX: xMaxCeil, maxX: xMax,
minY: 0, minY: yMin,
maxY: yMaxCeil, maxY: yMax,
), ),
), ),
); );

View File

@@ -152,8 +152,8 @@ class _HeartPointWidgetState extends State<HeartPointWidget> {
height: 31.rpx, height: 31.rpx,
), ),
Padding( Padding(
padding: EdgeInsetsDirectional.fromSTEB( padding:
30.rpx, 0.rpx, 30.rpx, 0.rpx), EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 30.rpx, 0.rpx),
child: Container( child: Container(
width: MediaQuery.of(context).size.width * 0.7, width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.width * 0.7, height: MediaQuery.of(context).size.width * 0.7,
@@ -163,10 +163,14 @@ class _HeartPointWidgetState extends State<HeartPointWidget> {
), ),
child: ScatterPlotChart( child: ScatterPlotChart(
points: data, points: data,
xMax: maxX.toInt(), // x轴最大值 // xMax: maxX.toInt(), // x轴最大值
yMax: maxY.toInt(), // y轴最大值 // yMax: maxY.toInt(), // y轴最大值
xMax: 3000, // x轴最大值
yMax: 3000, // y轴最大值
xMin: 0,
yMin: 0,
pointColor: stringToColor("#00C1AA"), // 点的颜色 pointColor: stringToColor("#00C1AA"), // 点的颜色
divisions: 7, // 刻度分割数量 // divisions: 7, // 刻度分割数量
), ),
), ),
), ),

View File

@@ -181,6 +181,7 @@ class _VitalSignsWidgetState extends State<VitalSignsWidget> {
'person_show': false, 'person_show': false,
'itemName': 206, 'itemName': 206,
'retrun_fresh': true, 'retrun_fresh': true,
'reportPadding':false,
}); });
if (widget.onRefresh != null) { if (widget.onRefresh != null) {
widget.onRefresh!(); widget.onRefresh!();

View File

@@ -173,6 +173,7 @@ class _NewSleepViewWidgetState extends State<NewSleepViewWidget> {
'backgroundImg': 'assets/images/new_background.png', 'backgroundImg': 'assets/images/new_background.png',
'person_show': false, 'person_show': false,
'retrun_fresh': true, 'retrun_fresh': true,
'reportPadding': false,
}); });
if (widget.onRefresh != null) { if (widget.onRefresh != null) {
widget.onRefresh!(); widget.onRefresh!();

View File

@@ -555,12 +555,14 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
), ),
Obx(() { Obx(() {
if (sleepReportController.isLoading.value) { if (sleepReportController.isLoading.value) {
return Center(child:CircularProgressIndicator( return Center(
child: CircularProgressIndicator(
strokeWidth: 2, strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>( valueColor: AlwaysStoppedAnimation<Color>(
themeController.currentColor.sc1, themeController.currentColor.sc1,
), ),
),); ),
);
} }
if (sleepReport == null || sleepReport.isEmpty) { if (sleepReport == null || sleepReport.isEmpty) {
// 空数据 // 空数据
@@ -595,8 +597,14 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
child: Column( child: Column(
children: [ children: [
Padding( Padding(
padding: padding: EdgeInsetsDirectional.fromSTEB(
EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0), 0,
(widget.data['reportPadding'] != null &&
widget.data['reportPadding'] == false)
? 0.rpx
: 30.rpx,
0,
0),
child: Container( child: Container(
width: double.infinity, width: double.infinity,
constraints: BoxConstraints( constraints: BoxConstraints(
@@ -852,12 +860,14 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
), ),
Obx(() { Obx(() {
if (sleepReportController.isLoading.value) { if (sleepReportController.isLoading.value) {
return Center(child:CircularProgressIndicator( return Center(
child: CircularProgressIndicator(
strokeWidth: 2, strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>( valueColor: AlwaysStoppedAnimation<Color>(
themeController.currentColor.sc1, themeController.currentColor.sc1,
), ),
),); ),
);
} }
switch (sleepReportController.model.type) { switch (sleepReportController.model.type) {
case 1: case 1: