Store.purs 4.39 KB
Newer Older
arturo's avatar
arturo committed
1 2 3 4 5 6
module Gargantext.Components.GraphExplorer.Store
  ( Store
  , State
  , options
  , context
  , provide
arturo's avatar
arturo committed
7
  , use
arturo's avatar
arturo committed
8 9 10 11 12 13 14 15 16
  ) where

import Gargantext.Prelude

import Data.Maybe (Maybe(..))
import Data.Set as Set
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Types as GT
17
import Gargantext.Utils (getter)
arturo's avatar
arturo committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import Gargantext.Utils.Range as Range
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Stores as Stores
import Reactix as R
import Toestand as T
import Unsafe.Coerce (unsafeCoerce)

here :: R2.Here
here = R2.here "Gargantext.Components.GraphExplorer.Store"

type Store =
  -- Data
  ( graph              :: T.Box SigmaxT.SGraph
  , graphId            :: T.Box GET.GraphId
  , mMetaData          :: T.Box (Maybe GET.MetaData)
  , hyperdataGraph     :: T.Box GET.HyperdataGraph
  -- Layout
  , showControls       :: T.Box Boolean
  , sideTab            :: T.Box GET.SideTab
  , showSidebar        :: T.Box GT.SidePanelState
  , showDoc            :: T.Box (Maybe GET.GraphSideDoc)
39 40
  , expandSelection    :: T.Box Boolean
  , expandNeighborhood :: T.Box Boolean
arturo's avatar
arturo committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  -- Controls
  , multiSelectEnabled :: T.Box Boolean
  , edgeConfluence     :: T.Box Range.NumberRange
  , edgeWeight         :: T.Box Range.NumberRange
  , forceAtlasState    :: T.Box SigmaxT.ForceAtlasState
  , graphStage         :: T.Box GET.Stage
  , nodeSize           :: T.Box Range.NumberRange
  , showEdges          :: T.Box SigmaxT.ShowEdgesState
  , showLouvain        :: T.Box Boolean
  , labelSize          :: T.Box Number
  , mouseSelectorSize  :: T.Box Number
  , startForceAtlas    :: T.Box Boolean
  -- Terms update
  , removedNodeIds     :: T.Box SigmaxT.NodeIds
  , selectedNodeIds    :: T.Box SigmaxT.NodeIds
  )

type State =
  -- Data
  ( graph              :: SigmaxT.SGraph
  , graphId            :: GET.GraphId
  , mMetaData          :: Maybe GET.MetaData
  , hyperdataGraph     :: GET.HyperdataGraph
  -- Layout
  , showControls       :: Boolean
  , sideTab            :: GET.SideTab
  , showSidebar        :: GT.SidePanelState
  , showDoc            :: Maybe GET.GraphSideDoc
69 70
  , expandSelection    :: Boolean
  , expandNeighborhood :: Boolean
arturo's avatar
arturo committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
  -- Controls
  , multiSelectEnabled :: Boolean
  , edgeConfluence     :: Range.NumberRange
  , edgeWeight         :: Range.NumberRange
  , forceAtlasState    :: SigmaxT.ForceAtlasState
  , graphStage         :: GET.Stage
  , nodeSize           :: Range.NumberRange
  , showEdges          :: SigmaxT.ShowEdgesState
  , showLouvain        :: Boolean
  , labelSize          :: Number
  , mouseSelectorSize  :: Number
  , startForceAtlas    :: Boolean
  -- Terms update
  , removedNodeIds     :: SigmaxT.NodeIds
  , selectedNodeIds    :: SigmaxT.NodeIds
  )

options ::
arturo's avatar
arturo committed
89 90
  -- Layout
  { showControls        :: Boolean
arturo's avatar
arturo committed
91 92 93
  , showDoc             :: Maybe GET.GraphSideDoc
  , showSidebar         :: GT.SidePanelState
  , sideTab             :: GET.SideTab
94 95
  , expandSelection     :: Boolean
  , expandNeighborhood  :: Boolean
arturo's avatar
arturo committed
96 97 98 99
  -- Controls
  , labelSize           :: Number
  , mouseSelectorSize   :: Number
  , multiSelectEnabled  :: Boolean
arturo's avatar
arturo committed
100 101 102 103 104
  , edgeConfluence      :: Range.NumberRange
  , graphStage          :: GET.Stage
  , nodeSize            :: Range.NumberRange
  , showLouvain         :: Boolean
  , showEdges           :: SigmaxT.ShowEdgesState
arturo's avatar
arturo committed
105 106 107
  -- Terms update
  , removedNodeIds      :: SigmaxT.NodeIds
  , selectedNodeIds     :: SigmaxT.NodeIds
arturo's avatar
arturo committed
108 109 110 111 112 113 114
  }
options =
  -- Layout
  { showControls        : false
  , sideTab             : GET.SideTabLegend
  , showSidebar         : GT.InitialClosed
  , showDoc             : Nothing
115 116
  , expandSelection     : getter _.expandSelection GET.defaultCacheParams
  , expandNeighborhood  : getter _.expandNeighborhood GET.defaultCacheParams
arturo's avatar
arturo committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  -- Controls
  , multiSelectEnabled  : false
  , labelSize           : 14.0
  , mouseSelectorSize   : 15.0
  , edgeConfluence      : Range.Closed { min: 0.0, max: 1.0 }
  , graphStage          : GET.Init
  , nodeSize            : Range.Closed { min: 0.0, max: 100.0 }
  , showLouvain         : false
  , showEdges           : SigmaxT.EShow
  -- Terms update
  , removedNodeIds      : Set.empty
  , selectedNodeIds     : Set.empty
  }

context :: R.Context (Record Store)
context = R.createContext $ unsafeCoerce unit

provide :: Record State -> Array R.Element -> R.Element
provide values = Stores.provideStore here.name values context
arturo's avatar
arturo committed
136 137 138

use :: R.Hooks (Record Store)
use = Stores.useStore context