'Returns a visualization\'s configuration. Only works for trackster visualizations right now.'

def get_visualization_config(self, trans, visualization):

    config = None
    if (visualization.type in ['trackster', 'genome']):
        latest_revision = visualization.latest_revision
        bookmarks = latest_revision.config.get('bookmarks', [])
        def pack_track(track_dict):
            dataset_id = track_dict['dataset_id']
            hda_ldda = track_dict.get('hda_ldda', 'hda')
            if (hda_ldda == 'ldda'):
                dataset_id = trans.security.encode_id(dataset_id)
            dataset = self.get_hda_or_ldda(trans, hda_ldda, dataset_id)
            try:
                prefs = track_dict['prefs']
            except KeyError:
                prefs = {}
            track_data_provider = trans.app.data_provider_registry.get_data_provider(trans, original_dataset=dataset, source='data')
            return {'track_type': dataset.datatype.track_type, 'dataset': trans.security.encode_dict_ids(dataset.to_dict()), 'prefs': prefs, 'mode': track_dict.get('mode', 'Auto'), 'filters': track_dict.get('filters', {'filters': track_data_provider.get_filters()}), 'tool': self.get_tool_def(trans, dataset), 'tool_state': track_dict.get('tool_state', {})}
        def pack_collection(collection_dict):
            drawables = []
            for drawable_dict in collection_dict['drawables']:
                if ('track_type' in drawable_dict):
                    drawables.append(pack_track(drawable_dict))
                else:
                    drawables.append(pack_collection(drawable_dict))
            return {'obj_type': collection_dict['obj_type'], 'drawables': drawables, 'prefs': collection_dict.get('prefs', []), 'filters': collection_dict.get('filters', {})}
        def encode_dbkey(dbkey):
            "\n                                                                Encodes    dbkey    as    needed.    For    now,    prepends    user's    public    name\n                                                                to    custom    dbkey    keys.\n                                                                "
            encoded_dbkey = dbkey
            user = visualization.user
            if (('dbkeys' in user.preferences) and (dbkey in user.preferences['dbkeys'])):
                encoded_dbkey = ('%s:%s' % (user.username, dbkey))
            return encoded_dbkey
        tracks = []
        if ('tracks' in latest_revision.config):
            for track_dict in visualization.latest_revision.config['tracks']:
                tracks.append(pack_track(track_dict))
        elif ('view' in latest_revision.config):
            for drawable_dict in visualization.latest_revision.config['view']['drawables']:
                if ('track_type' in drawable_dict):
                    tracks.append(pack_track(drawable_dict))
                else:
                    tracks.append(pack_collection(drawable_dict))
        config = {'title': visualization.title, 'vis_id': trans.security.encode_id(visualization.id), 'tracks': tracks, 'bookmarks': bookmarks, 'chrom': '', 'dbkey': encode_dbkey(visualization.dbkey)}
        if ('viewport' in latest_revision.config):
            config['viewport'] = latest_revision.config['viewport']
    else:
        latest_revision = visualization.latest_revision
        config = latest_revision.config
    return config
