squiggle/src/components/charts/DistPlusPlot.re

117 lines
3.2 KiB
ReasonML
Raw Normal View History

module DistPlusChart = {
[@react.component]
2020-02-23 13:27:52 +00:00
let make = (~distPlus: DistTypes.distPlus, ~onHover) => {
2020-02-23 13:14:14 +00:00
open Distributions.DistPlus;
2020-02-23 18:59:04 +00:00
// todo: Change to scaledContinuous and scaledDiscrete
let discrete = distPlus |> T.toDiscrete;
let continuous =
2020-02-23 13:14:14 +00:00
distPlus
|> T.toContinuous
|> E.O.fmap(Distributions.Continuous.getShape);
let minX = T.minX(distPlus);
let maxX = T.maxX(distPlus);
2020-02-23 13:27:52 +00:00
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
2020-02-23 18:34:34 +00:00
<DistributionPlot
minX
maxX
?discrete
?continuous
color={`hex("333")}
onHover
timeScale
/>;
};
};
module IntegralChart = {
[@react.component]
2020-02-23 13:27:52 +00:00
let make = (~distPlus: DistTypes.distPlus, ~onHover) => {
2020-02-23 13:14:14 +00:00
open Distributions.DistPlus;
let integral =
Distributions.DistPlus.T.Integral.get(~cache=None, distPlus);
let continuous =
integral
|> T.toContinuous
2020-02-23 13:14:14 +00:00
|> E.O.fmap(Distributions.Continuous.getShape);
let minX = T.minX(integral);
let maxX = T.maxX(integral);
2020-02-23 13:27:52 +00:00
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
2020-02-23 18:34:34 +00:00
<DistributionPlot
minX
maxX
?continuous
color={`hex("333")}
timeScale
onHover
/>;
};
};
[@react.component]
2020-02-23 13:27:52 +00:00
let make = (~distPlus: DistTypes.distPlus) => {
let (x, setX) = React.useState(() => 0.);
let chart =
React.useMemo1(
() => {<DistPlusChart distPlus onHover={r => {setX(_ => r)}} />},
[|distPlus|],
);
let chart2 =
React.useMemo1(
() => {<IntegralChart distPlus onHover={r => {setX(_ => r)}} />},
[|distPlus|],
);
2020-02-24 11:11:03 +00:00
Js.log4(
"distPlus",
x,
distPlus,
distPlus |> Distributions.DistPlus.T.xToY(x),
);
<div>
chart
chart2
<table className="table-auto">
<thead>
<tr>
<th className="px-4 py-2"> {"X Point" |> ReasonReact.string} </th>
<th className="px-4 py-2">
{"Discrete Value" |> ReasonReact.string}
</th>
<th className="px-4 py-2">
{"Continuous Value" |> ReasonReact.string}
</th>
<th className="px-4 py-2">
{"Y Integral to Point" |> ReasonReact.string}
</th>
</tr>
</thead>
<tbody>
<tr>
<th className="px-4 py-2 border ">
{x |> E.Float.toString |> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{distPlus
|> Distributions.DistPlus.T.xToY(x)
|> DistTypes.MixedPoint.toDiscreteValue
|> E.Float.with2DigitsPrecision
|> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{distPlus
|> Distributions.DistPlus.T.xToY(x)
|> DistTypes.MixedPoint.toContinuousValue
|> E.Float.with2DigitsPrecision
|> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{distPlus
2020-02-23 13:14:14 +00:00
|> Distributions.DistPlus.T.Integral.xToY(~cache=None, x)
|> E.Float.with2DigitsPrecision
|> ReasonReact.string}
</th>
</tr>
</tbody>
</table>
<div />
</div>;
};