Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
419aa14f
Commit
419aa14f
authored
Apr 23, 2019
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT][CHART] TreeMap.
parent
0529a6b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
105 deletions
+85
-105
Series.purs
src/Gargantext/Components/Charts/Options/Series.purs
+37
-22
Config.purs
src/Gargantext/Config.purs
+3
-2
Tree.purs
src/Gargantext/Pages/Corpus/Chart/Tree.purs
+15
-51
Dashboard.purs
src/Gargantext/Pages/Corpus/Dashboard.purs
+30
-30
No files found.
src/Gargantext/Components/Charts/Options/Series.purs
View file @
419aa14f
module Gargantext.Components.Charts.Options.Series where
module Gargantext.Components.Charts.Options.Series where
import Data.Maybe
import Data.Array (foldl)
import Record.Unsafe (unsafeSet)
import Record.Unsafe (unsafeSet)
import Unsafe.Coerce (unsafeCoerce)
import Unsafe.Coerce (unsafeCoerce)
import Prelude
import Prelude
import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Gargantext.Types (class Optional)
import Gargantext.Types (class Optional)
import Gargantext.Components.Charts.Options.Font (ItemStyle, Tooltip)
import Gargantext.Components.Charts.Options.Font (ItemStyle, Tooltip)
import Gargantext.Components.Charts.Options.Data (DataD1, DataD2)
import Gargantext.Components.Charts.Options.Data (DataD1, DataD2)
...
@@ -143,7 +146,7 @@ instance showTrees :: Show Trees where
...
@@ -143,7 +146,7 @@ instance showTrees :: Show Trees where
type RequiredTree o =
type RequiredTree o =
{ "type" :: SeriesType
{ "type" :: SeriesType
, "data" :: Array Tree
Data
, "data" :: Array Tree
Node
| o
| o
}
}
...
@@ -154,9 +157,9 @@ type OptionalTree =
...
@@ -154,9 +157,9 @@ type OptionalTree =
seriesTree :: forall o. Optional o OptionalTree => RequiredTree o -> Series
seriesTree :: forall o. Optional o OptionalTree => RequiredTree o -> Series
seriesTree = unsafeSeries
seriesTree = unsafeSeries
mkTree :: Trees -> Array Tree
Data
-> Series
mkTree :: Trees -> Array Tree
Node
-> Series
mkTree t ts = seriesTree { "type" : SeriesType (show t)
mkTree t ts = seriesTree { "type" : SeriesType (show t)
, "data" : map
toJsTree
ts
, "data" : map
(toJsTree Nothing)
ts
, layout : layout
, layout : layout
}
}
where
where
...
@@ -165,30 +168,42 @@ mkTree t ts = seriesTree { "type" : SeriesType (show t)
...
@@ -165,30 +168,42 @@ mkTree t ts = seriesTree { "type" : SeriesType (show t)
_ -> "none"
_ -> "none"
-- ** Data Structure of the Trees
-- ** Data Structure of the Trees
data TreeData = TreeLeaf TreeLeaf
data TreeData = Array TreeNode
| TreeNode TreeNode
toJsTree :: TreeData -> TreeData
treeValue :: TreeNode -> Int
toJsTree (TreeLeaf x) = unsafeCoerce x
treeValue (TreeNode x) = foldl (+) 0 $ [x.value] <> map treeValue x.children
toJsTree (TreeNode x) = unsafeCoerce { name : x.name
, value : x.value
toJsTree :: Maybe String -> TreeNode -> TreeNode
, children : (map toJsTree x.children)
toJsTree maybeSurname (TreeNode x) =
}
unsafeCoerce { name : name
, value : foldl (+) 0 $ [x.value] <> map treeValue x.children
type TreeNode = { name :: String
, children : (map (toJsTree (Just name)) x.children)
, value :: Number
}
, children :: Array TreeData
where
name = maybe "" (\x -> x <> ">") maybeSurname <> x.name
data TreeNode = TreeNode { name :: String
, value :: Int
, children :: Array TreeNode
}
}
type TreeLeaf = { name :: String
, value :: Number
}
treeNode :: String -> Number -> Array TreeData -> TreeData
instance decodeTreeNode :: DecodeJson TreeNode where
decodeJson json = do
obj <- decodeJson json
name <- obj .? "label"
value <- obj .? "value"
children <- obj .? "children"
pure $ TreeNode {name, value, children}
treeNode :: String -> Int -> Array TreeNode -> TreeNode
treeNode n v ts = TreeNode {name : n, value:v, children:ts}
treeNode n v ts = TreeNode {name : n, value:v, children:ts}
treeLeaf :: String ->
Number -> TreeData
treeLeaf :: String ->
Int -> TreeNode
treeLeaf n v = Tree
Leaf { name : n, value : v
}
treeLeaf n v = Tree
Node { name : n, value : v, children : []
}
-- | TODO
-- | TODO
...
...
src/Gargantext/Config.purs
View file @
419aa14f
...
@@ -173,7 +173,7 @@ pathUrl c (CorpusMetrics {tabType, listId, limit}) i =
...
@@ -173,7 +173,7 @@ pathUrl c (CorpusMetrics {tabType, listId, limit}) i =
pathUrl c (Chart {chartType, tabType}) i =
pathUrl c (Chart {chartType, tabType}) i =
pathUrl c (NodeAPI Corpus) i <> "/" <> show chartType
pathUrl c (NodeAPI Corpus) i <> "/" <> show chartType
<> "?ngramsType=" <> showTabType' tabType
<> "?ngramsType=" <> showTabType' tabType
-- <> "?list=1
" -- <> show listId
<> "&listType=GraphTerm
" -- <> show listId
-- <> maybe "" (\x -> "&limit=" <> show x) limit
-- <> maybe "" (\x -> "&limit=" <> show x) limit
...
@@ -263,13 +263,14 @@ data Path
...
@@ -263,13 +263,14 @@ data Path
-- , limit :: Maybe Limit
-- , limit :: Maybe Limit
}
}
data ChartType = Histo | Scatter | ChartPie
data ChartType = Histo | Scatter | ChartPie
| ChartTree
instance showChartType :: Show ChartType
instance showChartType :: Show ChartType
where
where
show Histo = "chart"
show Histo = "chart"
show Scatter = "scatter"
show Scatter = "scatter"
show ChartPie = "pie"
show ChartPie = "pie"
show ChartTree = "tree"
data End = Back | Front
data End = Back | Front
type Id = Int
type Id = Int
...
...
src/Gargantext/Pages/Corpus/Chart/Tree.purs
View file @
419aa14f
...
@@ -31,24 +31,9 @@ type Path =
...
@@ -31,24 +31,9 @@ type Path =
, limit :: Maybe Int
, limit :: Maybe Int
}
}
newtype Metric = Metric
{ label :: String
, x :: Number
, y :: Number
, cat :: TermList
}
instance decodeMetric :: DecodeJson Metric where
decodeJson json = do
obj <- decodeJson json
label <- obj .? "label"
x <- obj .? "x"
y <- obj .? "y"
cat <- obj .? "cat"
pure $ Metric { label, x, y, cat }
newtype Metrics = Metrics
newtype Metrics = Metrics
{ "data" :: Array
Metric
{ "data" :: Array
TreeNode
}
}
instance decodeMetrics :: DecodeJson Metrics where
instance decodeMetrics :: DecodeJson Metrics where
...
@@ -57,52 +42,31 @@ instance decodeMetrics :: DecodeJson Metrics where
...
@@ -57,52 +42,31 @@ instance decodeMetrics :: DecodeJson Metrics where
d <- obj .? "data"
d <- obj .? "data"
pure $ Metrics { "data": d }
pure $ Metrics { "data": d }
type Loaded = Array
Metric
type Loaded = Array
TreeNode
loadedMetricsSpec :: Spec {} (Loader.InnerProps Path Loaded ()) Void
loadedMetricsSpec :: Spec {} (Loader.InnerProps Path Loaded ()) Void
loadedMetricsSpec = simpleSpec defaultPerformAction render
loadedMetricsSpec = simpleSpec defaultPerformAction render
where
where
render :: Render {} (Loader.InnerProps Path Loaded ()) Void
render :: Render {} (Loader.InnerProps Path Loaded ()) Void
render dispatch {loaded} {} _ = [chart treeMapEx]
render dispatch {loaded} {} _ = [chart (scatterOptions loaded)]
--render dispatch {loaded} {} _ = [chart (scatterOptions loaded)]
scatterOptions :: Array TreeNode -> Options
scatterOptions :: Array Metric -> Options
scatterOptions nodes = Options
scatterOptions metrics = Options
{ mainTitle : "Tree"
{ mainTitle : "Ngrams Selection Metrics"
, subTitle : "Tree Sub Title"
, subTitle : "Local metrics (Inc/Exc, Spe/Gen), Global metrics (TFICF maillage)"
, xAxis : xAxis' []
, xAxis : xAxis { min: 0 }
, yAxis : yAxis' { position : "", show: false }
, yAxis : yAxis' { position : "", show: true }
, series : [ mkTree TreeMap nodes]
, series : map2series $ metric2map metrics
, addZoom : false
, addZoom : false
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
}
-- TODO improve the formatter:
where
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-obama
metric2map :: Array Metric -> Map TermList (Array Metric)
metric2map ds = Map.fromFoldableWith (<>) $ (\(Metric m) -> Tuple m.cat [Metric m]) <$> ds
--{-
}
map2series :: Map TermList (Array Metric) -> Array Series
map2series ms = toSeries <$> Map.toUnfoldable ms
where
-- TODO colors are not respected yet
toSeries (Tuple k ms) =
seriesScatterD2 {symbolSize: 5.0} (toSerie color <$> ms)
where
color =
case k of
StopTerm -> red
GraphTerm -> green
CandidateTerm -> grey
toSerie color (Metric {label,x,y}) =
dataSerie { name: label, itemStyle: itemStyle {color}
-- , label: {show: true}
, value: [x,y]
}
--}
getMetrics :: Path -> Aff Loaded
getMetrics :: Path -> Aff Loaded
getMetrics {corpusId, listId, limit, tabType} = do
getMetrics {corpusId, listId, limit, tabType} = do
Metrics ms <- get $ toUrl Back (C
orpusMetrics {listId, tabType, limit
}) $ Just corpusId
Metrics ms <- get $ toUrl Back (C
hart {chartType : ChartTree, tabType: tabType
}) $ Just corpusId
pure ms."data"
pure ms."data"
metricsLoaderClass :: ReactClass (Loader.Props Path Loaded)
metricsLoaderClass :: ReactClass (Loader.Props Path Loaded)
...
...
src/Gargantext/Pages/Corpus/Dashboard.purs
View file @
419aa14f
...
@@ -143,46 +143,46 @@ sankeyEx = Options
...
@@ -143,46 +143,46 @@ sankeyEx = Options
, addZoom : false
, addZoom : false
}
}
treeData :: Array Tree
Data
treeData :: Array Tree
Node
treeData = [ treeNode "nodeA" 10
.0 [ treeLeaf "nodeAa" 4.0
treeData = [ treeNode "nodeA" 10
[ treeNode "nodeAa" 4 []
, tree
Leaf "nodeAb" 5.0
, tree
Node "nodeAb" 5 []
, treeNode "nodeAc" 1
.0 [ treeLeaf "nodeAca" 0.5
, treeNode "nodeAc" 1
[ treeNode "nodeAca" 5 []
, tree
Leaf "nodeAcb" 0.5
, tree
Node "nodeAcb" 5 []
]
]
]
]
, treeNode "nodeB" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.0
]]
, treeNode "nodeB" 20
[ treeNode "nodeBa" 20 [ treeNode "nodeBa1" 20 []
]]
, treeNode "nodeC" 20
.0 [ treeNode "nodeCa" 20.0 [ treeLeaf "nodeCa1" 10.0
, treeNode "nodeC" 20
[ treeNode "nodeCa" 20 [ treeNode "nodeCa1" 10 []
, tree
Leaf "nodeCa2" 10.0
, tree
Node "nodeCa2" 10 []
]
]
]
]
, treeNode "nodeD" 20
.0 [ treeNode "nodeDa" 20.0 [ treeLeaf "nodeDa1" 2.0
, treeNode "nodeD" 20
[ treeNode "nodeDa" 20 [ treeNode "nodeDa1" 2 []
, tree
Leaf "nodeDa2" 2.0
, tree
Node "nodeDa2" 2 []
, tree
Leaf "nodeDa3" 2.0
, tree
Node "nodeDa3" 2 []
, tree
Leaf "nodeDa4" 2.0
, tree
Node "nodeDa4" 2 []
, tree
Leaf "nodeDa5" 2.0
, tree
Node "nodeDa5" 2 []
, tree
Leaf "nodeDa6" 2.0
, tree
Node "nodeDa6" 2 []
, tree
Leaf "nodeDa7" 2.0
, tree
Node "nodeDa7" 2 []
, tree
Leaf "nodeDa8" 2.0
, tree
Node "nodeDa8" 2 []
, tree
Leaf "nodeDa9" 2.0
, tree
Node "nodeDa9" 2 []
, tree
Leaf "nodeDa10" 2.0
, tree
Node "nodeDa10" 2 []
]
]
]
]
]
]
treeData' :: Array Tree
Data
treeData' :: Array Tree
Node
treeData' = [ treeNode "nodeA" 10
.0 [ treeLeaf "nodeAa" 4.0
treeData' = [ treeNode "nodeA" 10
[ treeLeaf "nodeAa" 4
, treeLeaf "nodeAb" 5
.0
, treeLeaf "nodeAb" 5
, treeNode "nodeAc" 1
.0 [ treeLeaf "nodeAca" 0.
5
, treeNode "nodeAc" 1
[ treeLeaf "nodeAca"
5
, treeLeaf "nodeAcb"
0.
5
, treeLeaf "nodeAcb" 5
]
]
, treeNode "nodeB" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeB" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
, treeNode "nodeC" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeC" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
, treeNode "nodeD" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeD" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
, treeNode "nodeE" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeE" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
, treeNode "nodeF" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeF" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
, treeNode "nodeG" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeG" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
, treeNode "nodeH" 20
.0 [ treeNode "nodeBa" 20.0 [ treeLeaf "nodeBa1" 20.
0]]
, treeNode "nodeH" 20
[ treeNode "nodeBa" 20 [ treeLeaf "nodeBa1" 2
0]]
]
]
]
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment