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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Fix after merge
  • Loading branch information
IKupriyanov-HORIS committed Jun 3, 2024
commit 23bc614378c69bb9b4ddf67743fc04004d26db44
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.jetbrains.letsPlot.commons.debounce
import org.jetbrains.letsPlot.commons.geometry.DoubleRectangle
import org.jetbrains.letsPlot.commons.registration.Registration
import org.jetbrains.letsPlot.core.interact.DrawRectFeedback
import org.jetbrains.letsPlot.core.interact.InteractionTarget
import org.jetbrains.letsPlot.core.interact.PanGeomFeedback
import org.jetbrains.letsPlot.core.interact.WheelZoomFeedback
import org.jetbrains.letsPlot.core.interact.event.ToolEventDispatcher
Expand Down Expand Up @@ -52,8 +51,8 @@ internal class PlotToolEventDispatcher(

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

Expand All @@ -75,7 +74,7 @@ internal class PlotToolEventDispatcher(

ToolInteractionSpec.WHEEL_ZOOM -> WheelZoomFeedback(
onCompleted = { dataBounds ->
debouncedWheelZoom(dataBounds)
completeInteractionDebounced(dataBounds)
}
)

Expand Down Expand Up @@ -160,4 +159,8 @@ internal class PlotToolEventDispatcher(
) {
val interactionName = interactionSpec.getValue(ToolInteractionSpec.NAME) as String
}

companion object {
private const val DEBOUNCE_DELAY_MS = 30L
}
}