2022-04-07 17:26:47 +00:00
|
|
|
import { SquiggleChart } from "../components/SquiggleChart";
|
2022-03-23 00:38:01 +00:00
|
|
|
import { Canvas, Meta, Story, Props } from "@storybook/addon-docs";
|
2022-02-28 23:59:48 +00:00
|
|
|
|
2022-03-23 00:38:01 +00:00
|
|
|
<Meta title="Squiggle/SquiggleChart" component={SquiggleChart} />
|
2022-02-28 23:59:48 +00:00
|
|
|
|
2022-03-23 00:38:01 +00:00
|
|
|
export const Template = SquiggleChart;
|
2022-04-15 18:51:08 +00:00
|
|
|
/*
|
|
|
|
We have to hardcode a width here, because otherwise some interaction with
|
|
|
|
Storybook creates an infinite loop with the internal width
|
|
|
|
*/
|
2022-04-15 21:14:07 +00:00
|
|
|
const width = 600;
|
2022-02-28 23:59:48 +00:00
|
|
|
|
|
|
|
# Squiggle Chart
|
|
|
|
|
|
|
|
Squiggle chart evaluates squiggle expressions, and then returns a graph representing
|
|
|
|
the result of a squiggle expression.
|
|
|
|
|
|
|
|
A squiggle expression can have three different types of returns. A distribution,
|
|
|
|
a constant, and a function.
|
|
|
|
|
|
|
|
A distribution means that the result forms a probability distribution. This
|
|
|
|
could be continuous, discrete or mixed.
|
|
|
|
|
|
|
|
## Distributions
|
|
|
|
|
2022-04-15 21:14:07 +00:00
|
|
|
### Continuous Distributions (Symbolic)
|
2022-03-23 00:38:01 +00:00
|
|
|
|
2022-02-28 23:59:48 +00:00
|
|
|
<Canvas>
|
|
|
|
<Story
|
2022-04-15 21:14:07 +00:00
|
|
|
name="Continuous Symbolic"
|
2022-02-28 23:59:48 +00:00
|
|
|
args={{
|
2022-03-23 00:38:01 +00:00
|
|
|
squiggleString: "normal(5,2)",
|
2022-04-15 18:51:08 +00:00
|
|
|
width,
|
2022-03-23 00:38:01 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-02-28 23:59:48 +00:00
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-15 21:14:07 +00:00
|
|
|
### Continuous Distributions (PointSet)
|
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Continuous Pointset"
|
|
|
|
args={{
|
|
|
|
squiggleString: "toPointSet(normal(5,2))",
|
|
|
|
width,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
|
|
|
### Continuous Distributions (SampleSet)
|
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Continuous SampleSet"
|
|
|
|
args={{
|
|
|
|
squiggleString: "toSampleSet(normal(5,2), 1000)",
|
|
|
|
width,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-06 21:51:24 +00:00
|
|
|
### Discrete Distributions
|
2022-03-23 00:38:01 +00:00
|
|
|
|
2022-02-28 23:59:48 +00:00
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Discrete"
|
|
|
|
args={{
|
2022-04-12 07:39:38 +00:00
|
|
|
squiggleString: "mx(0, 1, 3, 5, 8, 10, [0.1, 0.8, 0.5, 0.3, 0.2, 0.1])",
|
2022-04-15 18:51:08 +00:00
|
|
|
width,
|
2022-03-23 00:38:01 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-02-28 23:59:48 +00:00
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-06 21:51:24 +00:00
|
|
|
## Mixed distributions
|
2022-03-23 00:38:01 +00:00
|
|
|
|
2022-02-28 23:59:48 +00:00
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Mixed"
|
|
|
|
args={{
|
2022-04-12 05:41:36 +00:00
|
|
|
squiggleString:
|
2022-04-12 07:39:38 +00:00
|
|
|
"mx(0, 1, 3, 5, 8, normal(8, 1), [0.1, 0.3, 0.4, 0.35, 0.2, 0.8])",
|
2022-04-15 18:51:08 +00:00
|
|
|
width,
|
2022-03-23 00:38:01 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-02-28 23:59:48 +00:00
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
|
|
|
## Constants
|
2022-03-23 00:38:01 +00:00
|
|
|
|
2022-02-28 23:59:48 +00:00
|
|
|
A constant is a simple number as a result. This has special formatting rules
|
|
|
|
to allow large and small numbers being printed cleanly.
|
2022-03-23 00:38:01 +00:00
|
|
|
|
2022-02-28 23:59:48 +00:00
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Constant"
|
|
|
|
args={{
|
2022-04-06 21:51:24 +00:00
|
|
|
squiggleString: "500000000",
|
2022-04-15 18:51:08 +00:00
|
|
|
width,
|
2022-03-23 00:38:01 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-02-28 23:59:48 +00:00
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-15 21:14:07 +00:00
|
|
|
## Arrays
|
2022-02-28 23:59:48 +00:00
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
2022-04-15 21:14:07 +00:00
|
|
|
name="Array"
|
2022-02-28 23:59:48 +00:00
|
|
|
args={{
|
2022-04-15 21:14:07 +00:00
|
|
|
squiggleString: "[normal(5,2), normal(10,1), normal(40,2), 400000]",
|
2022-04-15 18:51:08 +00:00
|
|
|
width,
|
2022-03-23 00:38:01 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-02-28 23:59:48 +00:00
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-07 01:37:08 +00:00
|
|
|
## Errors
|
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Error"
|
|
|
|
args={{
|
|
|
|
squiggleString: "f(x) = normal(",
|
2022-04-15 18:51:08 +00:00
|
|
|
width,
|
2022-04-07 01:37:08 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-15 21:14:07 +00:00
|
|
|
## Booleans
|
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Boolean"
|
|
|
|
args={{
|
|
|
|
squiggleString: "3 == 3",
|
|
|
|
width,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-05-15 18:39:50 +00:00
|
|
|
## Functions
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Function"
|
|
|
|
args={{
|
|
|
|
squiggleString: "foo(t) = normal(t,2)*normal(5,3); foo",
|
|
|
|
width,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-04-15 21:14:07 +00:00
|
|
|
## Records
|
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="Record"
|
|
|
|
args={{
|
|
|
|
squiggleString: "{foo: 35 to 50, bar: [1,2,3]}",
|
|
|
|
width,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
|
|
|
## Strings
|
|
|
|
|
|
|
|
<Canvas>
|
|
|
|
<Story
|
|
|
|
name="String"
|
|
|
|
args={{
|
|
|
|
squiggleString: '"Lucky day!"',
|
|
|
|
width,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{Template.bind({})}
|
|
|
|
</Story>
|
|
|
|
</Canvas>
|
|
|
|
|
2022-03-01 07:43:35 +00:00
|
|
|
<Props of={SquiggleChart} />
|