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