Commit 0a60b1bd authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Graph] work on sigmajs not refreshing that much

Works better, but still can't get it to refresh with forceatlas paused.
parent 76c03a2b
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
max-width: 200px; max-width: 200px;
} }
#graph-explorer #sp-container { #graph-explorer #sp-container {
position: absolute;
left: 83%;
top: 150px;
z-index: 1;
border: 1px white solid; border: 1px white solid;
background-color: white; background-color: white;
} }
...@@ -28,6 +32,7 @@ ...@@ -28,6 +32,7 @@
} }
#graph-explorer #tree { #graph-explorer #tree {
position: absolute; position: absolute;
z-index: 1;
} }
/*# sourceMappingURL=Graph.css.map */ /*# sourceMappingURL=Graph.css.map */
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
max-width: 200px max-width: 200px
#sp-container #sp-container
position: absolute
left: 83%
top: 150px
z-index: 1
border: 1px white solid border: 1px white solid
background-color: white background-color: white
...@@ -29,3 +33,4 @@ ...@@ -29,3 +33,4 @@
#tree #tree
position: absolute position: absolute
z-index: 1
...@@ -42,11 +42,7 @@ graphCpt = R.hooksComponent "Graph" cpt ...@@ -42,11 +42,7 @@ graphCpt = R.hooksComponent "Graph" cpt
where where
cpt props _ = do cpt props _ = do
ref <- R.useRef null ref <- R.useRef null
sigma <- useSigma ref props.sigmaSettings props.sigmaRef startSigma ref props.sigmaRef props.sigmaSettings props.forceAtlas2Settings props.graph
useCanvasRenderer ref sigma
useData sigma props.graph
useForceAtlas2 sigma props.forceAtlas2Settings
pure $ RH.div { ref, style: {height: "95%"} } [] pure $ RH.div { ref, style: {height: "95%"} } []
......
...@@ -7,6 +7,7 @@ import Data.Foldable (foldMap) ...@@ -7,6 +7,7 @@ import Data.Foldable (foldMap)
import Data.Int (toNumber) import Data.Int (toNumber)
import Data.Maybe (Maybe(..), fromJust, fromMaybe) import Data.Maybe (Maybe(..), fromJust, fromMaybe)
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
...@@ -89,7 +90,7 @@ explorerCpt state = R.hooksComponent "GraphExplorer" cpt ...@@ -89,7 +90,7 @@ explorerCpt state = R.hooksComponent "GraphExplorer" cpt
, row [ Controls.controls controls ] , row [ Controls.controls controls ]
, row [ tree {mCurrentRoute, treeId} controls , row [ tree {mCurrentRoute, treeId} controls
, mGraph controls.sigmaRef {graphId, graph} , mGraph controls.sigmaRef {graphId, graph}
, Sidebar.sidebar controls ] , Sidebar.sidebar {showSidePanel: fst controls.showSidePanel} ]
, row [ ] , row [ ]
] ]
] ]
...@@ -120,8 +121,10 @@ type GraphProps = ( ...@@ -120,8 +121,10 @@ type GraphProps = (
) )
graphView :: R.Ref (Maybe Sigmax.Sigma) -> Record GraphProps -> R.Element graphView :: R.Ref (Maybe Sigmax.Sigma) -> Record GraphProps -> R.Element
graphView sigmaRef props = R.createElement (R.memo el (==)) props [] --graphView sigmaRef props = R.createElement (R.memo el memoCmp) props []
graphView sigmaRef props = R.createElement el props []
where where
--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
pure $ pure $
......
...@@ -104,7 +104,7 @@ useGraphControls = do ...@@ -104,7 +104,7 @@ useGraphControls = do
showControls <- R.useState' false showControls <- R.useState' false
showSidePanel <- R.useState' false showSidePanel <- R.useState' false
showTree <- R.useState' false showTree <- R.useState' false
sigmaRef <- R.useRef Nothing sigmaRef <- R2.nothingRef
pure { pure {
cursorSize cursorSize
......
...@@ -9,14 +9,18 @@ import Reactix.DOM.HTML as RH ...@@ -9,14 +9,18 @@ import Reactix.DOM.HTML as RH
import Gargantext.Components.GraphExplorer.Controls as Controls import Gargantext.Components.GraphExplorer.Controls as Controls
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
type Props = (
showSidePanel :: Boolean
)
sidebar :: Record Controls.Controls -> R.Element
sidebar controls = R.createElement sidebarCpt controls []
sidebarCpt :: R.Component Controls.Controls sidebar :: Record Props -> R.Element
sidebar props = R.createElement sidebarCpt props []
sidebarCpt :: R.Component Props
sidebarCpt = R.hooksComponent "Sidebar" cpt sidebarCpt = R.hooksComponent "Sidebar" cpt
where where
cpt {showSidePanel: (false /\ _)} _children = do cpt {showSidePanel: false} _children = do
pure $ RH.div {} [] pure $ RH.div {} []
cpt props _children = do cpt props _children = do
pure $ pure $
......
...@@ -13,8 +13,8 @@ import Data.Nullable (Nullable, null) ...@@ -13,8 +13,8 @@ import Data.Nullable (Nullable, null)
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.Sequence (Seq) import Data.Sequence (Seq)
import Data.Traversable (for, for_, traverse, traverse_) import Data.Traversable (for, for_, traverse, traverse_)
import DOM.Simple.Types (Element)
import DOM.Simple.Console (log, log2) import DOM.Simple.Console (log, log2)
import DOM.Simple.Types (Element)
import Effect (Effect) import Effect (Effect)
import FFI.Simple (delay) import FFI.Simple (delay)
import Reactix as R import Reactix as R
...@@ -27,6 +27,7 @@ import Gargantext.Hooks.Sigmax.Types ...@@ -27,6 +27,7 @@ import Gargantext.Hooks.Sigmax.Types
type Sigma = type Sigma =
{ sigma :: R.Ref (Maybe Sigma.Sigma) { sigma :: R.Ref (Maybe Sigma.Sigma)
-- TODO is Seq in cleanup really necessary?
, cleanup :: R.Ref (Seq (Effect Unit)) , cleanup :: R.Ref (Seq (Effect Unit))
} }
...@@ -50,21 +51,49 @@ cleanupFirst :: Sigma -> Effect Unit -> Effect Unit ...@@ -50,21 +51,49 @@ cleanupFirst :: Sigma -> Effect Unit -> Effect Unit
cleanupFirst sigma = cleanupFirst sigma =
R.setRef sigma.cleanup <<< (flip Seq.cons) (R.readRef sigma.cleanup) R.setRef sigma.cleanup <<< (flip Seq.cons) (R.readRef sigma.cleanup)
startSigma :: forall settings faSettings n e. R.Ref (Nullable Element) -> R.Ref (Maybe Sigma) -> settings -> faSettings -> Graph n e -> R.Hooks Unit
startSigma ref sigmaRef settings forceAtlas2Settings graph = do
{sigma, isNew} <- useSigma ref settings sigmaRef
useCanvasRenderer ref sigma
if isNew then do
useData sigma graph
useForceAtlas2 sigma forceAtlas2Settings
else
R.useEffect' $ do
log2 "refreshing" $ readSigma sigma
delay unit $ \_ -> pure $ Sigma.refresh <$> readSigma sigma
-- | Manages a sigma with the given settings -- | Manages a sigma with the given settings
useSigma :: forall settings. R.Ref (Nullable Element) -> settings -> R.Ref (Maybe Sigma) -> R.Hooks Sigma useSigma :: forall settings. R.Ref (Nullable Element) -> settings -> R.Ref (Maybe Sigma) -> R.Hooks {sigma :: Sigma, isNew :: Boolean}
useSigma container settings sigmaRef = do useSigma container settings sigmaRef = do
sigma <- newSigma <$> R2.nothingRef <*> R.useRef Seq.empty sigma <- newSigma sigmaRef
R.useEffect2 container sigma.sigma $ let isNew = case (readSigma sigma) of
Just _ -> false
_ -> true
R.useEffect1 isNew $ do
log2 "isNew" isNew
log2 "sigmaRef" $ R.readRef sigmaRef
log2 "sigma" sigma
delay unit $ handleSigma sigma (readSigma sigma) delay unit $ handleSigma sigma (readSigma sigma)
pure sigma pure $ {sigma, isNew}
where where
newSigma sigma cleanup = { sigma, cleanup } newSigma sigmaRef = do
handleSigma sigma (Just _) _ = pure R.nothing let mSigma = R.readRef sigmaRef
case mSigma of
Just sigma -> pure sigma
Nothing -> do
s <- R2.nothingRef
c <- R.useRef Seq.empty
pure {sigma: s, cleanup: c}
handleSigma sigma (Just _) _ = do
pure R.nothing
handleSigma sigma Nothing _ = do handleSigma sigma Nothing _ = do
ret <- createSigma settings ret <- createSigma settings
traverse_ (writeSigma sigma <<< Just) ret traverse_ (writeSigma sigma <<< Just) ret
R.setRef sigmaRef $ Just sigma R.setRef sigmaRef $ Just sigma
pure $ cleanupSigma sigma "useSigma" --pure $ cleanupSigma sigma "useSigma"
pure $ R.nothing
-- | Manages a renderer for the sigma -- | Manages a renderer for the sigma
useCanvasRenderer :: R.Ref (Nullable Element) -> Sigma -> R.Hooks Unit useCanvasRenderer :: R.Ref (Nullable Element) -> Sigma -> R.Hooks Unit
......
...@@ -6,12 +6,13 @@ import Data.Generic.Rep (class Generic) ...@@ -6,12 +6,13 @@ import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Data.Sequence as Seq import Data.Sequence as Seq
import Data.Sequence (Seq) import Data.Sequence (Seq)
import Reactix as R
import DOM.Simple.Types (Element) import DOM.Simple.Types (Element)
import Reactix as R
import Prim.RowList (RowToList)
newtype Graph n e = Graph { nodes :: Seq {|n}, edges :: Seq {|e} } newtype Graph n e = Graph { nodes :: Seq {|n}, edges :: Seq {|e} }
derive instance eqGraph :: Eq Graph --derive instance eqGraph :: Eq Graph
--instance eqGraph :: Eq Graph where --instance eqGraph :: Eq Graph where
-- eq (Graph {nodes: n1, edges: e1}) (Graph {nodes: n2, edges: e2}) = n1 == n2 && e1 == e2 -- eq (Graph {nodes: n1, edges: e1}) (Graph {nodes: n2, edges: e2}) = n1 == n2 && e1 == e2
......
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