Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
43f0d659
Unverified
Commit
43f0d659
authored
Apr 16, 2019
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[GraphExplorer] Workaround the state to access the camera
parent
43e812aa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
45 deletions
+47
-45
Sigmajs.js
src/Gargantext/Components/GraphExplorer/Sigmajs.js
+13
-8
Sigmajs.purs
src/Gargantext/Components/GraphExplorer/Sigmajs.purs
+23
-13
Config.purs
src/Gargantext/Config.purs
+0
-5
Graph.purs
src/Gargantext/Pages/Corpus/Graph.purs
+11
-19
No files found.
src/Gargantext/Components/GraphExplorer/Sigmajs.js
View file @
43f0d659
...
@@ -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
;
src/Gargantext/Components/GraphExplorer/Sigmajs.purs
View file @
43f0d659
...
@@ -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, runEffectFn
2
)
import Effect.Uncurried (EffectFn1, EffectFn2, mkEffectFn1, runEffectFn
1
)
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
...
...
src/Gargantext/Config.purs
View file @
43f0d659
...
@@ -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 <> "/"
...
...
src/Gargantext/Pages/Corpus/Graph.purs
View file @
43f0d659
...
@@ -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 (C
amera, Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, applyOnCamera
, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings)
import Gargantext.Components.GraphExplorer.Sigmajs (C
olor(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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment