feat(plot): lock axes and calculate marker levels in dB
This commit is contained in:
@@ -30,3 +30,5 @@ data class PlotBounds(val left: Double, val right: Double, val bottom: Double, v
|
||||
|
||||
fun plotTickStep(range: Double, pixels: Double): Double = NativePlot.call(5, range, pixels)[0]
|
||||
fun plotDelta(a: Double, b: Double, multiplier: Double = 1.0): Double = NativePlot.call(6, a, b, multiplier)[0]
|
||||
fun plotDbDelta(a: Double, b: Double): Double? =
|
||||
runCatching { NativePlot.call(7, a, b)[0] }.getOrNull()
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package ru.setcorp.setprotocol.trends
|
||||
|
||||
/** Normalized top-left viewport; independent of pixels, units, toolkit and samples. */
|
||||
data class PlotViewport(val x: Double = 0.0, val y: Double = 0.0, val width: Double = 1.0, val height: Double = 1.0) {
|
||||
data class PlotViewport(val x: Double = 0.0, val y: Double = 0.0, val width: Double = 1.0, val height: Double = 1.0,
|
||||
val locked: Boolean = false) {
|
||||
fun transform(zoomX: Double = 1.0, zoomY: Double = 1.0, panX: Double = 0.0, panY: Double = 0.0,
|
||||
focusX: Double = 0.5, focusY: Double = 0.5): PlotViewport {
|
||||
if (locked) return this
|
||||
val result = NativePlot.call(0, x, y, width, height, zoomX, zoomY, panX, panY, focusX, focusY)
|
||||
return PlotViewport(result[0], result[1], result[2], result[3])
|
||||
return PlotViewport(result[0], result[1], result[2], result[3], locked)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,4 +37,12 @@ class PlotContractTest {
|
||||
val crossed = markers.move(TrendMarker.A, 1900.0).move(TrendMarker.B, 1100.0)
|
||||
assertEquals(-800.0, plotDelta(crossed.a!!, crossed.b!!), 0.0)
|
||||
}
|
||||
|
||||
@Test fun lockedViewportIgnoresZoomAndPanAndDbUsesAmplitudeRatio() {
|
||||
val locked = PlotViewport(locked = true)
|
||||
assertEquals(locked, locked.transform(zoomX = 2.0, panY = 0.2))
|
||||
assertEquals(20.0, plotDbDelta(1.0, 10.0)!!, 1e-10)
|
||||
assertEquals(-20.0, plotDbDelta(10.0, 1.0)!!, 1e-10)
|
||||
assertNull(plotDbDelta(0.0, 1.0))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user