Source code for bokeh.models.renderers.glyph_renderer
#-----------------------------------------------------------------------------# 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.#-----------------------------------------------------------------------------''''''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromdifflibimportget_close_matchesfromtypingimportLiteral# Bokeh importsfrom...core.propertiesimport(Auto,Bool,Either,Instance,InstanceDefault,Nullable,)from...core.validationimporterrorfrom...core.validation.errorsimport(BAD_COLUMN_NAME,CDSVIEW_FILTERS_WITH_CONNECTED,MISSING_GLYPH,NO_SOURCE_FOR_GLYPH,)from..filtersimportAllIndicesfrom..glyphsimportConnectedXYGlyph,Glyphfrom..graphicsimportDecoration,Markingfrom..sourcesimport(CDSView,ColumnDataSource,DataSource,WebDataSource,)from.rendererimportDataRenderer#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=("GlyphRenderer",)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classGlyphRenderer(DataRenderer):''' '''# explicit __init__ to support Init signaturesdef__init__(self,*args,**kwargs)->None:super().__init__(*args,**kwargs)@error(CDSVIEW_FILTERS_WITH_CONNECTED)def_check_cdsview_filters_with_connected(self):ifisinstance(self.glyph,ConnectedXYGlyph)andnotisinstance(self.view.filter,AllIndices):returnstr(self)@error(MISSING_GLYPH)def_check_missing_glyph(self):ifnotself.glyph:returnstr(self)@error(NO_SOURCE_FOR_GLYPH)def_check_no_source_for_glyph(self):ifnotself.data_source:returnstr(self)@error(BAD_COLUMN_NAME)def_check_bad_column_name(self):ifnotself.glyph:returnifnotself.data_source:returnifisinstance(self.data_source,WebDataSource):returnmissing_values=set()specs=self.glyph.dataspecs()forname,iteminself.glyph.properties_with_values(include_defaults=False).items():ifnamenotinspecs:continueifnotisinstance(item,dict):continueifnotisinstance(self.data_source,ColumnDataSource):continueif'field'initemanditem['field']notinself.data_source.column_names:missing_values.add((item['field'],name))ifmissing_values:suggestions=['" (closest match: "%s")'%s[0]ifselse'"'forsin[get_close_matches(term[0],self.data_source.column_names,n=1)forterminmissing_values]]missing_values=[("".join([m[0],s]),m[1])form,sinzip(missing_values,suggestions)]missing=['key "%s" value "%s'%(k,v)forv,kinmissing_values]return"%s [renderer: %s]"%(", ".join(sorted(missing)),self)data_source=Instance(DataSource,help=""" Local data source to use when rendering glyphs on the plot. """)view=Instance(CDSView,default=InstanceDefault(CDSView),help=""" A view into the data source to use when rendering glyphs. A default view of the entire data source is created when a view is not passed in during initialization. .. note: Only the default (filterless) CDSView is compatible with glyphs that have connected topology, such as Line and Patch. Setting filters on views for these glyphs will result in a warning and undefined behavior. """)glyph=Instance(Glyph,help=""" The glyph to render, in conjunction with the supplied data source and ranges. """)selection_glyph=Nullable(Either(Auto,Instance(Glyph)),default="auto",help="""" An optional glyph used for selected points. If set to "auto" then the standard glyph will be used for selected points. """)nonselection_glyph=Nullable(Either(Auto,Instance(Glyph)),default="auto",help="""" An optional glyph used for explicitly non-selected points (i.e., non-selected when there are other points that are selected, but not when no points at all are selected.) If set to "auto" then a glyph with a low alpha value (0.1) will be used for non-selected points. """)hover_glyph=Nullable(Instance(Glyph),help=""" An optional glyph used for inspected points, e.g., those that are being hovered over by a ``HoverTool``. """)muted_glyph=Nullable(Either(Auto,Instance(Glyph)),default="auto",help="""" """)muted=Bool(False,help=""" """)defadd_decoration(self,marking:Marking,node:Literal["start","middle","end"])->Decoration:glyphs=[self.glyph,self.selection_glyph,self.nonselection_glyph,self.hover_glyph,self.muted_glyph]decoration=Decoration(marking=marking,node=node)forglyphinglyphs:ifisinstance(glyph,Glyph):glyph.decorations.append(decoration)returndecoration
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------