Respond to reducer playground PR comments

This commit is contained in:
Sam Nolan 2022-04-12 16:02:34 +10:00
parent 440bfabffa
commit 21458227ce
2 changed files with 16 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import type { Distribution } from "@quri/squiggle-lang";
import { distributionErrorToString } from "@quri/squiggle-lang"; import { distributionErrorToString } from "@quri/squiggle-lang";
import { createClassFromSpec } from "react-vega"; import { createClassFromSpec } from "react-vega";
import * as chartSpecification from "../vega-specs/spec-distributions.json"; import * as chartSpecification from "../vega-specs/spec-distributions.json";
import { ErrorBox } from "./ErrorBox";
let SquiggleVegaChart = createClassFromSpec({ let SquiggleVegaChart = createClassFromSpec({
spec: chartSpecification as Spec, spec: chartSpecification as Spec,
@ -21,7 +22,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = ({
width, width,
height, height,
}: DistributionChartProps) => { }: DistributionChartProps) => {
let shape = distribution.shape(); let shape = distribution.pointSet();
if (shape.tag === "Ok") { if (shape.tag === "Ok") {
return ( return (
<SquiggleVegaChart <SquiggleVegaChart
@ -32,6 +33,10 @@ export const DistributionChart: React.FC<DistributionChartProps> = ({
/> />
); );
} else { } else {
return <> {distributionErrorToString(shape.value)} </>; return (
<ErrorBox heading="Distribution Error">
{distributionErrorToString(shape.value)}
</ErrorBox>
);
} }
}; };

View File

@ -44,16 +44,16 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
xyPointLength: outputXYPoints, xyPointLength: outputXYPoints,
}; };
let result = run(squiggleString, samplingInputs, environment); let expressionResult = run(squiggleString, samplingInputs, environment);
if (result.tag === "Ok") { if (expressionResult.tag === "Ok") {
onEnvChange(environment); onEnvChange(environment);
let chartResult = result.value; let expression = expressionResult.value;
if (chartResult.tag === "number") { if (expression.tag === "number") {
return <NumberShower precision={3} number={chartResult.value} />; return <NumberShower precision={3} number={expression.value} />;
} else if (chartResult.tag === "distribution") { } else if (expression.tag === "distribution") {
return ( return (
<DistributionChart <DistributionChart
distribution={chartResult.value} distribution={expression.value}
height={height} height={height}
width={width} width={width}
/> />
@ -61,7 +61,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
} else { } else {
return ( return (
<ErrorBox heading="No Viewer"> <ErrorBox heading="No Viewer">
{"We don't currently have a viewer for this type: " + chartResult.tag} {"We don't currently have a viewer for this type: " + expression.tag}
</ErrorBox> </ErrorBox>
); );
} }
@ -69,7 +69,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
// At this point, we came across an error. What was our error? // At this point, we came across an error. What was our error?
return ( return (
<ErrorBox heading={"Parse Error"}> <ErrorBox heading={"Parse Error"}>
{errorValueToString(result.value)} {errorValueToString(expressionResult.value)}
</ErrorBox> </ErrorBox>
); );
} }