Commit edc959c8 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph] some work on node size

parent f07cc33d
......@@ -39,7 +39,7 @@ newtype Node = Node {
, children :: Array String
, id_ :: String
, label :: String
, size :: Int
, size :: Number
, type_ :: String
, x :: Number
, y :: Number
......
......@@ -9,7 +9,6 @@ import Data.Int (toNumber)
import Data.Map as Map
import Data.Maybe (Maybe(..), fromJust)
import Data.Nullable (null, Nullable)
import Data.Number as DN
import Data.Sequence as Seq
import Data.Set as Set
import Data.Tuple (Tuple(..))
......@@ -290,7 +289,11 @@ graphViewCpt = R.memo' $ here.component "graphView" cpt where
convert :: GET.GraphData -> Tuple (Maybe GET.MetaData) SigmaxT.SGraph
convert (GET.GraphData r) = Tuple r.metaData $ SigmaxT.Graph {nodes, edges}
where
nodes = foldMapWithIndex nodeFn $ GEU.normalizeNodeSize 1 10000 r.nodes
normalizedNodes :: Array GEGT.Node
normalizedNodes = GEGT.Node <$> (GEU.normalizeNodeSizeDefault $ (\(GEGT.Node n) -> n) <$> r.nodes)
nodes :: Seq.Seq (Record SigmaxT.Node)
nodes = foldMapWithIndex nodeFn normalizedNodes
nodeFn :: Int -> GEGT.Node -> Seq.Seq (Record SigmaxT.Node)
nodeFn _i nn@(GEGT.Node n) =
Seq.singleton {
borderColor: color
......@@ -302,7 +305,7 @@ convert (GET.GraphData r) = Tuple r.metaData $ SigmaxT.Graph {nodes, edges}
, highlighted: false
, id : n.id_
, label : n.label
, size : DN.log (toNumber n.size + 1.0)
, size : n.size
--, size: toNumber n.size
, type : modeGraphType gargType
, x : n.x -- cos (toNumber i)
......
......@@ -94,7 +94,7 @@ labelSizeButtonCpt = here.component "labelSizeButton" cpt
defaultLabelSize: newValue
, drawLabels: true
, labelSize: newValue
, maxNodeSize: newValue / 2.5
-- , maxNodeSize: newValue / 2.5
--, labelSizeRatio: newValue / 2.5
}
T.write_ newValue state
......
module Gargantext.Components.GraphExplorer.Utils
( stEdgeToGET, stNodeToGET
, normalizeNodes
, normalizeNodeSizeDefault
, normalizeNodeSize
, takeGreatestNodeByCluster, countNodeByCluster
) where
......@@ -13,6 +14,7 @@ import Data.Lens (Lens', lens, over, traversed, (^.))
import Data.Int (floor, toNumber)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Newtype (wrap)
import Data.Number as DN
import Data.Sequence as Seq
import Data.Traversable (class Traversable)
import Gargantext.Components.GraphExplorer.GraphTypes as GEGT
......@@ -49,8 +51,16 @@ normalizeNodes ns = GUL.normalizeLens xLens $ GUL.normalizeLens yLens ns
yLens :: Lens' GEGT.Node Number
yLens = lens (\(GEGT.Node { y }) -> y) $ (\(GEGT.Node n) val -> GEGT.Node (n { y = val }))
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 - sizeMin') * quotient)) ns
type NodeSize r = { size :: Number | r }
normalizeNodeSizeDefault :: forall t r. Traversable t => t (NodeSize r) -> t (NodeSize r)
normalizeNodeSizeDefault ns = logSize <$> normalizeNodeSize 50.0 100000.0 ns
where
logSize (n@{ size }) = n { size = DN.log (size + 1.0) }
normalizeNodeSize :: forall t r. Traversable t =>
Number -> Number -> t (NodeSize r) -> t (NodeSize r)
normalizeNodeSize minSize maxSize ns = over traversed (over sizeLens (\s -> minSize + (s - sizeMin') * quotient)) ns
where
sizes = over traversed (_ ^. sizeLens) ns
sizeMin = minimum sizes
......@@ -62,9 +72,12 @@ normalizeNodeSize minSize maxSize ns = over traversed (over sizeLens (\s -> toNu
sizeMin' = fromMaybe 0.0 sizeMin
divisor = maybe 1.0 (\r -> 1.0 / r) range
quotient :: Number
quotient = (toNumber $ maxSize - minSize) * divisor
sizeLens :: Lens' GEGT.Node Number
sizeLens = lens (\(GEGT.Node { size }) -> toNumber size) $ (\(GEGT.Node n) val -> GEGT.Node (n { size = floor val }))
quotient = (maxSize - minSize) * divisor
--quotient = (toNumber $ maxSize - minSize) * divisor
--sizeLens :: Lens' GEGT.Node Number
--sizeLens = lens (\(GEGT.Node { size }) -> size) $ (\(GEGT.Node n) val -> GEGT.Node (n { size = val }))
sizeLens :: Lens' { size :: Number | r } Number
sizeLens = lens (\{ size } -> size) $ \n val -> (n { size = val })
------------------------------------------------------------------------
......
......@@ -98,22 +98,22 @@ nodeCpt = here.component "node" cpt where
Tuple mMetaData graph = convert hyperdataGraph
in
hydrateStore
{ graph
{ cacheParams: cache'
, graph
, graphId
, hyperdataGraph: loaded
, mMetaData
, graphId
, cacheParams: cache'
}
}
--------------------------------------------------------
type HydrateStoreProps =
( mMetaData :: Maybe GET.MetaData
( cacheParams :: GET.CacheParams
, graph :: SigmaxT.SGraph
, hyperdataGraph :: GET.HyperdataGraph
, graphId :: GET.GraphId
, cacheParams :: GET.CacheParams
, hyperdataGraph :: GET.HyperdataGraph
, mMetaData :: Maybe GET.MetaData
)
hydrateStore :: R2.Leaf HydrateStoreProps
......
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