Fix multiple charting
This commit is contained in:
parent
c97d1d457e
commit
70f26a08ba
|
@ -80,7 +80,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = (props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ width: widthProp }}>
|
<div style={{ width: widthProp }}>
|
||||||
{logX && hasMassBelowZero(shape.value) ? (
|
{logX && shapes.value.some(hasMassBelowZero) ? (
|
||||||
<ErrorAlert heading="Log Domain Error">
|
<ErrorAlert heading="Log Domain Error">
|
||||||
Cannot graph distribution with negative values on logarithmic scale.
|
Cannot graph distribution with negative values on logarithmic scale.
|
||||||
</ErrorAlert>
|
</ErrorAlert>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { squiggleExpression, declaration } from "@quri/squiggle-lang";
|
import { squiggleExpression, declaration } from "@quri/squiggle-lang";
|
||||||
import { NumberShower } from "../NumberShower";
|
import { NumberShower } from "../NumberShower";
|
||||||
import { DistributionChart } from "../DistributionChart";
|
import { DistributionChart, defaultPlot, makePlot } from "../DistributionChart";
|
||||||
import { FunctionChart, FunctionChartSettings } from "../FunctionChart";
|
import { FunctionChart, FunctionChartSettings } from "../FunctionChart";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { VariableBox } from "./VariableBox";
|
import { VariableBox } from "./VariableBox";
|
||||||
|
@ -102,7 +102,7 @@ export const ExpressionViewer: React.FC<Props> = ({
|
||||||
{(settings) => {
|
{(settings) => {
|
||||||
return (
|
return (
|
||||||
<DistributionChart
|
<DistributionChart
|
||||||
distribution={expression.value}
|
plot={defaultPlot(expression.value)}
|
||||||
{...settings.distributionPlotSettings}
|
{...settings.distributionPlotSettings}
|
||||||
height={settings.height}
|
height={settings.height}
|
||||||
width={width}
|
width={width}
|
||||||
|
@ -241,9 +241,9 @@ export const ExpressionViewer: React.FC<Props> = ({
|
||||||
case "module": {
|
case "module": {
|
||||||
return (
|
return (
|
||||||
<VariableList path={path} heading="Module">
|
<VariableList path={path} heading="Module">
|
||||||
{(settings) =>
|
{(_) =>
|
||||||
Object.entries(expression.value)
|
Object.entries(expression.value)
|
||||||
.filter(([key, r]) => !key.match(/^(Math|System)\./))
|
.filter(([key, _]) => !key.match(/^(Math|System)\./))
|
||||||
.map(([key, r]) => (
|
.map(([key, r]) => (
|
||||||
<ExpressionViewer
|
<ExpressionViewer
|
||||||
key={key}
|
key={key}
|
||||||
|
@ -257,9 +257,45 @@ export const ExpressionViewer: React.FC<Props> = ({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
case "record":
|
case "record":
|
||||||
|
const plot = makePlot(expression.value);
|
||||||
|
if (plot) {
|
||||||
|
return (
|
||||||
|
<VariableBox
|
||||||
|
path={path}
|
||||||
|
heading={"Plot"}
|
||||||
|
renderSettingsMenu={({ onChange }) => {
|
||||||
|
let disableLogX = plot.distributions.some((x) => {
|
||||||
|
let pointSet = x.distribution.pointSet();
|
||||||
|
return (
|
||||||
|
pointSet.tag === "Ok" && hasMassBelowZero(pointSet.value)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<ItemSettingsMenu
|
||||||
|
path={path}
|
||||||
|
onChange={onChange}
|
||||||
|
disableLogX={disableLogX}
|
||||||
|
withFunctionSettings={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(settings) => {
|
||||||
|
return (
|
||||||
|
<DistributionChart
|
||||||
|
plot={plot}
|
||||||
|
{...settings.distributionPlotSettings}
|
||||||
|
height={settings.height}
|
||||||
|
width={width}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</VariableBox>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
return (
|
return (
|
||||||
<VariableList path={path} heading="Record">
|
<VariableList path={path} heading="Record">
|
||||||
{(settings) =>
|
{(_) =>
|
||||||
Object.entries(expression.value).map(([key, r]) => (
|
Object.entries(expression.value).map(([key, r]) => (
|
||||||
<ExpressionViewer
|
<ExpressionViewer
|
||||||
key={key}
|
key={key}
|
||||||
|
@ -271,10 +307,11 @@ export const ExpressionViewer: React.FC<Props> = ({
|
||||||
}
|
}
|
||||||
</VariableList>
|
</VariableList>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
case "array":
|
case "array":
|
||||||
return (
|
return (
|
||||||
<VariableList path={path} heading="Array">
|
<VariableList path={path} heading="Array">
|
||||||
{(settings) =>
|
{(_) =>
|
||||||
expression.value.map((r, i) => (
|
expression.value.map((r, i) => (
|
||||||
<ExpressionViewer
|
<ExpressionViewer
|
||||||
key={i}
|
key={i}
|
||||||
|
|
|
@ -31,3 +31,7 @@ export function resultBind<a, b, c>(
|
||||||
export function all(arr: boolean[]): boolean {
|
export function all(arr: boolean[]): boolean {
|
||||||
return arr.reduce((x, y) => x && y, true);
|
return arr.reduce((x, y) => x && y, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function some(arr: boolean[]): boolean {
|
||||||
|
return arr.reduce((x, y) => x || y, false);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user