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
d31416bc
Commit
d31416bc
authored
Nov 14, 2019
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Graph] some refactoring (use dependOnSigma)
parent
f32bd31b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
65 deletions
+53
-65
Button.purs
src/Gargantext/Components/GraphExplorer/Button.purs
+3
-5
RangeControl.purs
src/Gargantext/Components/GraphExplorer/RangeControl.purs
+12
-14
SlideButton.purs
src/Gargantext/Components/GraphExplorer/SlideButton.purs
+4
-5
ToggleButton.purs
src/Gargantext/Components/GraphExplorer/ToggleButton.purs
+8
-10
Sigmax.purs
src/Gargantext/Hooks/Sigmax.purs
+13
-18
Sigma.purs
src/Gargantext/Hooks/Sigmax/Sigma.purs
+13
-13
No files found.
src/Gargantext/Components/GraphExplorer/Button.purs
View file @
d31416bc
...
@@ -37,10 +37,8 @@ simpleButtonCpt = R.hooksComponent "SimpleButton" cpt
...
@@ -37,10 +37,8 @@ simpleButtonCpt = R.hooksComponent "SimpleButton" cpt
centerButton :: R.Ref Sigmax.Sigma -> R.Element
centerButton :: R.Ref Sigmax.Sigma -> R.Element
centerButton sigmaRef = simpleButton {
centerButton sigmaRef = simpleButton {
onClick: \_ -> do
onClick: \_ -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
let sigma = R.readRef sigmaRef
log2 "[centerButton] mSigma" mSigma
Sigmax.dependOnSigma sigma "[centerButton] sigma: Nothing" $ \s ->
case mSigma of
Sigma.goToAllCameras s {x: 0.0, y: 0.0, ratio: 1.0, angle: 0.0}
Just s -> Sigma.goToAllCameras s {x: 0.0, y: 0.0, ratio: 1.0, angle: 0.0}
_ -> pure unit
, text: "Center"
, text: "Center"
}
}
src/Gargantext/Components/GraphExplorer/RangeControl.purs
View file @
d31416bc
...
@@ -46,13 +46,12 @@ edgeSizeControl sigmaRef (state /\ setState) =
...
@@ -46,13 +46,12 @@ edgeSizeControl sigmaRef (state /\ setState) =
, width: 10.0
, width: 10.0
, height: 5.0
, height: 5.0
, onChange: \range@(Range.Closed {min, max}) -> do
, onChange: \range@(Range.Closed {min, max}) -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
let sigma = R.readRef sigmaRef
case mSigma of
Sigmax.dependOnSigma sigma "[edgeSizeControl] sigma: Nothing" $ \s -> do
Just s -> Sigma.setSettings s {
Sigma.setSettings s {
minEdgeSize: min
minEdgeSize: min
, maxEdgeSize: max
, maxEdgeSize: max
}
}
_ -> pure unit
setState $ const range
setState $ const range
}
}
}
}
...
@@ -69,13 +68,12 @@ nodeSizeControl sigmaRef (state /\ setState) =
...
@@ -69,13 +68,12 @@ nodeSizeControl sigmaRef (state /\ setState) =
, width: 10.0
, width: 10.0
, height: 5.0
, height: 5.0
, onChange: \range@(Range.Closed {min, max}) -> do
, onChange: \range@(Range.Closed {min, max}) -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
let sigma = R.readRef sigmaRef
case mSigma of
Sigmax.dependOnSigma sigma "[nodeSizeControl] sigma: Nothing" $ \s -> do
Just s -> Sigma.setSettings s {
Sigma.setSettings s {
minNodeSize: min
minNodeSize: min
, maxNodeSize: max
, maxNodeSize: max
}
}
_ -> pure unit
setState $ const range
setState $ const range
}
}
}
}
src/Gargantext/Components/GraphExplorer/SlideButton.purs
View file @
d31416bc
...
@@ -64,13 +64,12 @@ labelSizeButton sigmaRef state =
...
@@ -64,13 +64,12 @@ labelSizeButton sigmaRef state =
, min: 5.0
, min: 5.0
, max: 30.0
, max: 30.0
, onChange: \e -> do
, onChange: \e -> do
let
mSigma = Sigmax.readSigma $
R.readRef sigmaRef
let
sigma =
R.readRef sigmaRef
let newValue = readFloat $ R2.unsafeEventValue e
let newValue = readFloat $ R2.unsafeEventValue e
let (value /\ setValue) = state
let (value /\ setValue) = state
case mSigma of
Sigmax.dependOnSigma sigma "[labelSizeButton] sigma: Nothing" $ \s -> do
Just s ->
Sigma.setSettings s {
Sigma.setSettings s {
defaultLabelSize: newValue
defaultLabelSize: newValue
}
}
_ -> pure unit
setValue $ const newValue
setValue $ const newValue
}
}
src/Gargantext/Components/GraphExplorer/ToggleButton.purs
View file @
d31416bc
...
@@ -60,17 +60,15 @@ edgesToggleButton sigmaRef state =
...
@@ -60,17 +60,15 @@ edgesToggleButton sigmaRef state =
, onMessage: "Hide Edges"
, onMessage: "Hide Edges"
, offMessage: "Show Edges"
, offMessage: "Show Edges"
, onClick: \_ -> do
, onClick: \_ -> do
let
mSigma = Sigmax.readSigma $
R.readRef sigmaRef
let
sigma =
R.readRef sigmaRef
let (toggled /\ setToggled) = state
let (toggled /\ setToggled) = state
case mSigma of
Sigmax.dependOnSigma sigma "[edgesToggleButton] sigma: Nothing" $ \s -> do
Just s -> do
let settings = {
let settings = {
drawEdges: not toggled
drawEdges: not toggled
, drawEdgeLabels: not toggled
, drawEdgeLabels: not toggled
, hideEdgesOnMove: toggled
, hideEdgesOnMove: toggled
}
}
Sigma.setSettings s settings
Sigma.setSettings s settings
_ -> pure unit
setToggled not
setToggled not
}
}
...
...
src/Gargantext/Hooks/Sigmax.purs
View file @
d31416bc
...
@@ -68,13 +68,8 @@ startSigma ref sigmaRef settings forceAtlas2Settings graph = do
...
@@ -68,13 +68,8 @@ startSigma ref sigmaRef settings forceAtlas2Settings graph = do
delay unit $ handleRefresh sigma
delay unit $ handleRefresh sigma
where
where
handleRefresh sigma _ = do
handleRefresh sigma _ = pure $
let rSigma = readSigma sigma
dependOnSigma sigma "[handleRefresh] can't refresh" Sigma.refreshForceAtlas
_ <- case rSigma of
Nothing -> log2 "[handleRefresh] can't refresh" sigma
Just s -> do
Sigma.refreshForceAtlas s
pure $ pure unit
-- | Manages a sigma with the given settings
-- | Manages a sigma with the given settings
useSigma :: forall settings. settings -> R.Ref (Maybe Sigma) -> R.Hooks {sigma :: Sigma, isNew :: Boolean}
useSigma :: forall settings. settings -> R.Ref (Maybe Sigma) -> R.Hooks {sigma :: Sigma, isNew :: Boolean}
...
@@ -159,8 +154,8 @@ addRenderer sigma renderer = do
...
@@ -159,8 +154,8 @@ addRenderer sigma renderer = do
(const unit <$> ret) <$ report ret
(const unit <$> ret) <$ report ret
where
where
report = either (log2 errorMsg) (\_ -> log successMsg)
report = either (log2 errorMsg) (\_ -> log successMsg)
errorMsg = "[
use
Renderer] Error adding renderer:"
errorMsg = "[
add
Renderer] Error adding renderer:"
successMsg = "[
use
Renderer] Added renderer successfully"
successMsg = "[
add
Renderer] Added renderer successfully"
useData :: forall n e. Sigma -> Graph n e -> R.Hooks Unit
useData :: forall n e. Sigma -> Graph n e -> R.Hooks Unit
useData sigma graph =
useData sigma graph =
...
@@ -273,7 +268,7 @@ useDataEff :: forall n e. Sigma -> Graph n e -> Effect Unit
...
@@ -273,7 +268,7 @@ useDataEff :: forall n e. Sigma -> Graph n e -> Effect Unit
useDataEff sigma graph = dependOnSigma sigma sigmaNotFoundMsg withSigma
useDataEff sigma graph = dependOnSigma sigma sigmaNotFoundMsg withSigma
where
where
withSigma sig = refreshData sig (sigmafy graph)
withSigma sig = refreshData sig (sigmafy graph)
sigmaNotFoundMsg = "[useData] Sigma not found, not adding data"
sigmaNotFoundMsg = "[useData
Eff
] Sigma not found, not adding data"
useCanvasRendererEff :: R.Ref (Nullable Element) -> Sigma -> Effect Unit
useCanvasRendererEff :: R.Ref (Nullable Element) -> Sigma -> Effect Unit
useCanvasRendererEff container sigma =
useCanvasRendererEff container sigma =
...
@@ -285,17 +280,17 @@ useCanvasRendererEff container sigma =
...
@@ -285,17 +280,17 @@ useCanvasRendererEff container sigma =
withSigma sig = addRenderer sig renderer >>= handle
withSigma sig = addRenderer sig renderer >>= handle
where -- close over sig
where -- close over sig
renderer = { "type": "canvas", container: c }
renderer = { "type": "canvas", container: c }
handle _ = log "[useCanvasRenderer] cleanup handle"
handle _ = log "[useCanvasRenderer
Eff
] cleanup handle"
--handle (Right _) = cleanupFirst sigma (Sigma.killRenderer sig renderer >>= logCleanup)
--handle (Right _) = cleanupFirst sigma (Sigma.killRenderer sig renderer >>= logCleanup)
--handle (Left e) =
--handle (Left e) =
-- log2 errorAddingMsg e *> cleanupSigma sigma "useCanvasRenderer"
-- log2 errorAddingMsg e *> cleanupSigma sigma "useCanvasRenderer"
logCleanup (Left e) = log2 errorKillingMsg e
logCleanup (Left e) = log2 errorKillingMsg e
logCleanup _ = log killedMsg
logCleanup _ = log killedMsg
containerNotFoundMsg = "[useCanvasRenderer] Container not found, not adding renderer"
containerNotFoundMsg = "[useCanvasRenderer
Eff
] Container not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRenderer] Sigma not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRenderer
Eff
] Sigma not found, not adding renderer"
errorAddingMsg = "[useCanvasRenderer] Error adding canvas renderer: "
errorAddingMsg = "[useCanvasRenderer
Eff
] Error adding canvas renderer: "
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
errorKillingMsg = "[useCanvasRenderer
Eff
] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer"
killedMsg = "[useCanvasRenderer
Eff
] Killed renderer"
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Effect Unit
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Effect Unit
useForceAtlas2Eff sigma settings = effect
useForceAtlas2Eff sigma settings = effect
...
@@ -306,5 +301,5 @@ useForceAtlas2Eff sigma settings = effect
...
@@ -306,5 +301,5 @@ useForceAtlas2Eff sigma settings = effect
log sigma
log sigma
Sigma.startForceAtlas2 sig settings
Sigma.startForceAtlas2 sig settings
--cleanupFirst sigma (Sigma.killForceAtlas2 sig)
--cleanupFirst sigma (Sigma.killForceAtlas2 sig)
startingMsg = "[
Graph
] Starting ForceAtlas2"
startingMsg = "[
useForceAtlas2Eff
] Starting ForceAtlas2"
sigmaNotFoundMsg = "[
Graph
] Sigma not found, not initialising"
sigmaNotFoundMsg = "[
useForceAtlas2Eff
] Sigma not found, not initialising"
src/Gargantext/Hooks/Sigmax/Sigma.purs
View file @
d31416bc
...
@@ -53,19 +53,6 @@ refresh = runEffectFn1 _refresh
...
@@ -53,19 +53,6 @@ refresh = runEffectFn1 _refresh
foreign import _refresh :: EffectFn1 Sigma Unit
foreign import _refresh :: EffectFn1 Sigma Unit
refreshForceAtlas :: Sigma -> Effect Unit
refreshForceAtlas sigma = do
isRunning <- isForceAtlas2Running sigma
if isRunning then
pure unit
else do
_ <- setTimeout 100 $ do
restartForceAtlas2 sigma
_ <- setTimeout 100 $
stopForceAtlas2 sigma
pure unit
pure unit
addRenderer :: forall r err. Sigma -> r -> Effect (Either err Unit)
addRenderer :: forall r err. Sigma -> r -> Effect (Either err Unit)
addRenderer = runEffectFn4 _addRenderer Left Right
addRenderer = runEffectFn4 _addRenderer Left Right
...
@@ -135,6 +122,19 @@ foreign import _stopForceAtlas2 :: EffectFn1 Sigma Unit
...
@@ -135,6 +122,19 @@ foreign import _stopForceAtlas2 :: EffectFn1 Sigma Unit
foreign import _killForceAtlas2 :: EffectFn1 Sigma Unit
foreign import _killForceAtlas2 :: EffectFn1 Sigma Unit
foreign import _isForceAtlas2Running :: EffectFn1 Sigma Boolean
foreign import _isForceAtlas2Running :: EffectFn1 Sigma Boolean
refreshForceAtlas :: Sigma -> Effect Unit
refreshForceAtlas sigma = do
isRunning <- isForceAtlas2Running sigma
if isRunning then
pure unit
else do
_ <- setTimeout 100 $ do
restartForceAtlas2 sigma
_ <- setTimeout 100 $
stopForceAtlas2 sigma
pure unit
pure unit
newtype SigmaEasing = SigmaEasing String
newtype SigmaEasing = SigmaEasing String
sigmaEasing :: { linear :: SigmaEasing
sigmaEasing :: { linear :: SigmaEasing
...
...
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