Commit d31416bc authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] some refactoring (use dependOnSigma)

parent f32bd31b
...@@ -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"
} }
...@@ -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
} }
} }
...@@ -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
} }
...@@ -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
} }
......
...@@ -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 = "[useRenderer] Error adding renderer:" errorMsg = "[addRenderer] Error adding renderer:"
successMsg = "[useRenderer] Added renderer successfully" successMsg = "[addRenderer] 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 = "[useDataEff] 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 "[useCanvasRendererEff] 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 = "[useCanvasRendererEff] Container not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRenderer] Sigma not found, not adding renderer" sigmaNotFoundMsg = "[useCanvasRendererEff] Sigma not found, not adding renderer"
errorAddingMsg = "[useCanvasRenderer] Error adding canvas renderer: " errorAddingMsg = "[useCanvasRendererEff] Error adding canvas renderer: "
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:" errorKillingMsg = "[useCanvasRendererEff] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer" killedMsg = "[useCanvasRendererEff] 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"
...@@ -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
......
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