Commit 6f437bfd authored by arturo's avatar arturo

>>> continue

parent 1eb0d3f3
Pipeline #1567 failed with stage
module Gargantext.Components.Charts.Options.Data where module Gargantext.Components.Charts.Options.Data where
import Gargantext.Components.Charts.Options.Font (TextStyle, Icon, ItemStyle)
import Gargantext.Components.Charts.Options.Legend (SelectedMode)
import Gargantext.Types (class Optional)
import Record.Unsafe (unsafeSet) import Record.Unsafe (unsafeSet)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional)
import Gargantext.Components.Charts.Options.Font (TextStyle, Icon, ItemStyle)
type DataLegend = type DataLegend =
{ name :: String { name :: String
...@@ -22,11 +23,15 @@ type RequiredData v o = ...@@ -22,11 +23,15 @@ type RequiredData v o =
} }
type OptionalData = type OptionalData =
( name :: String ( name :: String
, symbolSize :: Number , symbolSize :: Number
, itemStyle :: ItemStyle , itemStyle :: ItemStyle
-- ^ the style setting about single data point(bubble). -- ^ the style setting about single data point(bubble).
, label :: { show :: Boolean } , label :: { show :: Boolean }
, emphasis :: { itemStyle :: ItemStyle }
, selectedMode :: SelectedMode
, select :: { itemStyle :: ItemStyle }
-- ^ need "selectedMode" to be defined
) )
type DataSerie v = RequiredData v OptionalData type DataSerie v = RequiredData v OptionalData
......
...@@ -6,6 +6,7 @@ exports.eChartsClass = ReactEcharts.default; ...@@ -6,6 +6,7 @@ exports.eChartsClass = ReactEcharts.default;
/** /**
* @XXX "echarts-for-react" unsuitable to proper PureScript implementation * @XXX "echarts-for-react" unsuitable to proper PureScript implementation
* regarding event listeners
* @name listenerFn1 * @name listenerFn1
* @param {function} fn * @param {function} fn
* @returns * @returns
...@@ -16,3 +17,17 @@ exports.listenerFn1 = function(fn) { ...@@ -16,3 +17,17 @@ exports.listenerFn1 = function(fn) {
fn(args[0])() fn(args[0])()
} }
}; };
/**
* @link https://echarts.apache.org/en/api.html#echartsInstance.dispatchAction
* @name dispatchAction
* @param {object} eChartsInstance instanceof ECharts
* @param {object} opts
* @returns
*/
exports.dispatchAction = function(eChartsInstance) {
return function(opts) {
return function() {
eChartsInstance.dispatchAction(opts);
}
}
}
...@@ -5,6 +5,7 @@ import Prelude ...@@ -5,6 +5,7 @@ import Prelude
import CSS (italic) import CSS (italic)
import CSS.Common (normal) import CSS.Common (normal)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Nullable (toMaybe)
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.Charts.Options.Color (transparent, violet, black) import Gargantext.Components.Charts.Options.Color (transparent, violet, black)
import Gargantext.Components.Charts.Options.Data (DataLegend, dataSerie) import Gargantext.Components.Charts.Options.Data (DataLegend, dataSerie)
...@@ -12,7 +13,7 @@ import Gargantext.Components.Charts.Options.Font (IconOptions(..), Shape(..), Te ...@@ -12,7 +13,7 @@ import Gargantext.Components.Charts.Options.Font (IconOptions(..), Shape(..), Te
import Gargantext.Components.Charts.Options.Legend (legendType, LegendMode(..), PlainOrScroll(..), selectedMode, Orientation(..), orient) import Gargantext.Components.Charts.Options.Legend (legendType, LegendMode(..), PlainOrScroll(..), selectedMode, Orientation(..), orient)
import Gargantext.Components.Charts.Options.Position (Align(..), LeftRelativePosition(..), TopRelativePosition(..), numberPosition, percentPosition, relativePosition) import Gargantext.Components.Charts.Options.Position (Align(..), LeftRelativePosition(..), TopRelativePosition(..), numberPosition, percentPosition, relativePosition)
import Gargantext.Components.Charts.Options.Series (Series, seriesPieD1) import Gargantext.Components.Charts.Options.Series (Series, seriesPieD1)
import Gargantext.Components.Charts.Options.Type (DataZoom, Echarts, Legend, Option, Title, XAxis, YAxis, MouseEvent, xAxis, yAxis) import Gargantext.Components.Charts.Options.Type (DataZoom, EChartsInstance, Echarts, Legend, MouseEvent, Option, Title, XAxis, YAxis, EChartRef, xAxis, yAxis)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import React (ReactClass, unsafeCreateElementDynamic) import React (ReactClass, unsafeCreateElementDynamic)
import Reactix as R import Reactix as R
...@@ -21,13 +22,16 @@ import Unsafe.Coerce (unsafeCoerce) ...@@ -21,13 +22,16 @@ import Unsafe.Coerce (unsafeCoerce)
foreign import eChartsClass :: ReactClass Echarts foreign import eChartsClass :: ReactClass Echarts
foreign import listenerFn1 :: forall evt. (evt -> Effect Unit) -> Effect Unit foreign import listenerFn1 :: forall evt. (evt -> Effect Unit) -> Effect Unit
-- | @XXX some eCharts "actions" not working ("select", ...)
-- | https://echarts.apache.org/en/api.html#echartsInstance.dispatchAction
foreign import dispatchAction :: forall payload. EChartsInstance -> payload -> Effect Unit
chart :: Options -> R.Element chart :: Options -> R.Element
chart = echarts <<< chartWith chart = echarts <<< chartWith
chartWith :: Options -> Echarts chartWith :: Options -> Echarts
chartWith options = chartWith options =
{ option: opts options { option : opts options
--, className : Nothing --, className : Nothing
--, style : Nothing --, style : Nothing
--, theme : Nothing --, theme : Nothing
...@@ -39,7 +43,8 @@ chartWith options = ...@@ -39,7 +43,8 @@ chartWith options =
--, optsLoading: Nothing --, optsLoading: Nothing
--, onReady : Nothing --, onReady : Nothing
--, resizable : Nothing --, resizable : Nothing
, onEvents: getEvents options , onEvents : getEvents options
, ref : refListener options
} }
where where
getEvents (Options { onClick }) = getEvents (Options { onClick }) =
...@@ -49,6 +54,14 @@ chartWith options = ...@@ -49,6 +54,14 @@ chartWith options =
Nothing -> pure unit Nothing -> pure unit
} }
refListener (Options { onInit }) = case onInit of
Nothing -> pure unit
Just fn -> listenerFn1 (_ # fn # execOnInit)
execOnInit fn = toMaybe >>> case _ of
Nothing -> pure unit
Just (ref :: Record EChartRef) -> fn =<< ref.getEchartsInstance
echarts :: Echarts -> R.Element echarts :: Echarts -> R.Element
echarts c = R2.buff $ unsafeCreateElementDynamic (unsafeCoerce eChartsClass) c [] echarts c = R2.buff $ unsafeCreateElementDynamic (unsafeCoerce eChartsClass) c []
...@@ -167,6 +180,19 @@ data Options = Options ...@@ -167,6 +180,19 @@ data Options = Options
, addZoom :: Boolean , addZoom :: Boolean
, tooltip :: Tooltip , tooltip :: Tooltip
, onClick :: Maybe (MouseEvent -> Effect Unit) , onClick :: Maybe (MouseEvent -> Effect Unit)
-- (?) `onInit` custom listener
--
-- * in addition of the already existing `onReady` native listener
-- which is executed on chart mount, but does not provide any arg
-- * the React library also contained another native listener as
-- `ref`, which adds the React Ref of the mounted chart
-- * this additional `onInit` is executed after the "Apache Echarts"
-- has been "initialised" (see more details [1]),
-- it intends to return the `eChartsInstance` used for every
-- library actions
--
-- [1] https://echarts.apache.org/en/api.html#echarts.init
, onInit :: Maybe (EChartsInstance -> Effect Unit)
} }
tooltipTriggerAxis :: Tooltip tooltipTriggerAxis :: Tooltip
......
module Gargantext.Components.Charts.Options.Series where module Gargantext.Components.Charts.Options.Series where
import Prelude (class Eq, class Show, bind, map, pure, show, ($), (+), (<<<), (<>), eq)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (~>), (:=)) import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (~>), (:=))
import Data.Argonaut.Core (jsonEmptyObject) import Data.Argonaut.Core (jsonEmptyObject)
import Data.Array (foldl) import Data.Array (foldl)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..), maybe) import Data.Maybe (Maybe(..), maybe)
import Gargantext.Components.Charts.Options.Data (DataD1, DataD2)
import Gargantext.Components.Charts.Options.Font (ItemStyle, Tooltip)
import Gargantext.Components.Charts.Options.Legend (SelectedMode)
import Gargantext.Types (class Optional)
import Prelude (class Eq, class Show, bind, map, pure, show, ($), (+), (<<<), (<>), eq)
import Record.Unsafe (unsafeSet) import Record.Unsafe (unsafeSet)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Types (class Optional)
import Gargantext.Components.Charts.Options.Font (ItemStyle, Tooltip)
import Gargantext.Components.Charts.Options.Data (DataD1, DataD2)
newtype SeriesType = SeriesType String newtype SeriesType = SeriesType String
type SeriesName = String type SeriesName = String
...@@ -57,13 +56,16 @@ seriesType = SeriesType <<< show ...@@ -57,13 +56,16 @@ seriesType = SeriesType <<< show
-- | Scatter Dimension 2 data -- | Scatter Dimension 2 data
type OptionalSeries = type OptionalSeries =
( name :: String ( name :: String
, symbolSize :: Number , symbolSize :: Number
, itemStyle :: ItemStyle , itemStyle :: ItemStyle
-- ^ Graphic style of, *emphasis* is the style when it is highlighted, like being hovered by mouse, or highlighted via legend connect. -- ^ Graphic style of, *emphasis* is the style when it is highlighted, like being hovered by mouse, or highlighted via legend connect.
-- https://ecomfe.github.io/echarts-doc/public/en/option.html#series-scatter.itemStyle -- https://ecomfe.github.io/echarts-doc/public/en/option.html#series-scatter.itemStyle
, tooltip :: Tooltip , tooltip :: Tooltip
, emphasis :: { itemStyle :: ItemStyle }
, selectedMode :: SelectedMode
, select :: { itemStyle :: ItemStyle }
-- ^ need "selectedMode" to be defined
-- many more... -- many more...
) )
......
...@@ -14,6 +14,9 @@ import Gargantext.Types (class Optional) ...@@ -14,6 +14,9 @@ import Gargantext.Types (class Optional)
import React as R import React as R
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
-- | https://echarts.apache.org/en/api.html#echartsInstance
foreign import data EChartsInstance :: Type
newtype ChartAlign = ChartAlign String newtype ChartAlign = ChartAlign String
-- TODO: Maybe is not working here => use Optional -- TODO: Maybe is not working here => use Optional
...@@ -32,6 +35,7 @@ type Echarts = ...@@ -32,6 +35,7 @@ type Echarts =
--, onReady :: Maybe String -- PropTypes.func, --, onReady :: Maybe String -- PropTypes.func,
--, resizable :: Maybe Boolean -- PropTypes.bool, --, resizable :: Maybe Boolean -- PropTypes.bool,
, onEvents :: OnEvents -- PropTypes.object , onEvents :: OnEvents -- PropTypes.object
, ref :: Effect Unit
} }
type Option = type Option =
...@@ -172,7 +176,7 @@ type Rich = {} ...@@ -172,7 +176,7 @@ type Rich = {}
-- | https://echarts.apache.org/en/api.html#events -- | https://echarts.apache.org/en/api.html#events
type OnEvents = type OnEvents =
{ click :: Effect Unit { click :: Effect Unit
-- and many more... -- ...
} }
-- | @XXX "echarts-for-react" third party library bases on "apache-echarts" -- | @XXX "echarts-for-react" third party library bases on "apache-echarts"
...@@ -199,5 +203,16 @@ type MouseEvent = ...@@ -199,5 +203,16 @@ type MouseEvent =
, seriesName :: String , seriesName :: String
, seriesType :: String , seriesType :: String
, type :: String , type :: String
, value :: String -- @WIP or Array ?? , value :: String -- or Array ??
} }
----
-- | @XXX partial definition given by the third library author
-- | POJO containing a mix of ReactElement field and custom method attached
-- |
-- | https://github.com/hustcc/echarts-for-react#component-api--echarts-api
type EChartRef =
( getEchartsInstance :: Effect EChartsInstance
-- ...
)
...@@ -34,11 +34,11 @@ metricsLoadView p = R.createElement metricsLoadViewCpt p [] ...@@ -34,11 +34,11 @@ metricsLoadView p = R.createElement metricsLoadViewCpt p []
metricsLoadViewCpt :: forall a. Eq a => R.Component (MetricsLoadViewProps a) metricsLoadViewCpt :: forall a. Eq a => R.Component (MetricsLoadViewProps a)
metricsLoadViewCpt = here.component "metricsLoadView" cpt metricsLoadViewCpt = here.component "metricsLoadView" cpt
where where
cpt { getMetrics, loaded, path, reload, session, onClick } _ = do cpt { getMetrics, loaded, path, reload, session, onClick, onInit } _ = do
reload' <- T.useLive T.unequal reload reload' <- T.useLive T.unequal reload
useLoader (reload' /\ path) (getMetrics session) $ \l -> useLoader (reload' /\ path) (getMetrics session) $ \l ->
loaded { path, reload, session, onClick } l loaded { path, reload, session, onClick, onInit } l
type MetricsWithCacheLoadViewProps res ret = ( type MetricsWithCacheLoadViewProps res ret = (
getMetricsHash :: Session -> ReloadPath -> Aff Hash getMetricsHash :: Session -> ReloadPath -> Aff Hash
...@@ -58,11 +58,11 @@ metricsWithCacheLoadViewCpt :: forall res ret. ...@@ -58,11 +58,11 @@ metricsWithCacheLoadViewCpt :: forall res ret.
R.Component (MetricsWithCacheLoadViewProps res ret) R.Component (MetricsWithCacheLoadViewProps res ret)
metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
where where
cpt { getMetricsHash, handleResponse, loaded, mkRequest, path, reload, session, onClick } _ = do cpt { getMetricsHash, handleResponse, loaded, mkRequest, path, reload, session, onClick, onInit } _ = do
reload' <- T.useLive T.unequal reload reload' <- T.useLive T.unequal reload
useLoaderWithCacheAPI { cacheEndpoint: (getMetricsHash session) useLoaderWithCacheAPI { cacheEndpoint: (getMetricsHash session)
, handleResponse , handleResponse
, mkRequest , mkRequest
, path: (reload' /\ path) , path: (reload' /\ path)
, renderer: loaded { path, reload, session, onClick } } , renderer: loaded { path, reload, session, onClick, onInit } }
...@@ -7,26 +7,25 @@ import Data.Generic.Rep.Eq (genericEq) ...@@ -7,26 +7,25 @@ import Data.Generic.Rep.Eq (genericEq)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Reactix as R import Gargantext.Components.Charts.Options.Color (grey, blue, green)
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude (class Eq, bind, map, pure, ($), (==))
import Gargantext.Components.Charts.Options.Color (grey)
import Gargantext.Components.Charts.Options.Data (dataSerie) import Gargantext.Components.Charts.Options.Data (dataSerie)
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis') import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter) import Gargantext.Components.Charts.Options.Font (itemStyle, mkTooltip, templateFormatter)
import Gargantext.Components.Charts.Options.Legend (LegendMode(..), selectedMode)
import Gargantext.Components.Charts.Options.Series (seriesBarD1) import Gargantext.Components.Charts.Options.Series (seriesBarD1)
import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsWithCacheLoadView) import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsWithCacheLoadView)
import Gargantext.Components.Nodes.Corpus.Chart.Types (MetricsProps, Path, Props, ReloadPath) import Gargantext.Components.Nodes.Corpus.Chart.Types (MetricsProps, Path, Props, ReloadPath)
import Gargantext.Hooks.Loader (HashedResponse(..)) import Gargantext.Hooks.Loader (HashedResponse(..))
import Gargantext.Prelude (class Eq, bind, map, pure, ($), (==))
import Gargantext.Routes (SessionRoute(..)) import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get) import Gargantext.Sessions (Session, get)
import Gargantext.Types (ChartType(..)) import Gargantext.Types (ChartType(..))
import Gargantext.Utils.CacheAPI as GUC import Gargantext.Utils.CacheAPI as GUC
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2 import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
here :: R2.Here here :: R2.Here
here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Histo" here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Histo"
...@@ -62,17 +61,31 @@ instance encodeHistoMetrics :: EncodeJson HistoMetrics where ...@@ -62,17 +61,31 @@ instance encodeHistoMetrics :: EncodeJson HistoMetrics where
type Loaded = HistoMetrics type Loaded = HistoMetrics
chartOptions :: Record MetricsProps -> HistoMetrics -> Options chartOptions :: Record MetricsProps -> HistoMetrics -> Options
chartOptions { onClick } (HistoMetrics { dates: dates', count: count'}) = Options chartOptions { onClick, onInit } (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'
, yAxis : yAxis' { position: "left", show: true, min:0} , yAxis : yAxis' { position: "left", show: true, min:0}
, addZoom : true , addZoom : true
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
, series : [seriesBarD1 {name: "Number of publication / year"} $ , series
map (\n -> dataSerie {value: n, itemStyle : itemStyle {color:grey}}) count']
, onClick , onClick
, onInit
} }
where
mapSeriesBar n = dataSerie
{ value: n
, itemStyle: itemStyle { color: grey }
, emphasis: { itemStyle: itemStyle { color: blue } }
-- @XXX "select" action not working
-- , selectedMode: selectedMode Single
, select: { itemStyle: itemStyle { color: green }}
}
series =
[ seriesBarD1 {name: "Number of publication / year"} $
map mapSeriesBar count'
]
getMetricsHash :: Session -> ReloadPath -> Aff String getMetricsHash :: Session -> ReloadPath -> Aff String
getMetricsHash session (_ /\ { corpusId, limit, listId, tabType }) = do getMetricsHash session (_ /\ { corpusId, limit, listId, tabType }) = do
...@@ -97,7 +110,7 @@ histo props = R.createElement histoCpt props [] ...@@ -97,7 +110,7 @@ histo props = R.createElement histoCpt props []
histoCpt :: R.Component Props histoCpt :: R.Component Props
histoCpt = here.component "histo" cpt histoCpt = here.component "histo" cpt
where where
cpt { path, session, onClick } _ = do cpt { path, session, onClick, onInit } _ = do
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
...@@ -109,6 +122,7 @@ histoCpt = here.component "histo" cpt ...@@ -109,6 +122,7 @@ histoCpt = here.component "histo" cpt
, reload , reload
, session , session
, onClick , onClick
, onInit
} }
loaded :: Record MetricsProps -> HistoMetrics -> R.Element loaded :: Record MetricsProps -> HistoMetrics -> R.Element
......
...@@ -74,7 +74,7 @@ instance decodeMetrics :: DecodeJson Metrics where ...@@ -74,7 +74,7 @@ instance decodeMetrics :: DecodeJson Metrics where
type Loaded = Array Metric type Loaded = Array Metric
scatterOptions :: Record MetricsProps -> Array Metric -> Options scatterOptions :: Record MetricsProps -> Array Metric -> Options
scatterOptions { onClick } metrics' = Options scatterOptions { onClick, onInit } 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 }
...@@ -83,6 +83,7 @@ scatterOptions { onClick } metrics' = Options ...@@ -83,6 +83,7 @@ scatterOptions { onClick } metrics' = Options
, addZoom : false , addZoom : false
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
, onClick , onClick
, onInit
} }
where where
metric2map :: Array Metric -> Map TermList (Array Metric) metric2map :: Array Metric -> Map TermList (Array Metric)
...@@ -127,7 +128,7 @@ metrics props = R.createElement metricsCpt props [] ...@@ -127,7 +128,7 @@ metrics props = R.createElement metricsCpt props []
metricsCpt :: R.Component Props metricsCpt :: R.Component Props
metricsCpt = here.component "etrics" cpt metricsCpt = here.component "etrics" cpt
where where
cpt {path, session, onClick } _ = do cpt {path, session, onClick, onInit } _ = do
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
...@@ -139,6 +140,7 @@ metricsCpt = here.component "etrics" cpt ...@@ -139,6 +140,7 @@ metricsCpt = here.component "etrics" cpt
, reload , reload
, session , session
, onClick , onClick
, onInit
} }
......
...@@ -69,7 +69,7 @@ instance encodeHistoMetrics :: EncodeJson HistoMetrics where ...@@ -69,7 +69,7 @@ instance encodeHistoMetrics :: EncodeJson HistoMetrics where
type Loaded = HistoMetrics type Loaded = HistoMetrics
chartOptionsBar :: Record MetricsProps -> HistoMetrics -> Options chartOptionsBar :: Record MetricsProps -> HistoMetrics -> Options
chartOptionsBar { onClick } (HistoMetrics { dates: dates', count: count'}) = Options chartOptionsBar { onClick, onInit } (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'
...@@ -78,10 +78,11 @@ chartOptionsBar { onClick } (HistoMetrics { dates: dates', count: count'}) = Opt ...@@ -78,10 +78,11 @@ chartOptionsBar { onClick } (HistoMetrics { dates: dates', count: count'}) = Opt
, addZoom : false , addZoom : false
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
, onClick , onClick
, onInit
} }
chartOptionsPie :: Record MetricsProps -> HistoMetrics -> Options chartOptionsPie :: Record MetricsProps -> HistoMetrics -> Options
chartOptionsPie { onClick } (HistoMetrics { dates: dates', count: count'}) = Options chartOptionsPie { onClick, onInit } (HistoMetrics { dates: dates', count: count'}) = Options
{ mainTitle : "Pie" { mainTitle : "Pie"
, subTitle : "Distribution by MapTerm" , subTitle : "Distribution by MapTerm"
, xAxis : xAxis' [] , xAxis : xAxis' []
...@@ -91,6 +92,7 @@ chartOptionsPie { onClick } (HistoMetrics { dates: dates', count: count'}) = Opt ...@@ -91,6 +92,7 @@ chartOptionsPie { onClick } (HistoMetrics { dates: dates', count: count'}) = Opt
, addZoom : false , addZoom : false
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
, onClick , onClick
, onInit
} }
getMetricsHash :: Session -> ReloadPath -> Aff String getMetricsHash :: Session -> ReloadPath -> Aff String
...@@ -116,7 +118,7 @@ pie props = R.createElement pieCpt props [] ...@@ -116,7 +118,7 @@ pie props = R.createElement pieCpt props []
pieCpt :: R.Component Props pieCpt :: R.Component Props
pieCpt = here.component "pie" cpt pieCpt = here.component "pie" cpt
where where
cpt { path, session, onClick } _ = do cpt { path, session, onClick, onInit } _ = do
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
...@@ -128,6 +130,7 @@ pieCpt = here.component "pie" cpt ...@@ -128,6 +130,7 @@ pieCpt = here.component "pie" cpt
, reload , reload
, session , session
, onClick , onClick
, onInit
} }
loadedPie :: Record MetricsProps -> HistoMetrics -> R.Element loadedPie :: Record MetricsProps -> HistoMetrics -> R.Element
...@@ -145,7 +148,7 @@ bar props = R.createElement barCpt props [] ...@@ -145,7 +148,7 @@ bar props = R.createElement barCpt props []
barCpt :: R.Component Props barCpt :: R.Component Props
barCpt = here.component "bar" cpt barCpt = here.component "bar" cpt
where where
cpt {path, session, onClick} _ = do cpt {path, session, onClick, onInit} _ = do
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
...@@ -157,6 +160,7 @@ barCpt = here.component "bar" cpt ...@@ -157,6 +160,7 @@ barCpt = here.component "bar" cpt
, reload , reload
, session , session
, onClick , onClick
, onInit
} }
loadedBar :: Record MetricsProps -> Loaded -> R.Element loadedBar :: Record MetricsProps -> Loaded -> R.Element
......
...@@ -7,8 +7,9 @@ import Data.Generic.Rep (class Generic) ...@@ -7,8 +7,9 @@ import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Ord (genericCompare) import Data.Generic.Rep.Ord (genericCompare)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..), fromMaybe) import Data.Maybe (Maybe(..), fromMaybe)
import Data.Nullable (Nullable)
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.Charts.Options.Type (MouseEvent) import Gargantext.Components.Charts.Options.Type (EChartsInstance, MouseEvent)
import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo) import Gargantext.Components.Nodes.Corpus.Chart.Histo (histo)
import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics) import Gargantext.Components.Nodes.Corpus.Chart.Metrics (metrics)
import Gargantext.Components.Nodes.Corpus.Chart.Pie (pie) import Gargantext.Components.Nodes.Corpus.Chart.Pie (pie)
...@@ -68,39 +69,40 @@ type Params = ...@@ -68,39 +69,40 @@ type Params =
-- optinal params -- optinal params
, limit :: Maybe Int , limit :: Maybe Int
, listId :: Maybe Int , listId :: Maybe Int
, onClick :: Maybe (MouseEvent -> Effect Unit) , onClick :: Maybe (MouseEvent -> Effect Unit)
, onInit :: Maybe (EChartsInstance -> Effect Unit)
) )
render :: PredefinedChart -> Record Params -> R.Element render :: PredefinedChart -> Record Params -> R.Element
render CDocsHistogram { corpusId, listId, session, onClick } = histo { path, session, onClick } render CDocsHistogram { corpusId, listId, session, onClick, onInit } = histo { path, session, onClick, onInit }
where where
path = { corpusId path = { corpusId
, listId: fromMaybe 0 listId , listId: fromMaybe 0 listId
, limit: Nothing , limit: Nothing
, tabType: TabCorpus TabDocs , tabType: TabCorpus TabDocs
} }
render CAuthorsPie { corpusId, listId, session, onClick } = pie { path, session, onClick } render CAuthorsPie { corpusId, listId, session, onClick, onInit } = pie { path, session, onClick, onInit }
where where
path = { corpusId path = { corpusId
, listId: fromMaybe 0 listId , listId: fromMaybe 0 listId
, limit: Nothing , limit: Nothing
, tabType: TabCorpus (TabNgramType $ modeTabType Authors) , tabType: TabCorpus (TabNgramType $ modeTabType Authors)
} }
render CInstitutesTree { corpusId, limit, listId, session, onClick } = tree { path, session, onClick } render CInstitutesTree { corpusId, limit, listId, session, onClick, onInit } = tree { path, session, onClick, onInit }
where where
path = { corpusId path = { corpusId
, limit , limit
, listId: fromMaybe 0 listId , listId: fromMaybe 0 listId
, tabType: TabCorpus (TabNgramType $ modeTabType Institutes) , tabType: TabCorpus (TabNgramType $ modeTabType Institutes)
} }
render CTermsMetrics { corpusId, limit, listId, session, onClick } = metrics { path, session, onClick } render CTermsMetrics { corpusId, limit, listId, session, onClick, onInit } = metrics { path, session, onClick, onInit }
where where
path = { corpusId path = { corpusId
, limit , limit
, listId: fromMaybe 0 listId , listId: fromMaybe 0 listId
, tabType: TabCorpus (TabNgramType $ modeTabType Terms) , tabType: TabCorpus (TabNgramType $ modeTabType Terms)
} }
render CSourcesBar { corpusId, limit, listId, session, onClick } = metrics { path, session, onClick } render CSourcesBar { corpusId, limit, listId, session, onClick, onInit } = metrics { path, session, onClick, onInit }
where where
path = { corpusId path = { corpusId
, limit , limit
......
...@@ -43,7 +43,7 @@ instance encodeMetrics :: EncodeJson Metrics where ...@@ -43,7 +43,7 @@ instance encodeMetrics :: EncodeJson Metrics where
type Loaded = Array TreeNode type Loaded = Array TreeNode
scatterOptions :: Record MetricsProps -> Array TreeNode -> Options scatterOptions :: Record MetricsProps -> Array TreeNode -> Options
scatterOptions { onClick } nodes = Options scatterOptions { onClick, onInit } nodes = Options
{ mainTitle : "Tree" { mainTitle : "Tree"
, subTitle : "Tree Sub Title" , subTitle : "Tree Sub Title"
, xAxis : xAxis' [] , xAxis : xAxis' []
...@@ -52,6 +52,7 @@ scatterOptions { onClick } nodes = Options ...@@ -52,6 +52,7 @@ scatterOptions { onClick } nodes = Options
, addZoom : false , addZoom : false
, tooltip : mkTooltip { formatter: templateFormatter "{b0}" } , tooltip : mkTooltip { formatter: templateFormatter "{b0}" }
, onClick , onClick
, onInit
-- TODO improve the formatter: -- TODO improve the formatter:
-- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-obama -- https://ecomfe.github.io/echarts-examples/public/editor.html?c=treemap-obama
...@@ -80,7 +81,7 @@ tree props = R.createElement treeCpt props [] ...@@ -80,7 +81,7 @@ tree props = R.createElement treeCpt props []
treeCpt :: R.Component Props treeCpt :: R.Component Props
treeCpt = here.component "tree" cpt treeCpt = here.component "tree" cpt
where where
cpt {path, session, onClick} _ = do cpt {path, session, onClick, onInit} _ = do
reload <- T.useBox T2.newReload reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView { pure $ metricsWithCacheLoadView {
...@@ -92,6 +93,7 @@ treeCpt = here.component "tree" cpt ...@@ -92,6 +93,7 @@ treeCpt = here.component "tree" cpt
, reload , reload
, session , session
, onClick , onClick
, onInit
} }
loaded :: Record MetricsProps -> Loaded -> R.Element loaded :: Record MetricsProps -> Loaded -> R.Element
......
...@@ -3,7 +3,7 @@ module Gargantext.Components.Nodes.Corpus.Chart.Types where ...@@ -3,7 +3,7 @@ module Gargantext.Components.Nodes.Corpus.Chart.Types where
import Data.Maybe (Maybe) import Data.Maybe (Maybe)
import Data.Tuple (Tuple) import Data.Tuple (Tuple)
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.Charts.Options.Type (MouseEvent) import Gargantext.Components.Charts.Options.Type (EChartsInstance, MouseEvent)
import Gargantext.Prelude (Unit) import Gargantext.Prelude (Unit)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (TabType) import Gargantext.Types (TabType)
...@@ -17,9 +17,10 @@ type Path = ( ...@@ -17,9 +17,10 @@ type Path = (
) )
type Props = ( type Props = (
path :: Record Path path :: Record Path
, session :: Session , session :: Session
, onClick :: Maybe (MouseEvent -> Effect Unit) , onClick :: Maybe (MouseEvent -> Effect Unit)
, onInit :: Maybe (EChartsInstance -> Effect Unit)
) )
type MetricsProps = ( type MetricsProps = (
......
...@@ -241,6 +241,7 @@ renderChartCpt = here.component "renderChart" cpt ...@@ -241,6 +241,7 @@ renderChartCpt = here.component "renderChart" cpt
, listId: Just defaultListId , listId: Just defaultListId
, session , session
, onClick: Nothing , onClick: Nothing
, onInit: Nothing
} }
-- aSchool school = H.div {className: "col-md-4 content"} [ chart $ focus school ] -- aSchool school = H.div {className: "col-md-4 content"} [ chart $ focus school ]
......
...@@ -161,7 +161,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where ...@@ -161,7 +161,7 @@ ngramsViewCpt = here.component "ngramsView" cpt where
] ]
charts params _ = [ chart params mode ] charts params _ = [ chart params mode ]
chart path Authors = pie { path, session, onClick: Nothing } chart path Authors = pie { path, session, onClick: Nothing, onInit: Nothing }
chart path Institutes = tree { path, session, onClick: Nothing } chart path Institutes = tree { path, session, onClick: Nothing, onInit: Nothing }
chart path Sources = bar { path, session, onClick: Nothing } chart path Sources = bar { path, session, onClick: Nothing, onInit: Nothing }
chart path Terms = metrics { path, session, onClick: Nothing } chart path Terms = metrics { path, session, onClick: Nothing, onInit: Nothing }
module Gargantext.Components.Nodes.Texts where module Gargantext.Components.Nodes.Texts where
import Gargantext.Prelude import Gargantext.Prelude
import Prelude
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow) import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Symbol (SProxy(..))
import Data.Tuple.Nested ((/\)) import Data.Tuple.Nested ((/\))
import Effect.Aff (launchAff_) import Effect.Aff (launchAff_)
import Gargantext.Components.Charts.Options.ECharts (dispatchAction)
import Gargantext.Components.Charts.Options.Type (EChartsInstance)
import Gargantext.Components.DocsTable as DT import Gargantext.Components.DocsTable as DT
import Gargantext.Components.DocsTable.Types (Year) import Gargantext.Components.DocsTable.Types (Year)
import Gargantext.Components.NgramsTable.Loader (clearCache) import Gargantext.Components.NgramsTable.Loader (clearCache)
...@@ -23,13 +25,12 @@ import Gargantext.Components.Tab as Tab ...@@ -23,13 +25,12 @@ import Gargantext.Components.Tab as Tab
import Gargantext.Components.Table as Table import Gargantext.Components.Table as Table
import Gargantext.Ends (Frontends) import Gargantext.Ends (Frontends)
import Gargantext.Hooks.Loader (useLoader) import Gargantext.Hooks.Loader (useLoader)
import Gargantext.Sessions (WithSession, WithSessionContext, Session, sessionId, getCacheState) import Gargantext.Sessions (WithSession, Session, getCacheState)
import Gargantext.Types (CTabNgramType(..), ListId, NodeID, SidePanelState(..), TabSubType(..), TabType(..)) import Gargantext.Types (CTabNgramType(..), ListId, NodeID, SidePanelState(..), TabSubType(..), TabType(..))
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
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 as Record import Record (set)
import Toestand as T import Toestand as T
here :: R2.Here here :: R2.Here
...@@ -87,9 +88,7 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt ...@@ -87,9 +88,7 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt
yearFilter <- T.useBox (Nothing :: Maybe Year) yearFilter <- T.useBox (Nothing :: Maybe Year)
R.useEffectOnce' do eChartsInstance <- T.useBox (Nothing :: Maybe EChartsInstance)
T.listen (\{ new } -> log2 "filter" new) yearFilter
R.useEffectOnce' $ do R.useEffectOnce' $ do
T.listen (\{ new } -> afterCacheStateChange new) cacheState T.listen (\{ new } -> afterCacheStateChange new) cacheState
...@@ -116,6 +115,7 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt ...@@ -116,6 +115,7 @@ textsLayoutWithKeyCpt = here.component "textsLayoutWithKey" cpt
, sidePanel , sidePanel
, sidePanelState , sidePanelState
, yearFilter , yearFilter
, eChartsInstance
} }
] ]
where where
...@@ -139,14 +139,15 @@ modeTabType MoreLikeFav = CTabAuthors -- TODO ...@@ -139,14 +139,15 @@ modeTabType MoreLikeFav = CTabAuthors -- TODO
modeTabType MoreLikeTrash = CTabSources -- TODO modeTabType MoreLikeTrash = CTabSources -- TODO
type TabsProps = type TabsProps =
( cacheState :: T.Box LT.CacheState ( cacheState :: T.Box LT.CacheState
, corpusData :: CorpusData , corpusData :: CorpusData
, corpusId :: NodeID , corpusId :: NodeID
, frontends :: Frontends , frontends :: Frontends
, session :: Session , session :: Session
, sidePanel :: T.Box (Maybe (Record TT.SidePanel)) , sidePanel :: T.Box (Maybe (Record TT.SidePanel))
, sidePanelState :: T.Box SidePanelState , sidePanelState :: T.Box SidePanelState
, yearFilter :: T.Box (Maybe Year) , yearFilter :: T.Box (Maybe Year)
, eChartsInstance :: T.Box (Maybe EChartsInstance)
) )
tabs :: Record TabsProps -> R.Element tabs :: Record TabsProps -> R.Element
...@@ -155,9 +156,23 @@ tabs props = R.createElement tabsCpt props [] ...@@ -155,9 +156,23 @@ tabs props = R.createElement tabsCpt props []
tabsCpt :: R.Component TabsProps tabsCpt :: R.Component TabsProps
tabsCpt = here.component "tabs" cpt tabsCpt = here.component "tabs" cpt
where where
cpt { cacheState, corpusId, corpusData, frontends, session, sidePanel, sidePanelState, yearFilter } _ = do cpt { cacheState, corpusId, corpusData, frontends, session, sidePanel, sidePanelState, yearFilter, eChartsInstance } _ = do
let path = initialPath
let onClick = Just \{ name } -> T.write_ (Just name) (yearFilter) let
path = initialPath
onInit = Just \i -> T.write_ (Just i) eChartsInstance
onClick = Just \opts@{ name } -> do
T.write_ (Just name) yearFilter
T.read eChartsInstance >>= case _ of
Nothing -> pure unit
Just i -> do
-- @XXX due to lack of support for "echart.select" action,
-- have to manually rely on a set/unset selection
-- targeting the "echart.emphasis" action
dispatchAction i { type: "downplay" }
dispatchAction i $ set (SProxy :: SProxy "type") "highlight" opts
activeTab <- T.useBox 0 activeTab <- T.useBox 0
...@@ -165,7 +180,7 @@ tabsCpt = here.component "tabs" cpt ...@@ -165,7 +180,7 @@ tabsCpt = here.component "tabs" cpt
activeTab activeTab
, tabs: [ , tabs: [
"Documents" /\ R.fragment [ "Documents" /\ R.fragment [
histo { path, session, onClick } histo { path, session, onClick, onInit }
, docView' path TabDocs , docView' path TabDocs
] ]
, "Trash" /\ docView' path TabTrash , "Trash" /\ docView' path TabTrash
......
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