[GraphExplorer] Workaround the state to access the camera

parent 43e812aa
...@@ -40,13 +40,18 @@ exports.forceLinkClass = FL.default; ...@@ -40,13 +40,18 @@ exports.forceLinkClass = FL.default;
} }
const applyOnCamera = function(props, f){ exports.setSigmaRef = function(props) {
if (props != null) { if (props.sigma) {
const camera = props.sigma.cameras[0]; window.sigmaGargInstance = props.sigma;
// console.log(camera); }
// console.log(f); };
f(camera)(); exports.getSigmaRef = function() {
} return window.sigmaGargInstance;
};
exports.goToImpl = function(cam) {
return function(props) {
console.log("goTo", cam, props);
return cam.goTo(props);
};
}; };
exports.applyOnCameraImpl = applyOnCamera;
...@@ -4,8 +4,9 @@ import Prelude ...@@ -4,8 +4,9 @@ import Prelude
import Data.Nullable (Nullable) import Data.Nullable (Nullable)
import Effect (Effect) import Effect (Effect)
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, runEffectFn2) import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, runEffectFn1)
import React (Children, ReactClass, ReactElement, ReactRef, SyntheticEventHandler, createElement, unsafeCreateElement) import React (Children, ReactClass, ReactElement, ReactRef, SyntheticEventHandler, createElement, unsafeCreateElement)
import Record.Unsafe (unsafeGet)
import Thermite (EventHandler) import Thermite (EventHandler)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional) import Gargantext.Types (class Optional)
...@@ -246,20 +247,29 @@ sigmaSettings = unsafeCoerce ...@@ -246,20 +247,29 @@ sigmaSettings = unsafeCoerce
foreign import data SigmaStyle :: Type foreign import data SigmaStyle :: Type
type Camera = type CameraProps =
{ ( x :: Number
x :: Number, , y :: Number
y :: Number, , ratio :: Number
ratio :: Number, , angle :: Number
angle :: Number )
}
foreign import data SigmaInstance' :: # Type
foreign import data CameraInstance' :: # Type
type SigmaInstance = { | SigmaInstance' }
type CameraInstance = { | CameraInstance' }
foreign import setSigmaRef :: EffectFn1 (Nullable ReactRef) Unit
foreign import getSigmaRef :: Effect SigmaInstance
cameras :: SigmaInstance -> Array CameraInstance
cameras = unsafeGet "cameras"
getCameraProps :: CameraInstance -> { | CameraProps }
getCameraProps = unsafeCoerce
foreign import applyOnCameraImpl :: forall a. EffectFn2 (Nullable ReactRef) (a -> EventHandler) Unit foreign import goToImpl :: forall o. CameraInstance -> EffectFn1 { | o } CameraInstance
applyOnCamera :: forall a. (a -> EventHandler) -> EffectFn1 (Nullable ReactRef) Unit goTo :: forall o. Optional o CameraProps => CameraInstance -> { | o } -> Effect CameraInstance
applyOnCamera a = mkEffectFn1 h goTo cam = runEffectFn1 (goToImpl cam)
where h :: Nullable ReactRef -> Effect Unit
h r = runEffectFn2 applyOnCameraImpl r a
type SigmaProps = type SigmaProps =
( renderer :: Renderer ( renderer :: Renderer
......
...@@ -62,11 +62,6 @@ backLocal v = { baseUrl: "http://localhost:8008" ...@@ -62,11 +62,6 @@ backLocal v = { baseUrl: "http://localhost:8008"
, prePath: "/api/" <> show v <> "/" , prePath: "/api/" <> show v <> "/"
} }
backDemo :: ApiVersion -> Config
backDemo v = { baseUrl: "https://demo.gargantext.org"
, prePath: "/api/" <> show v <> "/"
}
backDev :: ApiVersion -> Config backDev :: ApiVersion -> Config
backDev v = { baseUrl: "https://dev.gargantext.org" backDev v = { baseUrl: "https://dev.gargantext.org"
, prePath: "/api/" <> show v <> "/" , prePath: "/api/" <> show v <> "/"
......
...@@ -16,7 +16,7 @@ import Data.Int (fromString, toNumber) ...@@ -16,7 +16,7 @@ import Data.Int (fromString, toNumber)
import Data.Int as Int import Data.Int as Int
import Data.Lens (Lens, Lens', over, (%~), (+~), (.~), (^.)) import Data.Lens (Lens, Lens', over, (%~), (+~), (.~), (^.))
import Data.Lens.Record (prop) import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..), fromJust, fromMaybe) import Data.Maybe (Maybe(..), fromJust, fromMaybe, isNothing)
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.String (joinWith) import Data.String (joinWith)
import Data.Symbol (SProxy(..)) import Data.Symbol (SProxy(..))
...@@ -26,7 +26,7 @@ import Effect.Aff.Class (liftAff) ...@@ -26,7 +26,7 @@ import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Console (log) import Effect.Console (log)
import Effect.Uncurried (runEffectFn1, runEffectFn2) import Effect.Uncurried (runEffectFn1, runEffectFn2)
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.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, setSigmaRef, getSigmaRef, cameras, getCameraProps, goTo, 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)
...@@ -57,7 +57,6 @@ data Action ...@@ -57,7 +57,6 @@ data Action
| ChangeLabelSize Number | ChangeLabelSize Number
| ChangeNodeSize Number | ChangeNodeSize Number
| DisplayEdges | DisplayEdges
| SaveCamera Camera
-- | Zoom Boolean -- | Zoom Boolean
newtype SelectedNode = SelectedNode {id :: String, label :: String} newtype SelectedNode = SelectedNode {id :: String, label :: String}
...@@ -93,10 +92,6 @@ _drawEdges' = prop (SProxy :: SProxy "drawEdges") ...@@ -93,10 +92,6 @@ _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
{ graphData :: GraphData { graphData :: GraphData
...@@ -110,7 +105,6 @@ newtype State = State ...@@ -110,7 +105,6 @@ newtype State = State
, corpusId :: Int , corpusId :: Int
, treeId :: Maybe TreeId , treeId :: Maybe TreeId
, settings :: SigmaSettings , settings :: SigmaSettings
, camera :: Maybe Camera
} }
initialState :: State initialState :: State
...@@ -126,7 +120,6 @@ initialState = State ...@@ -126,7 +120,6 @@ 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.
...@@ -177,11 +170,6 @@ performAction DisplayEdges _ _ = ...@@ -177,11 +170,6 @@ 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) .~ cam) s
where cam = Just {x: 0.0, y: 0.0, ratio: 0.0, angle: 0.0}
--performAction (Zoom True) _ _ = --performAction (Zoom True) _ _ =
-- modifyState_ $ \() -> do -- modifyState_ $ \() -> do
-- State $ -- State $
...@@ -213,8 +201,7 @@ render d p (State {sigmaGraphData, settings, legendData}) c = ...@@ -213,8 +201,7 @@ render d p (State {sigmaGraphData, settings, legendData}) c =
, settings , settings
, renderer : canvas , renderer : canvas
, style : sStyle { height : "96%"} , style : sStyle { height : "96%"}
-- , ref: applyOnCamera , ref: saveSigmaRef
, 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
...@@ -522,7 +509,6 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -522,7 +509,6 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
pure unit pure unit
] [text "Save"] -- TODO: Implement Save! ] [text "Save"] -- TODO: Implement Save!
] ]
] ]
] ]
] ]
...@@ -540,11 +526,17 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -540,11 +526,17 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
[ sigma { graph, settings [ sigma { graph, settings
, renderer : canvas , renderer : canvas
, style : sStyle { height : "95%"} , style : sStyle { height : "95%"}
, ref: applyOnCamera $ d <<< SaveCamera , ref: setSigmaRef
, onClickNode : \e -> , onClickNode : \e ->
unsafePerformEffect $ do unsafePerformEffect $ do
_ <- log " hello 2" _ <- log " hello 2"
_ <- log $ show st.camera s <- getSigmaRef
case (cameras s !! 0) of
Just cam -> do
let camP = getCameraProps cam
_ <- log $ show camP
void $ goTo cam {ratio: camP.ratio / 2.0}
Nothing -> pure unit
_ <- d $ ShowSidePanel true _ <- d $ ShowSidePanel true
_ <- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label} _ <- d $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
pure unit pure unit
......
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