1
0
forked from M-Labs/kirdy

Add pglive patch for setting y-axis min range span

This commit is contained in:
linuswck 2024-10-23 12:24:42 +08:00
parent 49dc8a9b96
commit edb8099a26
2 changed files with 62 additions and 0 deletions

View File

@ -62,6 +62,7 @@
inherit pname version;
hash = "sha256-jqj8X6H1N5mJQ4OrY5ANqRB0YJByqg/bNneEALWmH1A=";
};
patches = ./patches/0001-Add-option-for-setting-min-range-span-for-y-axis.patch;
buildInputs = [ pkgs.python3Packages.poetry-core ];
propagatedBuildInputs = with pkgs.python3Packages; [ pyqtgraph numpy ];
};

View File

@ -0,0 +1,61 @@
From 59a14e06320fd42d56cd7d953da337c0fe4357fa Mon Sep 17 00:00:00 2001
From: linuswck <linuswck@m-labs.hk>
Date: Tue, 22 Oct 2024 17:30:36 +0800
Subject: [PATCH] Add option for setting min range span for y-axis
---
pglive/sources/live_axis_range.py | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/pglive/sources/live_axis_range.py b/pglive/sources/live_axis_range.py
index afbd806..9b62ba5 100644
--- a/pglive/sources/live_axis_range.py
+++ b/pglive/sources/live_axis_range.py
@@ -5,7 +5,7 @@ from typing import Optional, List, Tuple, Dict
class LiveAxisRange:
def __init__(self, roll_on_tick: int = 1, offset_left: float = 0., offset_right: float = 0., offset_top: float = 0.,
- offset_bottom: float = 0., fixed_range: Optional[List[float]] = None) -> None:
+ offset_bottom: float = 0., fixed_range: Optional[List[float]] = None, min_y_range_span: Optional[List[float]] = [None, None]) -> None:
self.roll_on_tick = roll_on_tick
self.offset_left = offset_left
self.offset_right = offset_right
@@ -21,6 +21,7 @@ class LiveAxisRange:
self.final_x_range = [0., 0.]
self.final_y_range = [0., 0.]
self.ignored_data_connectors: List[str] = []
+ self.min_y_range_span = min_y_range_span
def get_x_range(self, data_connector, tick: int) -> List[float]:
x, _ = data_connector.plot.getData()
@@ -116,6 +117,13 @@ class LiveAxisRange:
# therefore in that case we must set some range
final_range[0] -= 0.4
final_range[1] += 0.4
+
+ if self.min_y_range_span[0] is not None:
+ final_range[0] = min(self.min_y_range_span[0], final_range[0])
+
+ if self.min_y_range_span[1] is not None:
+ final_range[1] = max(self.min_y_range_span[1], final_range[1])
+
if self.final_y_range != final_range:
self.final_y_range = final_range
return self.final_y_range
@@ -139,6 +147,13 @@ class LiveAxisRange:
# therefore in that case we must set some range
final_range[0] -= 0.4
final_range[1] += 0.4
+
+ if self.min_y_range_span[0] is not None:
+ final_range[0] = min(self.min_y_range_span[0], final_range[0])
+
+ if self.min_y_range_span[1] is not None:
+ final_range[1] = max(self.min_y_range_span[1], final_range[1])
+
if self.final_y_range != final_range:
self.final_y_range = final_range
return self.final_y_range
--
2.44.1