Skip to main content

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:

  1. The result is a dictionary typed by AnnoItem.
  2. A None value comment will be removed.
  3. The position of the annotation mark will always have positive width and height. (Negative values means that the starting location is reversed.)
  4. 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

ArgumentTypeRequired
Description
data_itemAnnoItem | AnnoMarkThe annotation item data to be sanitized. If the data_item is just a mark, will add ID for it.

Returns

ArgumentType
Description
sanitized_itemAnnoItem | NoneThe sanitized copy of the data item. Will return None if the given data cannot be sanitized.

Examples

Sanitize a data item

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"}))