Keep props consistent

This commit is contained in:
Sam Nolan 2022-05-10 16:16:36 +00:00
parent 70ea9c1b14
commit 8d391f789d
2 changed files with 10 additions and 25 deletions

View File

@ -10,6 +10,7 @@ import {
jsImports, jsImports,
defaultImports, defaultImports,
defaultBindings, defaultBindings,
defaultEnvironment,
} from "@quri/squiggle-lang"; } from "@quri/squiggle-lang";
import { NumberShower } from "./NumberShower"; import { NumberShower } from "./NumberShower";
import { DistributionChart } from "./DistributionChart"; import { DistributionChart } from "./DistributionChart";
@ -204,7 +205,7 @@ export interface SquiggleChartProps {
/** If the output requires monte carlo sampling, the amount of samples */ /** If the output requires monte carlo sampling, the amount of samples */
sampleCount?: number; sampleCount?: number;
/** The amount of points returned to draw the distribution */ /** The amount of points returned to draw the distribution */
environment: environment; environment?: environment;
/** If the result is a function, where the function starts, ends and the amount of stops */ /** If the result is a function, where the function starts, ends and the amount of stops */
chartSettings?: FunctionChartSettings; chartSettings?: FunctionChartSettings;
/** When the environment changes */ /** When the environment changes */
@ -245,6 +246,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
chartSettings = defaultChartSettings, chartSettings = defaultChartSettings,
}: SquiggleChartProps) => { }: SquiggleChartProps) => {
let expressionResult = run(squiggleString, bindings, environment, jsImports); let expressionResult = run(squiggleString, bindings, environment, jsImports);
let e = environment ? environment : defaultEnvironment;
let internal: JSX.Element; let internal: JSX.Element;
if (expressionResult.tag === "Ok") { if (expressionResult.tag === "Ok") {
let expression = expressionResult.value; let expression = expressionResult.value;
@ -258,7 +260,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
showTypes={showTypes} showTypes={showTypes}
showControls={showControls} showControls={showControls}
chartSettings={chartSettings} chartSettings={chartSettings}
environment={environment} environment={e}
/> />
); );
} else { } else {

View File

@ -21,9 +21,7 @@ export interface SquiggleEditorProps {
/** The input string for squiggle */ /** The input string for squiggle */
initialSquiggleString?: string; initialSquiggleString?: string;
/** If the output requires monte carlo sampling, the amount of samples */ /** If the output requires monte carlo sampling, the amount of samples */
sampleCount?: number; environment?: environment;
/** The amount of points returned to draw the distribution */
outputXYPoints?: number;
/** If the result is a function, where the function starts */ /** If the result is a function, where the function starts */
diagramStart?: number; diagramStart?: number;
/** If the result is a function, where the function ends */ /** If the result is a function, where the function ends */
@ -55,8 +53,7 @@ const Input = styled.div`
export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
initialSquiggleString = "", initialSquiggleString = "",
width, width,
sampleCount = 1000, environment,
outputXYPoints = 1000,
diagramStart = 0, diagramStart = 0,
diagramStop = 10, diagramStop = 10,
diagramCount = 100, diagramCount = 100,
@ -73,10 +70,6 @@ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
stop: diagramStop, stop: diagramStop,
count: diagramCount, count: diagramCount,
}; };
let env: environment = {
sampleCount: sampleCount,
xyPointLength: outputXYPoints,
};
return ( return (
<div> <div>
<Input> <Input>
@ -90,9 +83,8 @@ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
</Input> </Input>
<SquiggleChart <SquiggleChart
width={width} width={width}
environment={env} environment={environment}
squiggleString={expression} squiggleString={expression}
sampleCount={sampleCount}
chartSettings={chartSettings} chartSettings={chartSettings}
onChange={onChange} onChange={onChange}
bindings={bindings} bindings={bindings}
@ -141,11 +133,7 @@ export interface SquigglePartialProps {
/** The input string for squiggle */ /** The input string for squiggle */
initialSquiggleString?: string; initialSquiggleString?: string;
/** If the output requires monte carlo sampling, the amount of samples */ /** If the output requires monte carlo sampling, the amount of samples */
sampleCount?: number; environment?: environment;
/** The amount of points returned to draw the distribution */
outputXYPoints?: number;
kernelWidth?: number;
pointDistLength?: number;
/** If the result is a function, where the function starts */ /** If the result is a function, where the function starts */
diagramStart?: number; diagramStart?: number;
/** If the result is a function, where the function ends */ /** If the result is a function, where the function ends */
@ -166,14 +154,9 @@ export let SquigglePartial: React.FC<SquigglePartialProps> = ({
initialSquiggleString = "", initialSquiggleString = "",
onChange, onChange,
bindings = defaultBindings, bindings = defaultBindings,
sampleCount = 1000, environment,
outputXYPoints = 1000,
jsImports = defaultImports, jsImports = defaultImports,
}: SquigglePartialProps) => { }: SquigglePartialProps) => {
let samplingInputs: environment = {
sampleCount: sampleCount,
xyPointLength: outputXYPoints,
};
let [expression, setExpression] = React.useState(initialSquiggleString); let [expression, setExpression] = React.useState(initialSquiggleString);
let [error, setError] = React.useState<string | null>(null); let [error, setError] = React.useState<string | null>(null);
@ -181,7 +164,7 @@ export let SquigglePartial: React.FC<SquigglePartialProps> = ({
let squiggleResult = runPartial( let squiggleResult = runPartial(
expression, expression,
bindings, bindings,
samplingInputs, environment,
jsImports jsImports
); );
if (squiggleResult.tag == "Ok") { if (squiggleResult.tag == "Ok") {