get_data_items
FunctionSource
items: [AnnoItem] = get_data_items(
    data: Annotations | [AnnoItem],
    comment: str | None = None,
    n: int | None = None,
)
Get one or several annotation items by exactly matching the comment.
Note that this method will not validate the format of each returned annotation items. Not well-formatted items will STILL be returned.
Aliases
This function can be acquired by
import dash_picture_annotation as dpa
dpa.get_data_items
dpa.utilities.get_data_items
Arguments
Requires
| Argument | Type | Required | |
|---|---|---|---|
data | Annotations | [AnnoItem] | The annotation data that is queried. | |
comment | str | None | The comment of the annoatations to be selected. This value will be exactly matched in the data, which means that it is space- and case-sensitive. If using   | |
n | int | None | Limit the maximal number of the items to be found. If not provided, will try to return all annotation items with a specified  Specifying a non-positive value will cause this number to be ignored.  | 
Returns
| Argument | Type | |
|---|---|---|
items | [AnnoItem] | The located annotation items. Modifying the content of these items will cause the data to be modified. | 
Examples
Get an annotation item by quering the comment
- Codes
 - Results
 
get_anno_items_by_comment.py
import pprint
import dash_picture_annotation as dpa
mark = lambda pos: {"x": pos, "y": pos, "width": 0, "height": 0, "type": "RECT"}
data = [
    {"id": "a", "mark": mark(0)},
    {"id": "b", "mark": mark(1)},
    {"id": "c", "mark": mark(2), "comment": "type-1"},
    {"id": "d", "mark": mark(3), "comment": "type-2"},
    {"id": "d", "mark": mark(4), "comment": "type-2"},
]
data_wrapped = {"timestamp": 0, "data": data}
pprint.pprint(dpa.get_data_items(data))
pprint.pprint(dpa.get_data_items(data_wrapped))
pprint.pprint(dpa.get_data_items(data, "type-1"))
pprint.pprint(dpa.get_data_items(data_wrapped, "type-1"))
pprint.pprint(dpa.get_data_items(data, "type-2"))
pprint.pprint(dpa.get_data_items(data_wrapped, "type-2"))
pprint.pprint(dpa.get_data_items(data, "type-2", 1))
pprint.pprint(dpa.get_data_items(data_wrapped, "type-2", 1))
try:
    pprint.pprint(dpa.get_data_item(data, "type-3"))
except KeyError as e:
    print(e)
({'id': 'a', 'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 0, 'y': 0}},
 {'id': 'b', 'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 1, 'y': 1}})
({'id': 'a', 'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 0, 'y': 0}},
 {'id': 'b', 'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 1, 'y': 1}})
({'comment': 'type-1',
  'id': 'c',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 2, 'y': 2}},)
({'comment': 'type-1',
  'id': 'c',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 2, 'y': 2}},)
({'comment': 'type-2',
  'id': 'd',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 3, 'y': 3}},
 {'comment': 'type-2',
  'id': 'd',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 4, 'y': 4}})
({'comment': 'type-2',
  'id': 'd',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 3, 'y': 3}},
 {'comment': 'type-2',
  'id': 'd',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 4, 'y': 4}})
({'comment': 'type-2',
  'id': 'd',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 3, 'y': 3}},)
({'comment': 'type-2',
  'id': 'd',
  'mark': {'height': 0, 'type': 'RECT', 'width': 0, 'x': 3, 'y': 3}},)
'The ID "type-3" is not found in the data.'