Commit 67d8fab

Roman Mashirov <mrj@mrj.spb.ru>
2024-06-12 18:07:43
- fixed offset by one bug in case there is no measurments with value max-1 - fixed bar order in graph, map keys not sorted
1 parent 3c4a748
Changed files (1)
app
lib
components
app/lib/components/statistics/value_distribution.dart
@@ -57,7 +57,7 @@ class ValueDistribution extends StatelessWidget {
       }
     }
     // Fill values between
-    for (int x = distribution.keys.min + 1; x < distribution.keys.max -1; x++) {
+    for (int x = distribution.keys.min + 1; x < distribution.keys.max; x++) {
       if (!distribution.containsKey(x)) distribution[x] = 0;
     }
     assert(distribution[distribution.keys.max]! > 0);
@@ -142,6 +142,8 @@ class _ValueDistributionPainter extends CustomPainter {
       final length = heightUnit * distribution[xPos]!;
       /// Offset from top so that the bar of [length] is centered.
       final startPos = (size.height - length) / 2;
+	  final barNumber = xPos - distribution.values.min; // number of bar in graph, from 0
+	  final barDrawXOffset = barWidth / 2 + (barWidth + barGapWidth)*barNumber;
       assert(barDrawXOffset >= 0 && barDrawXOffset <= size.width);
       assert(startPos >= 0); assert(startPos <= size.height);
       assert((startPos + length) >= 0 && (startPos + length) <= size.height);
@@ -150,8 +152,6 @@ class _ValueDistributionPainter extends CustomPainter {
         Offset(barDrawXOffset, startPos + length),
         barPainter,
       );
-
-      barDrawXOffset += barWidth + barGapWidth;
     }
 
     // Draw decorations on top: