Commit 3dcce699 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[utils] fix node normalization, add size normalization

parent fbf92edd
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 }
------------------------------------------------------------------------ ------------------------------------------------------------------------
......
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