Commit 471fbf05 authored by arturo's avatar arturo

>>> continue

parent 7a9fdad7
...@@ -14,7 +14,7 @@ import Effect.Aff (Aff, launchAff_) ...@@ -14,7 +14,7 @@ import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet) import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet)
import Gargantext.Components.PhyloExplorer.Layout (layout) import Gargantext.Components.PhyloExplorer.Layout (layout)
import Gargantext.Components.PhyloExplorer.Types (PhyloDataSet) import Gargantext.Components.PhyloExplorer.Types (PhyloDataSet, parsePhyloJSONSet)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (NodeID) import Gargantext.Types (NodeID)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
...@@ -37,7 +37,7 @@ phyloLayoutCpt :: R.Component Props ...@@ -37,7 +37,7 @@ phyloLayoutCpt :: R.Component Props
phyloLayoutCpt = here.component "phyloLayout" cpt where phyloLayoutCpt = here.component "phyloLayout" cpt where
cpt _ _ = do cpt _ _ = do
fetchedDataBox <- T.useBox (Nothing :: Maybe PhyloJSONSet) fetchedDataBox <- T.useBox (Nothing :: Maybe PhyloDataSet)
fetchedData <- T.useLive T.unequal fetchedDataBox fetchedData <- T.useLive T.unequal fetchedDataBox
R.useEffectOnce' $ launchAff_ do R.useEffectOnce' $ launchAff_ do
......
...@@ -42,8 +42,8 @@ type GraphData = ...@@ -42,8 +42,8 @@ type GraphData =
newtype PhyloJSONSet = PhyloJSONSet newtype PhyloJSONSet = PhyloJSONSet
{ _subgraph_cnt :: Int { _subgraph_cnt :: Int
, directed :: Boolean , directed :: Boolean
, edges :: Array Edge , edges :: Array RawEdge
, objects :: Array PhyloObject , objects :: Array RawObject
, strict :: Boolean , strict :: Boolean
| GraphData | GraphData
} }
...@@ -65,7 +65,7 @@ type NodeData = ...@@ -65,7 +65,7 @@ type NodeData =
, width :: String , width :: String
) )
data PhyloObject data RawObject
= Layer = Layer
{ _gvid :: Int { _gvid :: Int
, nodes :: Array Int , nodes :: Array Int
...@@ -116,10 +116,10 @@ data PhyloObject ...@@ -116,10 +116,10 @@ data PhyloObject
| NodeData | NodeData
} }
derive instance Generic PhyloObject _ derive instance Generic RawObject _
derive instance Eq PhyloObject derive instance Eq RawObject
instance Show PhyloObject where show = genericShow instance Show RawObject where show = genericShow
instance JSON.ReadForeign PhyloObject where instance JSON.ReadForeign RawObject where
readImpl f = GR.to <$> untaggedSumRep f readImpl f = GR.to <$> untaggedSumRep f
...@@ -133,7 +133,7 @@ type EdgeData = ...@@ -133,7 +133,7 @@ type EdgeData =
, width :: String , width :: String
) )
data Edge data RawEdge
= GroupToGroup = GroupToGroup
{ _gvid :: Int { _gvid :: Int
, constraint :: String , constraint :: String
...@@ -167,8 +167,8 @@ data Edge ...@@ -167,8 +167,8 @@ data Edge
| EdgeData | EdgeData
} }
derive instance Generic Edge _ derive instance Generic RawEdge _
derive instance Eq Edge derive instance Eq RawEdge
instance Show Edge where show = genericShow instance Show RawEdge where show = genericShow
instance JSON.ReadForeign Edge where instance JSON.ReadForeign RawEdge where
readImpl f = GR.to <$> untaggedSumRep f readImpl f = GR.to <$> untaggedSumRep f
...@@ -5,6 +5,7 @@ module Gargantext.Components.PhyloExplorer.Layout ...@@ -5,6 +5,7 @@ module Gargantext.Components.PhyloExplorer.Layout
import Gargantext.Prelude import Gargantext.Prelude
import DOM.Simple (Window, window) import DOM.Simple (Window, window)
import DOM.Simple.Console (log2)
import Data.Array as Array import Data.Array as Array
import Data.Date as Date import Data.Date as Date
import Data.FoldableWithIndex (forWithIndex_) import Data.FoldableWithIndex (forWithIndex_)
...@@ -12,17 +13,20 @@ import Data.Int as Int ...@@ -12,17 +13,20 @@ import Data.Int as Int
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.Number as Number import Data.Number as Number
import Data.String as String import Data.String as String
import Data.Traversable (for) import Data.Symbol (SProxy(..))
import Data.Traversable (for, for_)
import Data.Tuple as Tuple import Data.Tuple as Tuple
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect (Effect) import Effect (Effect)
import FFI.Simple (maybeGetProperty, (..), (...)) import FFI.Simple (maybeGetProperty, (..), (...), (.=), (.?))
import Gargantext.Components.PhyloExplorer.Types (Group, PhyloDataSet(..)) import Gargantext.Components.PhyloExplorer.Types (GlobalTerm(..), Group(..), PhyloDataSet(..))
import Gargantext.Utils (nbsp) import Gargantext.Utils (nbsp)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record (get)
import Toestand as T import Toestand as T
import Type.Proxy (Proxy(..))
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.PhyloExplorer" here = R2.here "Gargantext.Components.PhyloExplorer"
...@@ -41,7 +45,7 @@ layoutCpt = here.component "layout" cpt where ...@@ -41,7 +45,7 @@ layoutCpt = here.component "layout" cpt where
R.useEffectOnce' $ do R.useEffectOnce' $ do
pure unit setGlobalDependencies window (PhyloDataSet o)
-- @hightlightSource -- @hightlightSource
let let
...@@ -260,29 +264,55 @@ layoutCpt = here.component "layout" cpt where ...@@ -260,29 +264,55 @@ layoutCpt = here.component "layout" cpt where
setGlobalDependencies :: Window -> PhyloDataSet -> Effect Unit setGlobalDependencies :: Window -> PhyloDataSet -> Effect Unit
setGlobalDependencies w (PhyloDataSet o) setGlobalDependencies w (PhyloDataSet o)
= do = do
-- _ <- w ... "freq" $ {} _ <- pure $ (w .= "freq") {}
-- _ <- w ... "nbBranches" $ o.nbBranches _ <- pure $ (w .= "nbBranches") o.nbBranches
-- _ <- w ... "nbDocs" $ o.nbDocs _ <- pure $ (w .= "nbDocs") o.nbDocs
-- _ <- w ... "nbFoundations" $ o.nbFoundations _ <- pure $ (w .= "nbFoundations") o.nbFoundations
-- _ <- w ... "nbGroups" $ o.nbGroups _ <- pure $ (w .= "nbGroups") o.nbGroups
-- _ <- w ... "nbPeriods" $ o.nbPeriods _ <- pure $ (w .= "nbPeriods") o.nbPeriods
-- _ <- w ... "nbTerms" $ o.nbTerms _ <- pure $ (w .= "nbTerms") o.nbTerms
-- _ <- w ... "sources" $ o.sources _ <- pure $ (w .= "sources") o.sources
-- _ <- w ... "terms" $ {} _ <- pure $ (w .= "terms") []
-- _ <- w ... "timeScale" $ o.timeScale _ <- pure $ (w .= "timeScale") o.timeScale
-- _ <- w ... "weighted" $ o.weighted _ <- pure $ (w .= "weighted") o.weighted
(freq :: Array Int) <- pure $ w .. "freq" (freq :: Array Int) <- pure $ w .. "freq"
pure unit (terms :: Array GlobalTerm) <- pure $ w .. "terms"
-- forWithIndex_ o.foundations $ \i _ -> case maybeGetProperty (show i) freq of
-- Nothing -> freq ... (show i) $ 0 void $ for o.groups \(Group g) -> do
-- Just v -> freq ... (show i) $ (v + 1)
let
-- pure $ for o.groups \(g :: Group)-> pure unit f = g.foundation
l = g.label
log2 "FOUNDATION" f
log2 "LABEL" l
-- For each entries in group.foundation array,
-- increment consequently the global window.keys array
-- forWithIndex_ f \i _ ->
-- let i' = show i
-- in case (freq .? i') of
-- Nothing -> pure $ (freq .= i') 0
-- Just v -> pure $ (freq .= i') (v +1)
for_ f \i ->
let i' = show i
in case (freq .? i') of
Nothing -> pure $ (freq .= i') 0
Just v -> pure $ (freq .= i') (v +1)
-- For each entries in group.foundation array,
-- if the global window.terms does not have it in property,
-- append an item to the global window.terms
for_ f \i ->
let i' = show i
in case (terms .? i') of
Nothing -> pure unit
Just _ -> void <<< pure $ (terms .= i') $ GlobalTerm
{ label: l .. i'
, fdt : f .. i'
}
-------------------------------------------------------- --------------------------------------------------------
type PhyloCorpusProps = () type PhyloCorpusProps = ()
......
...@@ -52,74 +52,6 @@ exports.utcStringToDate = utcStringToDate; ...@@ -52,74 +52,6 @@ exports.utcStringToDate = utcStringToDate;
function draw(json) { function draw(json) {
// groups
window.weighted = false;
var groups = json.objects.filter(node => node.nodeType == "group").map(function(g){
// console.log(g.weight)
if ((g.weight != undefined) && (g.weight != "Nothing"))
window.weighted = true;
var keys = (g.foundation.slice(1, g.foundation.length - 1)).split('|')
var labels = (g.lbl.slice(1, g.lbl.length - 1)).split('|')
for (var i = 0; i < keys.length; i++) {
// freq
if (!((keys[i]).trim() in window.freq)) {
window.freq[(keys[i]).trim()] = 0;
} else {
window.freq[(keys[i]).trim()] += 1;
}
// terms
if (!((keys[i]).trim() in window.terms)) {
window.terms[(keys[i]).trim()] = {label:(labels[i]).trim(),fdt:(keys[i]).trim()}
}
}
var from = yearToDate(g.from),
to = yearToDate(g.to),
weight = 0;
source = [];
if (g.strFrom != undefined) {
if (window.timeScale == "epoch") {
from = utcStringToDate(g.strFrom)
} else {
from = stringToDate(g.strFrom)
}
}
if (g.strTo != undefined) {
if (window.timeScale == "epoch") {
to = utcStringToDate(g.strTo)
} else {
to = stringToDate(g.strTo)
}
}
if (g.source != undefined)
source = intArrToArr(g.source);
if (g.weight != undefined)
weight = parseFloat((g.weight).replace("Just ",""));
return { from : from,
to : to,
x : parseFloat(((g.pos).split(','))[0]) ,
y : parseFloat(((g.pos).split(','))[1]) ,
bId : parseInt(g.bId) ,
gId : parseInt(g._gvid) ,
size : parseInt(g.support),
source : source,
weight : weight,
label : labels,
foundation : keys,
role : ((g.role.slice(1, g.role.length - 1)).split('|')).map(e => parseInt(e.trim()))}
});
var links = json.edges.filter(edges => edges.edgeType == "link").map(function(l){ var links = json.edges.filter(edges => edges.edgeType == "link").map(function(l){
return { lId : parseInt(l._gvid), return { lId : parseInt(l._gvid),
......
module Gargantext.Components.PhyloExplorer.Types module Gargantext.Components.PhyloExplorer.Types
( PhyloDataSet(..) ( PhyloDataSet(..)
, Branch, Period, Group , Branch(..), Period(..), Group(..)
, GlobalTerm(..)
, parsePhyloJSONSet , parsePhyloJSONSet
) where ) where
...@@ -12,10 +13,11 @@ import Data.Generic.Rep (class Generic) ...@@ -12,10 +13,11 @@ import Data.Generic.Rep (class Generic)
import Data.Int as Int import Data.Int as Int
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Data.Number as Number import Data.Number as Number
import Data.Show.Generic (genericShow)
import Data.String as String import Data.String as String
import Data.Tuple as Tuple import Data.Tuple as Tuple
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet(..), PhyloObject(..)) import Gargantext.Components.PhyloExplorer.JSON (PhyloJSONSet(..), RawObject(..))
-- @WIP Date or foreign? -- @WIP Date or foreign?
...@@ -41,6 +43,8 @@ newtype PhyloDataSet = PhyloDataSet ...@@ -41,6 +43,8 @@ newtype PhyloDataSet = PhyloDataSet
} }
derive instance Generic PhyloDataSet _ derive instance Generic PhyloDataSet _
derive instance Eq PhyloDataSet
instance Show PhyloDataSet where show = genericShow
parsePhyloJSONSet :: PhyloJSONSet -> PhyloDataSet parsePhyloJSONSet :: PhyloJSONSet -> PhyloDataSet
parsePhyloJSONSet (PhyloJSONSet o) = PhyloDataSet parsePhyloJSONSet (PhyloJSONSet o) = PhyloDataSet
...@@ -76,13 +80,17 @@ data Branch = Branch ...@@ -76,13 +80,17 @@ data Branch = Branch
, y :: String , y :: String
} }
parseBranches :: Array PhyloObject -> Array Branch derive instance Generic Branch _
derive instance Eq Branch
instance Show Branch where show = genericShow
parseBranches :: Array RawObject -> Array Branch
parseBranches parseBranches
= map parse = map parse
>>> Array.catMaybes >>> Array.catMaybes
where where
parse :: PhyloObject -> Maybe Branch parse :: RawObject -> Maybe Branch
parse (BranchToNode o) = Just $ Branch parse (BranchToNode o) = Just $ Branch
{ bId : parseInt o.bId { bId : parseInt o.bId
, gvid : o._gvid , gvid : o._gvid
...@@ -101,13 +109,17 @@ data Period = Period ...@@ -101,13 +109,17 @@ data Period = Period
, y :: Number , y :: Number
} }
parsePeriods :: Boolean -> Array PhyloObject -> Array Period derive instance Generic Period _
derive instance Eq Period
instance Show Period where show = genericShow
parsePeriods :: Boolean -> Array RawObject -> Array Period
parsePeriods epoch parsePeriods epoch
= map parse = map parse
>>> Array.catMaybes >>> Array.catMaybes
where where
parse :: PhyloObject -> Maybe Period parse :: RawObject -> Maybe Period
parse (PeriodToNode o) = Just $ Period parse (PeriodToNode o) = Just $ Period
{ from : parseNodeDate o.strFrom o.from epoch { from : parseNodeDate o.strFrom o.from epoch
, to : parseNodeDate o.strTo o.to epoch , to : parseNodeDate o.strTo o.to epoch
...@@ -132,31 +144,46 @@ data Group = Group ...@@ -132,31 +144,46 @@ data Group = Group
, y :: Number , y :: Number
} }
parseGroups :: Boolean -> Array PhyloObject -> Array Group derive instance Generic Group _
derive instance Eq Group
instance Show Group where show = genericShow
parseGroups :: Boolean -> Array RawObject -> Array Group
parseGroups epoch parseGroups epoch
= map parse = map parse
>>> Array.catMaybes >>> Array.catMaybes
where where
parse :: PhyloObject -> Maybe Group parse :: RawObject -> Maybe Group
parse (GroupToNode o) = Just $ Group parse (GroupToNode o) = Just $ Group
{ from : parseNodeDate o.strFrom o.from epoch { bId : parseInt o.bId
, to : parseNodeDate o.strTo o.to epoch , foundation : stringedArrayToArray' o.foundation
, x : Tuple.fst $ parsePos o.pos , from : parseNodeDate o.strFrom o.from epoch
, y : Tuple.snd $ parsePos o.pos , gId : o._gvid
, bId : parseInt o.bId , label : stringedArrayToArray o.lbl
, gId : o._gvid , role : stringedArrayToArray' o.role
, size : parseInt o.support , size : parseInt o.support
, source: parseSources o.source , source : parseSources o.source
, weight: stringedMaybeToNumber o.weight , to : parseNodeDate o.strTo o.to epoch
, label : stringedArrayToArray o.lbl , weight : stringedMaybeToNumber o.weight
, role : stringedArrayToArray' o.role , x : Tuple.fst $ parsePos o.pos
, foundation: stringedArrayToArray' o.foundation , y : Tuple.snd $ parsePos o.pos
} }
parse _ = Nothing parse _ = Nothing
----------------------------------------------------------- -----------------------------------------------------------
data GlobalTerm = GlobalTerm
{ label :: String
, fdt :: String
}
derive instance Generic GlobalTerm _
derive instance Eq GlobalTerm
instance Show GlobalTerm where show = genericShow
-----------------------------------------------------------
parseInt :: String -> Int parseInt :: String -> Int
parseInt s = maybe 0 identity $ Int.fromString s parseInt s = maybe 0 identity $ Int.fromString s
......
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