示例#1
0
def update_default_options(tile):
    """Include the tile's :data:`tile_options` in a pool of default options belonging
    to the owner of the tile"""
    series_specs = tile.series_specs()
    if not series_specs:
        return

    old_options_list = c.dao.OptionsDAO.select_multi(
        tile.report_id, 'SeriesSpec', [
            serialize.mjson(series_spec_for_default_options(ss))
            for ss in series_specs
        ])

    default_options_by_ss = {}
    for ss_do_raw, options_raw in old_options_list:
        ss_do = series_spec_for_default_options(
            serialize.json_loads(ss_do_raw))
        default_options_by_ss[ss_do] = serialize.json_loads(options_raw)

    colors = tile.tile_options.get('colors')
    to_set = []
    for i, ss in enumerate(series_specs):
        ss_do = series_spec_for_default_options(ss)
        old_options = default_options_by_ss.get(ss_do, {})
        new_options = {}

        name = ss.params.get('name')
        if name:
            new_options['name'] = name

        color = util.safeget(colors, i)
        if color:
            new_options['color'] = color

        if old_options.get('color') and not new_options.get('color'):
            new_options['color'] = old_options['color']

        if old_options != new_options:
            to_set.append(
                (serialize.mjson(ss_do), serialize.mjson(new_options)))

    if to_set:
        c.dao.OptionsDAO.set_multi(tile.report_id, 'SeriesSpec', to_set)
        log.debug('Updated default options from tile %s', tile)
示例#2
0
 def _set_combined_colors(self, data):
     if not data.get('series_data'):
         return
     default_options_list = dataseries.select_default_series_spec_options(
         self.tile.report_id, self.tile.series_specs())
     # compute combined_colors
     data['combined_colors'] = []
     for series_index, series_data in enumerate(data['series_data']):
         tw_color = safeget(self.tile_options.get('colors'), series_index)
         if tw_color:
             data['combined_colors'].append(tw_color)
             continue
         default_color = nestedget(default_options_list[series_index],
                                   'color')
         if default_color:
             data['combined_colors'].append(default_color)
             continue
         fallback_color = cyclicget(mqeconfig.DEFAULT_COLORS, series_index)
         data['combined_colors'].append(fallback_color)
示例#3
0
def style_for_series(tile_data, series_index):
    color = safeget(tile_data['combined_colors'], series_index)
    if not color:
        return ''
    return 'color: %s;' % color