Unverified Commit 429b318a authored by Mael NICOLAS's avatar Mael NICOLAS Committed by Nicolas Pouillard

[WIP] Done FFI to save camera instance

parent 0874fa1b
...@@ -40,8 +40,9 @@ exports.forceLinkClass = FL.default; ...@@ -40,8 +40,9 @@ exports.forceLinkClass = FL.default;
} }
const myGoto = function(sigma){ const applyOnCamera = function(f, props){
const camera = sigma.sigma.cameras[0]; const camera = props.sigma.cameras[0];
f(camera);
}; };
exports.myGoto = myGoto; exports.applyOnCamera = applyOnCamera;
...@@ -6,6 +6,7 @@ import Data.Nullable (Nullable) ...@@ -6,6 +6,7 @@ import Data.Nullable (Nullable)
import Effect (Effect) import Effect (Effect)
import React (Children, ReactClass, ReactElement, ReactRef, SyntheticEventHandler, createElement, unsafeCreateElement) import React (Children, ReactClass, ReactElement, ReactRef, SyntheticEventHandler, createElement, unsafeCreateElement)
import React.DOM.Props (Props) import React.DOM.Props (Props)
import Thermite (EventHandler)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional) import Gargantext.Types (class Optional)
...@@ -244,7 +245,16 @@ sigmaSettings :: forall o. Optional o SigmaSettingProps => { | o } -> SigmaSetti ...@@ -244,7 +245,16 @@ sigmaSettings :: forall o. Optional o SigmaSettingProps => { | o } -> SigmaSetti
sigmaSettings = unsafeCoerce sigmaSettings = unsafeCoerce
foreign import data SigmaStyle :: Type foreign import data SigmaStyle :: Type
foreign import myGoto :: SyntheticEventHandler (Nullable ReactRef)
type Camera =
{
x :: Number,
y :: Number,
ratio :: Number,
angle :: Number
}
foreign import applyOnCamera :: forall a. (a -> EventHandler) -> SyntheticEventHandler (Nullable ReactRef)
type SigmaProps = type SigmaProps =
( renderer :: Renderer ( renderer :: Renderer
......
...@@ -25,7 +25,7 @@ import Effect.Aff (Aff, attempt) ...@@ -25,7 +25,7 @@ import Effect.Aff (Aff, attempt)
import Effect.Aff.Class (liftAff) import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Console (log) import Effect.Console (log)
import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, myGoto, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings) import Gargantext.Components.GraphExplorer.Sigmajs (Camera, Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, applyOnCamera, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
import Gargantext.Components.GraphExplorer.Types (Cluster(..), MetaData(..), Edge(..), GraphData(..), Legend(..), Node(..), getLegendData) import Gargantext.Components.GraphExplorer.Types (Cluster(..), MetaData(..), Edge(..), GraphData(..), Legend(..), Node(..), getLegendData)
import Gargantext.Components.Login.Types (AuthData(..), TreeId) import Gargantext.Components.Login.Types (AuthData(..), TreeId)
import Gargantext.Components.RandomText (words) import Gargantext.Components.RandomText (words)
...@@ -55,6 +55,7 @@ data Action ...@@ -55,6 +55,7 @@ data Action
| ChangeLabelSize Number | ChangeLabelSize Number
| ChangeNodeSize Number | ChangeNodeSize Number
| DisplayEdges | DisplayEdges
| SaveCamera Camera
newtype SelectedNode = SelectedNode {id :: String, label :: String} newtype SelectedNode = SelectedNode {id :: String, label :: String}
...@@ -89,6 +90,9 @@ _drawEdges' = prop (SProxy :: SProxy "drawEdges") ...@@ -89,6 +90,9 @@ _drawEdges' = prop (SProxy :: SProxy "drawEdges")
_drawEdges :: Lens' SigmaSettings Boolean _drawEdges :: Lens' SigmaSettings Boolean
_drawEdges f = unsafeCoerce $ _drawEdges' f _drawEdges f = unsafeCoerce $ _drawEdges' f
_camera :: forall s a. Lens' { camera :: a | s } a
_camera = prop (SProxy :: SProxy "camera")
-- TODO remove newtype here -- TODO remove newtype here
newtype State = State newtype State = State
...@@ -103,6 +107,7 @@ newtype State = State ...@@ -103,6 +107,7 @@ newtype State = State
, corpusId :: Int , corpusId :: Int
, treeId :: Maybe TreeId , treeId :: Maybe TreeId
, settings :: SigmaSettings , settings :: SigmaSettings
, camera :: Maybe Camera
} }
initialState :: State initialState :: State
...@@ -118,6 +123,7 @@ initialState = State ...@@ -118,6 +123,7 @@ initialState = State
, corpusId : 0 , corpusId : 0
, treeId : Nothing , treeId : Nothing
, settings : mySettings , settings : mySettings
, camera : Nothing
} }
-- This one is not used: specOld is the one being used. -- This one is not used: specOld is the one being used.
...@@ -166,6 +172,10 @@ performAction DisplayEdges _ _ = ...@@ -166,6 +172,10 @@ performAction DisplayEdges _ _ =
modifyState_ $ \(State s) -> do modifyState_ $ \(State s) -> do
State $ ((_settings <<< _drawEdges) %~ not) s State $ ((_settings <<< _drawEdges) %~ not) s
performAction (SaveCamera c) _ _ =
modifyState_ $ \(State s) -> do
State $ ((_camera) .~ (Just c)) s
convert :: GraphData -> SigmaGraphData convert :: GraphData -> SigmaGraphData
convert (GraphData r) = SigmaGraphData { nodes, edges} convert (GraphData r) = SigmaGraphData { nodes, edges}
where where
...@@ -192,7 +202,7 @@ render d p (State {sigmaGraphData, settings, legendData}) c = ...@@ -192,7 +202,7 @@ render d p (State {sigmaGraphData, settings, legendData}) c =
[ sigma { graph, settings [ sigma { graph, settings
, renderer : canvas , renderer : canvas
, style : sStyle { height : "96%"} , style : sStyle { height : "96%"}
, ref: myGoto , ref: applyOnCamera (d <<< SaveCamera)
, onClickNode : \e -> unsafePerformEffect $ do , onClickNode : \e -> unsafePerformEffect $ do
_ <- log "this should be deleted" _ <- log "this should be deleted"
-- _ <- logs $ unsafeCoerce e -- _ <- logs $ unsafeCoerce e
...@@ -502,7 +512,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -502,7 +512,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
else div [] [] else div [] []
] ]
, div [className "row"] , div [className "row"]
[ div [if (st.showSidePanel && st.showTree) then className "col-md-10" else if (st.showSidePanel || st.showTree) then className "col-md-10" else className "col-md-12"] [div [if (st.showSidePanel && st.showTree) then className "col-md-10" else if (st.showSidePanel || st.showTree) then className "col-md-10" else className "col-md-12"]
[ div [style {height: "90%"}] $ [ div [style {height: "90%"}] $
[ [
] ]
...@@ -512,8 +522,8 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -512,8 +522,8 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
Just graph -> Just graph ->
[ sigma { graph, settings [ sigma { graph, settings
, renderer : canvas , renderer : canvas
, style : sStyle { height : "96%"} , style : sStyle { height : "95%"}
, ref: myGoto , ref: applyOnCamera $ d <<< SaveCamera
, onClickNode : \e -> unsafePerformEffect $ do , onClickNode : \e -> unsafePerformEffect $ do
_ <- log " hello 2" _ <- log " hello 2"
--logs $ unsafeCoerce e --logs $ unsafeCoerce e
......
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