bokeh.core.query#

查询模块提供了用于搜索符合指定条件的Bokeh模型实例的函数。

class EQ[source]#

用于测试属性值是否等于某个值的谓词。

构造一个EQ谓词作为字典,其中EQ作为键,并提供一个值进行比较。

# matches any models with .size == 10
dict(size={ EQ: 10 })
class GEQ[source]#

用于测试属性值是否大于或等于某个值的谓词。

构造一个GEQ谓词作为字典,其中GEQ作为键,并提供一个值进行比较。

# matches any models with .size >= 10
dict(size={ GEQ: 10 })
class GT[source]#

用于测试属性值是否大于某个值的谓词。

构造一个GT谓词作为字典,其中GT作为键,并提供一个值进行比较。

# matches any models with .size > 10
dict(size={ GT: 10 })
class IN[source]#

用于测试属性值是否在某个集合中的谓词。

构造一个IN谓词作为字典,其中IN作为键,并提供一个要检查的值列表。

# matches any models with .name in ['a', 'mycircle', 'myline']
dict(name={ IN: ['a', 'mycircle', 'myline'] })
class LEQ[source]#

用于测试属性值是否小于或等于某个值的谓词。

构造一个LEQ谓词作为字典,其中LEQ作为键,并提供一个值进行比较。

# matches any models with .size <= 10
dict(size={ LEQ: 10 })
class LT[source]#

用于测试属性值是否小于某个值的谓词。

构造一个LT谓词作为字典,其中LT作为键,并提供一个值进行比较。

# matches any models with .size < 10
dict(size={ LT: 10 })
class NEQ[source]#

用于测试属性值是否不等于某个值的谓词。

构造一个NEQ谓词作为字典,其中NEQ作为键,并提供一个值进行比较。

# matches any models with .size != 10
dict(size={ NEQ: 10 })
class OR[源代码]#

从其他查询谓词中形成析取。

通过创建一个以OR为键,其他查询表达式列表为值的字典来构造一个OR表达式:

# matches any Axis subclasses or models with .name == "mycircle"
{ OR: [dict(type=Axis), dict(name="mycircle")] }
find(objs: Iterable[Model], selector: dict[str | type[_Operator], Any]) Iterable[Model][source]#

查询一组Bokeh模型并生成与选择器匹配的任何模型。

Parameters:
  • objs (Iterable[Model]) – 要测试的模型对象

  • selector (JSON-like) – 查询选择器

Yields:

模型 – 符合查询条件的对象

查询被指定为类似于MongoDB风格的查询选择器,如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]}})
is_single_string_selector(selector: dict[str | type[_Operator], Any], field: str) bool[source]#

选择器是否是一个简单的单字段,例如 {name: "foo"}

Parameters:
  • selector (JSON-like) – 查询选择器

  • field (str) – 要检查的字段名称

Returns

布尔

match(obj: Model, selector: dict[str | type[_Operator], Any]) bool[source]#

测试给定的Bokeh模型是否匹配给定的选择器。

Parameters:
  • obj (Model) – 要测试的对象

  • selector (JSON-like) – 查询选择器

Returns:

如果对象匹配则为真,否则为假

Return type:

bool

通常,选择器具有以下形式:

{ attrname : predicate }

其中谓词由运算符EQGT等构建,并用于与名为attrname的模型属性值进行比较。

例如:

>>> from bokeh.plotting import figure
>>> p = figure(width=400)

>>> match(p, {'width': {EQ: 400}})
True

>>> match(p, {'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'选择器键可以用来查询这个标签列表。如果选择器中的任何标签与对象上的任何标签匹配,则对象匹配:

>>> 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