Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
66dc5e27
Commit
66dc5e27
authored
Aug 12, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[RangeSlider] some types refactoring
parent
821d1728
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
20 deletions
+24
-20
GraphExplorer.purs
src/Gargantext/Components/GraphExplorer.purs
+10
-8
Types.purs
src/Gargantext/Components/GraphExplorer/Types.purs
+1
-0
RangeSlider.purs
src/Gargantext/Components/RangeSlider.purs
+11
-12
Range.purs
src/Gargantext/Utils/Range.purs
+2
-0
No files found.
src/Gargantext/Components/GraphExplorer.purs
View file @
66dc5e27
...
...
@@ -23,6 +23,15 @@ import Data.Tuple.Nested ((/\))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
import Partial.Unsafe (unsafePartial)
import Thermite (Render, Spec, simpleSpec, defaultPerformAction)
import Unsafe.Coerce (unsafeCoerce)
import Web.HTML (window)
import Web.HTML.Window (localStorage)
import Web.Storage.Storage (getItem)
import Reactix as R
import Reactix.DOM.HTML as RH
import Gargantext.Hooks.Sigmax.Types as Sigmax
import Gargantext.Hooks.Sigmax.Sigmajs (CameraProps, SigmaNode, cameras, getCameraProps, goTo, pauseForceAtlas2, sigmaOnMouseMove)
import Gargantext.Components.GraphExplorer.Controls as Controls
...
...
@@ -41,15 +50,8 @@ import Gargantext.Pages.Corpus.Graph.Tabs as GT
import Gargantext.Router (Routes(..))
import Gargantext.Types (class Optional)
import Gargantext.Utils (toggleSet)
import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
import Partial.Unsafe (unsafePartial)
import Thermite (Render, Spec, simpleSpec, defaultPerformAction)
import Unsafe.Coerce (unsafeCoerce)
import Web.HTML (window)
import Web.HTML.Window (localStorage)
import Web.Storage.Storage (getItem)
import Reactix as R
import Reactix.DOM.HTML as RH
type GraphId = Int
...
...
src/Gargantext/Components/GraphExplorer/Types.purs
View file @
66dc5e27
...
...
@@ -14,6 +14,7 @@ import Thermite (PerformAction, Spec)
import Gargantext.Components.Login.Types (TreeId)
import Gargantext.Components.Graph as Graph
import Gargantext.Utils.Range as Range
newtype Node = Node
{ id_ :: String
...
...
src/Gargantext/Components/RangeSlider.purs
View file @
66dc5e27
...
...
@@ -28,19 +28,18 @@ import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
-- data Axis = X | Y
type NumberRange = Range.Closed Number
-- To avoid overloading the terms 'min' and 'max' here, we treat 'min'
-- and 'max' as being the bounds of the scale and 'low' and 'high' as
-- being the selected values
type Props =
( bounds :: NumberRange -- The minimum and maximum values it is possible to select
, initialValue :: NumberRange -- The user's selection of minimum and maximum values
( bounds ::
Range.
NumberRange -- The minimum and maximum values it is possible to select
, initialValue ::
Range.
NumberRange -- The user's selection of minimum and maximum values
, epsilon :: Number -- The smallest possible change (for mouse)
, step :: Number -- The 'standard' change (for keyboard)
-- , axis :: Axis -- Which direction to move in
, width :: Number
, height :: Number
, onChange :: NumberRange -> Effect Unit )
, onChange ::
Range.
NumberRange -> Effect Unit )
rangeSlider :: Record Props -> R.Element
rangeSlider props = R.createElement rangeSliderCpt props []
...
...
@@ -82,7 +81,7 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt
R2.useLayoutEffect1' dragKnob $ \_ -> do
case dragKnob of
Just knob -> do
let drag = (getDragScale knob scalePos lowPos highPos) :: Maybe NumberRange
let drag = (getDragScale knob scalePos lowPos highPos) :: Maybe
Range.
NumberRange
R.setRef dragScale drag
let onMouseMove = EL.callback $ \(event :: Event.MouseEvent) ->
case reproject drag scalePos value (R2.domMousePosition event) of
...
...
@@ -111,13 +110,13 @@ destroyEventHandler name ref = traverse_ destroy $ R.readRef ref
EL.removeEventListener document name handler
R.setRef ref Nothing
setKnob :: Knob -> ((
NumberRange -> NumberRange) -> Effect Unit) ->
NumberRange -> Number -> Effect Unit
setKnob :: Knob -> ((
Range.NumberRange -> Range.NumberRange) -> Effect Unit) -> Range.
NumberRange -> Number -> Effect Unit
setKnob knob setValue r val = setValue $ const $ setter knob r val
where
setter MinKnob = Range.withMin
setter MaxKnob = Range.withMax
getDragScale :: Knob -> R.Ref (Maybe DOMRect) -> R.Ref (Maybe DOMRect) -> R.Ref (Maybe DOMRect) -> Maybe NumberRange
getDragScale :: Knob -> R.Ref (Maybe DOMRect) -> R.Ref (Maybe DOMRect) -> R.Ref (Maybe DOMRect) -> Maybe
Range.
NumberRange
getDragScale knob scalePos lowPos highPos = do
scale <- R.readRef scalePos
low <- R.readRef lowPos
...
...
@@ -144,25 +143,25 @@ renderKnob ref val label knob set =
onMouseDown = mkEffectFn1 $ \_ -> set $ const $ Just knob
-- todo round to nearest epsilon
reproject :: Maybe
NumberRange -> R.Ref (Maybe DOMRect) ->
NumberRange -> R2.Point -> Maybe Number
reproject :: Maybe
Range.NumberRange -> R.Ref (Maybe DOMRect) -> Range.
NumberRange -> R2.Point -> Maybe Number
reproject drag scale value (R2.Point mousePos) = do
drag_ <- drag
scale_ <- rectRange <$> R.readRef scale
let normal = Range.normalise scale_ (Range.clamp drag_ mousePos.x)
pure $ Range.projectNormal value normal
rectRange :: DOMRect -> NumberRange
rectRange :: DOMRect ->
Range.
NumberRange
rectRange rect = Range.Closed { min, max }
where min = rect.left
max = rect.right
initialValue :: Record Props -> NumberRange
initialValue :: Record Props ->
Range.
NumberRange
initialValue props = roundRange props.epsilon props.bounds props.initialValue
round :: Number -> NumberRange -> Number -> Number
round :: Number ->
Range.
NumberRange -> Number -> Number
round epsilon bounds = roundToMultiple epsilon <<< Range.clamp bounds
roundRange :: Number ->
NumberRange -> NumberRange ->
NumberRange
roundRange :: Number ->
Range.NumberRange -> Range.NumberRange -> Range.
NumberRange
roundRange epsilon bounds (Range.Closed initial) = Range.Closed { min, max }
where min = round epsilon bounds initial.min
max = round epsilon bounds initial.max
...
...
src/Gargantext/Utils/Range.purs
View file @
66dc5e27
...
...
@@ -17,6 +17,8 @@ instance closedRange :: Ord t => Range (Closed t) t where
clamp (Closed r) = max r.min <<< min r.max
within (Closed r) v = (v <= r.max) && (v >= r.min)
type NumberRange = Closed Number
range :: Closed Number -> Number
range (Closed r) = r.max - r.min
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment