Commit 5713d19c authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] RangeSlider logs, knob position adjusting still doesn't work

parent b9137508
...@@ -8,12 +8,14 @@ module Gargantext.Components.RangeSlider where ...@@ -8,12 +8,14 @@ module Gargantext.Components.RangeSlider where
import Prelude import Prelude
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Nullable (null) import Data.Nullable (Nullable, null, toMaybe)
import Data.Traversable (traverse_) import Data.Traversable (traverse_)
import Effect (Effect) import Effect (Effect)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Uncurried (EffectFn1, mkEffectFn1) import Effect.Uncurried (EffectFn1, mkEffectFn1)
import DOM.Simple as DOM
import DOM.Simple.Document (document) import DOM.Simple.Document (document)
import DOM.Simple.Element as Element
import DOM.Simple.EventListener as EL import DOM.Simple.EventListener as EL
import DOM.Simple.Types (DOMRect, Element) import DOM.Simple.Types (DOMRect, Element)
import DOM.Simple.Event as Event import DOM.Simple.Event as Event
...@@ -71,37 +73,42 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt ...@@ -71,37 +73,42 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt
-- the knob we are currently in a drag for. set by mousedown on a knob -- the knob we are currently in a drag for. set by mousedown on a knob
dragKnob /\ setDragKnob <- R.useState' $ (Nothing :: Maybe Knob) dragKnob /\ setDragKnob <- R.useState' $ (Nothing :: Maybe Knob)
-- the bounding box within which the mouse can drag -- the bounding box within which the mouse can drag
dragScale <- R.useRef $ Nothing --dragScale <- R.useRef $ Nothing
-- the handler functions for trapping mouse events, so they can be removed -- the handler functions for trapping mouse events, so they can be removed
mouseMoveHandler <- (R.useRef $ Nothing) :: R.Hooks (R.Ref (Maybe (EL.Callback Event.MouseEvent))) mouseMoveHandler <- (R.useRef $ Nothing) :: R.Hooks (R.Ref (Maybe (EL.Callback Event.MouseEvent)))
mouseUpHandler <- (R.useRef $ Nothing) :: R.Hooks (R.Ref (Maybe (EL.Callback Event.MouseEvent))) mouseUpHandler <- (R.useRef $ Nothing) :: R.Hooks (R.Ref (Maybe (EL.Callback Event.MouseEvent)))
let destroy = \_ -> let destroy = \_ -> do
do log "RangeSlider: Destroying event handlers" log "RangeSlider: Destroying event handlers"
destroyEventHandler "mousemove" mouseMoveHandler destroyEventHandler "mousemove" mouseMoveHandler
destroyEventHandler "mouseup" mouseUpHandler destroyEventHandler "mouseup" mouseUpHandler
R.setRef mouseMoveHandler $ Nothing
R.setRef mouseUpHandler $ Nothing
R2.useLayoutEffect1' dragKnob $ \_ -> do R2.useLayoutEffect1' dragKnob $ \_ -> do
case dragKnob of case dragKnob of
Just knob -> do Just knob -> do
let drag = (getDragScale knob scalePos lowPos highPos) :: Maybe Range.NumberRange let drag = (getDragScale knob scalePos lowPos highPos) :: Maybe Range.NumberRange
R.setRef dragScale drag --R.setRef dragScale drag
let onMouseMove = EL.callback $ \(event :: Event.MouseEvent) -> do let onMouseMove = EL.callback $ \(event :: Event.MouseEvent) -> do
-- log2 "drag" drag log2 "dragKnob" dragKnob
-- log2 "scale" scalePos log2 "lowPos" lowPos
-- -- log2 "value" value log2 "highPos" highPos
-- let (R2.Point mousePos) = R2.domMousePosition event log2 "drag" drag
-- log2 "mouse position" mousePos log2 "scale" scalePos
-- let scale = rectRange <$> R.readRef scalePos -- log2 "value" value
-- case scale of let (R2.Point mousePos) = R2.domMousePosition event
-- Just scale_ -> log2 "mouse position" mousePos
-- case drag of let scale = rectRange <$> R.readRef scalePos
-- Just drag_ -> do case scale of
-- let normal = Range.normalise scale_ (Range.clamp drag_ mousePos.x) Just scale_ ->
-- log2 "normal" normal case drag of
-- log2 "project normal" $ Range.projectNormal props.bounds normal Just drag_ -> do
-- _ -> log "drag is Nothing" let normal = Range.normalise scale_ (Range.clamp drag_ mousePos.x)
-- _ -> log "scale is Nothing" log2 "normal" normal
log2 "project normal" $ Range.projectNormal props.bounds normal
_ -> log "drag is Nothing"
_ -> log "scale is Nothing"
case reproject drag scalePos props.bounds (R2.domMousePosition event) of case reproject drag scalePos props.bounds (R2.domMousePosition event) of
Just val -> do Just val -> do
...@@ -178,7 +185,7 @@ reproject drag scale value (R2.Point mousePos) = do ...@@ -178,7 +185,7 @@ reproject drag scale value (R2.Point mousePos) = do
scale_ <- rectRange <$> R.readRef scale scale_ <- rectRange <$> R.readRef scale
let normal = Range.normalise scale_ (Range.clamp drag_ mousePos.x) let normal = Range.normalise scale_ (Range.clamp drag_ mousePos.x)
pure $ Range.projectNormal value normal pure $ Range.projectNormal value normal
rectRange :: DOMRect -> Range.NumberRange rectRange :: DOMRect -> Range.NumberRange
rectRange rect = Range.Closed { min, max } rectRange rect = Range.Closed { min, max }
where min = rect.left where min = rect.left
......
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