Skip to main content
Version: 0.2.1

sanitize_scale

FunctionSource

sanitized_scale: Scale = sanitize_scale(
scale: float | Mapping[str, Any],
offset_x: float | None = None,
offset_y: float | None = None,
)

Perform the sanitization on the annotated image scaling factor.

The sanitization will ensure that:

  1. A dictionary containing at least the scaling ratio will be returned.
  2. Optional offsets can be configured.
  3. A timestamp will be attached to the sanitized configuration. It ensures that the scaling event will be always triggered even if the configuration does not change.

Aliases

This function can be acquired by

import dash_picture_annotation as dpa


dpa.sanitize_scale
dpa.utilities.sanitize_scale

Arguments

Requires

ArgumentTypeRequired
Description
scalefloat | Mapping[str, Any]The scaling factor value (float) or a full scaling configuration dictionary.
offset_xfloat | NoneThe relative offset ratio along the X axis. This value will be added to the returned value only when it is configured and "offset_x" is not configured in scale.
offset_yfloat | NoneThe relative offset ratio along the Y axis. This value will be added to the returned value only when it is configured and "offset_y" is not configured in scale.

Returns

ArgumentType
Description
sanitized_scaleScaleThe santized scaling factor with a newly configured timestamp.

Examples

Sanitize a scale

sanitize_scale.py
import pprint
import dash_picture_annotation as dpa


pprint.pprint(dpa.sanitize_scale(1.0))
pprint.pprint(dpa.sanitize_scale(1.0, offset_x=0.1, offset_y=0.9))
pprint.pprint(dpa.sanitize_scale({"scale": 0.8, "offset_x": 0.1}, offset_y=0.9))
pprint.pprint(dpa.sanitize_scale({"scale": 0.8, "offset_x": 0.1}, offset_x=0.3, offset_y=0.9))