Index: trac/ticket/roadmap.py
===================================================================
--- trac/ticket/roadmap.py	(revision 5765)
+++ trac/ticket/roadmap.py	(working copy)
@@ -63,7 +63,8 @@
         self.done_percent = 0
         self.done_count = 0
 
-    def add_interval(self, title, count, qry_args, css_class, countsToProg=0):
+    def add_interval(self, title, count, qry_args, css_class,
+                     overall_completion=None, countsToProg=0):
         """Adds a division to this stats' group's progress bar.
 
         `title` is the display name (eg 'closed', 'spent effort') of this
@@ -72,16 +73,22 @@
         `qry_args` is a dict of extra params that will yield the subset of
           tickets in this interval on a query.
         `css_class` is the css class that will be used to display the division.
-        `countsToProg` can be set to true to make this interval count towards
-          overall completion of this group of tickets.
+        `overall_completion` can be set to true to make this interval count
+          towards overall completion of this group of tickets.
+          
+        (Warning: `countsToProg` argument will be removed in 0.12, use
+        `overall_completion` instead)
         """
+        if overall_completion is None:
+            overall_completion = countsToProg
         self.intervals.append({
             'title': title,
             'count': count,
             'qry_args': qry_args,
             'css_class': css_class,
             'percent': None,
-            'countsToProg': countsToProg
+            'countsToProg': overall_completion,
+            'overall_completion': overall_completion,
         })
         self.count = self.count + count
 
@@ -95,42 +102,95 @@
             interval['percent'] = round(float(interval['count'] / 
                                         float(self.count) * 100))
             total_percent = total_percent + interval['percent']
-            if interval['countsToProg']:
+            if interval['overall_completion']:
                 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%.
         if self.done_count and total_percent != 100:
-            fudge_int = [i for i in self.intervals if i['countsToProg']][0]
+            fudge_int = [i for i in self.intervals
+                         if i['overall_completion']][0]
             fudge_amt = 100 - total_percent
             fudge_int['percent'] += fudge_amt
             self.done_percent += fudge_amt
 
+
 class DefaultTicketGroupStatsProvider(Component):
+    """Configurable ticket group statistics provider.
+
+    Example configuration (which is also the default):
+
+    [milestone-groups]
+    closed = closed                      # a list of accepted status
+    closed.order = 0                     # sequence number in the progress bar
+    closed.args = group=resolution       # optional extra param for the query
+    closed.overall_completion = true     # count for overall completion
+
+    active = !closed                     # '!' for a list of rejected status
+    active.order = 1
+    active.css = open                    # css class for this interval
+    """
+    
     implements(ITicketGroupStatsProvider)
 
+    def _get_ticket_groups(self):
+        """Returns a dict describing the ticket groups used in milestone
+        progress bars.
+        """
+        if 'milestone-groups' in self.config:
+            groups = {}
+            order = 0
+            for option, value in self.config.options('milestone-groups'):
+                if '.' in option:
+                    name, qualifier = option.split('.', 1)
+                    group = groups.get(name)
+                    if group:
+                        group[qualifier] = value
+                else:
+                    groups[option] = {'name': option, 'status': value,
+                                      'order': order}
+                    order += 1
+            return [group for group in sorted(groups.values(),
+                                              key=lambda g: int(g['order']))]
+        else:
+            return [{'name': 'closed', 'status': 'closed',
+                     'args': 'group=resolution', 'overall_completion': 'true'},
+                    {'name': 'active', 'status': '!closed', 'css': 'open'}]
+
     def get_ticket_group_stats(self, ticket_ids):
         total_cnt = len(ticket_ids)
+        status_cnt = {}
+        for s in TicketSystem(self.env).get_all_status():
+            status_cnt[s] = 0
         if total_cnt:
             cursor = self.env.get_db_cnx().cursor()
             str_ids = [str(x) for x in sorted(ticket_ids)]
