[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
......@@ -17,7 +17,9 @@ import Data.Int as Int
import Data.Maybe (Maybe(..), fromJust, fromMaybe)
import Data.Newtype (class Newtype)
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.Aff (Aff, attempt)
import Effect.Aff.Class (liftAff)
......@@ -50,12 +52,24 @@ data Action
| ShowSidePanel Boolean
| ToggleControls
| ToggleTree
| BiggerLabels
newtype SelectedNode = SelectedNode {id :: String, label :: String}
derive instance eqSelectedNode :: Eq 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
{ graphData :: GraphData
, filePath :: String
......@@ -67,6 +81,7 @@ newtype State = State
, showTree :: Boolean
, corpusId :: Int
, treeId :: Maybe TreeId
, settings :: SigmaSettings
}
initialState :: State
......@@ -81,8 +96,11 @@ initialState = State
, showTree : false
, corpusId : 0
, treeId : Nothing
, settings : mySettings
}
-- This one is not used: specOld is the one being used.
-- TODO: code duplication
graphSpec :: Spec State {} Action
graphSpec = simpleSpec performAction render
......@@ -114,6 +132,9 @@ performAction (ToggleControls) _ (State state) = void do
performAction (ToggleTree) _ (State state) = void do
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 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}
render :: Render State {} Action
render d p (State s) c =
case s.sigmaGraphData of
render d p (State {sigmaGraphData, settings, legendData}) c =
case sigmaGraphData of
Nothing -> []
Just gData ->
[ sigma { graph: gData
Just graph ->
[ sigma { graph, settings
, renderer : canvas
, settings : mySettings
, style : sStyle { height : "95%"}
, onClickNode : \e -> unsafePerformEffect $ do
_ <- log "hello"
......@@ -156,7 +176,7 @@ render d p (State s) c =
]
-- TODO clean unused code: this seems to be not used
-- <>
-- [dispLegend s.legendData]
-- [dispLegend legendData]
forceAtlas2Config :: { slowDown :: Number
, startingIterations :: Number
......@@ -324,7 +344,7 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
Just treeId ->
(cmapProps (const {root: treeId}) (noState Tree.treeview))
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 "row"]
[ h2 [ style {textAlign : "center", position : "relative", top: "-38px"}]
......@@ -370,6 +390,11 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
, li'
[ 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"}]
......@@ -437,10 +462,9 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
<>
case st.sigmaGraphData of
Nothing -> []
Just gData ->
[ sigma { graph: gData
Just graph ->
[ sigma { graph, settings
, renderer : canvas
, settings : mySettings
, style : sStyle { height : "95%"}
, onClickNode : \e -> unsafePerformEffect $ do
_ <- log " hello 2"
......
......@@ -4523,10 +4523,9 @@ react-echarts-v3@^1.0.19:
element-resize-detector latest
lodash latest
react-sigma@^1.2.30:
version "1.2.30"
resolved "https://registry.yarnpkg.com/react-sigma/-/react-sigma-1.2.30.tgz#794f88e796c4f763158afe404d10d9635f848846"
integrity sha512-8KVwKwHO9vrX1VohusZZm8ldMab32EHLZKkU1TrAnvSOHv6it6EEMwPOOtkJZOirnydKM0cXpxfFQv2LdBFAqQ==
"react-sigma@git://github.com/np/react-sigma.git#shouldComponentUpdate":
version "1.2.29"
resolved "git://github.com/np/react-sigma.git#0023eb24248c7bc61aec872bc26552e3d569b974"
react@^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