Commit 413408b4 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge branch 'dev-merge' into dev

parents 56f57d04 6277f784
...@@ -89,7 +89,7 @@ cameraButton { id ...@@ -89,7 +89,7 @@ cameraButton { id
edges <- Sigmax.getEdges s edges <- Sigmax.getEdges s
nodes <- Sigmax.getNodes s nodes <- Sigmax.getNodes s
let graphData = GET.GraphData $ hyperdataGraph { edges = map GEU.stEdgeToGET edges let graphData = GET.GraphData $ hyperdataGraph { edges = map GEU.stEdgeToGET edges
, nodes = map GEU.stNodeToGET nodes } , nodes = GEU.normalizeNodes $ map GEU.stNodeToGET nodes }
let cameras = map Sigma.toCamera $ Sigma.cameras s let cameras = map Sigma.toCamera $ Sigma.cameras s
let camera = case cameras of let camera = case cameras of
[c] -> GET.Camera { ratio: c.ratio [c] -> GET.Camera { ratio: c.ratio
......
module Gargantext.Components.GraphExplorer.Utils module Gargantext.Components.GraphExplorer.Utils where
where
import Data.Maybe (Maybe(..))
import Gargantext.Prelude import Gargantext.Prelude
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
import Gargantext.Utils.Array as GUA
stEdgeToGET :: Record ST.Edge -> GET.Edge stEdgeToGET :: Record ST.Edge -> GET.Edge
...@@ -20,3 +22,29 @@ stNodeToGET { id, label, x, y, _original: GET.Node { attributes, size, type_ } } ...@@ -20,3 +22,29 @@ stNodeToGET { id, label, x, y, _original: GET.Node { attributes, size, type_ } }
, x , x
, y , y
} }
normalizeNodes :: Array GET.Node -> Array GET.Node
normalizeNodes ns = map normalizeNode ns
where
xs = map (\(GET.Node { x }) -> x) ns
ys = map (\(GET.Node { y }) -> y) ns
mMinx = GUA.min xs
mMaxx = GUA.max xs
mMiny = GUA.min ys
mMaxy = GUA.max ys
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 (GET.Node n@{ x, y }) = GET.Node $ n { x = x * xdivisor
, y = y * ydivisor }
module Gargantext.Utils.Array (push) where module Gargantext.Utils.Array (max, min, push) where
import Data.Array as A
import Data.Foldable (foldr)
import Data.Maybe (Maybe(..))
import Data.Ord as Ord
import Effect (Effect) import Effect (Effect)
import Data.Unit (Unit)
import Effect.Uncurried (EffectFn2, runEffectFn2) import Effect.Uncurried (EffectFn2, runEffectFn2)
import Gargantext.Prelude
foreign import _push :: forall a. EffectFn2 (Array a) a Unit foreign import _push :: forall a. EffectFn2 (Array a) a Unit
push :: forall a. Array a -> a -> Effect Unit push :: forall a. Array a -> a -> Effect Unit
push = runEffectFn2 _push push = runEffectFn2 _push
max :: forall a. Ord a => Array a -> Maybe a
max xs = foldr reducer (A.head xs) xs
where
reducer _ Nothing = Nothing
reducer v (Just acc) = Just $ Ord.max acc v
min :: forall a. Ord a => Array a -> Maybe a
min xs = foldr reducer (A.head xs) xs
where
reducer _ Nothing = Nothing
reducer v (Just acc) = Just $ Ord.min acc v
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