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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
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;
}
const
applyOnCamera
=
function
(
props
,
f
){
if
(
props
!=
null
)
{
const
camera
=
props
.
sigma
.
cameras
[
0
];
// console.log(camera);
// console.log(f);
f
(
camera
)();
}
exports
.
setSigmaRef
=
function
(
props
)
{
if
(
props
.
sigma
)
{
window
.
sigmaGargInstance
=
props
.
sigma
;
}
};
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
import Data.Nullable (Nullable)
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 Record.Unsafe (unsafeGet)
import Thermite (EventHandler)
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional)
...
...
@@ -246,20 +247,29 @@ sigmaSettings = unsafeCoerce
foreign import data SigmaStyle :: Type
type Camera =
{
x :: Number,
y :: Number,
ratio :: Number,
angle :: Number
}
type CameraProps =
( x :: Number
, y :: Number
, ratio :: 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
applyOnCamera a = mkEffectFn1 h
where h :: Nullable ReactRef -> Effect Unit
h r = runEffectFn2 applyOnCameraImpl r a
goTo :: forall o. Optional o CameraProps => CameraInstance -> { | o } -> Effect CameraInstance
goTo cam = runEffectFn1 (goToImpl cam)
type SigmaProps =
( renderer :: Renderer
...
...
src/Gargantext/Config.purs
View file @
43f0d659
...
...
@@ -62,11 +62,6 @@ backLocal v = { baseUrl: "http://localhost:8008"
, prePath: "/api/" <> show v <> "/"
}
backDemo :: ApiVersion -> Config
backDemo v = { baseUrl: "https://demo.gargantext.org"
, prePath: "/api/" <> show v <> "/"
}
backDev :: ApiVersion -> Config
backDev v = { baseUrl: "https://dev.gargantext.org"
, prePath: "/api/" <> show v <> "/"
...
...
src/Gargantext/Pages/Corpus/Graph.purs
View file @
43f0d659
...
...
@@ -16,7 +16,7 @@ import Data.Int (fromString, toNumber)
import Data.Int as Int
import Data.Lens (Lens, Lens', over, (%~), (+~), (.~), (^.))
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.String (joinWith)
import Data.Symbol (SProxy(..))
...
...
@@ -26,7 +26,7 @@ import Effect.Aff.Class (liftAff)
import Effect.Class (liftEffect)
import Effect.Console (log)
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.Login.Types (AuthData(..), TreeId)
import Gargantext.Components.RandomText (words)
...
...
@@ -57,7 +57,6 @@ data Action
| ChangeLabelSize Number
| ChangeNodeSize Number
| DisplayEdges
| SaveCamera Camera
-- | Zoom Boolean
newtype SelectedNode = SelectedNode {id :: String, label :: String}
...
...
@@ -93,10 +92,6 @@ _drawEdges' = prop (SProxy :: SProxy "drawEdges")
_drawEdges :: Lens' SigmaSettings Boolean
_drawEdges f = unsafeCoerce $ _drawEdges' f
_camera :: forall s a. Lens' { camera :: a | s } a
_camera = prop (SProxy :: SProxy "camera")
-- TODO remove newtype here
newtype State = State
{ graphData :: GraphData
...
...
@@ -110,7 +105,6 @@ newtype State = State
, corpusId :: Int
, treeId :: Maybe TreeId
, settings :: SigmaSettings
, camera :: Maybe Camera
}
initialState :: State
...
...
@@ -126,7 +120,6 @@ initialState = State
, corpusId : 0
, treeId : Nothing
, settings : mySettings
, camera : Nothing
}
-- This one is not used: specOld is the one being used.
...
...
@@ -177,11 +170,6 @@ performAction DisplayEdges _ _ =
modifyState_ $ \(State s) -> do
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) _ _ =
-- modifyState_ $ \() -> do
-- State $
...
...
@@ -213,8 +201,7 @@ render d p (State {sigmaGraphData, settings, legendData}) c =
, settings
, renderer : canvas
, style : sStyle { height : "96%"}
-- , ref: applyOnCamera
, ref: applyOnCamera $ d <<< SaveCamera
, ref: saveSigmaRef
, onClickNode : \e -> unsafePerformEffect $ do
_ <- log "this should be deleted"
-- _ <- logs $ unsafeCoerce e
...
...
@@ -522,7 +509,6 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
pure unit
] [text "Save"] -- TODO: Implement Save!
]
]
]
]
...
...
@@ -540,11 +526,17 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
[ sigma { graph, settings
, renderer : canvas
, style : sStyle { height : "95%"}
, ref:
applyOnCamera $ d <<< SaveCamera
, ref:
setSigmaRef
, onClickNode : \e ->
unsafePerformEffect $ do
_ <- 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 $ SelectNode $ SelectedNode {id : (unsafeCoerce e).data.node.id, label : (unsafeCoerce e).data.node.label}
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