Exemple #1
0
def map_marker(ctx, req):
    """allow for user-selectable markers.

    we have to look up a possible custom selection from the url params.
    """
    icon = None

    if IValue.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.domainelement.number,
                              ctx.domainelement.jsondata['icon'])
    elif IDomainElement.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.number, ctx.jsondata['icon'])
    elif ILanguage.providedBy(ctx):
        icon = req.params.get(ctx.genus.id, ctx.genus.icon)
    elif isinstance(ctx, Genus):
        icon = req.params.get(ctx.id, ctx.icon)

    if icon:
        if "'" in icon:
            icon = icon.split("'")[0]
        if len(icon) > 4 and len(icon) != 7:
            icon = icon[:4]
        if len(icon) == 4:
            icon = icon[0] + 2 * icon[1] + 2 * icon[2] + 2 * icon[3]
        if icon.startswith('a'):
            return svg.data_url(svg.icon('c000000', opacity='0'))
        try:
            return svg.data_url(svg.icon(icon))
        except KeyError:
            return ''
Exemple #2
0
 def __call__(self, ctx, req):
 
     if IValueSet.providedBy(ctx):
         if ctx.language.family:
             return data_url(icon(ctx.language.family.jsondata['icon']))
         return data_url(icon(req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON)))
 
     return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
Exemple #3
0
    def __call__(self, ctx, req):
        if IValue.providedBy(ctx):
            return data_url(icon('c' +
                                 ctx.valueset.language.jsondata['color']))
        if IValueSet.providedBy(ctx):
            return data_url(icon('c' + ctx.language.jsondata['color']))
        elif ILanguage.providedBy(ctx):
            return data_url(icon('c' + ctx.jsondata['color']))

        return super(LanguageByCantonMapMarker,
                     self).__call__(ctx, req)  # pragma: no cover
Exemple #4
0
class LanguageByFamilyMapMarker(util.LanguageByFamilyMapMarker):
    def __call__(self, ctx, req):
    {% if cookiecutter.cldf_module.lower() == 'wordlist' %}
        if IValueSet.providedBy(ctx):
            if ctx.language.family:
                return data_url(icon(ctx.language.family.jsondata['icon']))
            return data_url(icon(req.registry.settings.get('clld.isolates_icon', util.ISOLATES_ICON)))
    {% elif cookiecutter.cldf_module.lower() == 'structuredataset' %}
        if IValueSet.providedBy(ctx):
            c = collections.Counter([v.domainelement.jsondata['color'] for v in ctx.values])
            return data_url(pie(*list(zip(*[(v, k) for k, v in c.most_common()])), **dict(stroke_circle=True)))
        if IDomainElement.providedBy(ctx):
            return data_url(icon(ctx.jsondata['color'].replace('#', 'c')))
        if IValue.providedBy(ctx):
            return data_url(icon(ctx.domainelement.jsondata['color'].replace('#', 'c')))
Exemple #5
0
    def __call__(self, ctx, req):
        color = models.get_color(ctx)

        if not color:
            return MapMarker.__call__(self, ctx, req)

        return svg.data_url(svg.icon('c' + color))
Exemple #6
0
    def __call__(self, ctx, req):
        color, shape = None, 'c'
        if IValue.providedBy(ctx):
            if ctx.cognates:
                color = ctx.cognates[0].cognateset.color
            else:
                color = '#fff'

        if IValueSet.providedBy(ctx):
            v = ctx.values[0]
            if v.cognates:
                color = v.cognates[0].cognateset.color
            else:
                color = '#fff'
            if ctx.language.historical:
                shape = 'd'

        if ILanguage.providedBy(ctx):
            color = ctx.color
            if ctx.historical:
                shape = 'd'

        if color:
            if color.startswith('#'):
                color = color[1:]
            return svg.data_url(svg.icon(shape + color))

        return super(CoblMapMarker, self).__call__(ctx, req)
Exemple #7
0
class LeafletMarkerSpec:
    icon = attr.ib(default=svg.data_url(svg.icon('c000')))
    name = attr.ib(default=None)
    values = attr.ib(default=None)
    tooltip = attr.ib(default=None)
    tooltip_class = attr.ib(default=None)
    markersize = attr.ib(default=None)
    css = attr.ib(default=None)
