Commit 0529a6b5 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[WIP] Charts Bar/histo/Pie (next Tree), needs refacto.

parent 16d616e1
...@@ -33,7 +33,8 @@ red :: Color ...@@ -33,7 +33,8 @@ red :: Color
red = stringColor "red" red = stringColor "red"
blue :: Color blue :: Color
blue = stringColor "blue" blue = cssColor $ rgba 100 150 200 0.0
-- stringColor "blue"
magenta :: Color magenta :: Color
magenta = stringColor "magenta" magenta = stringColor "magenta"
......
...@@ -115,7 +115,6 @@ data3 :: DataLegend ...@@ -115,7 +115,6 @@ data3 :: DataLegend
data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'} data3 = {name: "Test", icon: icon $ Shape Diamond, textStyle: textStyle'}
yAxisVoid :: YAxis yAxisVoid :: YAxis
yAxisVoid = yAxis yAxisVoid = yAxis
{ "type": "" { "type": ""
...@@ -126,23 +125,13 @@ yAxisVoid = yAxis ...@@ -126,23 +125,13 @@ yAxisVoid = yAxis
, show: false , show: false
} }
yAxis1 :: YAxis
yAxis1 = yAxis
{ "type": "value"
, name: "data"
, min: 0
, position: "left"
, axisLabel: {formatter: "{value}"}
, show: true
}
xAxis' :: Array String -> XAxis xAxis' :: Array String -> XAxis
xAxis' [] = unsafeCoerce {} xAxis' [] = unsafeCoerce {}
xAxis' xs = xAxis xAxis' xs = xAxis
{ "data": xData xs { "data": xData xs
, "type": "category" , "type": "category"
, axisTick: {alignWithLabel: true} , axisTick: {alignWithLabel: true}
, show: length xs /= 0 , show: true
} }
where where
xData :: Array String -> Array DataAxis xData :: Array String -> Array DataAxis
......
...@@ -170,10 +170,10 @@ pathUrl c (CorpusMetrics {tabType, listId, limit}) i = ...@@ -170,10 +170,10 @@ pathUrl c (CorpusMetrics {tabType, listId, limit}) i =
<> "&ngramsType=" <> showTabType' tabType <> "&ngramsType=" <> showTabType' tabType
<> maybe "" (\x -> "&limit=" <> show x) limit <> maybe "" (\x -> "&limit=" <> show x) limit
-- TODO fix this url path -- TODO fix this url path
pathUrl c (Chart {chartType}) i = pathUrl c (Chart {chartType, tabType}) i =
pathUrl c (NodeAPI Corpus) i <> "/chart" pathUrl c (NodeAPI Corpus) i <> "/" <> show chartType
<> "?ngramsType=" <> showTabType' tabType
-- <> "?list=1" -- <> show listId -- <> "?list=1" -- <> show listId
-- <> "&ngramsType=Sources" -- <> showTabType' tabType
-- <> maybe "" (\x -> "&limit=" <> show x) limit -- <> maybe "" (\x -> "&limit=" <> show x) limit
...@@ -258,11 +258,18 @@ data Path ...@@ -258,11 +258,18 @@ data Path
, limit :: Maybe Limit , limit :: Maybe Limit
} }
| Chart { chartType :: ChartType | Chart { chartType :: ChartType
, tabType :: TabType
-- , listId :: ListId -- , listId :: ListId
-- , limit :: Maybe Limit -- , limit :: Maybe Limit
} }
data ChartType = Histo | Scatter data ChartType = Histo | Scatter | ChartPie
instance showChartType :: Show ChartType
where
show Histo = "chart"
show Scatter = "scatter"
show ChartPie = "pie"
data End = Back | Front data End = Back | Front
type Id = Int type Id = Int
......
...@@ -24,6 +24,7 @@ import Gargantext.Components.Charts.Options.Data ...@@ -24,6 +24,7 @@ import Gargantext.Components.Charts.Options.Data
type Path = type Path =
{ corpusId :: Int { corpusId :: Int
, tabType :: TabType
} }
newtype ChartMetrics = ChartMetrics newtype ChartMetrics = ChartMetrics
...@@ -62,7 +63,7 @@ chartOptions (HistoMetrics { dates: dates', count: count'}) = Options ...@@ -62,7 +63,7 @@ chartOptions (HistoMetrics { dates: dates', count: count'}) = Options
, subTitle : "Distribution of publications over time" , subTitle : "Distribution of publications over time"
, xAxis : xAxis' dates' , xAxis : xAxis' dates'
, yAxis : yAxis' { position: "left", show: true } , yAxis : yAxis' { position: "left", show: true }
, series : [seriesBarD1 {name: "Number of publication / year"} $ map (\n -> dataSerie {name: "", value: n }) count'] , series : [seriesBarD1 {name: "Number of publication / year"} $ map (\n -> dataSerie {name: "", value: n, itemStyle : itemStyle {color:grey}}) count']
, addZoom : true , addZoom : true
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
} }
...@@ -74,8 +75,8 @@ metricsLoader props = createElement metricsLoaderClass props [] ...@@ -74,8 +75,8 @@ metricsLoader props = createElement metricsLoaderClass props []
metricsLoaderClass = Loader.createLoaderClass "MetricsLoader" getMetrics metricsLoaderClass = Loader.createLoaderClass "MetricsLoader" getMetrics
getMetrics :: Path -> Aff HistoMetrics getMetrics :: Path -> Aff HistoMetrics
getMetrics {corpusId} = do getMetrics {corpusId, tabType} = do
ChartMetrics ms <- get $ toUrl Back (Chart {chartType: Histo}) $ Just corpusId ChartMetrics ms <- get $ toUrl Back (Chart {chartType: Histo, tabType: tabType}) $ Just corpusId
pure ms."data" pure ms."data"
histoSpec :: Spec {} Path Void histoSpec :: Spec {} Path Void
......
module Gargantext.Pages.Corpus.Chart.Pie where module Gargantext.Pages.Corpus.Chart.Pie where
import Data.Array (foldl) import Data.Array (foldl, zip)
import Data.Tuple (Tuple(..)) import Data.Tuple (Tuple(..))
import Data.Map as Map import Data.Map as Map
import Data.Int (toNumber)
import Data.Map (Map) import Data.Map (Map)
import Data.Argonaut (class DecodeJson, decodeJson, (.?)) import Data.Argonaut (class DecodeJson, decodeJson, (.?))
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
...@@ -21,98 +22,94 @@ import Gargantext.Components.Charts.Options.Color ...@@ -21,98 +22,94 @@ import Gargantext.Components.Charts.Options.Color
import Gargantext.Components.Charts.Options.Font import Gargantext.Components.Charts.Options.Font
import Gargantext.Components.Charts.Options.Data import Gargantext.Components.Charts.Options.Data
import Gargantext.Pages.Corpus.Dashboard (distriBySchool)
type Path = type Path =
{ corpusId :: Int { corpusId :: Int
, listId :: Int
, tabType :: TabType , tabType :: TabType
, limit :: Maybe Int
} }
newtype Metric = Metric newtype ChartMetrics = ChartMetrics
{ label :: String { "data" :: HistoMetrics
, x :: Number
, y :: Number
, cat :: TermList
} }
instance decodeMetric :: DecodeJson Metric where instance decodeChartMetrics :: DecodeJson ChartMetrics where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
label <- obj .? "label" d <- obj .? "data"
x <- obj .? "x" pure $ ChartMetrics { "data": d }
y <- obj .? "y"
cat <- obj .? "cat" newtype HistoMetrics = HistoMetrics
pure $ Metric { label, x, y, cat } { dates :: Array String
, count :: Array Number
newtype Metrics = Metrics
{ "data" :: Array Metric
} }
instance decodeMetrics :: DecodeJson Metrics where instance decodeHistoMetrics :: DecodeJson HistoMetrics where
decodeJson json = do decodeJson json = do
obj <- decodeJson json obj <- decodeJson json
d <- obj .? "data" d <- obj .? "dates"
pure $ Metrics { "data": d } c <- obj .? "count"
pure $ HistoMetrics { dates : d , count: c}
type Loaded = Array Metric type Loaded = HistoMetrics
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 distriBySchool] render dispatch {loaded : metricsData} {} _ = [chart (chartOptions metricsData)]
--render dispatch {loaded} {} _ = [chart (scatterOptions loaded)]
chartOptions :: HistoMetrics -> Options
scatterOptions :: Array Metric -> Options chartOptions (HistoMetrics { dates: dates', count: count'}) = Options
scatterOptions metrics = Options { mainTitle : "Bar"
{ mainTitle : "Ngrams Selection Metrics" , subTitle : "Count of GraphTerm"
, subTitle : "Local metrics (Inc/Exc, Spe/Gen), Global metrics (TFICF maillage)" , xAxis : xAxis' dates'
, xAxis : xAxis { min: 0 } , yAxis : yAxis' { position: "left", show: true }
, yAxis : yAxis' { position : "", show: true } , series : [seriesBarD1 {name: "Number of publication / year"} $ map (\n -> dataSerie {name: "", itemStyle: itemStyle {color:blue}, value: n }) count']
, series : map2series $ metric2map metrics
, addZoom : false , addZoom : false
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
} }
loadedMetricsSpecPie :: Spec {} (Loader.InnerProps Path Loaded ()) Void
loadedMetricsSpecPie = simpleSpec defaultPerformAction render
where where
metric2map :: Array Metric -> Map TermList (Array Metric) render :: Render {} (Loader.InnerProps Path Loaded ()) Void
metric2map ds = Map.fromFoldableWith (<>) $ (\(Metric m) -> Tuple m.cat [Metric m]) <$> ds render dispatch {loaded : metricsData} {} _ = [chart (chartOptionsPie metricsData)]
--{- chartOptionsPie :: HistoMetrics -> Options
map2series :: Map TermList (Array Metric) -> Array Series chartOptionsPie (HistoMetrics { dates: dates', count: count'}) = Options
map2series ms = toSeries <$> Map.toUnfoldable ms { mainTitle : "Pie"
where , subTitle : "Distribution by GraphTerm"
-- TODO colors are not respected yet , xAxis : xAxis' []
toSeries (Tuple k ms) = , yAxis : yAxis' { position: "", show: false }
seriesScatterD2 {symbolSize: 5.0} (toSerie color <$> ms) , series : [seriesPieD1 {name: "Data"} $ map (\(Tuple n v) -> dataSerie {name: n, value:v}) $ zip dates' count']
where -- , series : [seriesBarD1 {name: "Number of publication / year"} $ map (\n -> dataSerie {name: "", value: n }) count']
color = , addZoom : false
case k of , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
StopTerm -> red }
GraphTerm -> green
CandidateTerm -> grey
toSerie color (Metric {label,x,y}) = metricsLoader :: Loader.Props' Path HistoMetrics -> ReactElement
dataSerie { name: label, itemStyle: itemStyle {color}
-- , label: {show: true}
, value: [x,y]
}
--}
getMetrics :: Path -> Aff Loaded
getMetrics {corpusId, listId, limit, tabType} = do
Metrics ms <- get $ toUrl Back (CorpusMetrics {listId, tabType, limit}) $ Just corpusId
pure ms."data"
metricsLoaderClass :: ReactClass (Loader.Props Path Loaded)
metricsLoaderClass = Loader.createLoaderClass "MetricsLoader" getMetrics
metricsLoader :: Loader.Props' Path Loaded -> ReactElement
metricsLoader props = createElement metricsLoaderClass props [] metricsLoader props = createElement metricsLoaderClass props []
where
metricsLoaderClass :: ReactClass (Loader.Props Path HistoMetrics)
metricsLoaderClass = Loader.createLoaderClass "MetricsLoader" getMetrics
getMetrics :: Path -> Aff HistoMetrics
getMetrics {corpusId, tabType:tabType} = do
ChartMetrics ms <- get $ toUrl Back (Chart {chartType: ChartPie, tabType: tabType}) $ Just corpusId
pure ms."data"
pieSpec :: Spec {} Path Void pieSpec :: Spec {} Path Void
pieSpec = simpleSpec defaultPerformAction render pieSpec = simpleSpec defaultPerformAction render
where
render :: Render {} Path Void
render dispatch path {} _ =
[ metricsLoader
{ path
, component: createClass "LoadedMetrics" loadedMetricsSpecPie (const {})
} ]
barSpec :: Spec {} Path Void
barSpec = simpleSpec defaultPerformAction render
where where
render :: Render {} Path Void render :: Render {} Path Void
render dispatch path {} _ = render dispatch path {} _ =
...@@ -120,3 +117,4 @@ pieSpec = simpleSpec defaultPerformAction render ...@@ -120,3 +117,4 @@ pieSpec = simpleSpec defaultPerformAction render
{ path { path
, component: createClass "LoadedMetrics" loadedMetricsSpec (const {}) , component: createClass "LoadedMetrics" loadedMetricsSpec (const {})
} ] } ]
...@@ -14,7 +14,7 @@ import Gargantext.Pages.Corpus.Tabs.Types (Props) ...@@ -14,7 +14,7 @@ import Gargantext.Pages.Corpus.Tabs.Types (Props)
import Gargantext.Pages.Corpus.Chart.Histo (histoSpec) import Gargantext.Pages.Corpus.Chart.Histo (histoSpec)
import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec) import Gargantext.Pages.Corpus.Chart.Metrics (metricsSpec)
import Gargantext.Pages.Corpus.Chart.Pie (pieSpec) import Gargantext.Pages.Corpus.Chart.Pie (pieSpec, barSpec)
import Gargantext.Pages.Corpus.Chart.Tree (treeSpec) import Gargantext.Pages.Corpus.Chart.Tree (treeSpec)
import Gargantext.Pages.Corpus.Dashboard (globalPublis) import Gargantext.Pages.Corpus.Dashboard (globalPublis)
...@@ -49,8 +49,8 @@ statefulTabs :: Spec Tab.State Props Tab.Action ...@@ -49,8 +49,8 @@ statefulTabs :: Spec Tab.State Props Tab.Action
statefulTabs = statefulTabs =
Tab.tabs identity identity $ fromFoldable Tab.tabs identity identity $ fromFoldable
[ Tuple "Documents" $ docs [ Tuple "Documents" $ docs
, Tuple "Authors" $ ngramsViewSpec {mode: Authors }
, Tuple "Sources" $ ngramsViewSpec {mode: Sources } , Tuple "Sources" $ ngramsViewSpec {mode: Sources }
, Tuple "Authors" $ ngramsViewSpec {mode: Authors }
, Tuple "Institutes" $ ngramsViewSpec {mode: Institutes} , Tuple "Institutes" $ ngramsViewSpec {mode: Institutes}
, Tuple "Terms" $ ngramsViewSpec {mode: Terms } , Tuple "Terms" $ ngramsViewSpec {mode: Terms }
, Tuple "Trash" $ trash , Tuple "Trash" $ trash
...@@ -58,7 +58,7 @@ statefulTabs = ...@@ -58,7 +58,7 @@ statefulTabs =
where where
-- TODO totalRecords -- TODO totalRecords
docs = noState ( cmapProps (\{path: corpusId} -> {corpusId : corpusId}) histoSpec docs = noState ( cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType: TabCorpus TabDocs}) histoSpec
<> <>
(cmapProps (\{path: nodeId} -> { nodeId : nodeId (cmapProps (\{path: nodeId} -> { nodeId : nodeId
, chart : div [][] -- ECharts.chart globalPublis , chart : div [][] -- ECharts.chart globalPublis
...@@ -75,17 +75,21 @@ statefulTabs = ...@@ -75,17 +75,21 @@ statefulTabs =
ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action ngramsViewSpec :: {mode :: Mode} -> Spec Tab.State Props Tab.Action
ngramsViewSpec {mode} = ngramsViewSpec {mode} =
noState ( noState ( (chart mode) <>
cmapProps (\{loaded: {defaultListId}, path: corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 1000)}) -- TODO limit should be select in the chart by default it is 1000
(chart mode) <>
cmapProps (\{loaded: {defaultListId}, path, dispatch} -> cmapProps (\{loaded: {defaultListId}, path, dispatch} ->
{loaded: {defaultListId}, path, dispatch, tabType}) {loaded: {defaultListId}, path, dispatch, tabType})
NT.mainNgramsTableSpec NT.mainNgramsTableSpec
) )
where where
tabType = TabCorpus $ TabNgramType $ modeTabType mode tabType = TabCorpus $ TabNgramType $ modeTabType mode
chart Authors = pieSpec chart Authors = cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType}) pieSpec
chart Sources = pieSpec chart Sources = cmapProps (\{path: corpusId} -> {corpusId : corpusId, tabType}) barSpec
chart Institutes = treeSpec
chart Terms = metricsSpec chart Institutes = cmapProps (\{loaded: {defaultListId}, path: corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 10000)})
treeSpec
chart Terms = cmapProps (\{loaded: {defaultListId}, path: corpusId} ->
{corpusId, listId: defaultListId, tabType, limit: (Just 10000)})
-- TODO limit should be select in the chart by default it is 1000
metricsSpec
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