Store.purs 5.4 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
  ) where

import Gargantext.Prelude

import Data.Maybe (Maybe(..))
import Data.Set as Set
import Gargantext.Components.GraphExplorer.Types as GET
15
import Gargantext.Hooks.Sigmax.ForceAtlas2 as ForceAtlas
arturo's avatar
arturo committed
16 17
import Gargantext.Hooks.Sigmax.Types as SigmaxT
import Gargantext.Types as GT
18
import Gargantext.Utils (getter)
arturo's avatar
arturo committed
19 20 21 22 23 24 25 26 27 28 29 30
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
31 32 33 34
  ( graph                      :: T.Box SigmaxT.SGraph
  , graphId                    :: T.Box GET.GraphId
  , mMetaData                  :: T.Box (Maybe GET.MetaData)
  , hyperdataGraph             :: T.Box GET.HyperdataGraph
arturo's avatar
arturo committed
35
  -- Layout
36 37 38 39 40 41
  , showControls               :: T.Box Boolean
  , sideTab                    :: T.Box GET.SideTab
  , showSidebar                :: T.Box GT.SidePanelState
  , showDoc                    :: T.Box (Maybe GET.GraphSideDoc)
  , expandSelection            :: T.Box Boolean
  , expandNeighborhood         :: T.Box Boolean
arturo's avatar
arturo committed
42
  -- Controls
43 44
  , multiSelectEnabled         :: T.Box Boolean
  , edgeConfluence             :: T.Box Range.NumberRange
45
  , edgeConfluenceRange        :: T.Box Range.NumberRange
46 47 48 49
  , edgeWeight                 :: T.Box Range.NumberRange
  , forceAtlasState            :: T.Box SigmaxT.ForceAtlasState
  , graphStage                 :: T.Box GET.Stage
  , nodeSize                   :: T.Box Range.NumberRange
50
  , nodeSizeRange              :: T.Box Range.NumberRange
51 52 53 54 55 56
  , showEdges                  :: T.Box SigmaxT.ShowEdgesState
  , showLouvain                :: T.Box Boolean
  , labelSize                  :: T.Box Number
  , labelRenderedSizeThreshold :: T.Box Number
  , mouseSelectorSize          :: T.Box Number
  , startForceAtlas            :: T.Box Boolean
arturo's avatar
arturo committed
57
  -- Terms update
58 59
  , removedNodeIds             :: T.Box SigmaxT.NodeIds
  , selectedNodeIds            :: T.Box SigmaxT.NodeIds
arturo's avatar
arturo committed
60 61 62 63
  )

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

options ::
arturo's avatar
arturo committed
96
  -- Layout
97 98 99 100 101 102
  { showControls               :: Boolean
  , showDoc                    :: Maybe GET.GraphSideDoc
  , showSidebar                :: GT.SidePanelState
  , sideTab                    :: GET.SideTab
  , expandSelection            :: Boolean
  , expandNeighborhood         :: Boolean
arturo's avatar
arturo committed
103
  -- Controls
104 105 106 107 108 109 110 111 112
  , labelSize                  :: Number
  , labelRenderedSizeThreshold :: Number
  , mouseSelectorSize          :: Number
  , multiSelectEnabled         :: Boolean
  , edgeConfluence             :: Range.NumberRange
  , graphStage                 :: GET.Stage
  , nodeSize                   :: Range.NumberRange
  , showLouvain                :: Boolean
  , showEdges                  :: SigmaxT.ShowEdgesState
arturo's avatar
arturo committed
113
  -- Terms update
114 115
  , removedNodeIds             :: SigmaxT.NodeIds
  , selectedNodeIds            :: SigmaxT.NodeIds
arturo's avatar
arturo committed
116 117 118
  }
options =
  -- Layout
119 120 121 122 123 124
  { showControls               : false
  , sideTab                    : GET.SideTabLegend
  , showSidebar                : GT.InitialClosed
  , showDoc                    : Nothing
  , expandSelection            : getter _.expandSelection GET.defaultCacheParams
  , expandNeighborhood         : getter _.expandNeighborhood GET.defaultCacheParams
arturo's avatar
arturo committed
125
  -- Controls
126 127
  , multiSelectEnabled         : false
  , labelSize                  : 14.0
128
  , labelRenderedSizeThreshold : 2.0
129 130 131 132 133 134
  , 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
arturo's avatar
arturo committed
135
  -- Terms update
136 137
  , removedNodeIds             : Set.empty
  , selectedNodeIds            : Set.empty
arturo's avatar
arturo committed
138 139 140 141 142 143 144
  }

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
145 146 147

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