Exemple #8
0
    def __call__(self, ctx, req):
        
        mapping = {}
        count = -1
        shape = 'c'
        if IValueSet.providedBy(ctx):
            c = colors[ctx.language.family]
            if ctx.language.family in ['MIA', 'OIA'] or 'Old' in ctx.language.name:
                shape = 'd'
            return data_url(icon(shape + c))

        if ILanguage.providedBy(ctx):
            c = colors[ctx.family]
            if ctx.family in ['MIA', 'OIA'] or 'Old' in ctx.name:
                shape = 'd'
            return data_url(icon(shape + c))
    
        return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
Exemple #9
0
 def __call__(self, ctx, req):
     spec = None
     if IValueSet.providedBy(ctx):
         spec = 'c' + ctx.contribution.color
     elif IValue.providedBy(ctx):
         spec = 'c' + ctx.valueset.contribution.color
     elif ILanguage.providedBy(ctx):
         spec = 'ddd0000' if ctx.vocabulary else 'c4d6cee'
     return svg.data_url(svg.icon(spec)) if spec else \
         super(WoldMapMarker, self).__call__(ctx, req)
Exemple #10
0
 def format(self, item):
     item = self.get_obj(item)
     return HTML.span(
         HTML.img(width='20',
                  src=svg.data_url(svg.icon(item.jsondata['icon']))),
         ' ',
         HTML.a(item.family_name,
                href="http://glottolog.org/resource/languoid/id/" +
                item.family_id),
         style="white-space: nowrap;")
Exemple #11
0
def species_node(s, req, nex):
    return {
        'name': s.name,
        'id': s.id,
        'experiments': nex,
        'bubble_size': math.log(5 * nex) * 10,
        'bubble': svg.data_url(svg.icon('cf60', 0.5)),
        'gbif_logo': req.static_url('acc:static/gbif.png'),
        'gbif_url': s.gbif_url,
        'gbif_name': s.gbif_name,
        'family': s.family,
    }
Exemple #12
0
    def __call__(self, ctx, req):
        color = '#000000'
        if interfaces.ILanguage.providedBy(ctx):
            color = ctx.jsondata['color']
        elif interfaces.IValueSet.providedBy(ctx):
            color = ctx.language.jsondata['color']
        elif isinstance(ctx, tuple):
            try:
                color = ctx[0].jsondata['color']
            except KeyError:
                raise ValueError(ctx)

        return data_url(icon('c' + color[1:]))
Exemple #13
0
def browser(req):
    """
    The main GlottoScope view, with selection controls, map and tally table.
    """
    ms = MultiSelect(req,
                     'families',
                     'msfamily',
                     collection=family_query(req),
                     selected=_get_families(req))

    focus = req.params.get('focus', 'ed')

    im = get_icon_map()
    if focus == 'sdt':
        colors, shapes = im['med'], im['aes']
    else:
        shapes, colors = im['med'], im['aes']

    icon_map = {}
    for shape in [o.shape for o in shapes.values()]:
        for color in [o.color for o in colors.values()] + ['ffffff']:
            spec = shape + color
            icon_map[spec] = svg.data_url(svg.icon(spec))

    countries = OrderedDict()
    for c in req.params.getall('country'):
        countries[c] = DBSession.query(common.DomainElement).join(common.Parameter)\
            .filter(common.Parameter.id == 'country')\
            .filter(common.DomainElement.name == c)\
            .one().description

    return {
        'families':
        ms,
        'macroareas':
        get_parameter('macroarea'),
        'countries':
        countries,
        'map':
        DescStatsMap(language_query(req), req, icon_map, focus, im),
        'icon_map':
        icon_map,
        'focus':
        focus,
        'doctypes': [(de, Icon.from_spec(de.jsondata['icon']))
                     for de in get_parameter('med').domain],
        'endangerments': [(de, Icon.from_spec(de.jsondata['icon']))
                          for de in get_parameter('aes').domain],
    }
