diff --git a/packages/components/src/components/FunctionChart.tsx b/packages/components/src/components/FunctionChart.tsx index bfe50684..bb5a9e24 100644 --- a/packages/components/src/components/FunctionChart.tsx +++ b/packages/components/src/components/FunctionChart.tsx @@ -1,12 +1,5 @@ import * as React from "react"; -import type { Spec } from "vega"; -import { - Distribution, - result, - lambdaValue, - environment, - runForeign, -} from "@quri/squiggle-lang"; +import { lambdaValue, environment, runForeign } from "@quri/squiggle-lang"; import { FunctionChart1Dist } from "./FunctionChart1Dist"; import { FunctionChart1Number } from "./FunctionChart1Number"; import { ErrorBox } from "./ErrorBox"; @@ -44,7 +37,7 @@ export const FunctionChart: React.FC = ({ let validResult = getValidResult(); let resultType = validResult.tag === "Ok" ? validResult.value.tag : "Error"; - let comp = () => { + let component = () => { switch (resultType) { case "distribution": return ( @@ -77,5 +70,5 @@ export const FunctionChart: React.FC = ({ } }; - return comp(); + return component(); }; diff --git a/packages/components/src/components/FunctionChart1Dist.tsx b/packages/components/src/components/FunctionChart1Dist.tsx index 2090af44..836bcdd5 100644 --- a/packages/components/src/components/FunctionChart1Dist.tsx +++ b/packages/components/src/components/FunctionChart1Dist.tsx @@ -41,7 +41,7 @@ export type FunctionChartSettings = { count: number; }; -interface FunctionChartProps { +interface FunctionChart1DistProps { fn: lambdaValue; chartSettings: FunctionChartSettings; environment: environment; @@ -146,12 +146,12 @@ let getPercentiles = ({ chartSettings, fn, environment }) => { return { percentiles, errors: groupedErrors }; }; -export const FunctionChart1Dist: React.FC = ({ +export const FunctionChart1Dist: React.FC = ({ fn, chartSettings, environment, height, -}: FunctionChartProps) => { +}: FunctionChart1DistProps) => { let [mouseOverlay, setMouseOverlay] = React.useState(0); function handleHover(_name: string, value: unknown) { setMouseOverlay(value as number); diff --git a/packages/components/src/components/FunctionChart1Number.tsx b/packages/components/src/components/FunctionChart1Number.tsx index b07b9263..9d2feca7 100644 --- a/packages/components/src/components/FunctionChart1Number.tsx +++ b/packages/components/src/components/FunctionChart1Number.tsx @@ -2,19 +2,14 @@ import * as React from "react"; import _ from "lodash"; import type { Spec } from "vega"; import { - Distribution, result, lambdaValue, environment, runForeign, - squiggleExpression, - errorValue, errorValueToString, } from "@quri/squiggle-lang"; import { createClassFromSpec } from "react-vega"; import * as lineChartSpec from "../vega-specs/spec-line-chart.json"; -import { DistributionChart } from "./DistributionChart"; -import { NumberShower } from "./NumberShower"; import { ErrorBox } from "./ErrorBox"; let SquiggleLineChart = createClassFromSpec({ @@ -28,20 +23,13 @@ const _rangeByCount = (start: number, stop: number, count: number) => { return result; }; -function unwrap(x: result): a { - if (x.tag === "Ok") { - return x.value; - } else { - throw Error("FAILURE TO UNWRAP"); - } -} export type FunctionChartSettings = { start: number; stop: number; count: number; }; -interface FunctionChartProps { +interface FunctionChart1NumberProps { fn: lambdaValue; chartSettings: FunctionChartSettings; environment: environment; @@ -70,8 +58,7 @@ let getFunctionImage = ({ chartSettings, fn, environment }) => { x, value: { tag: "Error", - value: - "Cannot currently render functions that don't return distributions", + value: "This component expected number outputs", }, }; } @@ -100,30 +87,12 @@ let getFunctionImage = ({ chartSettings, fn, environment }) => { return { errors, functionImage }; }; -export const FunctionChart1Number: React.FC = ({ +export const FunctionChart1Number: React.FC = ({ fn, chartSettings, environment, height, -}: FunctionChartProps) => { - let [mouseOverlay, setMouseOverlay] = React.useState(0); - function handleHover(_name: string, value: unknown) { - setMouseOverlay(value as number); - } - function handleOut() { - setMouseOverlay(NaN); - } - const signalListeners = { mousemove: handleHover, mouseout: handleOut }; - let mouseItem: result = !!mouseOverlay - ? runForeign(fn, [mouseOverlay], environment) - : { - tag: "Error", - value: { - tag: "REExpectedType", - value: "Hover x-coordinate returned NaN. Expected a number.", - }, - }; - +}: FunctionChart1NumberProps) => { let getFunctionImageMemoized = React.useMemo( () => getFunctionImage({ chartSettings, fn, environment }), [environment, fn] @@ -139,7 +108,6 @@ export const FunctionChart1Number: React.FC = ({ data={{ facet: data }} height={height} actions={false} - signalListeners={signalListeners} /> {getFunctionImageMemoized.errors.map(({ x, value }) => ( diff --git a/packages/components/src/components/JsonEditor.tsx b/packages/components/src/components/JsonEditor.tsx index 6d9068c1..c81debf4 100644 --- a/packages/components/src/components/JsonEditor.tsx +++ b/packages/components/src/components/JsonEditor.tsx @@ -4,7 +4,6 @@ import AceEditor from "react-ace"; import "ace-builds/src-noconflict/mode-json"; import "ace-builds/src-noconflict/theme-github"; -import { jsImports, defaultImports } from "@quri/squiggle-lang"; interface CodeEditorProps { value: string;