-            active_cnt = cursor.execute("SELECT count(1) FROM ticket "
-                                        "WHERE status <> 'closed' AND id IN "
-                                        "(%s)" % ",".join(str_ids))
-            active_cnt = 0
-            for cnt, in cursor:
-                active_cnt = cnt
-        else:
-            active_cnt = 0
+            cursor.execute("SELECT status, count(status) FROM ticket "
+                           "WHERE id IN (%s) GROUP BY status" %
+                           ",".join(str_ids))
+            for s, cnt in cursor:
+                status_cnt[s] = cnt
 
-        closed_cnt = total_cnt - active_cnt
-
         stat = TicketGroupStats('ticket status', 'ticket')
-        stat.add_interval('closed', closed_cnt,
-                          {'status': 'closed', 'group': 'resolution'},
-                          'closed', True)
-        stat.add_interval('active', active_cnt,
-                          {'status': ['new', 'assigned', 'reopened']},
-                          'open', False)
+        for group in self._get_ticket_groups():
+            group_cnt = 0
+            accepted = [s.strip() for s in
+                        group['status'].replace('!', '').split(',')]
+            invert = '!' in group['status']
+            query_args = {}
+            for s, cnt in status_cnt.iteritems():
+                if (s in accepted) ^ invert:
+                    group_cnt += cnt
+                    query_args.setdefault('status', []).append(s)
+            for arg in [kv for kv in group.get('args', '').split(',')
+                        if '=' in kv]:
+                k, v = [a.strip() for a in arg.split('=', 1)]
+                query_args[k] = v
+            stat.add_interval(group['name'], group_cnt, query_args,
+                              group.get('css', group['name']),
+                              group.get('overall_completion', False))
         stat.refresh_calcs()
         return stat
 
@@ -631,8 +691,10 @@
 
             for idx, gstat in enumerate(group_stats):
                 gs_dict = milestone_groups[idx]
-                gs_dict['percent_of_max_total'] = (float(gstat.count) /
-                                                   float(max_count) * 100)
+                percent = 1.0
+                if max_count:
+                    percent = float(gstat.count) / float(max_count) * 100
+                gs_dict['percent_of_max_total'] = percent
 
         return 'milestone_view.html', data, None
 
Index: trac/ticket/workflows/basic-workflow.ini
===================================================================
--- trac/ticket/workflows/basic-workflow.ini	(revision 5765)
+++ trac/ticket/workflows/basic-workflow.ini	(working copy)
@@ -21,3 +21,16 @@
 reopen = closed -> reopened
 reopen.permissions = TICKET_CREATE
 reopen.operations = del_resolution
+
+[milestone-groups]
+closed = closed
+closed.order = 0
+closed.args = group=resolution
+closed.overall_completion = true
+
+active = assigned,accepted
+active.order = 1
+active.css = open
+
+new = new,reopened
+new.order = 2
Index: trac/htdocs/css/roadmap.css
===================================================================
--- trac/htdocs/css/roadmap.css	(revision 5765)
+++ trac/htdocs/css/roadmap.css	(working copy)
@@ -19,6 +19,7 @@
  text-decoration: none
 }
 table.progress td { background: #fff; padding: 0 }
+table.progress td.new { background: #f5f5b5 }
 table.progress td.closed { background: #bae0ba }
 table.progress td :hover { background: none }
 p.percent { font-size: 10px; line-height: 2.4em; margin: 0.9em 0 0 }
Index: trac/templates/macros.html
===================================================================
--- trac/templates/macros.html	(revision 5765)
+++ trac/templates/macros.html	(working copy)
@@ -237,7 +237,7 @@
         <dd><a href="${interval_hrefs[idx]}">${interval.count}</a></dd>
       </py:for>
       <py:if test="stats_href">
-        <dt>Total ${stats.unit}s:</dt>
+        <dt>/ Total ${stats.unit}s:</dt>
         <dd><a href="${stats_href}">${sum([x.count for x in stats.intervals], 0)}</a></dd>
       </py:if>
     </dl>

