[chart] fix components to be truly react components

parent 823a1866
Pipeline #3948 failed with stage
in 0 seconds
...@@ -56,7 +56,8 @@ metricsLoadViewCpt = here.component "metricsLoadView" cpt ...@@ -56,7 +56,8 @@ metricsLoadViewCpt = here.component "metricsLoadView" cpt
type MetricsWithCacheLoadViewProps res ret = type MetricsWithCacheLoadViewProps res ret =
( getMetricsHash :: Session -> ReloadPath -> AffRESTError Hash ( getMetricsHash :: Session -> ReloadPath -> AffRESTError Hash
, handleResponse :: HashedResponse res -> ret , handleResponse :: HashedResponse res -> ret
, loaded :: Record MetricsProps -> ret -> R.Element -- , loaded :: Record MetricsProps -> ret -> R.Element
, loaded :: Record (metrics :: ret | MetricsProps) -> R.Element
, mkRequest :: ReloadPath -> GUC.Request , mkRequest :: ReloadPath -> GUC.Request
| MetricsProps | MetricsProps
) )
...@@ -87,5 +88,5 @@ metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt ...@@ -87,5 +88,5 @@ metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
, handleResponse , handleResponse
, mkRequest , mkRequest
, path: (reload' /\ path) , path: (reload' /\ path)
, renderer: loaded { boxes, path, reload, session, onClick, onInit } , renderer: \metrics -> loaded { boxes, path, reload, session, onClick, onInit, metrics }
, spinnerClass: Just "echarts-for-react-spinner" } , spinnerClass: Just "echarts-for-react-spinner" }
...@@ -24,6 +24,7 @@ import Gargantext.Utils.Reactix as R2 ...@@ -24,6 +24,7 @@ import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Record.Extra as RX
import Simple.JSON as JSON import Simple.JSON as JSON
import Toestand as T import Toestand as T
...@@ -47,8 +48,14 @@ derive newtype instance JSON.WriteForeign HistoMetrics ...@@ -47,8 +48,14 @@ derive newtype instance JSON.WriteForeign HistoMetrics
type Loaded = HistoMetrics type Loaded = HistoMetrics
chartOptions :: Record MetricsProps -> HistoMetrics -> Options type LoadedProps =
chartOptions { onClick, onInit } (HistoMetrics { dates: dates', count: count'}) = Options ( metrics :: HistoMetrics
| MetricsProps )
chartOptions :: Record LoadedProps -> Options
chartOptions { onClick
, onInit
, metrics: HistoMetrics { dates: dates', count: count'} } = Options
{ mainTitle : "Histogram" { mainTitle : "Histogram"
, subTitle : "Distribution of publications over time" , subTitle : "Distribution of publications over time"
, xAxis : xAxis' dates' , xAxis : xAxis' dates'
...@@ -112,10 +119,15 @@ histoCpt = here.component "histo" cpt ...@@ -112,10 +119,15 @@ histoCpt = here.component "histo" cpt
, onInit , onInit
} }
loaded :: Record MetricsProps -> HistoMetrics -> R.Element loaded :: R2.Leaf LoadedProps
loaded p l = loaded = R2.leaf loadedCpt
H.div {} [ U.reloadButton p.reload loadedCpt :: R.Component LoadedProps
, U.chartUpdateButton { chartType: Histo, path:p.path, reload:p.reload, session:p.session } loadedCpt = here.component "loaded" cpt where
, chart $ chartOptions p l cpt p@{ path
] , reload
, session } _ = do
pure $ H.div {} [ U.reloadButton { reload }
, U.chartUpdateButton { chartType: Histo, path, reload, session }
, chart $ chartOptions p
]
-- TODO: parametrize ngramsType above -- TODO: parametrize ngramsType above
...@@ -54,8 +54,12 @@ derive newtype instance JSON.ReadForeign Metrics ...@@ -54,8 +54,12 @@ derive newtype instance JSON.ReadForeign Metrics
type Loaded = Array Metric type Loaded = Array Metric
scatterOptions :: Record MetricsProps -> Array Metric -> Options type LoadedProps =
scatterOptions { onClick, onInit } metrics' = Options ( metrics :: Array Metric
| MetricsProps )
scatterOptions :: Record LoadedProps -> Options
scatterOptions { onClick, onInit, metrics: metrics' } = Options
{ mainTitle : "Ngrams Selection Metrics" { mainTitle : "Ngrams Selection Metrics"
, subTitle : "Local metrics (Inc/Exc, Spe/Gen), Global metrics (TFICF maillage)" , subTitle : "Local metrics (Inc/Exc, Spe/Gen), Global metrics (TFICF maillage)"
, xAxis : xAxis { min: -1 } , xAxis : xAxis { min: -1 }
...@@ -125,10 +129,15 @@ metricsCpt = here.component "etrics" cpt ...@@ -125,10 +129,15 @@ metricsCpt = here.component "etrics" cpt
} }
loaded :: Record MetricsProps -> Loaded -> R.Element loaded :: R2.Leaf LoadedProps
loaded p loaded' = loaded = R2.leaf loadedCpt
H.div {} [ loadedCpt :: R.Component LoadedProps
{- U.reloadButton reload loadedCpt = here.component "loaded" cpt where
, U.chartUpdateButton { chartType: Scatter, path, reload, session } cpt p@{ path
, -} chart $ scatterOptions p loaded' , reload
] , session } _ = do
pure $ H.div {} [
{- U.reloadButton reload
, U.chartUpdateButton { chartType: Scatter, path, reload, session }
, -} chart $ scatterOptions p
]
...@@ -52,8 +52,14 @@ derive newtype instance JSON.WriteForeign HistoMetrics ...@@ -52,8 +52,14 @@ derive newtype instance JSON.WriteForeign HistoMetrics
type Loaded = HistoMetrics type Loaded = HistoMetrics
chartOptionsBar :: Record MetricsProps -> HistoMetrics -> Options type LoadedProps =
chartOptionsBar { onClick, onInit } (HistoMetrics { dates: dates', count: count'}) = Options ( metrics :: HistoMetrics
| MetricsProps )
chartOptionsBar :: Record LoadedProps -> Options
chartOptionsBar { onClick
, onInit
, metrics: HistoMetrics { dates: dates', count: count'} } = Options
{ mainTitle : "Bar" { mainTitle : "Bar"
, subTitle : "Count of MapTerm" , subTitle : "Count of MapTerm"
, xAxis : xAxis' $ map (\t -> joinWith " " $ map (take 3) $ A.take 3 $ filter (\s -> length s > 3) $ split (Pattern " ") t) dates' , xAxis : xAxis' $ map (\t -> joinWith " " $ map (take 3) $ A.take 3 $ filter (\s -> length s > 3) $ split (Pattern " ") t) dates'
...@@ -65,8 +71,10 @@ chartOptionsBar { onClick, onInit } (HistoMetrics { dates: dates', count: count' ...@@ -65,8 +71,10 @@ chartOptionsBar { onClick, onInit } (HistoMetrics { dates: dates', count: count'
, onInit , onInit
} }
chartOptionsPie :: Record MetricsProps -> HistoMetrics -> Options chartOptionsPie :: Record LoadedProps -> Options
chartOptionsPie { onClick, onInit } (HistoMetrics { dates: dates', count: count'}) = Options chartOptionsPie { onClick
, onInit
, metrics: HistoMetrics { dates: dates', count: count'} } = Options
{ mainTitle : "Pie" { mainTitle : "Pie"
, subTitle : "Distribution by MapTerm" , subTitle : "Distribution by MapTerm"
, xAxis : xAxis' [] , xAxis : xAxis' []
...@@ -117,13 +125,18 @@ pieCpt = here.component "pie" cpt ...@@ -117,13 +125,18 @@ pieCpt = here.component "pie" cpt
, onInit , onInit
} }
loadedPie :: Record MetricsProps -> HistoMetrics -> R.Element loadedPie :: R2.Leaf LoadedProps
loadedPie p loaded = loadedPie = R2.leaf loadedPieCpt
H.div {} [ loadedPieCpt :: R.Component LoadedProps
{- U.reloadButton reload loadedPieCpt = here.component "loadedPie" cpt where
cpt p@{ path
, reload
, session } _ = do
pure $ H.div {} [
{- U.reloadButton reload
, U.chartUpdateButton { chartType: ChartPie, path, reload, session } , U.chartUpdateButton { chartType: ChartPie, path, reload, session }
, -} chart $ chartOptionsPie p loaded , -} chart $ chartOptionsPie p
] ]
bar :: Record Props -> R.Element bar :: Record Props -> R.Element
...@@ -147,10 +160,15 @@ barCpt = here.component "bar" cpt ...@@ -147,10 +160,15 @@ barCpt = here.component "bar" cpt
, onInit , onInit
} }
loadedBar :: Record MetricsProps -> Loaded -> R.Element loadedBar :: R2.Leaf LoadedProps
loadedBar p loaded = loadedBar = R2.leaf loadedBarCpt
H.div {} [ loadedBarCpt :: R.Component LoadedProps
{- U.reloadButton reload loadedBarCpt = here.component "loadedBar" cpt where
cpt p@{ path
, reload
, session } _ = do
pure $ H.div {} [
{- U.reloadButton reload
, U.chartUpdateButton { chartType: ChartBar, path, reload, session } , U.chartUpdateButton { chartType: ChartBar, path, reload, session }
, -} chart $ chartOptionsBar p loaded , -} chart $ chartOptionsBar p
] ]
...@@ -37,8 +37,12 @@ derive newtype instance JSON.WriteForeign Metrics ...@@ -37,8 +37,12 @@ derive newtype instance JSON.WriteForeign Metrics
type Loaded = Array TreeNode type Loaded = Array TreeNode
scatterOptions :: Record MetricsProps -> Array TreeNode -> Options type LoadedProps =
scatterOptions { onClick, onInit } nodes = Options ( metrics :: Array TreeNode
| MetricsProps )
scatterOptions :: Record LoadedProps -> Options
scatterOptions { onClick, onInit, metrics: nodes } = Options
{ mainTitle : "Tree" { mainTitle : "Tree"
, subTitle : "Tree Sub Title" , subTitle : "Tree Sub Title"
, xAxis : xAxis' [] , xAxis : xAxis' []
...@@ -91,10 +95,15 @@ treeCpt = here.component "tree" cpt ...@@ -91,10 +95,15 @@ treeCpt = here.component "tree" cpt
, onInit , onInit
} }
loaded :: Record MetricsProps -> Loaded -> R.Element loaded :: R2.Leaf LoadedProps
loaded p loaded' = loaded = R2.leaf loadedCpt
H.div {} [ loadedCpt :: R.Component LoadedProps
{- U.reloadButton reload loadedCpt = here.component "loaded" cpt where
cpt p@{ path
, reload
, session } _ = do
pure $ H.div {} [
{- U.reloadButton reload
, U.chartUpdateButton { chartType: ChartTree, path, reload, session } , U.chartUpdateButton { chartType: ChartTree, path, reload, session }
, -} chart (scatterOptions p loaded') , -} chart $ scatterOptions p
] ]
...@@ -18,16 +18,18 @@ import Gargantext.Utils.Toestand as T2 ...@@ -18,16 +18,18 @@ import Gargantext.Utils.Toestand as T2
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Utils" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Utils"
reloadButtonWrap :: T2.ReloadS -> R.Element -> R.Element type ReloadButtonProps =
reloadButtonWrap setReload el = H.div {} [ ( reload :: T2.ReloadS )
reloadButton setReload
, el
]
reloadButton :: T2.ReloadS -> R.Element reloadButton :: R2.Leaf ReloadButtonProps
reloadButton reloadS = H.a { className, on: { click }, title: "Reload" } [] where reloadButton = R2.leaf reloadButtonCpt
className = "pr-1 fa fa-refresh" reloadButtonCpt :: R.Component ReloadButtonProps
click _ = T2.reload reloadS reloadButtonCpt = here.component "reloadButton" cpt where
cpt { reload } _ = do
pure $ H.a { className, on: { click }, title: "Reload" } []
where
className = "pr-1 fa fa-refresh"
click _ = T2.reload reload
mNgramsTypeFromTabType :: T.TabType -> Maybe T.CTabNgramType mNgramsTypeFromTabType :: T.TabType -> Maybe T.CTabNgramType
...@@ -43,9 +45,8 @@ type ChartUpdateButtonProps = ...@@ -43,9 +45,8 @@ type ChartUpdateButtonProps =
, session :: Session , session :: Session
) )
chartUpdateButton :: Record ChartUpdateButtonProps -> R.Element chartUpdateButton :: R2.Leaf ChartUpdateButtonProps
chartUpdateButton p = R.createElement chartUpdateButtonCpt p [] chartUpdateButton = R2.leaf chartUpdateButtonCpt
chartUpdateButtonCpt :: R.Component ChartUpdateButtonProps chartUpdateButtonCpt :: R.Component ChartUpdateButtonProps
chartUpdateButtonCpt = here.component "chartUpdateButton" cpt where chartUpdateButtonCpt = here.component "chartUpdateButton" cpt where
cpt { path: { corpusId, listId, tabType } cpt { path: { corpusId, listId, tabType }
......
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