feat(plot): lock axes and calculate marker levels in dB
This commit is contained in:
@@ -61,6 +61,12 @@ class PlotMath:
|
||||
def delta(self, a: float, b: float, multiplier: float = 1) -> float:
|
||||
return self.call(6, a, b, multiplier)[0]
|
||||
|
||||
def db_delta(self, a: float, b: float) -> Optional[float]:
|
||||
try:
|
||||
return self.call(7, a, b)[0]
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Viewport:
|
||||
@@ -68,12 +74,15 @@ class Viewport:
|
||||
y: float = 0.0
|
||||
width: float = 1.0
|
||||
height: float = 1.0
|
||||
locked: bool = False
|
||||
|
||||
def transform(self, core: PlotMath, zoom_x: float = 1, zoom_y: float = 1,
|
||||
pan_x: float = 0, pan_y: float = 0,
|
||||
focus_x: float = 0.5, focus_y: float = 0.5) -> "Viewport":
|
||||
if self.locked:
|
||||
return self
|
||||
return Viewport(*core.call(0, self.x, self.y, self.width, self.height,
|
||||
zoom_x, zoom_y, pan_x, pan_y, focus_x, focus_y))
|
||||
zoom_x, zoom_y, pan_x, pan_y, focus_x, focus_y), locked=self.locked)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
@@ -50,6 +50,13 @@ class PlotTests(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
self.core.pinch_axis(value, 10, 8)
|
||||
|
||||
def test_locked_viewport_and_decibel_delta(self):
|
||||
locked = Viewport(locked=True)
|
||||
self.assertEqual(locked, locked.transform(self.core, zoom_x=2, pan_y=.2))
|
||||
self.assertAlmostEqual(20, self.core.db_delta(1, 10))
|
||||
self.assertAlmostEqual(-20, self.core.db_delta(10, 1))
|
||||
self.assertIsNone(self.core.db_delta(0, 1))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user