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
centerButton :: R.Ref Sigmax.Sigma -> R.Element
centerButton sigmaRef = simpleButton {
onClick: \_ -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
log2 "[centerButton] mSigma" mSigma
case mSigma of
Just s -> Sigma.goToAllCameras s {x: 0.0, y: 0.0, ratio: 1.0, angle: 0.0}
_ -> pure unit
let sigma = R.readRef sigmaRef
Sigmax.dependOnSigma sigma "[centerButton] sigma: Nothing" $ \s ->
Sigma.goToAllCameras s {x: 0.0, y: 0.0, ratio: 1.0, angle: 0.0}
, text: "Center"
}
......@@ -46,13 +46,12 @@ edgeSizeControl sigmaRef (state /\ setState) =
, width: 10.0
, height: 5.0
, onChange: \range@(Range.Closed {min, max}) -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
case mSigma of
Just s -> Sigma.setSettings s {
minEdgeSize: min
, maxEdgeSize: max
}
_ -> pure unit
let sigma = R.readRef sigmaRef
Sigmax.dependOnSigma sigma "[edgeSizeControl] sigma: Nothing" $ \s -> do
Sigma.setSettings s {
minEdgeSize: min
, maxEdgeSize: max
}
setState $ const range
}
}
......@@ -69,13 +68,12 @@ nodeSizeControl sigmaRef (state /\ setState) =
, width: 10.0
, height: 5.0
, onChange: \range@(Range.Closed {min, max}) -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
case mSigma of
Just s -> Sigma.setSettings s {
minNodeSize: min
, maxNodeSize: max
}
_ -> pure unit
let sigma = R.readRef sigmaRef
Sigmax.dependOnSigma sigma "[nodeSizeControl] sigma: Nothing" $ \s -> do
Sigma.setSettings s {
minNodeSize: min
, maxNodeSize: max
}
setState $ const range
}
}
......@@ -64,13 +64,12 @@ labelSizeButton sigmaRef state =
, min: 5.0
, max: 30.0
, onChange: \e -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
let sigma = R.readRef sigmaRef
let newValue = readFloat $ R2.unsafeEventValue e
let (value /\ setValue) = state
case mSigma of
Just s -> Sigma.setSettings s {
Sigmax.dependOnSigma sigma "[labelSizeButton] sigma: Nothing" $ \s -> do
Sigma.setSettings s {
defaultLabelSize: newValue
}
_ -> pure unit
}
setValue $ const newValue
}
......@@ -60,17 +60,15 @@ edgesToggleButton sigmaRef state =
, onMessage: "Hide Edges"
, offMessage: "Show Edges"
, onClick: \_ -> do
let mSigma = Sigmax.readSigma $ R.readRef sigmaRef
let sigma = R.readRef sigmaRef
let (toggled /\ setToggled) = state
case mSigma of
Just s -> do
let settings = {
drawEdges: not toggled
, drawEdgeLabels: not toggled
, hideEdgesOnMove: toggled
}
Sigma.setSettings s settings
_ -> pure unit
Sigmax.dependOnSigma sigma "[edgesToggleButton] sigma: Nothing" $ \s -> do
let settings = {
drawEdges: not toggled
, drawEdgeLabels: not toggled
, hideEdgesOnMove: toggled
}
Sigma.setSettings s settings
setToggled not
}
......
......@@ -68,13 +68,8 @@ startSigma ref sigmaRef settings forceAtlas2Settings graph = do
delay unit $ handleRefresh sigma
where
handleRefresh sigma _ = do
let rSigma = readSigma sigma
_ <- case rSigma of
Nothing -> log2 "[handleRefresh] can't refresh" sigma
Just s -> do
Sigma.refreshForceAtlas s
pure $ pure unit
handleRefresh sigma _ = pure $
dependOnSigma sigma "[handleRefresh] can't refresh" Sigma.refreshForceAtlas
-- | Manages a sigma with the given settings
useSigma :: forall settings. settings -> R.Ref (Maybe Sigma) -> R.Hooks {sigma :: Sigma, isNew :: Boolean}
......@@ -159,8 +154,8 @@ addRenderer sigma renderer = do
(const unit <$> ret) <$ report ret
where
report = either (log2 errorMsg) (\_ -> log successMsg)
errorMsg = "[useRenderer] Error adding renderer:"
successMsg = "[useRenderer] Added renderer successfully"
errorMsg = "[addRenderer] Error adding renderer:"
successMsg = "[addRenderer] Added renderer successfully"
useData :: forall n e. Sigma -> Graph n e -> R.Hooks Unit
useData sigma graph =
......@@ -273,7 +268,7 @@ useDataEff :: forall n e. Sigma -> Graph n e -> Effect Unit
useDataEff sigma graph = dependOnSigma sigma sigmaNotFoundMsg withSigma
where
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 container sigma =
......@@ -285,17 +280,17 @@ useCanvasRendererEff container sigma =
withSigma sig = addRenderer sig renderer >>= handle
where -- close over sig
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 (Left e) =
-- log2 errorAddingMsg e *> cleanupSigma sigma "useCanvasRenderer"
logCleanup (Left e) = log2 errorKillingMsg e
logCleanup _ = log killedMsg
containerNotFoundMsg = "[useCanvasRenderer] Container not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRenderer] Sigma not found, not adding renderer"
errorAddingMsg = "[useCanvasRenderer] Error adding canvas renderer: "
errorKillingMsg = "[useCanvasRenderer] Error killing renderer:"
killedMsg = "[useCanvasRenderer] Killed renderer"
containerNotFoundMsg = "[useCanvasRendererEff] Container not found, not adding renderer"
sigmaNotFoundMsg = "[useCanvasRendererEff] Sigma not found, not adding renderer"
errorAddingMsg = "[useCanvasRendererEff] Error adding canvas renderer: "
errorKillingMsg = "[useCanvasRendererEff] Error killing renderer:"
killedMsg = "[useCanvasRendererEff] Killed renderer"
useForceAtlas2Eff :: forall settings. Sigma -> settings -> Effect Unit
useForceAtlas2Eff sigma settings = effect
......@@ -306,5 +301,5 @@ useForceAtlas2Eff sigma settings = effect
log sigma
Sigma.startForceAtlas2 sig settings
--cleanupFirst sigma (Sigma.killForceAtlas2 sig)
startingMsg = "[Graph] Starting ForceAtlas2"
sigmaNotFoundMsg = "[Graph] Sigma not found, not initialising"
startingMsg = "[useForceAtlas2Eff] Starting ForceAtlas2"
sigmaNotFoundMsg = "[useForceAtlas2Eff] Sigma not found, not initialising"
......@@ -53,19 +53,6 @@ refresh = runEffectFn1 _refresh
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 = runEffectFn4 _addRenderer Left Right
......@@ -135,6 +122,19 @@ foreign import _stopForceAtlas2 :: EffectFn1 Sigma Unit
foreign import _killForceAtlas2 :: EffectFn1 Sigma Unit
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
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