Skip to content

visualdynamics.plot.truncation

truncation

A truncation drawn on the time history it will be applied to.

A start and a stop time alone do not show whether the kept span covers the part of the record that was intended, so the span is drawn on the plot. The discarded ends are shaded gray, and the kept span can be dragged the same way as the averaging region: by an edge to move that time, or by the middle to slide the whole span along the record.

During a drag only the shading moves. TruncationOverlay.changed is emitted once, when the mouse is released. A locked overlay cannot be dragged, which is what a standalone plot needs: nothing there would keep the span.

Classes:

Name Description
TruncationOverlay

A truncation drawn as marks on a time history plot.

Classes

TruncationOverlay

TruncationOverlay(plot: Any, truncation: Truncation, first: float, last: float, colors: Mapping[str, str], parent: Any = None, locked: bool = False)

Bases: QObject

A truncation drawn as marks on a time history plot.

The overlay owns every item it adds and removes all of them in remove, so a redraw cannot leave shading behind. A drag that leaves a span shorter than a thousandth of the record is undone. Any other finished drag is reported through changed and not acted on here: storing the new span and updating the table are left to whatever created the overlay.

Methods:

Name Description
set_truncation

Move the marks to a span set elsewhere, without emitting changed.

Source code in src/visualdynamics/plot/truncation.py
def __init__(self, plot: Any, truncation: Truncation,
             first: float, last: float,
             colors: Mapping[str, str], parent: Any = None,
             locked: bool = False) -> None:
    super().__init__(parent)
    import pyqtgraph as pg

    self.plot: Any = plot
    self.locked: bool = bool(locked)
    self.truncation: Truncation = truncation
    self.first: float = float(first)
    self.last: float = float(last)
    self.colors: dict[str, str] = dict(colors)
    #: set while this overlay writes its own region, so a
    #: programmatic restate does not read as a drag —
    #: `setRegion` raises both region signals, unlike an
    #: InfiniteLine's `setValue`
    self._restating = False

    shade = QColor(self.colors['specification_curve'])
    shade.setAlpha(SHADE_ALPHA)
    self.shades: list[Any] = []
    for _ in range(2):
        zone = pg.LinearRegionItem(
            values=(self.first, self.first), movable=False,
            brush=pg.mkBrush(shade), pen=pg.mkPen(None))
        zone.setZValue(15)          # over the trace: it dims it
        for line in zone.lines:
            line.setPen(pg.mkPen(None))
        self.plot.addItem(zone, ignoreBounds=True)
        self.shades.append(zone)
    # the span's edges are the handles, the foreground's dashed
    # line — the corner line's own dress, because it is the same
    # kind of thing: a draggable boundary that is not data
    self.region: Any = pg.LinearRegionItem(
        values=(truncation.start, truncation.stop),
        movable=not self.locked,
        brush=pg.mkBrush(QColor(0, 0, 0, 0)),
        pen=pg.mkPen(self.colors['plot_foreground'], width=2),
        hoverPen=pg.mkPen(self.colors['filter_preview'], width=2),
        bounds=(self.first, self.last))
    self.region.setZValue(20)
    self.region.sigRegionChanged.connect(self._dragging)
    self.region.sigRegionChangeFinished.connect(self._dragged)
    self.plot.addItem(self.region, ignoreBounds=True)
    self._shade_ends(truncation.start, truncation.stop)
Methods:
set_truncation
set_truncation(truncation: Truncation) -> None

Move the marks to a span set elsewhere, without emitting changed.

Source code in src/visualdynamics/plot/truncation.py
def set_truncation(self, truncation: Truncation) -> None:
    """Move the marks to a span set elsewhere, without emitting `changed`."""
    self.truncation = truncation
    self._restating = True
    try:
        self.region.setRegion((truncation.start, truncation.stop))
    finally:
        self._restating = False
    self._shade_ends(truncation.start, truncation.stop)