Exemple #14
0
 def __call__(self, ctx, req):
     if IValue.providedBy(ctx):
         icon = ctx.domainelement.jsondata['icon']
     elif IValueSet.providedBy(ctx):
         icon = ctx.values[0].domainelement.jsondata['icon']
     elif IDomainElement.providedBy(ctx):
         icon = ctx.jsondata['icon']
     else:
         icon = LanguageByFamilyMapMarker.get_icon(self, ctx, req)
     icon = {
         'cffffff': 'c0077bb',
         'cff0000': 'ccc3311',
         'c0000ff': 'c009988',
         'cffff00': 'cee7733',
     }.get(icon, icon)
     return svg.data_url(svg.icon(icon, opacity=0.8))
Exemple #15
0
    def __call__(self, ctx, req):
        #if ILanguage.providedBy(ctx) or IValueSet.providedBy(ctx):
        #    return req.registry.getUtility(IIcon, 'c{0}'.format(ctx.jsondata['color'])).url(req)
        icon = None
        if ILanguage.providedBy(ctx):
            icon = ctx.languoid.jsondata['icon']
        elif IValue.providedBy(ctx):
            icon = ctx.jsondata['icon']
        elif IValueSet.providedBy(ctx):
            icon = ctx.jsondata['icon']
        if icon:
            try:
                return svg.data_url(svg.icon(icon))
            except:
                raise ValueError(icon)

        return super(GelatoMapMarker, self).__call__(ctx,
                                                     req)  # pragma: no cover
Exemple #16
0
    def __call__(self, ctx, req):
        icon = None

        if interfaces.ILanguage.providedBy(ctx):
            icon = ctx.jsondata['icon']

        if interfaces.IContribution.providedBy(ctx):
            return self.__call__(ctx.language, req)

        if interfaces.IValueSet.providedBy(ctx):
            icon = ctx.languagee.jsondata['icon']

        if interfaces.IValue.providedBy(ctx):
            return self.__call__(ctx.valueset, req)

        if icon:
            return svg.data_url(svg.icon(icon))

        return super(ABVDMapMarker, self).__call__(ctx,
                                                   req)  # pragma: no cover
Exemple #17
0
 def add_language(self, language, values, colormaps, spec=None):
     icon = self._icon(
         [colormaps[pid](vals[0].v) for pid, vals in values.items()])
     props = {
         "name":
         language.name,
         "tooltip":
         language.name,
         "values":
         ' / '.join([
             '{}: {}'.format(pid, vals[0].v)
             for pid, vals in values.items() if vals
         ]),
         "icon":
         svg.data_url(icon),
         "markersize":
         self.args.markersize,
         "tooltip_class":
         "tt",
     }
     if spec:
         if spec.css:
             self.css.add(spec.css)
         props.update({
             k: v
             for k, v in attr.asdict(spec).items()
             if v is not None and k != 'css'
         })
     self.features.append({
         # A language as GeoJSON point with svg marker icon
         "geometry": {
             "coordinates": self._lonlat(language),
             "type": "Point"
         },
         "id": language.id,
         "properties": props,
         "type": "Feature"
     })
Exemple #18
0
    def __call__(self, ctx, req):
        icon = None

        if interfaces.ILanguage.providedBy(ctx):
            icon = ctx.type.jsondata['shape'] + ctx.type.jsondata['color']

        if interfaces.IContribution.providedBy(ctx):
            return self.__call__(ctx.variety, req)

        if interfaces.IValueSet.providedBy(ctx):
            icon = ctx.language.type.jsondata['shape'] + ctx.jsondata['color']

        if interfaces.IValue.providedBy(ctx):
            return self.__call__(ctx.valueset, req)

        if interfaces.IDomainElement.providedBy(ctx):
            icon = 'c' + ctx.jsondata['color']

        if icon:
            return svg.data_url(svg.icon(icon))

        return super(WaveMapMarker, self).__call__(ctx,
                                                   req)  # pragma: no cover
Exemple #19
0
def url(spec):
    return data_url(icon(spec, opacity=0.8))
Exemple #20
0
def icon_url(req, type_):
    return svg.data_url(svg.icon(ICONS[type_]))
Exemple #21
0
 def img(spec):
     return HTML.img(src=svg.data_url(svg.icon(spec)),
                     height='20',
                     width='20',
                     style='margin-left: 0.5em;')
Exemple #22
0
 def __call__(self, ctx, req):
 {% if cookiecutter.cldf_module.lower() == 'wordlist' %}
     if IValueSet.providedBy(ctx):
         if ctx.language.family:
             return data_url(icon(ctx.language.family.jsondata['icon']))
         return data_url(icon(req.registry.settings.get('clld.isolates_icon', util.ISOLATES_ICON)))
