sanitize_data_item
FunctionSource
sanitized_item: AnnoItem | None = sanitize_data_item(data_item: AnnoItem | AnnoMark)
Perform the full sanitization on an annotation item.
The sanitization will ensure that:
- The result is a dictionary typed by
AnnoItem
. - A
None
value comment will be removed. - The position of the annotation mark will always have positive width and height. (Negative values means that the starting location is reversed.)
- If no ID is specified, will return a randomly generated 6-character ID.
Aliases
This function can be acquired by
import dash_picture_annotation as dpa
dpa.sanitize_data_item
dpa.utilities.sanitize_data_item
Arguments
Requires
Argument | Type | Required | |
---|---|---|---|
data_item | AnnoItem | AnnoMark | The annotation item data to be sanitized. If the data_item is just a mark, will add ID for it. |
Returns
Argument | Type | |
---|---|---|
sanitized_item | AnnoItem | None | The sanitized copy of the data item. Will return None if the given data cannot be sanitized. |
Examples
Sanitize a data item
- Codes
- Results
sanitize_data_item.py
import pprint
import dash_picture_annotation as dpa
mark = lambda pos: {"x": pos, "y": 0, "width": 0, "height": pos, "type": "RECT"}
mark_eq = lambda pos: {"x": pos, "y": pos, "width": 0, "height": -pos, "type": "RECT"}
pprint.pprint(dpa.sanitize_data_item(mark(17.7)))
pprint.pprint(dpa.sanitize_data_item(mark_eq(17.7)))
pprint.pprint(dpa.sanitize_data_item({"mark": mark(-17.7), "comment": "test"}))
{'id': '1f0ef8',
'mark': {'height': 17.7, 'type': 'RECT', 'width': 0, 'x': 17.7, 'y': 0}}
{'id': '2b672d',
'mark': {'height': 17.7, 'type': 'RECT', 'width': 0, 'x': 17.7, 'y': 0.0}}
{'comment': 'test',
'id': 'efbef4',
'mark': {'height': 17.7, 'type': 'RECT', 'width': 0, 'x': -17.7, 'y': -17.7}}