diff --git a/src/components/charts/DistPlusPlot.re b/src/components/charts/DistPlusPlot.re index 1c957dda..083986e7 100644 --- a/src/components/charts/DistPlusPlot.re +++ b/src/components/charts/DistPlusPlot.re @@ -1,3 +1,14 @@ +type state = { + log: bool, + showStats: bool, + height: int, +}; + +type action = + | CHANGE_LOG + | CHANGE_SHOW_STATS + | CHANGE_HEIGHT(int); + let table = (distPlus, x) => {
@@ -127,7 +138,7 @@ let adjustBoth = discreteProbabilityMass => { module DistPlusChart = { [@react.component] - let make = (~distPlus: DistTypes.distPlus, ~onHover) => { + let make = (~distPlus: DistTypes.distPlus, ~state: state, ~onHover) => { open Distributions.DistPlus; let discrete = distPlus |> T.toScaledDiscrete; let continuous = @@ -148,11 +159,12 @@ module DistPlusChart = { let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) = adjustBoth(toDiscreteProbabilityMass); { let (x, setX) = React.useState(() => 0.); + let (state, dispatch) = + React.useReducer( + (state: state, action: action) => + switch (action) { + | CHANGE_LOG => {...state, log: !state.log} + | CHANGE_HEIGHT(height) => {...state, height} + | CHANGE_SHOW_STATS => {...state, showStats: !state.showStats} + }, + {log: true, height: 120, showStats: false}, + ); let chart = - React.useMemo1( - () => { {setX(_ => r)}} />}, - [|distPlus|], + React.useMemo2( + () => { {setX(_ => r)}} />}, + (distPlus, state), ); let chart2 = React.useMemo1( () => { {setX(_ => r)}} />}, [|distPlus|], ); -
chart chart2 {table(distPlus, x)}
; +
+
dispatch(CHANGE_LOG)}> + {(state.log ? "true" : "False") |> ReasonReact.string} +
+
dispatch(CHANGE_SHOW_STATS)}> + {"Stats" |> ReasonReact.string} +
+
dispatch(CHANGE_HEIGHT(state.height + 40))}> + {"HightPlus" |> ReasonReact.string} +
+
dispatch(CHANGE_HEIGHT(state.height - 40))}> + {"HightMinus" |> ReasonReact.string} +
+ chart + chart2 + {state.showStats ? table(distPlus, x) : ReasonReact.null} +
; // chart -}; +}; \ No newline at end of file