Adds time support

This commit is contained in:
Roman Galochkin 2020-02-18 15:11:22 +03:00
parent 7eb1781079
commit 702044d4d5
5 changed files with 13 additions and 9 deletions

View File

@ -20,6 +20,7 @@ let make =
~minX=?, ~minX=?,
~onHover=(f: float) => (), ~onHover=(f: float) => (),
~primaryDistribution=?, ~primaryDistribution=?,
~scale=?,
~children=[||], ~children=[||],
) => ) =>
ReasonReact.wrapJsForReason( ReasonReact.wrapJsForReason(
@ -36,6 +37,7 @@ let make =
~maxX?, ~maxX?,
~minX?, ~minX?,
~primaryDistribution?, ~primaryDistribution?,
~scale?,
(), (),
), ),
children, children,

View File

@ -21,6 +21,7 @@ let make =
~data, ~data,
~minX=?, ~minX=?,
~maxX=?, ~maxX=?,
~scale=?,
~height=200, ~height=200,
~color=`hex("111"), ~color=`hex("111"),
~onHover: float => unit, ~onHover: float => unit,
@ -30,6 +31,7 @@ let make =
height height
?minX ?minX
?maxX ?maxX
?scale
marginBottom=50 marginBottom=50
marginTop=0 marginTop=0
onHover onHover

View File

@ -1,6 +1,6 @@
module Continuous = { module Continuous = {
[@react.component] [@react.component]
let make = (~data) => { let make = (~data, ~unit) => {
let (x, setX) = React.useState(() => 0.); let (x, setX) = React.useState(() => 0.);
let chart = let chart =
React.useMemo1( React.useMemo1(
@ -51,6 +51,7 @@ module Continuous = {
let make = (~dist) => { let make = (~dist) => {
switch ((dist: option(DistributionTypes.genericDistribution))) { switch ((dist: option(DistributionTypes.genericDistribution))) {
| Some({ | Some({
unit,
generationSource: generationSource:
Shape( Shape(
Mixed({ Mixed({
@ -61,7 +62,7 @@ let make = (~dist) => {
), ),
}) => }) =>
<div> <div>
<Continuous data={n |> Shape.Continuous.toPdf} /> <Continuous data={n |> Shape.Continuous.toPdf} unit />
{d |> Shape.Discrete.scaleYToTotal(f) |> Shape.Discrete.render} {d |> Shape.Discrete.scaleYToTotal(f) |> Shape.Discrete.render}
</div> </div>
| _ => <div /> | _ => <div />

View File

@ -14,13 +14,6 @@ function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min; return Math.floor(Math.random() * (max - min + 1)) + min;
} }
/**
* Example input:
* {
* xs: [50,100,300,400,500,600],
* ys: [0.1, 0.4, 0.6, 0.7,0.8, 0.9]}
* }
*/
function CdfChart(props) { function CdfChart(props) {
const id = "chart-" + getRandomInt(0, 100000); const id = "chart-" + getRandomInt(0, 100000);
const [sized, { width }] = useSize(() => { const [sized, { width }] = useSize(() => {
@ -47,6 +40,7 @@ function CdfChart(props) {
.showVerticalLine(props.showVerticalLine) .showVerticalLine(props.showVerticalLine)
.container("#" + id) .container("#" + id)
.data({ primary: props.primaryDistribution }) .data({ primary: props.primaryDistribution })
.scale('linear')
.render(); .render();
}); });

View File

@ -76,6 +76,11 @@ class Chartigo {
return this; return this;
} }
scale(scale) {
this.attrs.scale = scale;
return this;
}
onHover(onHover) { onHover(onHover) {
this.attrs.onHover = onHover; this.attrs.onHover = onHover;
return this; return this;