Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debounce with coroutines #1107

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'refs/heads/master' into debounce-with-coroutines
# Conflicts:
#	plot-builder/src/commonMain/kotlin/org/jetbrains/letsPlot/core/plot/builder/PlotTile.kt
#	plot-builder/src/commonMain/kotlin/org/jetbrains/letsPlot/core/plot/builder/interact/PlotToolEventDispatcher.kt
  • Loading branch information
IKupriyanov-HORIS committed Jun 3, 2024
commit 55ed4ede142fbd16656e6c9bd8a7bf675ea48e94
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,9 @@ internal class PlotTile(
}

inner class InteractionSupport {
var scale = 1.0
private set
var pan = DoubleVector.ZERO // total offset in pixels at scale = 1.0
private set
private val geomContentBounds = tileLayoutInfo.geomContentBounds
private var scale = DoubleVector(1.0, 1.0) // scale factor
private var pan = DoubleVector.ZERO // total offset in pixels at scale = 1.0

fun updateTransform(scaleDelta: DoubleVector, panDelta: DoubleVector) {
pan = DoubleVector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ internal class PlotToolEventDispatcher(
deactivateOverlappingInteractions(origin, interactionSpec)

val interactionName = interactionSpec.getValue(ToolInteractionSpec.NAME) as String
val debouncedWheelZoom =
debounce<Pair<DoubleRectangle, InteractionTarget>>(500, CoroutineScope(Dispatchers.Default)) { (rect, _) ->
println("Wheel zoom tool: apply: $rect")
val completeInteractionDebounced =
debounce<DoubleRectangle>(500, CoroutineScope(Dispatchers.Default)) { dataBounds ->
println("Wheel zoom tool: apply: $dataBounds")
completeInteraction(origin, interactionName, dataBounds)
}

// ToDo: sent "completed" event in "onCompleted"
val feedback = when (interactionName) {
ToolInteractionSpec.DRAG_PAN -> PanGeomFeedback(
Expand All @@ -73,10 +74,8 @@ internal class PlotToolEventDispatcher(
)

ToolInteractionSpec.WHEEL_ZOOM -> WheelZoomFeedback(
onZoomed = { rect, target ->
//println("Wheel zoom: apply: $rect")
//target.zoom(delta)
debouncedWheelZoom(rect to target)
onCompleted = { dataBounds ->
debouncedWheelZoom(dataBounds)
}
)

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.