step 4: add digital bar level and status gauges
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import math
|
||||
from collections.abc import Sequence
|
||||
from typing import Literal
|
||||
|
||||
from .exceptions import GaugeConfigError, GaugeValueError
|
||||
from .types import GaugeMarker, ThresholdBand
|
||||
@@ -59,6 +60,29 @@ def fill_fraction(value: float, min_value: float, max_value: float, *, clamp: bo
|
||||
return normalize_value(value, min_value, max_value, clamp=clamp)
|
||||
|
||||
|
||||
def fill_span(
|
||||
value: float,
|
||||
min_value: float,
|
||||
max_value: float,
|
||||
*,
|
||||
fill_mode: Literal["clamp", "centered"] = "clamp",
|
||||
clamp: bool = True,
|
||||
) -> tuple[float, float]:
|
||||
fraction = fill_fraction(value, min_value, max_value, clamp=clamp)
|
||||
if fill_mode == "clamp":
|
||||
return 0.0, fraction
|
||||
zero = fill_fraction(0.0, min_value, max_value, clamp=True)
|
||||
return min(zero, fraction), max(zero, fraction)
|
||||
|
||||
|
||||
def normalized_span(
|
||||
start: float, end: float, min_value: float, max_value: float
|
||||
) -> tuple[float, float]:
|
||||
first = fill_fraction(start, min_value, max_value, clamp=True)
|
||||
second = fill_fraction(end, min_value, max_value, clamp=True)
|
||||
return min(first, second), max(first, second)
|
||||
|
||||
|
||||
def generate_ticks(min_value: float, max_value: float, count: int) -> list[float]:
|
||||
validate_range(min_value, max_value)
|
||||
if count < 2:
|
||||
|
||||
Reference in New Issue
Block a user