Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
0d381e14
Commit
0d381e14
authored
Oct 13, 2022
by
Przemyslaw Kaminski
Committed by
Alexandre Delanoë
Oct 18, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[graph] fix node size transformation
parent
037ea73b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
13 deletions
+30
-13
Layout.purs
src/Gargantext/Components/GraphExplorer/Layout.purs
+3
-1
Utils.purs
src/Gargantext/Components/GraphExplorer/Utils.purs
+16
-6
Graph.purs
src/Gargantext/Components/Nodes/Graph.purs
+7
-1
Lens.purs
src/Gargantext/Utils/Lens.purs
+4
-5
No files found.
src/Gargantext/Components/GraphExplorer/Layout.purs
View file @
0d381e14
...
@@ -25,6 +25,7 @@ import Gargantext.Components.GraphExplorer.Toolbar.Controls as Controls
...
@@ -25,6 +25,7 @@ import Gargantext.Components.GraphExplorer.Toolbar.Controls as Controls
import Gargantext.Components.GraphExplorer.TopBar as GETB
import Gargantext.Components.GraphExplorer.TopBar as GETB
import Gargantext.Components.GraphExplorer.Types (GraphSideDoc)
import Gargantext.Components.GraphExplorer.Types (GraphSideDoc)
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Components.GraphExplorer.Utils as GEU
import Gargantext.Config (defaultFrontends)
import Gargantext.Config (defaultFrontends)
import Gargantext.Data.Louvain as Louvain
import Gargantext.Data.Louvain as Louvain
import Gargantext.Hooks.Session (useSession)
import Gargantext.Hooks.Session (useSession)
...
@@ -289,7 +290,7 @@ graphViewCpt = R.memo' $ here.component "graphView" cpt where
...
@@ -289,7 +290,7 @@ graphViewCpt = R.memo' $ here.component "graphView" cpt where
convert :: GET.GraphData -> Tuple (Maybe GET.MetaData) SigmaxT.SGraph
convert :: GET.GraphData -> Tuple (Maybe GET.MetaData) SigmaxT.SGraph
convert (GET.GraphData r) = Tuple r.metaData $ SigmaxT.Graph {nodes, edges}
convert (GET.GraphData r) = Tuple r.metaData $ SigmaxT.Graph {nodes, edges}
where
where
nodes = foldMapWithIndex nodeFn r.nodes
nodes = foldMapWithIndex nodeFn
$ GEU.normalizeNodeSize 1 10000
r.nodes
nodeFn _i nn@(GEGT.Node n) =
nodeFn _i nn@(GEGT.Node n) =
Seq.singleton {
Seq.singleton {
borderColor: color
borderColor: color
...
@@ -302,6 +303,7 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxT.Graph {nodes, edges}
...
@@ -302,6 +303,7 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxT.Graph {nodes, edges}
, id : n.id_
, id : n.id_
, label : n.label
, label : n.label
, size : DN.log (toNumber n.size + 1.0)
, size : DN.log (toNumber n.size + 1.0)
--, size: toNumber n.size
, type : modeGraphType gargType
, type : modeGraphType gargType
, x : n.x -- cos (toNumber i)
, x : n.x -- cos (toNumber i)
, y : n.y -- sin (toNumber i)
, y : n.y -- sin (toNumber i)
...
...
src/Gargantext/Components/GraphExplorer/Utils.purs
View file @
0d381e14
...
@@ -9,11 +9,12 @@ import Gargantext.Prelude
...
@@ -9,11 +9,12 @@ import Gargantext.Prelude
import Data.Array as A
import Data.Array as A
import Data.Foldable (maximum, minimum)
import Data.Foldable (maximum, minimum)
import Data.Lens (Lens', lens, over, traversed)
import Data.Lens (Lens', lens, over, traversed
, (^.)
)
import Data.Int (floor, toNumber)
import Data.Int (floor, toNumber)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..)
, fromMaybe, maybe
)
import Data.Newtype (wrap)
import Data.Newtype (wrap)
import Data.Sequence as Seq
import Data.Sequence as Seq
import Data.Traversable (class Traversable)
import Gargantext.Components.GraphExplorer.GraphTypes as GEGT
import Gargantext.Components.GraphExplorer.GraphTypes as GEGT
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Hooks.Sigmax.Types as ST
import Gargantext.Hooks.Sigmax.Types as ST
...
@@ -40,7 +41,7 @@ stNodeToGET { id, label, x, y, _original: GEGT.Node { attributes, size, type_ }
...
@@ -40,7 +41,7 @@ stNodeToGET { id, label, x, y, _original: GEGT.Node { attributes, size, type_ }
-- | Normalize nodes, i.e. set their {x, y} values so that they are in
-- | Normalize nodes, i.e. set their {x, y} values so that they are in
-- | range [0, 1].
-- | range [0, 1].
normalizeNodes ::
Seq.Seq GEGT.Node -> Seq.Seq
GEGT.Node
normalizeNodes ::
forall t. Traversable t => t GEGT.Node -> t
GEGT.Node
normalizeNodes ns = GUL.normalizeLens xLens $ GUL.normalizeLens yLens ns
normalizeNodes ns = GUL.normalizeLens xLens $ GUL.normalizeLens yLens ns
where
where
xLens :: Lens' GEGT.Node Number
xLens :: Lens' GEGT.Node Number
...
@@ -48,11 +49,20 @@ normalizeNodes ns = GUL.normalizeLens xLens $ GUL.normalizeLens yLens ns
...
@@ -48,11 +49,20 @@ normalizeNodes ns = GUL.normalizeLens xLens $ GUL.normalizeLens yLens ns
yLens :: Lens' GEGT.Node Number
yLens :: Lens' GEGT.Node Number
yLens = lens (\(GEGT.Node { y }) -> y) $ (\(GEGT.Node n) val -> GEGT.Node (n { y = val }))
yLens = lens (\(GEGT.Node { y }) -> y) $ (\(GEGT.Node n) val -> GEGT.Node (n { y = val }))
normalizeNodeSize ::
Int -> Int -> Seq.Seq GEGT.Node -> Seq.Seq
GEGT.Node
normalizeNodeSize ::
forall t. Traversable t => Int -> Int -> t GEGT.Node -> t
GEGT.Node
normalizeNodeSize minSize maxSize ns = over traversed (over sizeLens (\s -> toNumber minSize +
s * quotient)) $ GUL.normalizeLens sizeLens
ns
normalizeNodeSize minSize maxSize ns = over traversed (over sizeLens (\s -> toNumber minSize +
(s - sizeMin') * quotient))
ns
where
where
sizes = over traversed (_ ^. sizeLens) ns
sizeMin = minimum sizes
sizeMax = maximum sizes
range = do
sMin <- sizeMin
sMax <- sizeMax
pure $ sMax - sMin
sizeMin' = fromMaybe 0.0 sizeMin
divisor = maybe 1.0 (\r -> 1.0 / r) range
quotient :: Number
quotient :: Number
quotient =
toNumber $ maxSize - minSize
quotient =
(toNumber $ maxSize - minSize) * divisor
sizeLens :: Lens' GEGT.Node Number
sizeLens :: Lens' GEGT.Node Number
sizeLens = lens (\(GEGT.Node { size }) -> toNumber size) $ (\(GEGT.Node n) val -> GEGT.Node (n { size = floor val }))
sizeLens = lens (\(GEGT.Node { size }) -> toNumber size) $ (\(GEGT.Node n) val -> GEGT.Node (n { size = floor val }))
...
...
src/Gargantext/Components/Nodes/Graph.purs
View file @
0d381e14
...
@@ -13,6 +13,7 @@ import Data.Tuple.Nested ((/\))
...
@@ -13,6 +13,7 @@ import Data.Tuple.Nested ((/\))
import Gargantext.Components.App.Store as AppStore
import Gargantext.Components.App.Store as AppStore
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.GraphExplorer.API as GraphAPI
import Gargantext.Components.GraphExplorer.API as GraphAPI
import Gargantext.Components.GraphExplorer.GraphTypes as GEGT
import Gargantext.Components.GraphExplorer.Layout (convert, layout)
import Gargantext.Components.GraphExplorer.Layout (convert, layout)
import Gargantext.Components.GraphExplorer.Store as GraphStore
import Gargantext.Components.GraphExplorer.Store as GraphStore
import Gargantext.Components.GraphExplorer.Types as GET
import Gargantext.Components.GraphExplorer.Types as GET
...
@@ -116,7 +117,7 @@ type HydrateStoreProps =
...
@@ -116,7 +117,7 @@ type HydrateStoreProps =
, cacheParams :: GET.CacheParams
, cacheParams :: GET.CacheParams
)
)
hydrateStore:: R2.Leaf HydrateStoreProps
hydrateStore
:: R2.Leaf HydrateStoreProps
hydrateStore = R2.leaf hydrateStoreCpt
hydrateStore = R2.leaf hydrateStoreCpt
hydrateStoreCpt :: R.Component HydrateStoreProps
hydrateStoreCpt :: R.Component HydrateStoreProps
hydrateStoreCpt = here.component "hydrateStore" cpt where
hydrateStoreCpt = here.component "hydrateStore" cpt where
...
@@ -126,6 +127,11 @@ hydrateStoreCpt = here.component "hydrateStore" cpt where
...
@@ -126,6 +127,11 @@ hydrateStoreCpt = here.component "hydrateStore" cpt where
, hyperdataGraph
, hyperdataGraph
, cacheParams
, cacheParams
} _ = do
} _ = do
R.useEffect' $ do
let (GET.HyperdataGraph { graph: hg }) = hyperdataGraph
let GET.GraphData g = hg
here.log2 "[hydrateStore] sizes" $ (\(GEGT.Node { id_, size }) -> "id: " <> id_ <> ", size: " <> show size) <$> g.nodes
-- | Computed
-- | Computed
-- |
-- |
let
let
...
...
src/Gargantext/Utils/Lens.purs
View file @
0d381e14
...
@@ -3,7 +3,7 @@ module Gargantext.Utils.Lens where
...
@@ -3,7 +3,7 @@ module Gargantext.Utils.Lens where
import Gargantext.Prelude
import Gargantext.Prelude
import Data.Foldable (maximum, minimum)
import Data.Foldable (maximum, minimum)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..)
, fromMaybe, maybe
)
import Data.Lens
import Data.Lens
import Data.Traversable
import Data.Traversable
...
@@ -20,7 +20,6 @@ normalizeLens l ns = over traversed normalize' ns
...
@@ -20,7 +20,6 @@ normalizeLens l ns = over traversed normalize' ns
minv <- vMin
minv <- vMin
maxv <- vMax
maxv <- vMax
pure $ maxv - minv
pure $ maxv - minv
divisor = case vRange of
divisor = maybe 1.0 (\r -> 1.0 / r) vRange
Nothing -> 1.0
min = fromMaybe 0.0 vMin
Just d -> 1.0 / d
normalize' n = over l (\v -> (v - min) * divisor) n
normalize' n = over l (_ * divisor) n
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment