Adjust panel spans to take up the available width.

    For each group of panels that would be laid out on the same level, scale up
    the unspecified panel spans to fill up the level.

def _auto_adjust_panel_spans(dashboard):
    '''Adjust panel spans to take up the available width.

    For each group of panels that would be laid out on the same level, scale up
    the unspecified panel spans to fill up the level.
    '''
    for row in dashboard.get('rows', []):
        levels = []
        current_level = []
        levels.append(current_level)
        for panel in row.get('panels', []):
            current_level_span = sum(panel.get('span', _DEFAULT_PANEL_SPAN)
                                     for panel in current_level)
            span = panel.get('span', _DEFAULT_PANEL_SPAN)
            if current_level_span + span > _FULL_LEVEL_SPAN:
                current_level = [panel]
                levels.append(current_level)
            else:
                current_level.append(panel)

        for level in levels:
            specified_panels = [panel for panel in level if 'span' in panel]
            unspecified_panels = [panel for panel in level
                                  if 'span' not in panel]
            if not unspecified_panels:
                continue

            specified_span = sum(panel['span'] for panel in specified_panels)
            available_span = _FULL_LEVEL_SPAN - specified_span
            auto_span = float(available_span) / len(unspecified_panels)
            for panel in unspecified_panels:
                panel['span'] = auto_span