#-----------------------------------------------------------------------------# Copyright (c) 2012 - 2022, Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Display a variety of visual shapes whose attributes can be associatedwith data columns from ``ColumnDataSources``.All these glyphs share a minimal common interface through their base class``Glyph``:.. autoclass:: Glyph :members:'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfrominspectimportParameter# Bokeh importsfrom..core.has_propsimportabstractfrom..core.property._sphinximporttype_linkfrom..modelimportModel#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('ConnectedXYGlyph','Glyph','XYGlyph',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]@abstractclassGlyph(Model):''' Base class for all glyph models. '''# a canonical order for positional args that can be# used for any functions derived from this class_args=()_extra_kws={}
[docs]@classmethoddefparameters(cls):''' Generate Python ``Parameter`` values suitable for functions that are derived from the glyph. Returns: list(Parameter) '''arg_params=[]no_more_defaults=Falseforarginreversed(cls._args):descriptor=cls.lookup(arg)default=descriptor.class_default(cls)ifdefaultisNone:no_more_defaults=True# simplify field(x) defaults to just present the column nameifisinstance(default,dict)andset(default)=={"field"}:default=default["field"]# make sure we don't hold on to references to actual Modelsifisinstance(default,Model):default=_ModelRepr(default)param=Parameter(name=arg,kind=Parameter.POSITIONAL_OR_KEYWORD,# For positional arg properties, default=None means no default.default=Parameter.emptyifno_more_defaultselsedefault)ifdefault:deldefaulttyp=type_link(descriptor.property)arg_params.insert(0,(param,typ,descriptor.__doc__))# these are not really useful, and should also really be private, just skip themomissions={'js_event_callbacks','js_property_callbacks','subscribed_events'}kwarg_params=[]kws=set(cls.properties())-set(cls._args)-omissionsforkwinkws:descriptor=cls.lookup(kw)default=descriptor.class_default(cls)# simplify field(x) defaults to just present the column nameifisinstance(default,dict)andset(default)=={"field"}:default=default["field"]# make sure we don't hold on to references to actual Modelsifisinstance(default,Model):default=_ModelRepr(default)param=Parameter(name=kw,kind=Parameter.KEYWORD_ONLY,default=default)deldefaulttyp=type_link(descriptor.property)kwarg_params.append((param,typ,descriptor.__doc__))forkw,(typ,doc)incls._extra_kws.items():param=Parameter(name=kw,kind=Parameter.KEYWORD_ONLY,)kwarg_params.append((param,typ,doc))kwarg_params.sort(key=lambdax:x[0].name)returnarg_params+kwarg_params
@abstractclassXYGlyph(Glyph):''' Base class of glyphs with `x` and `y` coordinate attributes. '''@abstractclassConnectedXYGlyph(XYGlyph):''' Base class of glyphs with `x` and `y` coordinate attributes and a connected topology. '''@abstractclassLineGlyph(Glyph):''' Glyphs with line properties '''@abstractclassFillGlyph(Glyph):''' Glyphs with fill properties '''@abstractclassTextGlyph(Glyph):''' Glyphs with text properties '''@abstractclassHatchGlyph(Glyph):''' Glyphs with Hatch properties '''#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------class_ModelRepr:''' This proxy is for storing reprs of Bokeh models that are property defaults, so that holding references to those Models may be avoided. '''def__init__(self,model:Model)->None:self._repr=repr(model)def__repr__(self)->str:returnself._repr#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------