From 2944b0f79fc7b1a9f36585a5231e621810663ea8 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 24 Jun 2022 11:28:20 -0400 Subject: [PATCH] feat: Fix distribution display Distribution display now keeps to the [0.03, 0.97] confidence interval. This fixes a longstanding annoying bug. The [0.03, 0.97] confidence interval was chosen after a bit of testing, but I have no particular attachment to it. --- .../src/components/DistributionChart.tsx | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/components/src/components/DistributionChart.tsx b/packages/components/src/components/DistributionChart.tsx index f2ca811b..b2ba25e8 100644 --- a/packages/components/src/components/DistributionChart.tsx +++ b/packages/components/src/components/DistributionChart.tsx @@ -38,8 +38,32 @@ export const DistributionChart: React.FC = ({ }) => { const [isLogX, setLogX] = React.useState(false); const [isExpY, setExpY] = React.useState(false); - const shape = distribution.pointSet(); + const [sized] = useSize((size) => { + + const p3wrapped = distribution.inv(0.03); + const p97wrapped = distribution.inv(0.97); + if (p3wrapped.tag == "Error") { + return + {distributionErrorToString(p3wrapped.value)} + + } else if (p97wrapped.tag == "Error") { + return + {distributionErrorToString(p97wrapped.value)} + + } + const p3 = p3wrapped.value + const p97 = p97wrapped.value + + const truncatedDistributionWrapper = distribution.truncate(p3, p97) + if (truncatedDistributionWrapper.tag == "Error") { + return + {distributionErrorToString(truncatedDistributionWrapper.value)} + + } + const truncatedDistribution = truncatedDistributionWrapper.value + + const shape = truncatedDistribution.pointSet(); //distribution.pointSet(); if (shape.tag === "Error") { return ( @@ -82,10 +106,10 @@ export const DistributionChart: React.FC = ({ // Check whether we should disable the checkbox {...(massBelow0 ? { - disabled: true, - tooltip: - "Your distribution has mass lower than or equal to 0. Log only works on strictly positive values.", - } + disabled: true, + tooltip: + "Your distribution has mass lower than or equal to 0. Log only works on strictly positive values.", + } : {})} /> @@ -158,12 +182,12 @@ const SummaryTable: React.FC = ({ distribution }) => { const mean = distribution.mean(); const stdev = distribution.stdev(); const p5 = distribution.inv(0.05); - const p10 = distribution.inv(0.1); + const p30 = distribution.inv(0.1); const p25 = distribution.inv(0.25); const p50 = distribution.inv(0.5); const p75 = distribution.inv(0.75); const p90 = distribution.inv(0.9); - const p95 = distribution.inv(0.95); + const p97 = distribution.inv(0.95); const hasResult = (x: result): boolean => x.tag === "Ok"; @@ -202,12 +226,12 @@ const SummaryTable: React.FC = ({ distribution }) => { {unwrapResult(mean)} {hasResult(stdev) && {unwrapResult(stdev)}} {unwrapResult(p5)} - {unwrapResult(p10)} + {unwrapResult(p30)} {unwrapResult(p25)} {unwrapResult(p50)} {unwrapResult(p75)} {unwrapResult(p90)} - {unwrapResult(p95)} + {unwrapResult(p97)}