From 0abb4a125af42372e8d1c866419721e84677c2df Mon Sep 17 00:00:00 2001 From: rahul31124 Date: Thu, 3 Jul 2025 19:09:01 +0530 Subject: [PATCH] percentage alignment --- lib/providers/robotic_arm_state_provider.dart | 8 ++++++ lib/view/widgets/robotic_arm_summary.dart | 27 +++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/providers/robotic_arm_state_provider.dart b/lib/providers/robotic_arm_state_provider.dart index 0a608754e..56cfa7e53 100644 --- a/lib/providers/robotic_arm_state_provider.dart +++ b/lib/providers/robotic_arm_state_provider.dart @@ -235,6 +235,7 @@ class RoboticArmStateProvider extends ChangeNotifier { List spots = []; List dutyCycles = []; List angleList = []; + List> dutyLabelPoints = []; double time = 0; @@ -254,6 +255,12 @@ class RoboticArmStateProvider extends ChangeNotifier { final duty = (pulseHigh / period) * 100; dutyCycles.add(duty); + final mid = time + highMs / 2; + dutyLabelPoints.add({ + 'x': mid, + 'label': '${duty.toStringAsFixed(1)}$percentage', + }); + spots.add(FlSpot(time, 0)); spots.add(FlSpot(time, 1)); spots.add(FlSpot(time + highMs, 1)); @@ -287,6 +294,7 @@ class RoboticArmStateProvider extends ChangeNotifier { 'avgAngle': avgAngle, 'minAngle': minAngle, 'maxAngle': maxAngleVal, + 'dutyLabelPoints': dutyLabelPoints, }; } } diff --git a/lib/view/widgets/robotic_arm_summary.dart b/lib/view/widgets/robotic_arm_summary.dart index f0c2cac5e..a3be51c6a 100644 --- a/lib/view/widgets/robotic_arm_summary.dart +++ b/lib/view/widgets/robotic_arm_summary.dart @@ -37,6 +37,7 @@ class _PlaybackSummaryDialogState extends State { final double avg = data['avgAngle']; final double max = data['maxAngle']; final double min = data['minAngle']; + final List> labelPoints = data['dutyLabelPoints']; return Dialog( backgroundColor: Colors.white, @@ -235,23 +236,18 @@ class _PlaybackSummaryDialogState extends State { reservedSize: 12, interval: 1, getTitlesWidget: (value, _) { - final double period = - 1000 / widget.frequency; - for (int i = 0; - i < data['dutyList'].length; - i++) { - final double start = - i * period; - final double high = - (data['dutyList'][i] / - 100) * - period; - final double mid = - start + high / 2; - if ((value - mid).abs() < + if (pwmSpots.isEmpty) { + return const SizedBox + .shrink(); + } + + for (final label + in labelPoints) { + if ((label['x'] - value) + .abs() < 0.5) { return Text( - '${data['dutyList'][i].toStringAsFixed(1)}$percentage', + label['label'], style: const TextStyle( color: Colors.white70, fontSize: 9, @@ -261,6 +257,7 @@ class _PlaybackSummaryDialogState extends State { ); } } + return const SizedBox.shrink(); }, ),