Commit 3a1dc8f0 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] doesn't flicker now at all!

Turns out the issue was also at parent getting rerenders.
So the trick is that I added an empty div with ref for parent node and,
next to it, the Graph component pointing to that ref.
Graph component calls react's usePortal with that parent ref and a small
'createElement' div to hold sigma canvases.
parent 0c587e36
...@@ -11,6 +11,7 @@ import Data.Sequence as Seq ...@@ -11,6 +11,7 @@ import Data.Sequence as Seq
import DOM.Simple (createElement, setAttr) import DOM.Simple (createElement, setAttr)
import DOM.Simple.Console (log, log2) import DOM.Simple.Console (log, log2)
import DOM.Simple.Types (Element) import DOM.Simple.Types (Element)
import Effect.Timer (setTimeout)
import FFI.Simple (delay) import FFI.Simple (delay)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as RH import Reactix.DOM.HTML as RH
...@@ -49,7 +50,7 @@ graphCpt :: forall s fa2. R.Component (Props s fa2) ...@@ -49,7 +50,7 @@ graphCpt :: forall s fa2. R.Component (Props s fa2)
graphCpt = R.hooksComponent "Graph" cpt graphCpt = R.hooksComponent "Graph" cpt
where where
cpt props _ = do cpt props _ = do
R.useEffect' $ do R.useEffectOnce' $ do
el <- case R.readNullableRef props.elRef of el <- case R.readNullableRef props.elRef of
Just el -> do Just el -> do
pure el pure el
...@@ -61,12 +62,12 @@ graphCpt = R.hooksComponent "Graph" cpt ...@@ -61,12 +62,12 @@ graphCpt = R.hooksComponent "Graph" cpt
pure el pure el
case R.readNullableRef props.parentRef of case R.readNullableRef props.parentRef of
Nothing -> R2.addRootElement el Nothing -> pure unit
Just parentEl -> R2.appendChild parentEl el Just parentEl -> R2.appendChild parentEl el
pure unit pure unit
R.useEffectOnce $ do R.useEffectOnce $ do
log "[graphCpt] calling startSigmaEff" --log "[graphCpt] calling startSigmaEff"
startSigmaEff props.elRef props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph startSigmaEff props.elRef props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
delay unit $ \_ -> do delay unit $ \_ -> do
......
...@@ -41,7 +41,7 @@ type LayoutProps = ...@@ -41,7 +41,7 @@ type LayoutProps =
) )
type Props = ( type Props = (
graphElRef :: R.Ref (Nullable Element) graphParentRef :: R.Ref (Nullable Element)
, graph :: Maybe Graph.Graph | LayoutProps , graph :: Maybe Graph.Graph | LayoutProps
) )
...@@ -53,11 +53,11 @@ explorerLayoutCpt :: R.Component LayoutProps ...@@ -53,11 +53,11 @@ explorerLayoutCpt :: R.Component LayoutProps
explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt explorerLayoutCpt = R.hooksComponent "G.C.GraphExplorer.explorerLayout" cpt
where where
cpt {graphId, mCurrentRoute, treeId, session, sessions, frontends} _ = do cpt {graphId, mCurrentRoute, treeId, session, sessions, frontends} _ = do
graphElRef <- R.useRef null graphParentRef <- R.useRef null
useLoader graphId (getNodes session) (handler graphElRef) useLoader graphId (getNodes session) (handler graphParentRef)
where where
handler graphElRef loaded = handler graphParentRef loaded =
explorer {graphElRef, graphId, mCurrentRoute, treeId, session, sessions, graph, frontends} explorer {graphParentRef, graphId, mCurrentRoute, treeId, session, sessions, graph, frontends}
where graph = Just (convert loaded) where graph = Just (convert loaded)
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -67,7 +67,7 @@ explorer props = R.createElement explorerCpt props [] ...@@ -67,7 +67,7 @@ explorer props = R.createElement explorerCpt props []
explorerCpt :: R.Component Props explorerCpt :: R.Component Props
explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
where where
cpt {graphElRef, sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do cpt {graphParentRef, sessions, session, graphId, mCurrentRoute, treeId, graph, frontends} _ = do
controls <- Controls.useGraphControls controls <- Controls.useGraphControls
state <- useExplorerState state <- useExplorerState
x /\ setX <- R.useState' 0 x /\ setX <- R.useState' 0
...@@ -87,7 +87,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -87,7 +87,8 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, RH.div {on: {click: \e -> setX $ \x_ -> x_ + 1}} [ RH.text ("Counter: " <> (show x)) ] , RH.div {on: {click: \e -> setX $ \x_ -> x_ + 1}} [ RH.text ("Counter: " <> (show x)) ]
] ]
, row [ tree {mCurrentRoute, treeId} controls showLogin , row [ tree {mCurrentRoute, treeId} controls showLogin
, mGraph graphElRef controls.sigmaRef {graphId, graph} , RH.div { ref: graphParentRef, id: "graph-view", className: "col-md-12" } [] -- graph parent
, mGraph graphParentRef controls.sigmaRef {graphId, graph}
, Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ] , Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ]
, row [ , row [
] ]
...@@ -112,7 +113,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -112,7 +113,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
mGraph :: R.Ref (Nullable Element) -> R.Ref Sigma -> {graphId :: GraphId, graph :: Maybe Graph.Graph} -> R.Element mGraph :: R.Ref (Nullable Element) -> R.Ref Sigma -> {graphId :: GraphId, graph :: Maybe Graph.Graph} -> R.Element
mGraph _ _ {graph: Nothing} = RH.div {} [] mGraph _ _ {graph: Nothing} = RH.div {} []
mGraph graphElRef sigmaRef {graphId, graph: Just graph} = graphView graphElRef sigmaRef {graphId, graph} mGraph graphParentRef sigmaRef {graphId, graph: Just graph} = graphView graphParentRef sigmaRef {graphId, graph}
useExplorerState :: R.Hooks (Record GET.State) useExplorerState :: R.Hooks (Record GET.State)
useExplorerState = do pure {} useExplorerState = do pure {}
...@@ -139,17 +140,14 @@ type GraphProps = ( ...@@ -139,17 +140,14 @@ type GraphProps = (
graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element graphView :: R.Ref (Nullable Element) -> R.Ref Sigma -> Record GraphProps -> R.Element
--graphView sigmaRef props = R.createElement (R.memo el memoCmp) props [] --graphView sigmaRef props = R.createElement (R.memo el memoCmp) props []
graphView elRef sigmaRef props = R.createElement el props [] graphView parentRef sigmaRef props = R.createElement el props []
where where
--memoCmp props1 props2 = props1.graphId == props2.graphId --memoCmp props1 props2 = props1.graphId == props2.graphId
el = R.hooksComponent "GraphView" cpt el = R.hooksComponent "GraphView" cpt
cpt {graphId, graph} _children = do cpt {graphId, graph} _children = do
parentRef <- R.useRef null elRef <- R.useRef null
pure $ pure $ Graph.graph {
RH.div { ref: parentRef, id: "graph-view", className: "col-md-12" }
[
Graph.graph {
elRef elRef
, forceAtlas2Settings: Graph.forceAtlas2Settings , forceAtlas2Settings: Graph.forceAtlas2Settings
, graph , graph
...@@ -157,7 +155,6 @@ graphView elRef sigmaRef props = R.createElement el props [] ...@@ -157,7 +155,6 @@ graphView elRef sigmaRef props = R.createElement el props []
, sigmaSettings: Graph.sigmaSettings , sigmaSettings: Graph.sigmaSettings
, sigmaRef: sigmaRef , sigmaRef: sigmaRef
} }
]
convert :: GET.GraphData -> Graph.Graph convert :: GET.GraphData -> Graph.Graph
convert (GET.GraphData r) = Sigmax.Graph {nodes, edges} convert (GET.GraphData r) = Sigmax.Graph {nodes, edges}
......
...@@ -220,23 +220,23 @@ startSigmaEff ref sigmaRef settings forceAtlas2Settings graph = do ...@@ -220,23 +220,23 @@ startSigmaEff ref sigmaRef settings forceAtlas2Settings graph = do
let rSigma = R.readRef sigmaRef let rSigma = R.readRef sigmaRef
case readSigma rSigma of case readSigma rSigma of
Nothing -> do Nothing -> do
log "[startSigmaEff] calling useSigmaEff" --log "[startSigmaEff] calling useSigmaEff"
sigma <- useSigmaEff settings sigmaRef sigma <- useSigmaEff settings sigmaRef
log "[startSigmaEff] calling useCanvasRendererEff" --log "[startSigmaEff] calling useCanvasRendererEff"
useCanvasRendererEff ref sigma useCanvasRendererEff ref sigma
log "[startSigmaEff] calling useDataEff" --log "[startSigmaEff] calling useDataEff"
useDataEff sigma graph useDataEff sigma graph
log "[startSigmaEff] calling useForceAtlas2Eff" --log "[startSigmaEff] calling useForceAtlas2Eff"
useForceAtlas2Eff sigma forceAtlas2Settings useForceAtlas2Eff sigma forceAtlas2Settings
Just sig -> do Just sig -> do
log "[startSigmaEff] sigma initialized already" --log "[startSigmaEff] sigma initialized already"
--Sigma.swapRendererContainer ref sig --Sigma.swapRendererContainer ref sig
--dependOnContainer ref "[startSigmaEff] no container" $ Sigma.setRendererContainer sig --dependOnContainer ref "[startSigmaEff] no container" $ Sigma.setRendererContainer sig
--useCanvasRendererEff ref rSigma --useCanvasRendererEff ref rSigma
--useDataEff rSigma graph --useDataEff rSigma graph
--useForceAtlas2Eff rSigma forceAtlas2Settings --useForceAtlas2Eff rSigma forceAtlas2Settings
log "[startSigmaEff] refreshForceAtlas" --log "[startSigmaEff] refreshForceAtlas"
--Sigma.refreshForceAtlas sig --Sigma.refreshForceAtlas sig
--if isFARunning then --if isFARunning then
-- Sigma.restartForceAtlas2 sig -- Sigma.restartForceAtlas2 sig
...@@ -301,8 +301,7 @@ useForceAtlas2Eff sigma settings = effect ...@@ -301,8 +301,7 @@ useForceAtlas2Eff sigma settings = effect
where where
effect = dependOnSigma sigma sigmaNotFoundMsg withSigma effect = dependOnSigma sigma sigmaNotFoundMsg withSigma
withSigma sig = do withSigma sig = do
log startingMsg --log2 startingMsg sigma
log sigma
Sigma.startForceAtlas2 sig settings Sigma.startForceAtlas2 sig settings
--cleanupFirst sigma (Sigma.killForceAtlas2 sig) --cleanupFirst sigma (Sigma.killForceAtlas2 sig)
startingMsg = "[useForceAtlas2Eff] Starting ForceAtlas2" startingMsg = "[useForceAtlas2Eff] Starting ForceAtlas2"
...@@ -313,10 +312,10 @@ handleForceAtlas2Pause :: R.Ref Sigma -> R.State Boolean -> Effect Unit ...@@ -313,10 +312,10 @@ handleForceAtlas2Pause :: R.Ref Sigma -> R.State Boolean -> Effect Unit
handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) = do handleForceAtlas2Pause sigmaRef (toggled /\ setToggled) = do
let sigma = R.readRef sigmaRef let sigma = R.readRef sigmaRef
dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do dependOnSigma sigma "[handleForceAtlas2Pause] sigma: Nothing" $ \s -> do
log2 "[handleForceAtlas2Pause] mSigma: Just " s --log2 "[handleForceAtlas2Pause] mSigma: Just " s
log2 "[handleForceAtlas2Pause] toggled: " toggled --log2 "[handleForceAtlas2Pause] toggled: " toggled
isFARunning <- Sigma.isForceAtlas2Running s isFARunning <- Sigma.isForceAtlas2Running s
log2 "[handleForceAtlas2Pause] isFARunning: " isFARunning --log2 "[handleForceAtlas2Pause] isFARunning: " isFARunning
case Tuple toggled isFARunning of case Tuple toggled isFARunning of
Tuple true false -> Sigma.restartForceAtlas2 s Tuple true false -> Sigma.restartForceAtlas2 s
Tuple false true -> Sigma.stopForceAtlas2 s Tuple false true -> Sigma.stopForceAtlas2 s
......
...@@ -6,6 +6,7 @@ import Data.Nullable (Nullable, null, toMaybe) ...@@ -6,6 +6,7 @@ import Data.Nullable (Nullable, null, toMaybe)
import Data.Tuple (Tuple) import Data.Tuple (Tuple)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import DOM.Simple as DOM import DOM.Simple as DOM
import DOM.Simple.Console (log, log2)
import DOM.Simple.Document (document) import DOM.Simple.Document (document)
import DOM.Simple.Event as DE import DOM.Simple.Event as DE
import DOM.Simple.Element as Element import DOM.Simple.Element as Element
...@@ -177,3 +178,12 @@ foreign import _addRootElement ...@@ -177,3 +178,12 @@ foreign import _addRootElement
appendChild :: forall n m. IsNode n => IsNode m => n -> m -> Effect Unit appendChild :: forall n m. IsNode n => IsNode m => n -> m -> Effect Unit
appendChild n c = delay unit $ \_ -> pure $ n ... "appendChild" $ [c] appendChild n c = delay unit $ \_ -> pure $ n ... "appendChild" $ [c]
appendChildToParentId :: forall c. IsNode c => String -> c -> Effect Unit
appendChildToParentId ps c = delay unit $ \_ -> do
parentEl <- getElementById ps
log2 "[appendChildToParentId] ps" ps
log2 "[appendChildToParentId] parentEl" parentEl
case parentEl of
Nothing -> pure unit
Just el -> appendChild el c
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