Commit a1ba6d5b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph] screenshot works properly now, with storing camera position

parent 646baddf
...@@ -16,6 +16,7 @@ import FFI.Simple (delay) ...@@ -16,6 +16,7 @@ import FFI.Simple (delay)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as RH import Reactix.DOM.HTML as RH
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax as Sigmax import Gargantext.Hooks.Sigmax as Sigmax
import Gargantext.Hooks.Sigmax.Types as SigmaxTypes import Gargantext.Hooks.Sigmax.Types as SigmaxTypes
import Gargantext.Hooks.Sigmax.Sigma as Sigma import Gargantext.Hooks.Sigmax.Sigma as Sigma
...@@ -24,10 +25,11 @@ type OnProps = () ...@@ -24,10 +25,11 @@ type OnProps = ()
data Stage = Init | Ready | Cleanup data Stage = Init | Ready | Cleanup
type Props sigma forceatlas2 = type Props sigma forceatlas2 = (
( elRef :: R.Ref (Nullable Element) elRef :: R.Ref (Nullable Element)
, forceAtlas2Settings :: forceatlas2 , forceAtlas2Settings :: forceatlas2
, graph :: SigmaxTypes.SGraph , graph :: SigmaxTypes.SGraph
, mCamera :: Maybe GET.Camera
, multiSelectEnabledRef :: R.Ref Boolean , multiSelectEnabledRef :: R.Ref Boolean
, selectedNodeIds :: R.State SigmaxTypes.NodeIds , selectedNodeIds :: R.State SigmaxTypes.NodeIds
, showEdges :: R.State SigmaxTypes.ShowEdgesState , showEdges :: R.State SigmaxTypes.ShowEdgesState
...@@ -84,12 +86,17 @@ graphCpt = R.hooksComponent "G.C.Graph" cpt ...@@ -84,12 +86,17 @@ graphCpt = R.hooksComponent "G.C.Graph" cpt
Sigmax.setEdges sig false Sigmax.setEdges sig false
log2 "[graph] startForceAtlas" props.startForceAtlas -- log2 "[graph] startForceAtlas" props.startForceAtlas
if props.startForceAtlas then if props.startForceAtlas then
Sigma.startForceAtlas2 sig props.forceAtlas2Settings Sigma.startForceAtlas2 sig props.forceAtlas2Settings
else else
Sigma.stopForceAtlas2 sig Sigma.stopForceAtlas2 sig
case props.mCamera of
Nothing -> pure unit
Just (GET.Camera { ratio, x, y }) -> do
Sigma.updateCamera sig { ratio, x, y }
pure unit pure unit
Just sig -> do Just sig -> do
pure unit pure unit
......
...@@ -50,8 +50,8 @@ type LayoutProps = ...@@ -50,8 +50,8 @@ type LayoutProps =
type Props = ( type Props = (
graph :: SigmaxT.SGraph graph :: SigmaxT.SGraph
, graphData :: GET.GraphData
, graphVersion :: R.State Int , graphVersion :: R.State Int
, hyperdataGraph :: GET.HyperdataGraph
, mMetaData :: Maybe GET.MetaData , mMetaData :: Maybe GET.MetaData
| LayoutProps | LayoutProps
) )
...@@ -76,8 +76,10 @@ explorerLayoutView graphVersion p = R.createElement el p [] ...@@ -76,8 +76,10 @@ explorerLayoutView graphVersion p = R.createElement el p []
useLoader graphId (getNodes session graphVersion) handler useLoader graphId (getNodes session graphVersion) handler
where where
handler loaded = handler loaded =
explorer (Record.merge props { graph, graphData: loaded, graphVersion, mMetaData }) explorer (Record.merge props { graph, graphVersion, hyperdataGraph: loaded, mMetaData })
where (Tuple mMetaData graph) = convert loaded where
GET.HyperdataGraph { graph: hyperdataGraph } = loaded
(Tuple mMetaData graph) = convert hyperdataGraph
-------------------------------------------------------------- --------------------------------------------------------------
explorer :: Record Props -> R.Element explorer :: Record Props -> R.Element
...@@ -88,10 +90,10 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -88,10 +90,10 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
where where
cpt props@{ frontends cpt props@{ frontends
, graph , graph
, graphData
, graphId , graphId
, graphVersion , graphVersion
, handed , handed
, hyperdataGraph
, mCurrentRoute , mCurrentRoute
, mMetaData , mMetaData
, session , session
...@@ -105,7 +107,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -105,7 +107,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
dataRef <- R.useRef graph dataRef <- R.useRef graph
graphRef <- R.useRef null graphRef <- R.useRef null
graphVersionRef <- R.useRef (fst graphVersion) graphVersionRef <- R.useRef (fst graphVersion)
controls <- Controls.useGraphControls graph graphData graphId session forceAtlasS controls <- Controls.useGraphControls graph graphId hyperdataGraph session forceAtlasS
multiSelectEnabledRef <- R.useRef $ fst controls.multiSelectEnabled multiSelectEnabledRef <- R.useRef $ fst controls.multiSelectEnabled
R.useEffect' $ do R.useEffect' $ do
...@@ -151,6 +153,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt ...@@ -151,6 +153,7 @@ explorerCpt = R.hooksComponent "G.C.GraphExplorer.explorer" cpt
, elRef: graphRef , elRef: graphRef
, graphId , graphId
, graph , graph
, hyperdataGraph
, mMetaData , mMetaData
, multiSelectEnabledRef , multiSelectEnabledRef
} }
...@@ -218,11 +221,12 @@ type MSidebarProps = ...@@ -218,11 +221,12 @@ type MSidebarProps =
) )
type GraphProps = ( type GraphProps = (
controls :: Record Controls.Controls controls :: Record Controls.Controls
, elRef :: R.Ref (Nullable Element) , elRef :: R.Ref (Nullable Element)
, graphId :: GET.GraphId , graphId :: GET.GraphId
, graph :: SigmaxT.SGraph , graph :: SigmaxT.SGraph
, mMetaData :: Maybe GET.MetaData , hyperdataGraph :: GET.HyperdataGraph
, mMetaData :: Maybe GET.MetaData
, multiSelectEnabledRef :: R.Ref Boolean , multiSelectEnabledRef :: R.Ref Boolean
) )
...@@ -233,7 +237,13 @@ graphView props = R.createElement graphViewCpt props [] ...@@ -233,7 +237,13 @@ graphView props = R.createElement graphViewCpt props []
graphViewCpt :: R.Component GraphProps graphViewCpt :: R.Component GraphProps
graphViewCpt = R.hooksComponent "GraphView" cpt graphViewCpt = R.hooksComponent "GraphView" cpt
where where
cpt {controls, elRef, graphId, graph, mMetaData, multiSelectEnabledRef} _children = do cpt { controls
, elRef
, graphId
, graph
, hyperdataGraph: GET.HyperdataGraph { mCamera }
, mMetaData
, multiSelectEnabledRef } _children = do
-- TODO Cache this? -- TODO Cache this?
let louvainGraph = let louvainGraph =
if (fst controls.showLouvain) then if (fst controls.showLouvain) then
...@@ -252,6 +262,7 @@ graphViewCpt = R.hooksComponent "GraphView" cpt ...@@ -252,6 +262,7 @@ graphViewCpt = R.hooksComponent "GraphView" cpt
elRef elRef
, forceAtlas2Settings: Graph.forceAtlas2Settings , forceAtlas2Settings: Graph.forceAtlas2Settings
, graph , graph
, mCamera
, multiSelectEnabledRef , multiSelectEnabledRef
, selectedNodeIds: controls.selectedNodeIds , selectedNodeIds: controls.selectedNodeIds
, showEdges: controls.showEdges , showEdges: controls.showEdges
...@@ -315,7 +326,7 @@ modeGraphType Types.Sources = "star" ...@@ -315,7 +326,7 @@ modeGraphType Types.Sources = "star"
modeGraphType Types.Terms = "def" modeGraphType Types.Terms = "def"
getNodes :: Session -> R.State Int -> GET.GraphId -> Aff GET.GraphData getNodes :: Session -> R.State Int -> GET.GraphId -> Aff GET.HyperdataGraph
getNodes session (graphVersion /\ _) graphId = get session $ NodeAPI Types.Graph (Just graphId) ("?version=" <> show graphVersion) getNodes session (graphVersion /\ _) graphId = get session $ NodeAPI Types.Graph (Just graphId) ("?version=" <> show graphVersion)
......
module Gargantext.Components.GraphExplorer.API where module Gargantext.Components.GraphExplorer.API where
import Data.Maybe (Maybe) import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Gargantext.Components.GraphExplorer.Types as GET import Gargantext.Components.GraphExplorer.Types as GET
...@@ -84,10 +84,10 @@ updateGraphVersions { graphId, session } = post session (GR.GraphAPI graphId $ " ...@@ -84,10 +84,10 @@ updateGraphVersions { graphId, session } = post session (GR.GraphAPI graphId $ "
type CloneGraphParams = type CloneGraphParams =
( (
graphData :: GET.GraphData hyperdataGraph :: GET.HyperdataGraph
, id :: Int , id :: Int
, session :: Session , session :: Session
) )
cloneGraph :: Record CloneGraphParams -> Aff Int cloneGraph :: Record CloneGraphParams -> Aff Int
cloneGraph { graphData, id, session } = post session (GR.GraphAPI id $ "clone") graphData cloneGraph { hyperdataGraph, id, session } = post session (GR.GraphAPI id $ "clone") hyperdataGraph
...@@ -59,7 +59,7 @@ centerButton sigmaRef = simpleButton { ...@@ -59,7 +59,7 @@ centerButton sigmaRef = simpleButton {
type CameraButtonProps = ( type CameraButtonProps = (
id :: Int id :: Int
, graphData :: GET.GraphData , hyperdataGraph :: GET.HyperdataGraph
, session :: Session , session :: Session
, sigmaRef :: R.Ref Sigmax.Sigma , sigmaRef :: R.Ref Sigmax.Sigma
) )
...@@ -67,7 +67,7 @@ type CameraButtonProps = ( ...@@ -67,7 +67,7 @@ type CameraButtonProps = (
cameraButton :: Record CameraButtonProps -> R.Element cameraButton :: Record CameraButtonProps -> R.Element
cameraButton { id cameraButton { id
, graphData: GET.GraphData graphData' , hyperdataGraph: GET.HyperdataGraph { graph: GET.GraphData hyperdataGraph }
, session , session
, sigmaRef } = simpleButton { , sigmaRef } = simpleButton {
onClick: \_ -> do onClick: \_ -> do
...@@ -86,10 +86,20 @@ cameraButton { id ...@@ -86,10 +86,20 @@ cameraButton { id
, show $ fromEnum $ DDT.second nowt ] , show $ fromEnum $ DDT.second nowt ]
edges <- Sigmax.getEdges s edges <- Sigmax.getEdges s
nodes <- Sigmax.getNodes s nodes <- Sigmax.getNodes s
let graphData = GET.GraphData $ graphData' { edges = map GEU.stEdgeToGET edges let graphData = GET.GraphData $ hyperdataGraph { edges = map GEU.stEdgeToGET edges
, nodes = map GEU.stNodeToGET nodes } , nodes = map GEU.stNodeToGET nodes }
let cameras = map Sigma.toCamera $ Sigma.cameras s
let camera = case cameras of
[c] -> GET.Camera { ratio: c.ratio
, x: c.x
, y: c.y }
_ -> GET.Camera { ratio: 1.0
, x: 0.0
, y: 0.0 }
let hyperdataGraph = GET.HyperdataGraph { graph: graphData
, mCamera: Just camera }
launchAff_ $ do launchAff_ $ do
_ <- cloneGraph { id, graphData, session } clonedGraphId <- cloneGraph { id, hyperdataGraph, session }
uploadArbitraryDataURL session id (Just $ nowStr <> "-" <> "screenshot.png") screen uploadArbitraryDataURL session clonedGraphId (Just $ nowStr <> "-" <> "screenshot.png") screen
, text: "Screenshot" , text: "Screenshot"
} }
...@@ -38,9 +38,9 @@ type Controls = ...@@ -38,9 +38,9 @@ type Controls =
, edgeWeight :: R.State Range.NumberRange , edgeWeight :: R.State Range.NumberRange
, forceAtlasState :: R.State SigmaxT.ForceAtlasState , forceAtlasState :: R.State SigmaxT.ForceAtlasState
, graph :: SigmaxT.SGraph , graph :: SigmaxT.SGraph
, graphData :: GET.GraphData
, graphId :: GET.GraphId , graphId :: GET.GraphId
, graphStage :: R.State Graph.Stage , graphStage :: R.State Graph.Stage
, hyperdataGraph :: GET.HyperdataGraph
, multiSelectEnabled :: R.State Boolean , multiSelectEnabled :: R.State Boolean
, nodeSize :: R.State Range.NumberRange , nodeSize :: R.State Range.NumberRange
, removedNodeIds :: R.State SigmaxT.NodeIds , removedNodeIds :: R.State SigmaxT.NodeIds
...@@ -163,7 +163,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -163,7 +163,7 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
, selectedNodeIds: props.selectedNodeIds } ] , selectedNodeIds: props.selectedNodeIds } ]
, RH.li {} [ mouseSelectorSizeButton props.sigmaRef localControls.mouseSelectorSize ] , RH.li {} [ mouseSelectorSizeButton props.sigmaRef localControls.mouseSelectorSize ]
, RH.li {} [ cameraButton { id: props.graphId , RH.li {} [ cameraButton { id: props.graphId
, graphData: props.graphData , hyperdataGraph: props.hyperdataGraph
, session: props.session , session: props.session
, sigmaRef: props.sigmaRef } ] , sigmaRef: props.sigmaRef } ]
] ]
...@@ -171,12 +171,12 @@ controlsCpt = R.hooksComponent "GraphControls" cpt ...@@ -171,12 +171,12 @@ controlsCpt = R.hooksComponent "GraphControls" cpt
] ]
useGraphControls :: SigmaxT.SGraph useGraphControls :: SigmaxT.SGraph
-> GET.GraphData
-> GET.GraphId -> GET.GraphId
-> GET.HyperdataGraph
-> Session -> Session
-> SigmaxT.ForceAtlasState -> SigmaxT.ForceAtlasState
-> R.Hooks (Record Controls) -> R.Hooks (Record Controls)
useGraphControls graph graphData graphId session forceAtlasS = do useGraphControls graph graphId hyperdataGraph session forceAtlasS = do
edgeConfluence <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 } edgeConfluence <- R.useState' $ Range.Closed { min: 0.0, max: 1.0 }
edgeWeight <- R.useState' $ Range.Closed { edgeWeight <- R.useState' $ Range.Closed {
min: 0.0 min: 0.0
...@@ -200,9 +200,9 @@ useGraphControls graph graphData graphId session forceAtlasS = do ...@@ -200,9 +200,9 @@ useGraphControls graph graphData graphId session forceAtlasS = do
, edgeWeight , edgeWeight
, forceAtlasState , forceAtlasState
, graph , graph
, graphData
, graphId , graphId
, graphStage , graphStage
, hyperdataGraph
, multiSelectEnabled , multiSelectEnabled
, nodeSize , nodeSize
, removedNodeIds , removedNodeIds
......
module Gargantext.Components.GraphExplorer.Types where module Gargantext.Components.GraphExplorer.Types where
import Data.Argonaut (class DecodeJson, decodeJson, class EncodeJson, encodeJson, (.:), jsonEmptyObject, (~>), (:=)) import Data.Argonaut (class DecodeJson, decodeJson, class EncodeJson, encodeJson, (.:), (.:?), jsonEmptyObject, (~>), (:=))
import Data.Array ((!!), length) import Data.Array ((!!), length)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq) import Data.Generic.Rep.Eq (genericEq)
...@@ -286,8 +286,42 @@ instance showSideTab :: Show SideTab where ...@@ -286,8 +286,42 @@ instance showSideTab :: Show SideTab where
show SideTabCommunity = "Community" show SideTabCommunity = "Community"
newtype Camera = Camera {
ratio :: Number
, x :: Number
, y :: Number
}
instance decodeCamera :: DecodeJson Camera where
decodeJson json = do
obj <- decodeJson json
ratio <- obj .: "ratio"
x <- obj .: "x"
y <- obj .: "y"
pure $ Camera { ratio, x, y }
instance jsonEncodeCamera :: EncodeJson Camera where
encodeJson (Camera c) =
"ratio" := c.ratio
~> "x" := c.x
~> "y" := c.y
~> jsonEmptyObject
newtype HyperdataGraph = HyperdataGraph {
graph :: GraphData
, mCamera :: Maybe Camera
}
instance decodeHyperdataGraph :: DecodeJson HyperdataGraph where
decodeJson json = do
obj <- decodeJson json
graph <- obj .: "graph"
mCamera <- obj .:? "camera"
pure $ HyperdataGraph { graph, mCamera }
instance jsonEncodeHyperdataGraph :: EncodeJson HyperdataGraph where
encodeJson (HyperdataGraph c) =
"camera" := c.mCamera
~> "graph" := c.graph
~> jsonEmptyObject
...@@ -286,6 +286,22 @@ cameras s = Object.values cs ...@@ -286,6 +286,22 @@ cameras s = Object.values cs
-- For some reason, `sigma.cameras` is an object with integer keys. -- For some reason, `sigma.cameras` is an object with integer keys.
cs = s .. "cameras" :: Object.Object CameraInstance cs = s .. "cameras" :: Object.Object CameraInstance
toCamera :: CameraInstance -> Record CameraProps
toCamera c = { angle, ratio, x, y }
where
angle = c .. "angle" :: Number
ratio = c .. "ratio" :: Number
x = c .. "x" :: Number
y = c .. "y" :: Number
updateCamera :: Sigma -> { ratio :: Number, x :: Number, y :: Number } -> Effect Unit
updateCamera sig { ratio, x, y } = do
let camera = sig .. "camera"
_ <- pure $ (camera .= "ratio") ratio
_ <- pure $ (camera .= "x") x
_ <- pure $ (camera .= "y") y
pure unit
goTo :: Record CameraProps -> CameraInstance -> Effect Unit goTo :: Record CameraProps -> CameraInstance -> Effect Unit
goTo props cam = pure $ cam ... "goTo" $ [props] goTo props cam = pure $ cam ... "goTo" $ [props]
......
...@@ -10,6 +10,7 @@ import Effect (Effect) ...@@ -10,6 +10,7 @@ import Effect (Effect)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.String.CodeUnits (length, slice) -- TODO: double check i'm the right choice import Data.String.CodeUnits (length, slice) -- TODO: double check i'm the right choice
import Data.String.Regex (Regex) import Data.String.Regex (Regex)
import Gargantext.Utils.Regex (cloneRegex, execRegex, getRegexLastIndex) import Gargantext.Utils.Regex (cloneRegex, execRegex, getRegexLastIndex)
import Gargantext.Utils.Array (push) import Gargantext.Utils.Array (push)
......
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