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