Keep props consistent

This commit is contained in:
Sam Nolan 2022-05-10 16:16:36 +00:00 committed by Quinn Dougherty
parent b0c84450ff
commit 4758fca19b
2 changed files with 10 additions and 25 deletions

View File

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

View File

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