From 56728c7ea5bc8aed9fc25482b19764676cdffade Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 15 May 2022 15:23:58 -0400 Subject: [PATCH] Removed unneeded code --- .../src/components/FunctionChart.tsx | 74 +------------------ 1 file changed, 4 insertions(+), 70 deletions(-) diff --git a/packages/components/src/components/FunctionChart.tsx b/packages/components/src/components/FunctionChart.tsx index 32919d67..10f97b7d 100644 --- a/packages/components/src/components/FunctionChart.tsx +++ b/packages/components/src/components/FunctionChart.tsx @@ -173,76 +173,10 @@ export const FunctionChart: React.FC = ({ <> ); - let getPercentiles2: () => { - percentiles: percentiles; - errors: errors; - } = () => { - let data1 = _rangeByCount( - chartSettings.start, - chartSettings.stop, - chartSettings.count - ); - let valueData: point[] = data1.map((x) => { - let result = runForeign(fn, [x], environment); - if (result.tag === "Ok") { - if (result.value.tag == "distribution") { - return { x, value: { tag: "Ok", value: result.value.value } }; - } else { - return { - x, - value: { - tag: "Error", - value: - "Cannot currently render functions that don't return distributions", - }, - }; - } - } else { - return { - x, - value: { tag: "Error", value: errorValueToString(result.value) }, - }; - } - }); - let initialPartition: [ - { x: number; value: Distribution }[], - { x: number; value: string }[] - ] = [[], []]; - let [functionImage, errors] = valueData.reduce((acc, current) => { - if (current.value.tag === "Ok") { - acc[0].push({ x: current.x, value: current.value.value }); - } else { - acc[1].push({ x: current.x, value: current.value.value }); - } - return acc; - }, initialPartition); - let groupedErrors: errors = _.groupBy(errors, (x) => x.value); - let percentiles: percentiles = functionImage.map(({ x, value }) => { - // We convert it to to a pointSet distribution first, so that in case its a sample set - // distribution, it doesn't internally convert it to a pointSet distribution for every - // single inv() call. - let toPointSet: Distribution = unwrap(value.toPointSet()); - return { - x: x, - p1: unwrap(toPointSet.inv(0.01)), - p5: unwrap(toPointSet.inv(0.05)), - p10: unwrap(toPointSet.inv(0.12)), - p20: unwrap(toPointSet.inv(0.2)), - p30: unwrap(toPointSet.inv(0.3)), - p40: unwrap(toPointSet.inv(0.4)), - p50: unwrap(toPointSet.inv(0.5)), - p60: unwrap(toPointSet.inv(0.6)), - p70: unwrap(toPointSet.inv(0.7)), - p80: unwrap(toPointSet.inv(0.8)), - p90: unwrap(toPointSet.inv(0.9)), - p95: unwrap(toPointSet.inv(0.95)), - p99: unwrap(toPointSet.inv(0.99)), - }; - }); - return { percentiles, errors: groupedErrors }; - }; - - let _getPercentiles = React.useMemo(getPercentiles2, [environment, fn]); + let _getPercentiles = React.useMemo( + () => getPercentiles({ chartSettings, fn, environment }), + [environment, fn] + ); return ( <>