Commits

Anonymous committed 6c3f958

0.12.2dev: Fixed percentage "fudging" in progress bars in the case where the sum of the (rounded) percentages amounts to >100%.

Patch by Andrew C Martin. Closes #9718.

Comments (0)

Files changed (2)

trac/templates/progress_bar.html

     <tr>
       <td py:for="idx, interval in enumerate(stats.intervals)"
           class="$interval.css_class"
-          style="${interval.percent and 'width: %d%%' % interval.percent or 'display: none'}">
+          style="${interval.percent > 0 and 'width: %d%%' % interval.percent or 'display: none'}">
         <a href="${interval_hrefs and interval_hrefs[idx] or None}"
            title="${_('%(count)s/%(total)s %(title)s',
                       count=interval.count, total=stats.count, title=interval.title)}"></a>

trac/ticket/roadmap.py

                 self.done_percent += interval['percent']
                 self.done_count += interval['count']
 
-        # We want the percentages to add up to 100%.  To do that, we fudge the
-        # first interval that counts as "completed".  That interval is adjusted
-        # by enough to make the intervals sum to 100%.
+        # We want the percentages to add up to 100%. To do that, we fudge one
+        # of the intervals. If we're <100%, we add to the smallest non-zero
+        # interval. If we're >100%, we subtract from the largest interval.
+        # The interval is adjusted by enough to make the intervals sum to 100%.
         if self.done_count and total_percent != 100:
-            fudge_int = [i for i in self.intervals
-                         if i['overall_completion']][0]
             fudge_amt = 100 - total_percent
+            fudge_int = [i for i in sorted(self.intervals,
+                                           key=lambda k: k['percent'],
+                                           reverse=(fudge_amt < 0))
+                         if i['percent']][0]
             fudge_int['percent'] += fudge_amt
             self.done_percent += fudge_amt