[graph] add debouncing/throttling to slider and range controls

parent f976830d
Pipeline #6055 canceled with stages
in 9 minutes and 59 seconds
...@@ -732,7 +732,7 @@ workspace: ...@@ -732,7 +732,7 @@ workspace:
data-default: data-default:
git: https://github.com/garganscript/purescript-data-default.git git: https://github.com/garganscript/purescript-data-default.git
ref: v0.4.0 ref: v0.4.0
debouncing: 0.1.0 debouncing: 0.1.2
graphql-client: graphql-client:
git: https://github.com/garganscript/purescript-graphql-client.git git: https://github.com/garganscript/purescript-graphql-client.git
ref: spago-next-9.3.2 ref: spago-next-9.3.2
...@@ -1058,8 +1058,8 @@ packages: ...@@ -1058,8 +1058,8 @@ packages:
- tuples - tuples
debouncing: debouncing:
type: registry type: registry
version: 0.1.0 version: 0.1.2
integrity: sha256-iAfmC8stYPctDdevBWYgydUZ02OB96uYYSACF5Zzyy4= integrity: sha256-2Ajskjmc+r3gnpcv6L8U4BfiSKj4N7sCINiBD99RjO8=
dependencies: dependencies:
- effect - effect
- prelude - prelude
......
...@@ -6,7 +6,7 @@ workspace: ...@@ -6,7 +6,7 @@ workspace:
d3: d3:
git: https://github.com/garganscript/purescript-d3.git git: https://github.com/garganscript/purescript-d3.git
ref: v0.11.0 ref: v0.11.0
debouncing: 0.1.0 debouncing: 0.1.2
reactix: 0.6.1 reactix: 0.6.1
string-search: string-search:
git: https://gitlab.iscpif.fr/gargantext/purescript-string-search.git git: https://gitlab.iscpif.fr/gargantext/purescript-string-search.git
......
...@@ -7,10 +7,11 @@ module Gargantext.Components.GraphExplorer.Toolbar.SlideButton ...@@ -7,10 +7,11 @@ module Gargantext.Components.GraphExplorer.Toolbar.SlideButton
) where ) where
import Data.Map as Map import Data.Map as Map
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Number as DN import Data.Number as DN
import Prelude
import Effect (Effect) import Effect (Effect)
import Effect.Debouncing as Debounce
import Prelude
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Toestand as T import Toestand as T
...@@ -25,20 +26,29 @@ import Gargantext.Utils.Reactix as R2 ...@@ -25,20 +26,29 @@ import Gargantext.Utils.Reactix as R2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer.Toolbar.SlideButton" here = R2.here "Gargantext.Components.GraphExplorer.Toolbar.SlideButton"
defaultThrottleInterval :: Int
defaultThrottleInterval = 500
type Props = type Props =
( caption :: String ( caption :: String
, forceAtlasState :: T.Box SigmaxTypes.ForceAtlasState , forceAtlasState :: T.Box SigmaxTypes.ForceAtlasState
, min :: Number , min :: Number
, max :: Number , max :: Number
, onChange :: forall e. e -> Effect Unit , onChange :: Number -> Effect Unit
, state :: T.Box Number , state :: T.Box Number
, throttleInterval :: Maybe Int -- then Nothing, no throttling is done
) )
sizeButton :: Record Props -> R.Element sizeButton :: Record Props -> R.Element
sizeButton props = R.createElement sizeButtonCpt props [] sizeButton props = R.createElement sizeButtonCpt props []
sizeButtonCpt :: R.Component Props sizeButtonCpt :: R.Component Props
sizeButtonCpt = here.component "sizeButton" cpt where sizeButtonCpt = here.component "sizeButton" cpt where
cpt { state, caption, forceAtlasState, min, max, onChange } _ = do cpt { state, caption, forceAtlasState, min, max, onChange, throttleInterval } _ = do
let throttled = Debounce.throttleWithDebounceAtEnd onChange (fromMaybe 0 throttleInterval)
let onChangeThrottled = case throttleInterval of
Nothing -> onChange
Just ti -> \rng -> Debounce.call throttled rng
defaultValue <- T.useLive T.unequal state defaultValue <- T.useLive T.unequal state
forceAtlasState' <- R2.useLive' forceAtlasState forceAtlasState' <- R2.useLive' forceAtlasState
...@@ -61,7 +71,11 @@ sizeButtonCpt = here.component "sizeButton" cpt where ...@@ -61,7 +71,11 @@ sizeButtonCpt = here.component "sizeButton" cpt where
, min: show min , min: show min
, max: show max , max: show max
, defaultValue , defaultValue
, on: { input: onChange } , on: { input: \e -> do
let v = DN.fromString $ R.unsafeEventValue e
case v of
Nothing -> pure unit
Just vv -> onChangeThrottled vv }
, className: "range-simple__input" , className: "range-simple__input"
, disabled: status == Disabled , disabled: status == Disabled
} }
...@@ -92,30 +106,27 @@ labelSizeButtonCpt = here.component "labelSizeButton" cpt ...@@ -92,30 +106,27 @@ labelSizeButtonCpt = here.component "labelSizeButton" cpt
, forceAtlasState , forceAtlasState
, min: minLabelSize , min: minLabelSize
, max: maxLabelSize , max: maxLabelSize
, onChange: \e -> do , onChange: \newValue -> do
let sigma = R.readRef sigmaRef let sigma = R.readRef sigmaRef
let newValue' = DN.fromString $ R.unsafeEventValue e Sigmax.dependOnSigma sigma "[labelSizeButton] sigma: Nothing" $ \s -> do
case newValue' of let ratio = (newValue - minLabelSize) / (defaultLabelSize - minLabelSize)
Nothing -> pure unit let nodes = SigmaxTypes.graphNodes graph'
Just newValue -> let nodesResized = (\n@{ size } -> n { size = size * ratio }) <$> nodes
Sigmax.dependOnSigma sigma "[labelSizeButton] sigma: Nothing" $ \s -> do let nodesMap = SigmaxTypes.idMap nodesResized
let ratio = (newValue - minLabelSize) / (defaultLabelSize - minLabelSize) Graphology.forEachNode (Sigma.graph s) $ \{ id } -> do
let nodes = SigmaxTypes.graphNodes graph' case Map.lookup id nodesMap of
let nodesResized = (\n@{ size } -> n { size = size * ratio }) <$> nodes Nothing -> pure unit
let nodesMap = SigmaxTypes.idMap nodesResized Just { size } -> Graphology.mergeNodeAttributes (Sigma.graph s) id { size }
Graphology.forEachNode (Sigma.graph s) $ \{ id } -> do
case Map.lookup id nodesMap of Sigma.setSettings s {
Nothing -> pure unit defaultLabelSize: newValue
Just { size } -> Graphology.mergeNodeAttributes (Sigma.graph s) id { size } , drawLabels: true
, labelSize: newValue
Sigma.setSettings s { -- , maxNodeSize: newValue / 2.5
defaultLabelSize: newValue --, labelSizeRatio: newValue / 2.5
, drawLabels: true }
, labelSize: newValue T.write_ newValue state
-- , maxNodeSize: newValue / 2.5 , throttleInterval: Just defaultThrottleInterval
--, labelSizeRatio: newValue / 2.5
}
T.write_ newValue state
} }
type LabelRenderedSizeThresholdButtonProps = type LabelRenderedSizeThresholdButtonProps =
...@@ -135,17 +146,14 @@ labelRenderedSizeThresholdButtonCpt = here.component "labelRenderedSizeThreshold ...@@ -135,17 +146,14 @@ labelRenderedSizeThresholdButtonCpt = here.component "labelRenderedSizeThreshold
, forceAtlasState , forceAtlasState
, min: 0.0 , min: 0.0
, max: 10.0 , max: 10.0
, onChange: \e -> do , onChange: \newValue -> do
let sigma = R.readRef sigmaRef let sigma = R.readRef sigmaRef
let newValue' = DN.fromString $ R.unsafeEventValue e Sigmax.dependOnSigma sigma "[labelRenderdSizeThresholdButton] sigma: Nothing" $ \s -> do
case newValue' of Sigma.setSettings s {
Nothing -> pure unit labelRenderedSizeThreshold: newValue
Just newValue -> }
Sigmax.dependOnSigma sigma "[labelRenderdSizeThresholdButton] sigma: Nothing" $ \s -> do T.write_ newValue state
Sigma.setSettings s { , throttleInterval: Just defaultThrottleInterval
labelRenderedSizeThreshold: newValue
}
T.write_ newValue state
} }
type MouseSelectorSizeSliderProps = type MouseSelectorSizeSliderProps =
...@@ -164,16 +172,13 @@ mouseSelectorSizeSliderCpt = here.component "mouseSelectorSizeSlider" cpt ...@@ -164,16 +172,13 @@ mouseSelectorSizeSliderCpt = here.component "mouseSelectorSizeSlider" cpt
, forceAtlasState , forceAtlasState
, min: 1.0 , min: 1.0
, max: 100.0 , max: 100.0
, onChange: \e -> do , onChange: \newValue -> do
let sigma = R.readRef sigmaRef let sigma = R.readRef sigmaRef
let newValue' = DN.fromString $ R.unsafeEventValue e Sigmax.dependOnSigma sigma "[mouseSelectorSizeButton] sigma: Nothing" $ \s -> do
case newValue' of Sigma.setSettings s {
Nothing -> pure unit mouseSelectorSize: newValue
Just newValue -> }
Sigmax.dependOnSigma sigma "[mouseSelectorSizeButton] sigma: Nothing" $ \s -> do T.write_ newValue state
Sigma.setSettings s {
mouseSelectorSize: newValue
}
T.write_ newValue state
, state , state
, throttleInterval: Just defaultThrottleInterval
} }
...@@ -67,7 +67,7 @@ rangeSlider props = R.createElement rangeSliderCpt props [] ...@@ -67,7 +67,7 @@ rangeSlider props = R.createElement rangeSliderCpt props []
rangeSliderCpt :: R.Component Props rangeSliderCpt :: R.Component Props
rangeSliderCpt = here.component "rangeSlider" cpt where rangeSliderCpt = here.component "rangeSlider" cpt where
cpt props _ = do cpt props _ = do
let throttled = Debounce.throttle props.onChange (fromMaybe 0 props.throttleInterval) let throttled = Debounce.throttleWithDebounceAtEnd props.onChange (fromMaybe 0 props.throttleInterval)
let onChangeThrottled = case props.throttleInterval of let onChangeThrottled = case props.throttleInterval of
Nothing -> props.onChange Nothing -> props.onChange
Just ti -> \rng -> Debounce.call throttled rng Just ti -> \rng -> Debounce.call throttled rng
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment