Skip to content

Commit

Permalink
Deprecated definitions shouldn't show, fixes Plot.dists example
Browse files Browse the repository at this point in the history
  • Loading branch information
OAGr committed Jan 7, 2024
1 parent a7be13a commit 788a9b2
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 80 deletions.
8 changes: 5 additions & 3 deletions packages/components/src/components/ui/FnDocumentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ export const FnDocumentation: FC<{
textSize
)}
>
{definitions.map((def, id) => (
<StyleDefinition fullName={fullName} def={def} key={id} />
))}
{definitions
.filter((def) => !def.deprecated)
.map((def, id) => (
<StyleDefinition fullName={fullName} def={def} key={id} />
))}
</div>
</Section>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FnStory.story = {
name: "All",
};

const fnDocumentation = getFunctionDocumentation("Plot.dist");
const fnDocumentation = getFunctionDocumentation("Plot.dists");
if (!fnDocumentation) {
throw new Error("fnDocumentation is undefined");
}
Expand Down
152 changes: 76 additions & 76 deletions packages/squiggle-lang/src/fr/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,86 @@ const numericFnDef = () => {

export const library = [
maker.make({
name: "dists",
name: "dist",
output: "Plot",
interactiveExamples: [
`Plot.distFn(
{|t|normal(t, 2) * normal(5, 3)},
`Plot.dist(
normal(5, 2),
{
title: "A Function of Value over Time",
xScale: Scale.log({ min: 3, max: 100, title: "Time (years)" }),
yScale: Scale.linear({ title: "Value" }),
distXScale: Scale.linear({ tickFormat: "#x" }),
xScale: Scale.linear({ min: -2, max: 6, title: "X Axis Title" }),
title: "A Simple Normal Distribution",
showSummary: true,
}
)`,
],

definitions: [
makeDefinition(
[
frNamed("dist", frDist),
frNamed(
"params",
frOptional(
frDict(
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["showSummary", frOptional(frBool)]
)
)
),
],
frPlot,
([dist, params]) => {
const { xScale, yScale, title, showSummary } = params ?? {};
return {
type: "distributions",
distributions: [{ distribution: dist }],
xScale: xScale ?? defaultScale,
yScale: yScale ?? defaultScale,
title: title ?? undefined,
showSummary: showSummary ?? true,
};
}
),
makeDefinition(
[
frDict(
["dist", frDist],
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["showSummary", frOptional(frBool)]
),
],
frPlot,
([{ dist, xScale, yScale, title, showSummary }]) => {
_assertYScaleNotDateScale(yScale);
return {
type: "distributions",
distributions: [{ distribution: dist }],
xScale: xScale ?? defaultScale,
yScale: yScale ?? defaultScale,
title: title ?? undefined,
showSummary: showSummary ?? true,
};
},
{ deprecated: "0.8.7" }
),
],
}),
maker.make({
name: "dists",
output: "Plot",
interactiveExamples: [
`Plot.dists(
{
dists: [
{ name: "First Dist", value: normal(0, 1) },
{ name: "Second Dist", value: uniform(2, 4) },
],
xScale: Scale.symlog({ min: -2, max: 5 }),
}
)`,
],
definitions: [
Expand Down Expand Up @@ -333,75 +402,6 @@ export const library = [
),
],
}),
maker.make({
name: "dist",
output: "Plot",
interactiveExamples: [
`Plot.dist(
normal(5, 2),
{
xScale: Scale.linear({ min: -2, max: 6, title: "X Axis Title" }),
title: "A Simple Normal Distribution",
showSummary: true,
}
)`,
],

definitions: [
makeDefinition(
[
frNamed("dist", frDist),
frNamed(
"params",
frOptional(
frDict(
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["showSummary", frOptional(frBool)]
)
)
),
],
frPlot,
([dist, params]) => {
const { xScale, yScale, title, showSummary } = params ?? {};
return {
type: "distributions",
distributions: [{ distribution: dist }],
xScale: xScale ?? defaultScale,
yScale: yScale ?? defaultScale,
title: title ?? undefined,
showSummary: showSummary ?? true,
};
}
),
makeDefinition(
[
frDict(
["dist", frDist],
["xScale", frOptional(frScale)],
["yScale", frOptional(frScale)],
["title", frOptional(frString)],
["showSummary", frOptional(frBool)]
),
],
frPlot,
([{ dist, xScale, yScale, title, showSummary }]) => {
_assertYScaleNotDateScale(yScale);
return {
type: "distributions",
distributions: [{ distribution: dist }],
xScale: xScale ?? defaultScale,
yScale: yScale ?? defaultScale,
title: title ?? undefined,
showSummary: showSummary ?? true,
};
},
{ deprecated: "0.8.7" }
),
],
}),
numericFnDef(),
maker.make({
name: "distFn",
Expand Down
7 changes: 7 additions & 0 deletions packages/website/templates.mts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ Lists are immutable, meaning that they cannot be modified. Instead, all list fun
## Functions
`,
},
{
name: "Plot",
description: "",
intro: `The Plot module provides functions to create plots of distributions and functions.
Raw functions and distributions are plotted with default parameters, while plot objects created by functions from this module give you more control over chart parameters and access to more complex charts.`,
},
{
name: "Number",
Expand Down

0 comments on commit 788a9b2

Please sign in to comment.