Commit ba207d95 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] various fixes

- range slider precision fix
- added edge size bounds
- fixed Globals 4.1.0 dependency (was 4.0.0 which was missing lots of
functions)
- upgraded purescript to 0.13.3 (has better error messages, with diff)
parent 41b2021e
...@@ -1092,9 +1092,12 @@ ...@@ -1092,9 +1092,12 @@
"version": "v6.1.1" "version": "v6.1.1"
}, },
"globals": { "globals": {
"dependencies": [], "dependencies": [
"repo": "https://github.com/purescript/purescript-globals.git", "functions",
"version": "v4.0.0" "maybe"
],
"repo": "https://github.com/purescript/purescript-globals",
"version": "v4.1.0"
}, },
"gomtang-basic": { "gomtang-basic": {
"dependencies": [ "dependencies": [
......
...@@ -127,6 +127,13 @@ let overrides = ...@@ -127,6 +127,13 @@ let overrides =
] ]
"https://github.com/np/purescript-thermite.git" "https://github.com/np/purescript-thermite.git"
"hide" "hide"
, globals =
mkPackage
[ "functions"
, "maybe"
]
"https://github.com/purescript/purescript-globals"
"v4.1.0"
} }
let additions = let additions =
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"effect", "effect",
"foreign-object", "foreign-object",
"generics-rep", "generics-rep",
"globals",
"integers", "integers",
"js-timers", "js-timers",
"math", "math",
......
...@@ -15,6 +15,7 @@ import Gargantext.Types ( TermList(..), termListName ) ...@@ -15,6 +15,7 @@ import Gargantext.Types ( TermList(..), termListName )
import Gargantext.Components.Annotation.Utils ( termBootstrapClass ) import Gargantext.Components.Annotation.Utils ( termBootstrapClass )
import Gargantext.Components.ContextMenu.ContextMenu as CM import Gargantext.Components.ContextMenu.ContextMenu as CM
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Selection (Selection, selectionToString) import Gargantext.Utils.Selection (Selection, selectionToString)
data MenuType = NewNgram | SetTermListItem data MenuType = NewNgram | SetTermListItem
...@@ -29,7 +30,7 @@ type AnnotationMenu = { x :: Number, y :: Number | Props } ...@@ -29,7 +30,7 @@ type AnnotationMenu = { x :: Number, y :: Number | Props }
-- | An Annotation Menu is parameterised by a Maybe Termlist of the -- | An Annotation Menu is parameterised by a Maybe Termlist of the
-- | TermList the currently selected text belongs to -- | TermList the currently selected text belongs to
annotationMenu :: ((Maybe AnnotationMenu -> Maybe AnnotationMenu) -> Effect Unit) -> AnnotationMenu -> R.Element annotationMenu :: R2.StateSetter (Maybe AnnotationMenu) -> AnnotationMenu -> R.Element
annotationMenu setMenu { x,y,list,menuType,setList } = annotationMenu setMenu { x,y,list,menuType,setList } =
CM.contextMenu { x,y,setMenu } [ CM.contextMenu { x,y,setMenu } [
R.createElement annotationMenuCpt {list,menuType,setList} [] R.createElement annotationMenuCpt {list,menuType,setList} []
......
...@@ -21,7 +21,7 @@ import Reactix as R ...@@ -21,7 +21,7 @@ import Reactix as R
import Reactix.DOM.HTML as RH import Reactix.DOM.HTML as RH
import Gargantext.Components.Graph as Graph import Gargantext.Components.Graph as Graph
import Gargantext.Components.GraphExplorer.RangeControl (nodeSizeControl) import Gargantext.Components.GraphExplorer.RangeControl (edgeSizeControl, nodeSizeControl)
import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton) import Gargantext.Components.GraphExplorer.SlideButton (cursorSizeButton, labelSizeButton)
import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton) import Gargantext.Components.GraphExplorer.ToggleButton (edgesToggleButton)
import Gargantext.Utils.Range as Range import Gargantext.Utils.Range as Range
...@@ -30,6 +30,7 @@ import Gargantext.Utils.Reactix as R2 ...@@ -30,6 +30,7 @@ import Gargantext.Utils.Reactix as R2
type Controls = type Controls =
( cursorSize :: R.State Number ( cursorSize :: R.State Number
, edgeSize :: R.State Range.NumberRange
, labelSize :: R.State Number , labelSize :: R.State Number
, nodeSize :: R.State Range.NumberRange , nodeSize :: R.State Range.NumberRange
, multiNodeSelect :: R.Ref Boolean , multiNodeSelect :: R.Ref Boolean
...@@ -41,6 +42,7 @@ type Controls = ...@@ -41,6 +42,7 @@ type Controls =
controlsToSigmaSettings :: Record Controls -> Record Graph.SigmaSettings controlsToSigmaSettings :: Record Controls -> Record Graph.SigmaSettings
controlsToSigmaSettings { cursorSize: (cursorSize /\ _) controlsToSigmaSettings { cursorSize: (cursorSize /\ _)
, edgeSize: (Range.Closed { min: edgeSizeMin, max: edgeSizeMax } /\ _)
, labelSize: (labelSize /\ _) , labelSize: (labelSize /\ _)
, nodeSize: (Range.Closed { min: nodeSizeMin, max: nodeSizeMax } /\ _) , nodeSize: (Range.Closed { min: nodeSizeMin, max: nodeSizeMax } /\ _)
, showEdges: (showEdges /\ _)} = Graph.sigmaSettings { , showEdges: (showEdges /\ _)} = Graph.sigmaSettings {
...@@ -48,10 +50,10 @@ controlsToSigmaSettings { cursorSize: (cursorSize /\ _) ...@@ -48,10 +50,10 @@ controlsToSigmaSettings { cursorSize: (cursorSize /\ _)
, drawEdges = showEdges , drawEdges = showEdges
, drawEdgeLabels = showEdges , drawEdgeLabels = showEdges
, hideEdgesOnMove = not showEdges , hideEdgesOnMove = not showEdges
, maxEdgeSize = if showEdges then 1.0 else 0.0 , minEdgeSize = if showEdges then edgeSizeMin else 0.0
, minEdgeSize = if showEdges then 1.0 else 0.0 , maxEdgeSize = if showEdges then edgeSizeMax else 0.0
, maxNodeSize = nodeSizeMax
, minNodeSize = nodeSizeMin , minNodeSize = nodeSizeMin
, maxNodeSize = nodeSizeMax
} }
controls :: Record Controls -> R.Element controls :: Record Controls -> R.Element
...@@ -69,6 +71,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -69,6 +71,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
[ RH.ul {} [ RH.ul {}
[ -- change type button (?) [ -- change type button (?)
RH.li {} [ edgesToggleButton props.showEdges ] RH.li {} [ edgesToggleButton props.showEdges ]
, RH.li {} [ edgeSizeControl props.edgeSize ] -- edge size : 0-3
-- change level -- change level
-- file upload -- file upload
-- run demo -- run demo
...@@ -77,7 +80,6 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -77,7 +80,6 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
, RH.li {} [ cursorSizeButton props.cursorSize ] -- cursor size: 0-100 , RH.li {} [ cursorSizeButton props.cursorSize ] -- cursor size: 0-100
, RH.li {} [ labelSizeButton props.labelSize ] -- labels size: 1-4 , RH.li {} [ labelSizeButton props.labelSize ] -- labels size: 1-4
, RH.li {} [ nodeSizeControl props.nodeSize ] -- node size : 5-15 , RH.li {} [ nodeSizeControl props.nodeSize ] -- node size : 5-15
-- edge size : ??
-- zoom: 0 -100 - calculate ratio -- zoom: 0 -100 - calculate ratio
-- toggle multi node selection -- toggle multi node selection
-- spatialization (pause ForceAtlas2) -- spatialization (pause ForceAtlas2)
...@@ -89,6 +91,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -89,6 +91,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
useGraphControls :: R.Hooks (Record Controls) useGraphControls :: R.Hooks (Record Controls)
useGraphControls = do useGraphControls = do
cursorSize <- R.useState' 10.0 cursorSize <- R.useState' 10.0
edgeSize <- R.useState' $ Range.Closed { min: 0.5, max: 1.0 }
labelSize <- R.useState' 3.0 labelSize <- R.useState' 3.0
nodeSize <- R.useState' $ Range.Closed { min: 5.0, max: 10.0 } nodeSize <- R.useState' $ Range.Closed { min: 5.0, max: 10.0 }
multiNodeSelect <- R.useRef false multiNodeSelect <- R.useRef false
...@@ -96,7 +99,17 @@ useGraphControls = do ...@@ -96,7 +99,17 @@ useGraphControls = do
showEdges <- R.useState' true showEdges <- R.useState' true
showSidePanel <- R.useState' false showSidePanel <- R.useState' false
showTree <- R.useState' false showTree <- R.useState' false
pure { showTree, showControls, showSidePanel, showEdges, cursorSize, labelSize, nodeSize, multiNodeSelect } pure {
showTree
, showControls
, showSidePanel
, showEdges
, cursorSize
, edgeSize
, labelSize
, nodeSize
, multiNodeSelect
}
getShowTree :: Record Controls -> Boolean getShowTree :: Record Controls -> Boolean
getShowTree { showTree: ( should /\ _ ) } = should getShowTree { showTree: ( should /\ _ ) } = should
......
module Gargantext.Components.GraphExplorer.RangeControl module Gargantext.Components.GraphExplorer.RangeControl
( Props ( Props
, rangeControl , rangeControl
, edgeSizeControl
, nodeSizeControl , nodeSizeControl
) where ) where
...@@ -32,6 +33,21 @@ rangeControlCpt = R.hooksComponent "RangeButton" cpt ...@@ -32,6 +33,21 @@ rangeControlCpt = R.hooksComponent "RangeButton" cpt
, RS.rangeSlider sliderProps , RS.rangeSlider sliderProps
] ]
edgeSizeControl :: R.State Range.NumberRange -> R.Element
edgeSizeControl (state /\ setState) =
rangeControl {
caption: "Edge Size"
, sliderProps: {
bounds: Range.Closed { min: 0.0, max: 3.0 }
, initialValue: state
, epsilon: 0.1
, step: 1.0
, width: 10.0
, height: 5.0
, onChange: setState <<< const
}
}
nodeSizeControl :: R.State Range.NumberRange -> R.Element nodeSizeControl :: R.State Range.NumberRange -> R.Element
nodeSizeControl (state /\ setState) = nodeSizeControl (state /\ setState) =
rangeControl { rangeControl {
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
module Gargantext.Components.RangeSlider where module Gargantext.Components.RangeSlider where
import Prelude import Prelude
import Data.Maybe (Maybe(..)) import Data.Int (fromNumber)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Nullable (Nullable, null, toMaybe) import Data.Nullable (Nullable, null, toMaybe)
import Data.Traversable (traverse_) import Data.Traversable (traverse_)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
...@@ -18,10 +19,12 @@ import DOM.Simple.Element as Element ...@@ -18,10 +19,12 @@ import DOM.Simple.Element as Element
import DOM.Simple.Event as Event import DOM.Simple.Event as Event
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 Global (toFixed)
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 Global (toFixed) --import Global (toFixed)
import Math as M
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Reactix.SyntheticEvent as RE import Reactix.SyntheticEvent as RE
...@@ -58,6 +61,9 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt ...@@ -58,6 +61,9 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt
--R.useEffect' $ do --R.useEffect' $ do
-- liftEffect $ log2 "Props: " props -- liftEffect $ log2 "Props: " props
-- rounding precision (i.e. how many decimal digits are in epsilon)
let precision = fromMaybe 0 $ fromNumber $ max 0.0 $ - M.floor $ (M.log props.epsilon) / M.ln10
-- scale bar -- scale bar
scaleElem <- (R.useRef null) :: R.Hooks (R.Ref (Nullable DOM.Element)) -- dom ref scaleElem <- (R.useRef null) :: R.Hooks (R.Ref (Nullable DOM.Element)) -- dom ref
--scalePos <- R2.usePositionRef scaleElem --scalePos <- R2.usePositionRef scaleElem
...@@ -137,8 +143,8 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt ...@@ -137,8 +143,8 @@ rangeSliderCpt = R.hooksComponent "RangeSlider" cpt
Nothing -> destroy unit Nothing -> destroy unit
pure $ H.div { className, aria } pure $ H.div { className, aria }
[ renderScale scaleElem props value' [ renderScale scaleElem props value'
, renderKnob lowElem value'.min props.bounds MinKnob setDragKnob props.epsilon , renderKnob MinKnob lowElem value'.min props.bounds setDragKnob precision
, renderKnob highElem value'.max props.bounds MaxKnob setDragKnob props.epsilon , renderKnob MaxKnob highElem value'.max props.bounds setDragKnob precision
] ]
className = "range-slider" className = "range-slider"
aria = { label: "Range Slider Control. Expresses filtering data by a minimum and maximum value range through two slider knobs. Knobs can be adjusted with the arrow keys." } aria = { label: "Range Slider Control. Expresses filtering data by a minimum and maximum value range through two slider knobs. Knobs can be adjusted with the arrow keys." }
...@@ -153,7 +159,7 @@ destroyEventHandler name ref = traverse_ destroy $ R.readRef ref ...@@ -153,7 +159,7 @@ destroyEventHandler name ref = traverse_ destroy $ R.readRef ref
EL.removeEventListener document name handler EL.removeEventListener document name handler
R.setRef ref Nothing R.setRef ref Nothing
setKnob :: Knob -> ((Range.NumberRange -> Range.NumberRange) -> Effect Unit) -> Range.NumberRange -> Number -> Effect Unit setKnob :: Knob -> R2.StateSetter Range.NumberRange -> Range.NumberRange -> Number -> Effect Unit
setKnob knob setValue r val = setValue $ const $ setter knob r val setKnob knob setValue r val = setValue $ const $ setter knob r val
where where
setter MinKnob = Range.withMin setter MinKnob = Range.withMin
...@@ -178,13 +184,14 @@ renderScale ref {width,height} {min, max} = ...@@ -178,13 +184,14 @@ renderScale ref {width,height} {min, max} =
aria = { label: "Scale running from " <> show min <> " to " <> show max } aria = { label: "Scale running from " <> show min <> " to " <> show max }
style = { width: "100%", height: "3px" } style = { width: "100%", height: "3px" }
renderKnob ref val bounds knob set epsilon = renderKnob :: Knob -> R.Ref (Nullable DOM.Element) -> Number -> Range.NumberRange -> R2.StateSetter (Maybe Knob) -> Int -> R.Element
renderKnob knob ref val bounds set precision =
H.div { ref, tabIndex, className, aria, onMouseDown, style } [ H.div { ref, tabIndex, className, aria, onMouseDown, style } [
H.div { className: "button" } [] H.div { className: "button" } []
, H.text (text $ Just val) , H.text $ text $ toFixed precision val
] ]
where where
text (Just num) = show num text (Just num) = num
text Nothing = "error" text Nothing = "error"
tabIndex = 0 tabIndex = 0
className = "knob" className = "knob"
......
...@@ -26,6 +26,8 @@ import Unsafe.Coerce (unsafeCoerce) ...@@ -26,6 +26,8 @@ import Unsafe.Coerce (unsafeCoerce)
newtype Point = Point { x :: Number, y :: Number } newtype Point = Point { x :: Number, y :: Number }
type StateSetter a = (a -> a) -> Effect Unit
-- | Turns a ReactElement into aReactix Element -- | Turns a ReactElement into aReactix Element
-- | buff (v.) to polish -- | buff (v.) to polish
buff :: ReactElement -> R.Element buff :: ReactElement -> R.Element
......
...@@ -5177,10 +5177,10 @@ purescript-installer@^0.2.0: ...@@ -5177,10 +5177,10 @@ purescript-installer@^0.2.0:
which "^1.3.1" which "^1.3.1"
zen-observable "^0.8.14" zen-observable "^0.8.14"
purescript@^0.13.2: purescript@^0.13.3:
version "0.13.2" version "0.13.3"
resolved "https://registry.yarnpkg.com/purescript/-/purescript-0.13.2.tgz#9d7e8cde0e1a23bb2ec008449675cb6434933165" resolved "https://registry.yarnpkg.com/purescript/-/purescript-0.13.3.tgz#18e0a8c0a21332fc16b02218a8b136a699d444bb"
integrity sha512-HdB8KzEjXDUq1OXLU+FCfjWWX28suNfsrBYqpAbWVKKg6hvJs+fyCc1earfwZeVL/QimL1734AlmhRP0fQrN+A== integrity sha512-YFznjWSFrl6pbds0JxWXJ/ztzyGgUsR5pvdF/wH1i1BqSqxpFtWgREUIOCCkzmuc+X9U2Ntf5DMQ56RxawE3gQ==
dependencies: dependencies:
purescript-installer "^0.2.0" purescript-installer "^0.2.0"
......
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