查询模块提供用于搜索Bokeh模型集合以查找符合指定条件的实例的函数。
EQ
用于测试属性值是否等于某个值的谓词。
建造和 EQ 谓词作为dict EQ 作为键,以及要比较的值。
# matches any models with .size == 10 dict(size={ EQ: 10 })
GEQ
用于测试属性值是否大于或等于某个值的谓词。
建造和 GEQ 谓词作为dict GEQ 作为键,以及要比较的值。
# matches any models with .size >= 10 dict(size={ GEQ: 10 })
GT
用于测试属性值是否大于某个值的谓词。
建造和 GT 谓词作为dict GT 作为键,以及要比较的值。
# matches any models with .size > 10 dict(size={ GT: 10 })
IN
用于测试属性值是否在某个集合中的谓词。
建造和 IN 谓词作为dict IN 作为键,以及要检查的值列表。
# matches any models with .name in ['a', 'mycircle', 'myline'] dict(name={ IN: ['a', 'mycircle', 'myline'] })
LEQ
用于测试属性值是否小于或等于某个值的谓词。
建造和 LEQ 谓词作为dict LEQ 作为键,以及要比较的值。
# matches any models with .size <= 10 dict(size={ LEQ: 10 })
LT
用于测试属性值是否小于某个值的谓词。
建造和 LT 谓词作为dict LT 作为键,以及要比较的值。
# matches any models with .size < 10 dict(size={ LT: 10 })
NEQ
建造和 NEQ 谓词作为dict NEQ 作为键,以及要比较的值。
# matches any models with .size != 10 dict(size={ NEQ: 10 })
OR
形成与其他查询谓词的析取。
构建一个 OR 口述表达 OR 作为键,并将其他查询表达式的列表作为值:
# matches any Axis subclasses or models with .name == "mycircle" { OR: [dict(type=Axis), dict(name="mycircle")] }
find
查询Bokeh模型的集合并生成与a选择器匹配的任何模型。
obj (Model) -- 测试对象
selector (JSON-like) -- 查询选择器
context (dict) -- 提供可调用查询属性的kwargs
模型 --与查询匹配的对象
查询被指定为选择器,类似于MongoDB样式的查询选择器,如所述 match() .
match()
实际案例
# find all objects with type Grid find(p.references(), {'type': Grid}) # find all objects with type Grid or Axis find(p.references(), {OR: [ {'type': Grid}, {'type': Axis} ]}) # same query, using IN operator find(p.references(), {'type': {IN: [Grid, Axis]}}) # find all plot objects on the 'left' layout of the Plot # here layout is a method that takes a plot as context find(p.references(), {'layout': 'left'}, {'plot': p})
match
测试给定的Bokeh模型是否与给定的选择器匹配。
如果对象匹配,则为True,否则为False
bool
通常,选择器的形式如下:
{ attrname : predicate }
其中谓词是由运算符构造的 EQ , GT ,并用于与名为的模型属性的值进行比较 attrname .
attrname
例如:
>>> from bokeh.plotting import figure >>> p = figure(plot_width=400) >>> match(p, {'plot_width': {EQ: 400}}) True >>> match(p, {'plot_width': {GT: 500}}) False
有两个特别处理的选择键。第一个是“type”,它将执行isinstance检查:
>>> from bokeh.plotting import figure >>> from bokeh.models import Axis >>> p = figure() >>> match(p.xaxis[0], {'type': Axis}) True >>> match(p.title, {'type': Axis}) False
还有一个 'tags' 认为 Model 对象具有,即用户提供的值的列表。这个 'tags' 选择器键可用于查询此标记列表。如果选择器中的任何标记与对象上的任何标记匹配,则对象匹配:
'tags'
Model
>>> from bokeh.plotting import figure >>> p = figure(tags = ["my plot", 10]) >>> match(p, {'tags': "my plot"}) True >>> match(p, {'tags': ["my plot", 10]}) True >>> match(p, {'tags': ["foo"]}) False