Skip to main content

get_data_item

FunctionSource

item: AnnoItem = get_data_item(
data: Annotations | [AnnoItem],
id: str,
)

Get an annotation item by its unique ID.

Note that this method will not validate the format of data. If the item cannot be found, will raise a KeyError.

Aliases

This function can be acquired by

import dash_picture_annotation as dpa


dpa.get_data_item
dpa.utilities.get_data_item

Arguments

Requires

ArgumentTypeRequired
Description
dataAnnotations | [AnnoItem]The annotation data that is queried.
idstrThe ID of the annotation item to be found.

Returns

ArgumentType
Description
itemAnnoItemThe queried value. If not found, raise an KeyError.

Examples

Get an annotation item by quering its ID

get_anno_item_by_id.py
import pprint
import dash_picture_annotation as dpa


data = [
{"id": "a", "mark": {"x": 0, "y": 0, "width": 0, "height": 0, "type": "RECT"}},
{"id": "b", "mark": {"x": 0, "y": 0, "width": 0, "height": 0, "type": "RECT"}},
{"id": "c", "mark": {"x": 0, "y": 0, "width": 0, "height": 0, "type": "RECT"}},
{"id": "c", "mark": {"x": 1, "y": 1, "width": 0, "height": 0, "type": "RECT"}},
]

data_wrapped = {"timestamp": 0, "data": data}

pprint.pprint(dpa.get_data_item(data, "a"))
pprint.pprint(dpa.get_data_item(data_wrapped, "a"))
pprint.pprint(dpa.get_data_item(data, "c"))
pprint.pprint(dpa.get_data_item(data_wrapped, "c"))
try:
pprint.pprint(dpa.get_data_item(data, "d"))
except KeyError as e:
print(e)