From 788a9b2092591637cf37c5fe7f3ffe7dd75514a2 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:37:40 -0800 Subject: [PATCH] Deprecated definitions shouldn't show, fixes Plot.dists example --- .../src/components/ui/FnDocumentation.tsx | 8 +- .../FnDocumentation.stories.tsx | 2 +- packages/squiggle-lang/src/fr/plot.ts | 152 +++++++++--------- packages/website/templates.mts | 7 + 4 files changed, 89 insertions(+), 80 deletions(-) diff --git a/packages/components/src/components/ui/FnDocumentation.tsx b/packages/components/src/components/ui/FnDocumentation.tsx index ab00aad9cc..dd9c19ef66 100644 --- a/packages/components/src/components/ui/FnDocumentation.tsx +++ b/packages/components/src/components/ui/FnDocumentation.tsx @@ -152,9 +152,11 @@ export const FnDocumentation: FC<{ textSize )} > - {definitions.map((def, id) => ( - - ))} + {definitions + .filter((def) => !def.deprecated) + .map((def, id) => ( + + ))} ) : null} diff --git a/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx b/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx index 099ac0ff51..77b3baefbf 100644 --- a/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx +++ b/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx @@ -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"); } diff --git a/packages/squiggle-lang/src/fr/plot.ts b/packages/squiggle-lang/src/fr/plot.ts index 6693496710..6893623a60 100644 --- a/packages/squiggle-lang/src/fr/plot.ts +++ b/packages/squiggle-lang/src/fr/plot.ts @@ -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: [ @@ -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", diff --git a/packages/website/templates.mts b/packages/website/templates.mts index 195cea7527..10e3176c9f 100644 --- a/packages/website/templates.mts +++ b/packages/website/templates.mts @@ -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",