|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -from typing import Any |
| 3 | +from typing import Any, overload |
| 4 | + |
| 5 | +from rerun.datatypes.visible_time_range import VisibleTimeRange |
4 | 6 |
|
5 | 7 | from ... import datatypes
|
6 | 8 | from ...error_utils import _send_warning_or_raise, catch_and_log_exceptions
|
|
9 | 11 | class VisibleTimeRangesExt:
|
10 | 12 | """Extension for [VisibleTimeRanges][rerun.blueprint.archetypes.VisibleTimeRanges]."""
|
11 | 13 |
|
12 |
| - def __init__(self: Any, ranges: datatypes.VisibleTimeRangeArrayLike) -> None: |
| 14 | + @overload |
| 15 | + def __init__(self: Any, ranges: datatypes.VisibleTimeRangeArrayLike) -> None: ... |
| 16 | + |
| 17 | + @overload |
| 18 | + def __init__( |
| 19 | + self: Any, |
| 20 | + *, |
| 21 | + timeline: datatypes.Utf8Like, |
| 22 | + range: datatypes.TimeRangeLike, |
| 23 | + ) -> None: ... |
| 24 | + |
| 25 | + @overload |
| 26 | + def __init__( |
| 27 | + self: Any, |
| 28 | + *, |
| 29 | + timeline: datatypes.Utf8Like, |
| 30 | + start: datatypes.TimeRangeBoundary, |
| 31 | + end: datatypes.TimeRangeBoundary, |
| 32 | + ) -> None: ... |
| 33 | + |
| 34 | + def __init__( |
| 35 | + self: Any, |
| 36 | + ranges: datatypes.VisibleTimeRangeArrayLike | None = None, |
| 37 | + *, |
| 38 | + timeline: datatypes.Utf8Like | None = None, |
| 39 | + range: datatypes.TimeRangeLike | None = None, |
| 40 | + start: datatypes.TimeRangeBoundary | None = None, |
| 41 | + end: datatypes.TimeRangeBoundary | None = None, |
| 42 | + ) -> None: |
13 | 43 | """
|
14 | 44 | Create a new instance of the VisibleTimeRanges archetype.
|
15 | 45 |
|
| 46 | + Either from a list of `VisibleTimeRange` objects, or from a single `timeline`-name plus either `range` or `start` & `end`. |
| 47 | +
|
16 | 48 | Parameters
|
17 | 49 | ----------
|
18 | 50 | ranges:
|
19 | 51 | The time ranges to show for each timeline unless specified otherwise on a per-entity basis.
|
20 | 52 |
|
21 | 53 | If a timeline is listed twice, a warning will be issued and the first entry will be used.
|
22 | 54 |
|
| 55 | + timeline: |
| 56 | + The name of the timeline to show. |
| 57 | + Mutually exclusive with `ranges`. |
| 58 | + range: |
| 59 | + The range of the timeline to show. |
| 60 | + Requires `timeline` to be set. Mutually exclusive with `start` & `end`. |
| 61 | + start: |
| 62 | + The start of the timeline to show. |
| 63 | + Requires `timeline` to be set. Mutually exclusive with `range`. |
| 64 | + end: |
| 65 | + The end of the timeline to show. |
| 66 | + Requires `timeline` to be set. Mutually exclusive with `range`. |
| 67 | +
|
23 | 68 | """
|
24 | 69 |
|
25 |
| - if isinstance(ranges, datatypes.VisibleTimeRange): |
26 |
| - ranges = [ranges] |
| 70 | + with catch_and_log_exceptions(context=self.__class__.__name__): |
| 71 | + if timeline is not None: |
| 72 | + if ranges is not None: |
| 73 | + raise ValueError("`timeline` and `ranges` are mutually exclusive.") |
| 74 | + ranges = [VisibleTimeRange(timeline=timeline, range=range, start=start, end=end)] |
| 75 | + elif ranges is None: |
| 76 | + raise ValueError("Either `ranges` or `timeline` must be set.") |
27 | 77 |
|
28 |
| - timelines = set() |
29 |
| - for range in ranges: |
30 |
| - if range.timeline in timelines: |
31 |
| - _send_warning_or_raise( |
32 |
| - f"Warning: Timeline {range.timeline} is listed twice in the list of visible time ranges. Only the first entry will be used.", |
33 |
| - 1, |
34 |
| - ) |
35 |
| - timelines.add(range.timeline) |
| 78 | + if isinstance(ranges, datatypes.VisibleTimeRange): |
| 79 | + ranges = [ranges] |
| 80 | + |
| 81 | + timelines = set() |
| 82 | + for visible_time_range in ranges: |
| 83 | + if visible_time_range.timeline in timelines: |
| 84 | + _send_warning_or_raise( |
| 85 | + f"Warning: Timeline {visible_time_range.timeline} is listed twice in the list of visible time ranges. Only the first entry will be used.", |
| 86 | + 1, |
| 87 | + ) |
| 88 | + timelines.add(visible_time_range.timeline) |
36 | 89 |
|
37 |
| - with catch_and_log_exceptions(context=self.__class__.__name__): |
38 | 90 | self.__attrs_init__(ranges=ranges)
|
39 | 91 | return
|
| 92 | + |
40 | 93 | self.__attrs_clear__()
|
0 commit comments