From d38caff28f7671595b8ce8012b3db8401ae0c8ba Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 26 May 2022 16:16:40 -0400 Subject: [PATCH] Minor cleanup --- .../src/components/FunctionChart.tsx | 16 ++++- .../src/components/FunctionChart1Number.tsx | 5 +- .../src/components/SquiggleChart.tsx | 24 ++++--- .../src/components/SquigglePlayground.tsx | 71 +++++++++++-------- 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/packages/components/src/components/FunctionChart.tsx b/packages/components/src/components/FunctionChart.tsx index 5a37f0ca..bfe50684 100644 --- a/packages/components/src/components/FunctionChart.tsx +++ b/packages/components/src/components/FunctionChart.tsx @@ -1,5 +1,4 @@ import * as React from "react"; -import _ from "lodash"; import type { Spec } from "vega"; import { Distribution, @@ -31,8 +30,19 @@ export const FunctionChart: React.FC = ({ environment, height, }: FunctionChartProps) => { - let result = runForeign(fn, [chartSettings.start], environment); - let resultType = result.tag === "Ok" ? result.value.tag : "Error"; + let result1 = runForeign(fn, [chartSettings.start], environment); + let result2 = runForeign(fn, [chartSettings.stop], environment); + let getValidResult = () => { + if (result1.tag === "Ok") { + return result1; + } else if (result2.tag === "Ok") { + return result2; + } else { + return result1; + } + }; + let validResult = getValidResult(); + let resultType = validResult.tag === "Ok" ? validResult.value.tag : "Error"; let comp = () => { switch (resultType) { diff --git a/packages/components/src/components/FunctionChart1Number.tsx b/packages/components/src/components/FunctionChart1Number.tsx index fa72bf71..4dae8cf0 100644 --- a/packages/components/src/components/FunctionChart1Number.tsx +++ b/packages/components/src/components/FunctionChart1Number.tsx @@ -51,10 +51,13 @@ interface FunctionChartProps { type point = { x: number; value: result }; let getFunctionImage = ({ chartSettings, fn, environment }) => { + //We adjust the count, because the count is made for distributions, which are much more expensive to estimate + let adjustedCount = chartSettings.count * 20; + let chartPointsToRender = _rangeByCount( chartSettings.start, chartSettings.stop, - chartSettings.count + adjustedCount ); let chartPointsData: point[] = chartPointsToRender.map((x) => { diff --git a/packages/components/src/components/SquiggleChart.tsx b/packages/components/src/components/SquiggleChart.tsx index 5cbebc8e..f07f5cc8 100644 --- a/packages/components/src/components/SquiggleChart.tsx +++ b/packages/components/src/components/SquiggleChart.tsx @@ -172,7 +172,7 @@ const SquiggleItem: React.FC = ({ = ({ } case "lambda": return ( - + + + ); } }; @@ -255,7 +257,7 @@ export const SquiggleChart: React.FC = ({ squiggleString = "", environment, onChange = () => {}, - height = 60, + height = 200, bindings = defaultBindings, jsImports = defaultImports, showSummary = false, diff --git a/packages/components/src/components/SquigglePlayground.tsx b/packages/components/src/components/SquigglePlayground.tsx index c28bf11a..1c7acd6f 100644 --- a/packages/components/src/components/SquigglePlayground.tsx +++ b/packages/components/src/components/SquigglePlayground.tsx @@ -78,7 +78,8 @@ interface RowProps { const Row = styled.div` display: grid; - grid-template-columns: ${(p) => p.leftPercentage}% ${(p) => 100 - p.leftPercentage}%; + grid-template-columns: ${(p) => p.leftPercentage}% ${(p) => + 100 - p.leftPercentage}%; `; const Col = styled.div``; @@ -115,10 +116,18 @@ const schema = yup .min(10) .max(10000), chartHeight: yup.number().required().positive().integer().default(350), - leftSize: yup.number().required().positive().integer().min(10).max(100).default(50), + leftSizePercent: yup + .number() + .required() + .positive() + .integer() + .min(10) + .max(100) + .default(50), showTypes: yup.boolean(), showControls: yup.boolean(), showSummary: yup.boolean(), + showSettingsPage: yup.boolean().default(false), }) .required(); @@ -133,9 +142,6 @@ let SquigglePlayground: FC = ({ let [importString, setImportString] = useState("{}"); let [imports, setImports] = useState({}); let [importsAreValid, setImportsAreValid] = useState(true); - let [showTypesInput, setShowTypesInput] = useState(showTypes); - let [showControlsInput, setShowControlsInput] = useState(showControls); - let [showSummaryInput, setShowSummaryInput] = useState(showSummary); let [diagramStart, setDiagramStart] = useState(0); let [diagramStop, setDiagramStop] = useState(10); let [diagramCount, setDiagramCount] = useState(20); @@ -157,7 +163,8 @@ let SquigglePlayground: FC = ({ showTypes: showTypes, showControls: showControls, showSummary: showSummary, - leftSize: 50, + leftSizePercent: 50, + showSettingsPage: false, }, }); const vars = useWatch({ @@ -178,30 +185,36 @@ let SquigglePlayground: FC = ({ }; return ( - - - - - - - - + + - - - {importsAreValid ? "Valid" : "INVALID"} + {vars.showSettingsPage ? ( +
+ + + + + + + + + {importsAreValid ? "Valid" : "Invalid"} +
+ ) : ( + + )}