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 ''
def map_marker(ctx, req): """to allow for user-selectable markers, we have to look up a possible custom selection from the url params. """ icon_map = req.registry.settings['icons'] icon = None if IValue.providedBy(ctx): if 'v%s' % ctx.domainelement.number in req.params: icon = icon_map.get(req.params['v%s' % ctx.domainelement.number]) else: icon = ctx.domainelement.jsondata['icon'] elif IDomainElement.providedBy(ctx): if 'v%s' % ctx.number in req.params: icon = icon_map.get(req.params['v%s' % ctx.number]) else: icon = ctx.jsondata['icon'] elif ILanguage.providedBy(ctx): if ctx.genus.id in req.params: icon = icon_map.get(req.params[ctx.genus.id]) else: icon = ctx.genus.icon elif isinstance(ctx, Genus): if ctx.id in req.params: icon = icon_map.get(req.params[ctx.id]) else: icon = ctx.icon if icon: return req.static_url('clld:web/static/icons/' + icon + '.png')
def __call__(self, ctx, req): if IDomainElement.providedBy(ctx): return url('c' + ctx.jsondata['color']) if IValue.providedBy(ctx): if ctx.domainelement: return url('c' + ctx.domainelement.jsondata['color']) if ctx.valueset.language.jsondata['icon']: return url(ctx.valueset.language.jsondata['icon']) if IValueSet.providedBy(ctx): if ctx.values[0].domainelement: return url('c' + ctx.values[0].domainelement.jsondata['color']) if ctx.language.jsondata['icon']: return url(ctx.language.jsondata['icon']) if ctx.language.family: return url(ctx.language.family.jsondata['icon']) return url( req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON)) if ILanguage.providedBy(ctx): icon_ = ctx.jsondata['icon'] return url(icon_) return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
def __call__(self, ctx, req): if IValue.providedBy(ctx): #print ctx.jsondata['family']#,ctx,[self],ctx.domainelement.jsondata['icon'] ##return ctx.domainelement.jsondata['icon'] return req.static_url('lsi:static/icons/' + ctx.jsondata['family'] + ctx.domainelement.jsondata['icon'] + '.png') ##return req.static_url('lsi:static/icons/c000000.png') if IValueSet.providedBy(ctx): #print ctx.domainelement ##return ctx.values[0].domainelement.jsondata['icon'] req.static_url('lsi:static/icons/' + ctx.values[0].domainelement.jsondata['icon'] + '.png') if IDomainElement.providedBy(ctx): ##return None print ctx.jsondata return req.static_url('lsi:static/icons/' + 'cr' + ''.join(ctx.jsondata['icon'][:]) + '.png') ##return ctx.jsondata['icon'] #print LanguageByFamilyMapMarker #print LanguageByFamilyMapMarker.get_icon(self, ctx, req) ##return LanguageByFamilyMapMarker.get_icon(self, ctx, req) return req.static_url( 'lsi:static/icons/' + LanguageByFamilyMapMarker.get_icon(self, ctx, req) + '.png')
def __call__(self, ctx, req): if IDomainElement.providedBy(ctx): return url('c' + ctx.jsondata['color']) if IValue.providedBy(ctx): if ctx.domainelement: return url('c' + ctx.domainelement.jsondata['color']) return url(ctx.valueset.language.family.jsondata['icon']) if IValueSet.providedBy(ctx): # # FIXME: To add genericity, draw a pie chart respecting all values! # if ctx.values[0].domainelement: return url('c' + ctx.values[0].domainelement.jsondata['color']) if ctx.language.family: return url(ctx.language.family.jsondata['icon']) return url( req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON)) if ILanguage.providedBy(ctx): icon_ = super(LanguageByFamilyMapMarker, self).get_icon(ctx, req) if ctx.subgroup: icon_ = ctx.jsondata['shape'] + icon_[1:] return url(icon_) return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
def get_icon(self, ctx, req): if IValue.providedBy(ctx): return ctx.domainelement.jsondata['icon'] if IValueSet.providedBy(ctx): return ctx.values[0].domainelement.jsondata['icon'] if IDomainElement.providedBy(ctx): return ctx.jsondata['icon'] return LanguageByFamilyMapMarker.get_icon(self, ctx, req)
def get_icon(self, ctx, req): """to 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 = ctx.domainelement.jsondata['icon'] elif IDomainElement.providedBy(ctx): icon = ctx.jsondata['icon'] if icon: return icon return super(NtsMapMarker, self).get_icon(ctx, req)
def map_marker(ctx, req): """to allow for user-selectable markers, we have to look up a possible custom selection from the url params. """ icon_map = {i.name: i for i in req.registry.getUtility(IIconList)} 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' + str(ctx.number), ctx.jsondata['icon']) elif ILanguage.providedBy(ctx): icon = ctx.family.jsondata['icon'] if icon and icon in icon_map: return icon_map[icon].url(req)
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')))
def __call__(self, ctx, req): if IDomainElement.providedBy(ctx): return self.svg_icon(ctx) if IValue.providedBy(ctx): if ctx.domainelement_pk: return self.svg_icon(ctx.domainelement) return LanguageByFamilyMapMarker.__call__(self, ctx.valueset.language, req) if IValueSet.providedBy(ctx): if ctx.values[0].domainelement_pk: return self.svg_icon(ctx.values[0].domainelement) return LanguageByFamilyMapMarker.__call__(self, ctx.language, req) if ILanguage.providedBy(ctx): if ctx.family: return data_url(icon(ctx.family.jsondata['icon'])) return data_url(icon(req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON))) return LanguageByFamilyMapMarker.__call__(self, ctx, req)
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))
def map_marker(ctx, req): """to allow for user-selectable markers, we have to look up a possible custom selection from the url params. """ icon_map = {i.name: i for i in req.registry.getUtility(IIconList)} 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' + str(ctx.number), ctx.jsondata['icon']) elif ILanguage.providedBy(ctx): icon = ctx.family.jsondata['icon'] if icon and icon in icon_map: return icon_map[icon].url(req)
def __call__(self, ctx, req): if IValueSet.providedBy(ctx): if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued: return self.pie((100, ctx.values[0].domainelement.jsondata['color'])) return self.pie_from_filename(ctx.jsondata['icon']) if IValue.providedBy(ctx): freq = ctx.frequency or 100 slices = [(freq, ctx.domainelement.jsondata['color'])] if freq < 100: slices.append((100 - freq, 'ffffff')) return self.pie(*slices) if IDomainElement.providedBy(ctx): return self.pie((100, ctx.jsondata['color'])) return super(ApicsMapMarker, self).__call__(ctx, req)
def __call__(self, ctx, req): icon = None if IValueSet.providedBy(ctx): if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued: return '' icon = ctx.jsondata['icon'] if IValue.providedBy(ctx): icon = ctx.domainelement.jsondata['icon'] if IDomainElement.providedBy(ctx): icon = ctx.jsondata['icon'] if icon: return req.static_url('apics:static/icons/%s' % icon) return super(ApicsMapMarker, self).__call__(ctx, req)
def __call__(self, ctx, req): if IValueSet.providedBy(ctx): if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued: return self.pie( (100, ctx.values[0].domainelement.jsondata['color'])) return self.pie_from_filename(ctx.jsondata['icon']) if IValue.providedBy(ctx): freq = ctx.frequency or 100 slices = [(freq, ctx.domainelement.jsondata['color'])] if freq < 100: slices.append((100 - freq, 'ffffff')) return self.pie(*slices) if IDomainElement.providedBy(ctx): return self.pie((100, ctx.jsondata['color'])) return super(ApicsMapMarker, self).__call__(ctx, req)
def map_marker(ctx, req): """to allow for user-selectable markers, we have to look up a possible custom selection from the url params. """ icon_map = {i.name: i for i in req.registry.getUtility(IIconList)} 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 len(icon) == 7: icon = ''.join([icon[i] for i in [0, 2, 4, 6]]) if icon in icon_map: return icon_map[icon].url(req)
def map_marker(ctx, req): """to allow for user-selectable markers, we have to look up a possible custom selection from the url params. """ icon_map = {i.name: i for i in req.registry.getUtility(IIconList)} 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 len(icon) == 7: icon = ''.join([icon[i] for i in [0, 2, 4, 6]]) if icon in icon_map: return icon_map[icon].url(req)