Commit 519dc93f authored by Mael NICOLAS's avatar Mael NICOLAS Committed by Alexandre Delanoë

Node size control done #43

We can now resize the size of nodes. Done with ChangedNodeSize action.
We should really refactor this file tho
parent b134255c
module Gargantext.Pages.Corpus.Graph where module Gargantext.Pages.Corpus.Graph where
import Effect.Unsafe import Effect.Unsafe
import Gargantext.Prelude import Gargantext.Prelude hiding (max,min)
import Affjax (defaultRequest, request) import Affjax (defaultRequest, request)
import Affjax.ResponseFormat (ResponseFormat(..), printResponseFormatError) import Affjax.ResponseFormat (ResponseFormat(..), printResponseFormatError)
...@@ -14,21 +14,21 @@ import Data.Either (Either(..)) ...@@ -14,21 +14,21 @@ import Data.Either (Either(..))
import Data.HTTP.Method (Method(..)) import Data.HTTP.Method (Method(..))
import Data.Int (fromString, toNumber) import Data.Int (fromString, toNumber)
import Data.Int as Int import Data.Int as Int
import Data.Lens (over, (+~), (.~), Lens, Lens')
import Data.Lens.Record (prop)
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.Symbol (SProxy(..)) 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)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Effect.Console (log) import Effect.Console (log)
import Gargantext.Components.RandomText (words)
import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, sStyle, sigma, sigmaEasing, sigmaEdge, sigmaEnableWebGL, sigmaNode, sigmaSettings) import Gargantext.Components.GraphExplorer.Sigmajs (Color(Color), SigmaEasing, SigmaGraphData(SigmaGraphData), SigmaNode, SigmaSettings, canvas, edgeShape, edgeShapes, forceAtlas2, 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.Tree as Tree import Gargantext.Components.Tree as Tree
import Gargantext.Config as Config import Gargantext.Config as Config
import Gargantext.Config.REST (get, post) import Gargantext.Config.REST (get, post)
...@@ -37,9 +37,9 @@ import Gargantext.Utils (getter) ...@@ -37,9 +37,9 @@ import Gargantext.Utils (getter)
import Math (cos, sin) import Math (cos, sin)
import Partial.Unsafe (unsafePartial) import Partial.Unsafe (unsafePartial)
import React (ReactElement) import React (ReactElement)
import React.DOM (a, br', h2,button, div, form', input, li, li', menu, option, p, select, span, text, ul, ul') import React.DOM (a, br', h2, button, div, form', input, li, li', menu, option, p, select, span, text, ul, ul')
import React.DOM.Props (_id, _type, checked, className, href, name, onChange, onClick, placeholder, style, title, value) import React.DOM.Props (_id, _type, checked, className, href, max, min, name, onChange, onClick, placeholder, style, title, value)
import Thermite (PerformAction, Render, Spec, _render,cmapProps, createClass, defaultPerformAction, defaultRender, modifyState, modifyState_, noState, simpleSpec, withState) import Thermite (PerformAction, Render, Spec, _render, cmapProps, createClass, defaultPerformAction, defaultRender, modifyState, modifyState_, noState, simpleSpec, withState)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Web.HTML (window) import Web.HTML (window)
import Web.HTML.Window (localStorage) import Web.HTML.Window (localStorage)
...@@ -53,6 +53,7 @@ data Action ...@@ -53,6 +53,7 @@ data Action
| ToggleControls | ToggleControls
| ToggleTree | ToggleTree
| BiggerLabels | BiggerLabels
| ChangeNodeSize Number
newtype SelectedNode = SelectedNode {id :: String, label :: String} newtype SelectedNode = SelectedNode {id :: String, label :: String}
...@@ -69,6 +70,18 @@ _labelSizeRatio' = prop (SProxy :: SProxy "labelSizeRatio") ...@@ -69,6 +70,18 @@ _labelSizeRatio' = prop (SProxy :: SProxy "labelSizeRatio")
_labelSizeRatio :: Lens' SigmaSettings Number _labelSizeRatio :: Lens' SigmaSettings Number
_labelSizeRatio f = unsafeCoerce $ _labelSizeRatio' f _labelSizeRatio f = unsafeCoerce $ _labelSizeRatio' f
_maxNodeSize' :: forall s a. Lens' { maxNodeSize :: a | s} a
_maxNodeSize' = prop (SProxy :: SProxy "maxNodeSize")
_maxNodeSize :: Lens' SigmaSettings Number
_maxNodeSize f = unsafeCoerce $ _maxNodeSize' f
_minNodeSize' :: forall s a. Lens' { minNodeSize :: a | s} a
_minNodeSize' = prop (SProxy :: SProxy "minNodeSize")
_minNodeSize :: Lens' SigmaSettings Number
_minNodeSize f = unsafeCoerce $ _minNodeSize' f
-- TODO remove newtype here -- TODO remove newtype here
newtype State = State newtype State = State
{ graphData :: GraphData { graphData :: GraphData
...@@ -136,6 +149,11 @@ performAction BiggerLabels _ _ = ...@@ -136,6 +149,11 @@ performAction BiggerLabels _ _ =
modifyState_ $ \(State s) -> modifyState_ $ \(State s) ->
State $ ((_settings <<< _labelSizeRatio) +~ 1.0) s State $ ((_settings <<< _labelSizeRatio) +~ 1.0) s
performAction (ChangeNodeSize size) _ _ =
modifyState_ $ \(State s) -> do
let maxNoded = ((_settings <<< _maxNodeSize) .~ size) s
State $ ((_settings <<< _minNodeSize) .~ (size * 0.20)) maxNoded
convert :: GraphData -> SigmaGraphData convert :: GraphData -> SigmaGraphData
convert (GraphData r) = SigmaGraphData { nodes, edges} convert (GraphData r) = SigmaGraphData { nodes, edges}
where where
...@@ -442,7 +460,12 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render'] ...@@ -442,7 +460,12 @@ specOld = fold [treespec treeSpec, graphspec $ simpleSpec performAction render']
] ]
, li [className "col-md-2"] , li [className "col-md-2"]
[ span [] [text "Nodes"],input [_type "range", _id "myRange", value "90"] [ span [] [text "Nodes"],input [_type "range"
, _id "myRange"
, max "20"
, min "0"
, onChange \e -> d $ ChangeNodeSize (unsafeCoerce e).target.value
]
] ]
, li [className "col-md-2"] , li [className "col-md-2"]
[ span [] [text "Edges"],input [_type "range", _id "myRange", value "90"] [ span [] [text "Edges"],input [_type "range", _id "myRange", value "90"]
......
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