[GRAPH] settings are now updatable, we depend now on a version of react-sigma...

[GRAPH] settings are now updatable, we depend now on a version of react-sigma fixing a refresh issue
parent 80ba4297
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"react": "^16.4.2", "react": "^16.4.2",
"react-dom": "^16.4.2", "react-dom": "^16.4.2",
"react-echarts-v3": "^1.0.19", "react-echarts-v3": "^1.0.19",
"react-sigma": "^1.2.30" "react-sigma": "git://github.com/np/react-sigma.git#shouldComponentUpdate"
}, },
"browserify": { "browserify": {
"transform": [ "transform": [
......
...@@ -17,7 +17,9 @@ import Data.Int as Int ...@@ -17,7 +17,9 @@ import Data.Int as Int
import Data.Maybe (Maybe(..), fromJust, fromMaybe) import Data.Maybe (Maybe(..), fromJust, fromMaybe)
import Data.Newtype (class Newtype) import Data.Newtype (class Newtype)
import Data.String (joinWith) import Data.String (joinWith)
import Data.Lens (over) import Data.Symbol (SProxy(..))
import Data.Lens (over, (+~), Lens, Lens')
import Data.Lens.Record (prop)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff, attempt) import Effect.Aff (Aff, attempt)
import Effect.Aff.Class (liftAff) import Effect.Aff.Class (liftAff)
...@@ -50,12 +52,24 @@ data Action ...@@ -50,12 +52,24 @@ data Action
| ShowSidePanel Boolean | ShowSidePanel Boolean
| ToggleControls | ToggleControls
| ToggleTree | ToggleTree
| BiggerLabels
newtype SelectedNode = SelectedNode {id :: String, label :: String} newtype SelectedNode = SelectedNode {id :: String, label :: String}
derive instance eqSelectedNode :: Eq SelectedNode derive instance eqSelectedNode :: Eq SelectedNode
derive instance newtypeSelectedNode :: Newtype SelectedNode _ derive instance newtypeSelectedNode :: Newtype SelectedNode _
-- _settings :: forall s t a b. Lens { settings :: a | s } { settings :: b | t } a b
_settings :: forall s a. Lens' { settings :: a | s } a
_settings = prop (SProxy :: SProxy "settings")
_labelSizeRatio' :: forall s a. Lens' { labelSizeRatio :: a | s } a
_labelSizeRatio' = prop (SProxy :: SProxy "labelSizeRatio")
_labelSizeRatio :: Lens' SigmaSettings Number
_labelSizeRatio f = unsafeCoerce $ _labelSizeRatio' f
-- TODO remove newtype here
newtype State = State newtype State = State
{ graphData :: GraphData { graphData :: GraphData
, filePath :: String , filePath :: String
...@@ -67,6 +81,7 @@ newtype State = State ...@@ -67,6 +81,7 @@ newtype State = State
, showTree :: Boolean , showTree :: Boolean
, corpusId :: Int , corpusId :: Int
, treeId :: Maybe TreeId , treeId :: Maybe TreeId
, settings :: SigmaSettings
} }
initialState :: State initialState :: State
...@@ -81,8 +96,11 @@ initialState = State ...@@ -81,8 +96,11 @@ initialState = State
, showTree : false , showTree : false
, corpusId : 0 , corpusId : 0
, treeId : Nothing , treeId : Nothing
, settings : mySettings
} }
-- This one is not used: specOld is the one being used.
-- TODO: code duplication
graphSpec :: Spec State {} Action graphSpec :: Spec State {} Action
graphSpec = simpleSpec performAction render graphSpec = simpleSpec performAction render
...@@ -114,6 +132,9 @@ performAction (ToggleControls) _ (State state) = void do ...@@ -114,6 +132,9 @@ performAction (ToggleControls) _ (State state) = void do
performAction (ToggleTree) _ (State state) = void do performAction (ToggleTree) _ (State state) = void do
modifyState $ \(State s) -> State s {showTree = not (state.showTree) } modifyState $ \(State s) -> State s {showTree = not (state.showTree) }
performAction BiggerLabels _ _ =
modifyState_ $ \(State s) ->
State $ ((_settings <<< _labelSizeRatio) +~ 1.0) s
convert :: GraphData -> SigmaGraphData convert :: GraphData -> SigmaGraphData
convert (GraphData r) = SigmaGraphData { nodes, edges} convert (GraphData r) = SigmaGraphData { nodes, edges}
...@@ -134,13 +155,12 @@ convert (GraphData r) = SigmaGraphData { nodes, edges} ...@@ -134,13 +155,12 @@ convert (GraphData r) = SigmaGraphData { nodes, edges}
edgeFn (Edge e) = sigmaEdge {id : e.id_, source : e.source, target : e.target} edgeFn (Edge e) = sigmaEdge {id : e.id_, source : e.source, target : e.target}
render :: Render State {} Action render :: Render State {} Action
render d p (State s) c = render d p (State {sigmaGraphData, settings, legendData}) c =
case s.sigmaGraphData of case sigmaGraphData of
Nothing -> [] Nothing -> []
Just gData -> Just graph ->
[ sigma { graph: gData [ sigma { graph, settings
, renderer : canvas , renderer : canvas
, settings : mySettings
, style : sStyle { height : "95%"} , style : sStyle { height : "95%"}
, onClickNode : \e -> unsafePerformEffect $ do , onClickNode : \e -> unsafePerformEffect $ do
_ <- log "hello" _ <- log "hello"
...@@ -156,7 +176,7 @@ render d p (State s) c = ...@@ -156,7 +176,7 @@ render d p (State s) c =
] ]
-- TODO clean unused code: this seems to be not used -- TODO clean unused code: this seems to be not used
-- <> -- <>
-- [dispLegend s.legendData] -- [dispLegend legendData]
forceAtlas2Config :: { slowDown :: Number forceAtlas2Config :: { slowDown :: Number
, startingIterations :: Number , startingIterations :: Number
...@@ -324,7 +344,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -324,7 +344,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
Just treeId -> Just treeId ->
(cmapProps (const {root: treeId}) (noState Tree.treeview)) (cmapProps (const {root: treeId}) (noState Tree.treeview))
render' :: Render State {} Action render' :: Render State {} Action
render' d _ (State st@{graphData: GraphData {sides,metaData }}) _ = render' d _ (State st@{settings, graphData: GraphData {sides,metaData }}) _ =
[ div [className "container-fluid", style {"padding-top" : "100px"}] [ div [className "container-fluid", style {"padding-top" : "100px"}]
[ div [ className "row"] [ div [ className "row"]
[ h2 [ style {textAlign : "center", position : "relative", top: "-38px"}] [ h2 [ style {textAlign : "center", position : "relative", top: "-38px"}]
...@@ -370,6 +390,11 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -370,6 +390,11 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
, li' , li'
[ button [className "btn btn-primary btn-sm"] [text "Change Level"] [ button [className "btn btn-primary btn-sm"] [text "Change Level"]
] ]
, li'
[ button [className "btn btn-primary btn-sm"
,onClick \_ -> d BiggerLabels]
[text "Bigger Labels"]
]
,li [style {display : "inline-block"}] ,li [style {display : "inline-block"}]
...@@ -437,10 +462,9 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -437,10 +462,9 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
<> <>
case st.sigmaGraphData of case st.sigmaGraphData of
Nothing -> [] Nothing -> []
Just gData -> Just graph ->
[ sigma { graph: gData [ sigma { graph, settings
, renderer : canvas , renderer : canvas
, settings : mySettings
, style : sStyle { height : "95%"} , style : sStyle { height : "95%"}
, onClickNode : \e -> unsafePerformEffect $ do , onClickNode : \e -> unsafePerformEffect $ do
_ <- log " hello 2" _ <- log " hello 2"
......
...@@ -4523,10 +4523,9 @@ react-echarts-v3@^1.0.19: ...@@ -4523,10 +4523,9 @@ react-echarts-v3@^1.0.19:
element-resize-detector latest element-resize-detector latest
lodash latest lodash latest
react-sigma@^1.2.30: "react-sigma@git://github.com/np/react-sigma.git#shouldComponentUpdate":
version "1.2.30" version "1.2.29"
resolved "https://registry.yarnpkg.com/react-sigma/-/react-sigma-1.2.30.tgz#794f88e796c4f763158afe404d10d9635f848846" resolved "git://github.com/np/react-sigma.git#0023eb24248c7bc61aec872bc26552e3d569b974"
integrity sha512-8KVwKwHO9vrX1VohusZZm8ldMab32EHLZKkU1TrAnvSOHv6it6EEMwPOOtkJZOirnydKM0cXpxfFQv2LdBFAqQ==
react@^16.4.2: react@^16.4.2:
version "16.4.2" version "16.4.2"
......
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