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