Commit 930256db authored by Karen Konou's avatar Karen Konou

[WIP] [Docs histo] Legend change types

parent 09ec80f7
Pipeline #3388 failed with stage
in 0 seconds
...@@ -11,7 +11,7 @@ import Gargantext.Components.Charts.Options.Font (IconOptions(..), Shape(..), Te ...@@ -11,7 +11,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, EChartsInstance, Echarts, Legend, MouseEvent, Option, Title, XAxis, YAxis, EChartRef, xAxis, yAxis) import Gargantext.Components.Charts.Options.Type (DataZoom, EChartRef, EChartsInstance, Echarts, Legend, MouseEvent, Option, Title, XAxis, YAxis, xAxis, yAxis)
import Gargantext.Utils.Reactix as R2 import Gargantext.Utils.Reactix as R2
import Prelude import Prelude
import React (ReactClass, unsafeCreateElementDynamic) import React (ReactClass, unsafeCreateElementDynamic)
...@@ -45,11 +45,14 @@ chartWith options = ...@@ -45,11 +45,14 @@ chartWith options =
, ref : refListener options , ref : refListener options
} }
where where
getEvents (Options { onClick }) = getEvents (Options { onClick, onLegendChanged }) =
{ click: listenerFn1 \e -> case onClick of { click: listenerFn1 \e -> case onClick of
-- sanitize parsing (see MouseEvent comment) -- sanitize parsing (see MouseEvent comment)
Just fn -> RX.pick (e :: MouseEvent) # fn Just fn -> RX.pick (e :: MouseEvent) # fn
Nothing -> pure unit Nothing -> pure unit
, legendselectchanged: listenerFn1 \e -> case onLegendChanged of
Just fn -> fn e
Nothing -> pure unit
} }
refListener (Options { onInit }) = case onInit of refListener (Options { onInit }) = case onInit of
...@@ -174,14 +177,15 @@ yAxis' {position, show, min} = yAxis ...@@ -174,14 +177,15 @@ yAxis' {position, show, min} = yAxis
} }
data Options = Options data Options = Options
{ mainTitle :: MainTitle { mainTitle :: MainTitle
, subTitle :: SubTitle , subTitle :: SubTitle
, xAxis :: XAxis , xAxis :: XAxis
, yAxis :: YAxis , yAxis :: YAxis
, series :: Array Series , series :: Array Series
, addZoom :: Boolean , addZoom :: Boolean
, tooltip :: Tooltip , tooltip :: Tooltip
, onClick :: Maybe (MouseEvent -> Effect Unit) , onClick :: Maybe (MouseEvent -> Effect Unit)
, onLegendChanged :: Maybe (MouseEvent -> Effect Unit)
-- (?) `onInit` custom listener -- (?) `onInit` custom listener
-- --
-- * in addition of the already existing `onReady` native listener -- * in addition of the already existing `onReady` native listener
...@@ -194,7 +198,7 @@ data Options = Options ...@@ -194,7 +198,7 @@ data Options = Options
-- library actions -- library actions
-- --
-- [1] https://echarts.apache.org/v4/en/api.html#echarts.init -- [1] https://echarts.apache.org/v4/en/api.html#echarts.init
, onInit :: Maybe (EChartsInstance -> Effect Unit) , onInit :: Maybe (EChartsInstance -> Effect Unit)
} }
tooltipTriggerAxis :: Tooltip tooltipTriggerAxis :: Tooltip
......
...@@ -175,7 +175,8 @@ type Rich = {} ...@@ -175,7 +175,8 @@ type Rich = {}
-- | "echarts/dist/echarts.common.js" and -- | "echarts/dist/echarts.common.js" and
-- | 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
, legendselectchanged :: Effect Unit
-- ... -- ...
} }
...@@ -206,6 +207,13 @@ type MouseEvent = ...@@ -206,6 +207,13 @@ type MouseEvent =
, value :: String -- or Array ?? , value :: String -- or Array ??
} }
-- | https://echarts.apache.org/en/api.html#events.legendselectchanged
type LegendSelectChangedEvent =
{ type :: String
, name :: String
, selected :: Array String -- ??
}
---- ----
-- | @XXX partial definition given by the third library author -- | @XXX partial definition given by the third library author
......
...@@ -44,10 +44,12 @@ metricsLoadViewCpt = here.component "metricsLoadView" cpt ...@@ -44,10 +44,12 @@ metricsLoadViewCpt = here.component "metricsLoadView" cpt
, session } _ = do , session } _ = do
reload' <- T.useLive T.unequal reload reload' <- T.useLive T.unequal reload
let onLegendChanged = Nothing
useLoader { errorHandler useLoader { errorHandler
, loader: getMetrics session , loader: getMetrics session
, path: reload' /\ path , path: reload' /\ path
, render: \l -> loaded { boxes, path, reload, session, onClick, onInit } l } , render: \l -> loaded { boxes, path, reload, session, onClick, onLegendChanged, onInit } l }
where where
errorHandler error = do errorHandler error = do
T.modify_ (A.cons $ FRESTError { error }) errors T.modify_ (A.cons $ FRESTError { error }) errors
...@@ -79,6 +81,7 @@ metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt ...@@ -79,6 +81,7 @@ metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
, reload , reload
, session , session
, onClick , onClick
, onLegendChanged
, onInit } _ = do , onInit } _ = do
reload' <- T.useLive T.unequal reload reload' <- T.useLive T.unequal reload
...@@ -87,5 +90,5 @@ metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt ...@@ -87,5 +90,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: loaded { boxes, path, reload, session, onClick, onLegendChanged, onInit }
, spinnerClass: Just "echarts-for-react-spinner" } , spinnerClass: Just "echarts-for-react-spinner" }
...@@ -4,7 +4,7 @@ import Data.Maybe (Maybe) ...@@ -4,7 +4,7 @@ import Data.Maybe (Maybe)
import Data.Tuple (Tuple) import Data.Tuple (Tuple)
import Effect (Effect) import Effect (Effect)
import Gargantext.Components.App.Store (Boxes) import Gargantext.Components.App.Store (Boxes)
import Gargantext.Components.Charts.Options.Type (EChartsInstance, MouseEvent) import Gargantext.Components.Charts.Options.Type (EChartsInstance, MouseEvent, LegendSelectChangedEvent)
import Gargantext.Prelude (Unit) import Gargantext.Prelude (Unit)
import Gargantext.Sessions (Session) import Gargantext.Sessions (Session)
import Gargantext.Types (TabType) import Gargantext.Types (TabType)
...@@ -18,11 +18,12 @@ type Path = ( ...@@ -18,11 +18,12 @@ type Path = (
) )
type Props = ( type Props = (
boxes :: Boxes boxes :: Boxes
, 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) , onLegendChanged :: Maybe (LegendSelectChangedEvent -> Effect Unit)
, onInit :: Maybe (EChartsInstance -> Effect Unit)
) )
type MetricsProps = ( type MetricsProps = (
......
...@@ -2,6 +2,7 @@ module Gargantext.Components.Nodes.Texts where ...@@ -2,6 +2,7 @@ module Gargantext.Components.Nodes.Texts where
import Gargantext.Prelude import Gargantext.Prelude
import DOM.Simple.Console (log)
import Data.Generic.Rep (class Generic) import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..), isJust) import Data.Maybe (Maybe(..), isJust)
import Data.Show.Generic (genericShow) import Data.Show.Generic (genericShow)
...@@ -204,6 +205,9 @@ tabsCpt = here.component "tabs" cpt ...@@ -204,6 +205,9 @@ tabsCpt = here.component "tabs" cpt
} }
dispatchAction i { type: "downplay" } dispatchAction i { type: "downplay" }
dispatchAction i opts' dispatchAction i opts'
onLegendChanged = Just \opts -> do
log opts
activeTab <- T.useBox 0 activeTab <- T.useBox 0
...@@ -215,7 +219,7 @@ tabsCpt = here.component "tabs" cpt ...@@ -215,7 +219,7 @@ tabsCpt = here.component "tabs" cpt
, activeTab , activeTab
, tabs: [ , tabs: [
"Documents" /\ R.fragment [ "Documents" /\ R.fragment [
histoRender { boxes, path, onClick, onInit, reload: chartReload, session } [] histoRender { boxes, path, onClick, onLegendChanged, onInit, reload: chartReload, session } []
, docView' path chartReload TabDocs , docView' path chartReload TabDocs
] ]
, "Trash" /\ docView' path chartReload TabTrash , "Trash" /\ docView' path chartReload TabTrash
...@@ -252,10 +256,10 @@ histoRender :: R2.Component HistoProps ...@@ -252,10 +256,10 @@ histoRender :: R2.Component HistoProps
histoRender = R.createElement histoRenderCpt histoRender = R.createElement histoRenderCpt
histoRenderCpt :: R.Component HistoProps histoRenderCpt :: R.Component HistoProps
histoRenderCpt = here.component "histoRender" cpt where histoRenderCpt = here.component "histoRender" cpt where
cpt { boxes, path, onClick, onInit, reload, session } _ = do cpt { boxes, path, onClick, onLegendChanged, onInit, reload, session } _ = do
_ <- T.useLive T.unequal reload _ <- T.useLive T.unequal reload
pure $ histo { boxes, path, onClick, onInit, session } pure $ histo { boxes, path, onClick, onLegendChanged, onInit, session }
type DocViewProps a = type DocViewProps a =
( boxes :: Boxes ( boxes :: Boxes
......
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