From 702044d4d5591b05940d5e70ae97407d74c0a1f1 Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Tue, 18 Feb 2020 15:11:22 +0300 Subject: [PATCH] Adds time support --- src/components/charts/CdfChart__Base.re | 2 ++ src/components/charts/CdfChart__Plain.re | 2 ++ src/components/charts/GenericDistributionChart.re | 5 +++-- src/components/charts/cdfChartReact.js | 8 +------- src/components/charts/cdfChartd3.js | 5 +++++ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/charts/CdfChart__Base.re b/src/components/charts/CdfChart__Base.re index 6abb50bc..273bc028 100644 --- a/src/components/charts/CdfChart__Base.re +++ b/src/components/charts/CdfChart__Base.re @@ -20,6 +20,7 @@ let make = ~minX=?, ~onHover=(f: float) => (), ~primaryDistribution=?, + ~scale=?, ~children=[||], ) => ReasonReact.wrapJsForReason( @@ -36,6 +37,7 @@ let make = ~maxX?, ~minX?, ~primaryDistribution?, + ~scale?, (), ), children, diff --git a/src/components/charts/CdfChart__Plain.re b/src/components/charts/CdfChart__Plain.re index 72067a3e..8f4859de 100644 --- a/src/components/charts/CdfChart__Plain.re +++ b/src/components/charts/CdfChart__Plain.re @@ -21,6 +21,7 @@ let make = ~data, ~minX=?, ~maxX=?, + ~scale=?, ~height=200, ~color=`hex("111"), ~onHover: float => unit, @@ -30,6 +31,7 @@ let make = height ?minX ?maxX + ?scale marginBottom=50 marginTop=0 onHover diff --git a/src/components/charts/GenericDistributionChart.re b/src/components/charts/GenericDistributionChart.re index c7d2fa85..3e0b96f7 100644 --- a/src/components/charts/GenericDistributionChart.re +++ b/src/components/charts/GenericDistributionChart.re @@ -1,6 +1,6 @@ module Continuous = { [@react.component] - let make = (~data) => { + let make = (~data, ~unit) => { let (x, setX) = React.useState(() => 0.); let chart = React.useMemo1( @@ -51,6 +51,7 @@ module Continuous = { let make = (~dist) => { switch ((dist: option(DistributionTypes.genericDistribution))) { | Some({ + unit, generationSource: Shape( Mixed({ @@ -61,7 +62,7 @@ let make = (~dist) => { ), }) =>
- Shape.Continuous.toPdf} /> + Shape.Continuous.toPdf} unit /> {d |> Shape.Discrete.scaleYToTotal(f) |> Shape.Discrete.render}
| _ =>
diff --git a/src/components/charts/cdfChartReact.js b/src/components/charts/cdfChartReact.js index 11c3504b..be5b13a4 100644 --- a/src/components/charts/cdfChartReact.js +++ b/src/components/charts/cdfChartReact.js @@ -14,13 +14,6 @@ function getRandomInt(min, max) { 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) { const id = "chart-" + getRandomInt(0, 100000); const [sized, { width }] = useSize(() => { @@ -47,6 +40,7 @@ function CdfChart(props) { .showVerticalLine(props.showVerticalLine) .container("#" + id) .data({ primary: props.primaryDistribution }) + .scale('linear') .render(); }); diff --git a/src/components/charts/cdfChartd3.js b/src/components/charts/cdfChartd3.js index 3dee5f99..535717c4 100644 --- a/src/components/charts/cdfChartd3.js +++ b/src/components/charts/cdfChartd3.js @@ -76,6 +76,11 @@ class Chartigo { return this; } + scale(scale) { + this.attrs.scale = scale; + return this; + } + onHover(onHover) { this.attrs.onHover = onHover; return this;