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
3dcce699
Commit
3dcce699
authored
Oct 12, 2022
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[utils] fix node normalization, add size normalization
parent
fbf92edd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
25 deletions
+13
-25
Utils.purs
src/Gargantext/Components/GraphExplorer/Utils.purs
+13
-25
No files found.
src/Gargantext/Components/GraphExplorer/Utils.purs
View file @
3dcce699
module Gargantext.Components.GraphExplorer.Utils
module Gargantext.Components.GraphExplorer.Utils
( stEdgeToGET, stNodeToGET
( stEdgeToGET, stNodeToGET
, normalizeNodes
, normalizeNodes
, normalizeNodeSize
, takeGreatestNodeByCluster, countNodeByCluster
, takeGreatestNodeByCluster, countNodeByCluster
) where
) where
...
@@ -8,7 +9,8 @@ import Gargantext.Prelude
...
@@ -8,7 +9,8 @@ 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)
import Data.Lens (Lens', lens, over, traversed)
import Data.Int (floor, toNumber)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (wrap)
import Data.Newtype (wrap)
import Data.Sequence as Seq
import Data.Sequence as Seq
...
@@ -41,32 +43,18 @@ stNodeToGET { id, label, x, y, _original: GEGT.Node { attributes, size, type_ }
...
@@ -41,32 +43,18 @@ stNodeToGET { id, label, x, y, _original: GEGT.Node { attributes, size, type_ }
normalizeNodes :: Seq.Seq GEGT.Node -> Seq.Seq GEGT.Node
normalizeNodes :: Seq.Seq GEGT.Node -> Seq.Seq 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 { x }) -> x) $ (\(GEGT.Node n) val -> GEGT.Node (n { x = val }))
xLens = lens (\(GEGT.Node { x }) -> x) $ (\(GEGT.Node n) val -> GEGT.Node (n { x = val }))
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 }))
-- normalizeNodes ns = Seq.map normalizeNode ns
-- where
normalizeNodeSize :: Int -> Int -> Seq.Seq GEGT.Node -> Seq.Seq GEGT.Node
-- xs = map (\(GEGT.Node { x }) -> x) ns
normalizeNodeSize minSize maxSize ns = over traversed (over sizeLens (\s -> toNumber minSize + s * quotient)) $ GUL.normalizeLens sizeLens ns
-- ys = map (\(GEGT.Node { y }) -> y) ns
where
-- mMinx = minimum xs
quotient :: Number
-- mMaxx = maximum xs
quotient = toNumber $ maxSize - minSize
-- mMiny = minimum ys
sizeLens :: Lens' GEGT.Node Number
-- mMaxy = maximum ys
sizeLens = lens (\(GEGT.Node { size }) -> toNumber size) $ (\(GEGT.Node n) val -> GEGT.Node (n { size = floor val }))
-- mXrange = do
-- minx <- mMinx
-- maxx <- mMaxx
-- pure $ maxx - minx
-- mYrange = do
-- miny <- mMiny
-- maxy <- mMaxy
-- pure $ maxy - miny
-- xdivisor = case mXrange of
-- Nothing -> 1.0
-- Just xdiv -> 1.0 / xdiv
-- ydivisor = case mYrange of
-- Nothing -> 1.0
-- Just ydiv -> 1.0 / ydiv
-- normalizeNode (GEGT.Node n@{ x, y }) = GEGT.Node $ n { x = x * xdivisor
-- , y = y * ydivisor }
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
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