Exemple #23
0
 def url(self, req):
     return svg.data_url(svg.icon(self.name))
Exemple #24
0
def tree_data(req,
              species_query,
              experiment_count=lambda s: s.count_experiments):
    node_data = {}
    ntrees = []
    colormap = collections.Counter()
    colormap2 = collections.Counter()
    count_leafs = species_query.count()
    species = species_query.order_by(
        Species.kingdom, Species.phylum_sortkey, Species.klass_sortkey,
        Species.order_sortkey, Species.family_sortkey, Species.genus_sortkey,
        Species.sortkey).options(
            joinedload(common.Language.valuesets).joinedload(
                common.ValueSet.values))
    coverage = {}
    nodes = []

    ngenus = 0
    for kingdom, items1 in itertools.groupby(species, lambda s: s.kingdom):
        node1 = newick.Node()
        for phylum, items2 in itertools.groupby(items1, lambda s: s.phylum):
            nid = '_'.join((phylum, ))
            nodes.append((nid, 'Phylum', 'classes'))
            if phylum not in coverage:
                coverage[phylum] = {}

            node2 = newick.Node(nid)
            for klass, items3 in itertools.groupby(items2, lambda s: s.klass):
                nid = '_'.join((phylum, klass))
                nodes.append((nid, 'Class', 'orders'))
                if klass not in coverage[phylum]:
                    coverage[phylum][klass] = {}

                node3 = newick.Node(nid)
                for order, items4 in itertools.groupby(items3,
                                                       lambda s: s.order):
                    nid = '_'.join((phylum, klass, order))
                    nodes.append((nid, 'Order', 'families'))
                    if order not in coverage[phylum][klass]:
                        coverage[phylum][klass][order] = {}

                    node4 = newick.Node(nid)
                    for family, items5 in itertools.groupby(
                            items4, lambda s: s.family):
                        nid = '_'.join((phylum, klass, order, family))
                        nodes.append((nid, 'Family', 'genera'))
                        if family not in coverage[phylum][klass][order]:
                            coverage[phylum][klass][order][family] = {}

                        node5 = newick.Node(nid)
                        for genus, items6 in itertools.groupby(
                                items5, lambda s: s.genus):
                            ngenus += 1
                            nid = '_'.join(
                                (phylum, klass, order, family, genus))
                            nodes.append((nid, 'Genus', 'species'))

                            items6 = list(items6)
                            coverage[phylum][klass][order][family][
                                genus] = len(items6)

                            colormap.update([s.family for s in items6])
                            colormap2.update([s.klass for s in items6])
                            node6 = newick.Node.create(
                                name=nid,
                                descendants=[
                                    newick.Node(
                                        '%s{__id__%s}' %
                                        (s.name.replace(' ', '_'), s.id))
                                    for s in items6
                                ])
                            node_data.update({
                                s.id: species_node(s, req, experiment_count(s))
                                for s in items6
                            })
                            node5.add_descendant(node6)
                        node4.add_descendant(node5)
                    node3.add_descendant(node4)
                node2.add_descendant(node3)
            node1.add_descendant(node2)
        ntrees.append(node1)

    node_data.update({
        nid: coverage_data(req, nid, rank, subranks, coverage)
        for nid, rank, subranks in nodes
    })

    res = dict(
        count_leafs=count_leafs,
        newick=newick.dumps(ntrees),
        colormap={
            k[0]: (v, svg.data_url(svg.icon(v.replace('#', 'c'))))
            for k, v in zip(colormap.most_common(),
                            color.qualitative_colors(len(colormap)))
        },
        colormap2={
            k[0]: (v, svg.data_url(svg.icon(v.replace('#', 's'))))
            for k, v in zip(colormap2.most_common(),
                            color.qualitative_colors(len(colormap), set='tol'))
        },
        node_data=node_data)
    res['edgecolors'] = {k: v[0] for k, v in res['colormap2'].items()}
    return res
Exemple #25
0
 def marker(colors):
     doc.stag('img',
              src=svg.data_url(self._icon(colors)),
              width="{}".format(min([20, self.args.markersize * 2])))