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 { createClassFromSpec } from "react-vega";
import * as chartSpecification from "../vega-specs/spec-distributions.json";
import { ErrorBox } from "./ErrorBox";
let SquiggleVegaChart = createClassFromSpec({
spec: chartSpecification as Spec,
@ -21,7 +22,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = ({
width,
height,
}: DistributionChartProps) => {
let shape = distribution.shape();
let shape = distribution.pointSet();
if (shape.tag === "Ok") {
return (
<SquiggleVegaChart
@ -32,6 +33,10 @@ export const DistributionChart: React.FC<DistributionChartProps> = ({
/>
);
} 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,
};
let result = run(squiggleString, samplingInputs, environment);
if (result.tag === "Ok") {
let expressionResult = run(squiggleString, samplingInputs, environment);
if (expressionResult.tag === "Ok") {
onEnvChange(environment);
let chartResult = result.value;
if (chartResult.tag === "number") {
return <NumberShower precision={3} number={chartResult.value} />;
} else if (chartResult.tag === "distribution") {
let expression = expressionResult.value;
if (expression.tag === "number") {
return <NumberShower precision={3} number={expression.value} />;
} else if (expression.tag === "distribution") {
return (
<DistributionChart
distribution={chartResult.value}
distribution={expression.value}
height={height}
width={width}
/>
@ -61,7 +61,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
} else {
return (
<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>
);
}
@ -69,7 +69,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
// At this point, we came across an error. What was our error?
return (
<ErrorBox heading={"Parse Error"}>
{errorValueToString(result.value)}
{errorValueToString(expressionResult.value)}
</ErrorBox>
);
}