From 0c0a9b4d324d73fcb9ba2048f87f164df2ad63a8 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 3 Jan 2024 21:57:43 -0800 Subject: [PATCH 01/16] Docs automation for number and string --- .../__tests__/reducer/various_test.ts | 6 +- packages/squiggle-lang/src/fr/boolean.ts | 22 +++ packages/squiggle-lang/src/fr/builtin.ts | 62 +----- packages/squiggle-lang/src/fr/list.ts | 16 +- packages/squiggle-lang/src/fr/number.ts | 110 +++++++++-- packages/squiggle-lang/src/fr/string.ts | 24 +++ .../src/library/registry/index.ts | 4 +- packages/website/.gitignore | 2 + .../website/src/pages/docs/Api/Number.mdx | 177 ------------------ packages/website/src/pages/docs/Api/String.md | 47 ----- packages/website/templates.mjs | 23 +++ packages/website/turbo.json | 2 + 12 files changed, 190 insertions(+), 305 deletions(-) create mode 100644 packages/squiggle-lang/src/fr/boolean.ts delete mode 100644 packages/website/src/pages/docs/Api/Number.mdx delete mode 100644 packages/website/src/pages/docs/Api/String.md diff --git a/packages/squiggle-lang/__tests__/reducer/various_test.ts b/packages/squiggle-lang/__tests__/reducer/various_test.ts index 32d295b2df..b4565529cd 100644 --- a/packages/squiggle-lang/__tests__/reducer/various_test.ts +++ b/packages/squiggle-lang/__tests__/reducer/various_test.ts @@ -127,15 +127,15 @@ describe("stacktraces", () => { expect(error).toBe( `Error: There are function matches for add(), but with different arguments: - add(Number, Number) => Number - add(String, String) => String - add(String, any) => String add(Date, Duration) => Date add(Duration, Date) => Date add(Duration, Duration) => Duration + add(Number, Number) => Number add(Dist, Number) => Dist add(Number, Dist) => Dist add(Dist, Dist) => Dist + add(String, String) => String + add(String, any) => String Was given arguments: (5,"a") Stack trace: f at line 4, column 5, file main diff --git a/packages/squiggle-lang/src/fr/boolean.ts b/packages/squiggle-lang/src/fr/boolean.ts new file mode 100644 index 0000000000..4039ff3262 --- /dev/null +++ b/packages/squiggle-lang/src/fr/boolean.ts @@ -0,0 +1,22 @@ +import { makeDefinition } from "../library/registry/fnDefinition.js"; +import { frBool } from "../library/registry/frTypes.js"; +import { FnFactory } from "../library/registry/helpers.js"; + +const maker = new FnFactory({ + nameSpace: "Boolean", + requiresNamespace: false, +}); + +export const library = [ + maker.bb2b({ name: "or", fn: (x, y) => x || y }), // infix || + maker.bb2b({ name: "and", fn: (x, y) => x && y }), // infix && + maker.make({ + name: "not", + definitions: [ + makeDefinition([frBool], frBool, ([x]) => { + // unary prefix ! + return !x; + }), + ], + }), +]; diff --git a/packages/squiggle-lang/src/fr/builtin.ts b/packages/squiggle-lang/src/fr/builtin.ts index e161505769..8537be71fb 100644 --- a/packages/squiggle-lang/src/fr/builtin.ts +++ b/packages/squiggle-lang/src/fr/builtin.ts @@ -1,17 +1,12 @@ import { makeDefinition } from "../library/registry/fnDefinition.js"; import { frAny, - frArray, frBool, frNamed, - frNumber, frOptional, frString, } from "../library/registry/frTypes.js"; -import { - FnFactory, - makeNumericComparisons, -} from "../library/registry/helpers.js"; +import { FnFactory } from "../library/registry/helpers.js"; import { isEqual } from "../value/index.js"; const maker = new FnFactory({ @@ -20,61 +15,6 @@ const maker = new FnFactory({ }); export const library = [ - maker.nn2n({ name: "add", fn: (x, y) => x + y }), // infix + (see Reducer/Reducer_Peggy/helpers.ts) - maker.ss2s({ name: "add", fn: (x, y) => x + y }), // infix + on strings - maker.nn2n({ name: "subtract", fn: (x, y) => x - y }), // infix - - maker.nn2n({ name: "multiply", fn: (x, y) => x * y }), // infix * - maker.nn2n({ name: "divide", fn: (x, y) => x / y }), // infix / - maker.nn2n({ name: "pow", fn: (x, y) => Math.pow(x, y) }), // infix ^ - ...makeNumericComparisons( - maker, - (d1, d2) => d1 < d2, - (d1, d2) => d1 > d2, - (d1, d2) => d1 === d2, - frNumber - ), - maker.bb2b({ name: "or", fn: (x, y) => x || y }), // infix || - maker.bb2b({ name: "and", fn: (x, y) => x && y }), // infix && - maker.n2n({ name: "unaryMinus", fn: (x) => -x }), // unary prefix - - maker.make({ - name: "not", - definitions: [ - makeDefinition([frNumber], frBool, ([x]) => { - // unary prefix ! - return x === 0; - }), - makeDefinition([frBool], frBool, ([x]) => { - // unary prefix ! - return !x; - }), - ], - }), - maker.make({ - name: "concat", - definitions: [ - makeDefinition([frString, frString], frString, ([a, b]) => { - return a + b; - }), - makeDefinition( - [frArray(frAny()), frArray(frAny())], - frArray(frAny()), - ([a, b]) => { - return [...a, ...b]; - } - ), - makeDefinition([frString, frAny()], frString, ([a, b]) => { - return a + b.toString(); - }), - ], - }), - maker.make({ - name: "add", - definitions: [ - makeDefinition([frString, frAny()], frString, ([a, b]) => { - return a + b.toString(); - }), - ], - }), maker.make({ name: "equal", definitions: [ diff --git a/packages/squiggle-lang/src/fr/list.ts b/packages/squiggle-lang/src/fr/list.ts index a8d83f03e1..5116d3bf3f 100644 --- a/packages/squiggle-lang/src/fr/list.ts +++ b/packages/squiggle-lang/src/fr/list.ts @@ -273,7 +273,7 @@ export const library = [ maker.make({ name: "concat", - requiresNamespace: true, + requiresNamespace: false, examples: [`List.concat([1,2,3], [4, 5, 6])`], displaySection: "Modifications", definitions: [ @@ -678,6 +678,7 @@ List.reduceWhile([5, 6, 7], { x: 0 }, {|acc, curr| { x: acc.x + curr }}, {|acc| name: "join", requiresNamespace: true, examples: [`List.join(["a", "b", "c"], ",") // "a,b,c"`], + displaySection: "Modifications", definitions: [ makeDefinition( [frArray(frString), frNamed("separator", frOptional(frString))], @@ -687,6 +688,19 @@ List.reduceWhile([5, 6, 7], { x: 0 }, {|acc, curr| { x: acc.x + curr }}, {|acc| makeDefinition([frArray(frString)], frString, ([array]) => array.join()), ], }), + maker.make({ + name: "concat", + displaySection: "Modifications", + definitions: [ + makeDefinition( + [frArray(frAny()), frArray(frAny())], + frArray(frAny()), + ([a, b]) => { + return [...a, ...b]; + } + ), + ], + }), maker.make({ name: "flatten", requiresNamespace: true, diff --git a/packages/squiggle-lang/src/fr/number.ts b/packages/squiggle-lang/src/fr/number.ts index 71223f33e3..56114e9fa0 100644 --- a/packages/squiggle-lang/src/fr/number.ts +++ b/packages/squiggle-lang/src/fr/number.ts @@ -2,11 +2,15 @@ import { REArgumentError } from "../errors/messages.js"; import { makeDefinition } from "../library/registry/fnDefinition.js"; import { frArray, + frBool, frDomain, frNamed, frNumber, } from "../library/registry/frTypes.js"; -import { FnFactory } from "../library/registry/helpers.js"; +import { + FnFactory, + makeNumericComparisons, +} from "../library/registry/helpers.js"; import * as E_A_Floats from "../utility/E_A_Floats.js"; import { NumericRangeDomain } from "../value/domain.js"; @@ -42,28 +46,51 @@ function makeNumberArrayToNumberArrayDefinition( } export const library = [ - maker.n2n({ - name: "floor", - output: "Number", - examples: [`floor(3.5)`], - fn: Math.floor, + ...makeNumericComparisons( + maker, + (d1, d2) => d1 < d2, + (d1, d2) => d1 > d2, + (d1, d2) => d1 === d2, + frNumber, + "Comparison" + ), + maker.nn2n({ + name: "add", + displaySection: "Algebra (Number)", + fn: (x, y) => x + y, }), - maker.n2n({ - name: "ceil", - output: "Number", - examples: ["ceil(3.5)"], - fn: Math.ceil, + maker.nn2n({ + name: "subtract", + displaySection: "Algebra (Number)", + fn: (x, y) => x - y, + }), + maker.nn2n({ + name: "multiply", + displaySection: "Algebra (Number)", + fn: (x, y) => x * y, + }), + maker.nn2n({ + name: "divide", + displaySection: "Algebra (Number)", + fn: (x, y) => x / y, + }), + maker.nn2n({ + name: "pow", + displaySection: "Algebra (Number)", + fn: (x, y) => Math.pow(x, y), }), maker.n2n({ - name: "abs", + name: "unaryMinus", output: "Number", - description: "absolute value", - examples: [`abs(3.5)`], - fn: Math.abs, + displaySection: "Functions (Number)", + description: "exponent", + examples: [`exp(3.5)`], + fn: (x) => -x, }), maker.n2n({ name: "exp", output: "Number", + displaySection: "Functions (Number)", description: "exponent", examples: [`exp(3.5)`], fn: Math.exp, @@ -71,30 +98,69 @@ export const library = [ maker.n2n({ name: "log", output: "Number", + displaySection: "Functions (Number)", examples: [`log(3.5)`], fn: Math.log, }), maker.n2n({ name: "log10", output: "Number", + displaySection: "Functions (Number)", examples: [`log10(3.5)`], fn: Math.log10, }), maker.n2n({ name: "log2", output: "Number", + displaySection: "Functions (Number)", examples: [`log2(3.5)`], fn: Math.log2, }), + maker.n2n({ + name: "floor", + output: "Number", + displaySection: "Functions (Number)", + examples: [`floor(3.5)`], + fn: Math.floor, + }), + maker.n2n({ + name: "ceil", + output: "Number", + displaySection: "Functions (Number)", + examples: ["ceil(3.5)"], + fn: Math.ceil, + }), + maker.n2n({ + name: "abs", + output: "Number", + displaySection: "Functions (Number)", + description: "absolute value", + examples: [`abs(3.5)`], + fn: Math.abs, + }), maker.n2n({ name: "round", output: "Number", + displaySection: "Functions (Number)", examples: [`round(3.5)`], fn: Math.round, }), + maker.make({ + name: "not", + output: "Bool", + displaySection: "Function (Number)", + examples: [`not(3.5)`], + definitions: [ + makeDefinition([frNumber], frBool, ([x]) => { + // unary prefix ! + return x === 0; + }), + ], + }), maker.make({ name: "sum", output: "Number", + displaySection: "Algebra (List)", examples: [`sum([3,5,2])`], definitions: [ makeNumberArrayToNumberDefinition((arr) => E_A_Floats.sum(arr), false), @@ -103,6 +169,7 @@ export const library = [ maker.make({ name: "product", output: "Number", + displaySection: "Algebra (List)", examples: [`product([3,5,2])`], definitions: [ makeNumberArrayToNumberDefinition( @@ -114,6 +181,7 @@ export const library = [ maker.make({ name: "min", output: "Number", + displaySection: "Functions (List)", examples: [`min([3,5,2])`], definitions: [ makeNumberArrayToNumberDefinition((arr) => Math.min(...arr)), @@ -125,6 +193,7 @@ export const library = [ maker.make({ name: "max", output: "Number", + displaySection: "Functions (List)", examples: [`max([3,5,2])`], definitions: [ makeNumberArrayToNumberDefinition((arr) => Math.max(...arr)), @@ -136,6 +205,7 @@ export const library = [ maker.make({ name: "mean", output: "Number", + displaySection: "Functions (List)", examples: [`mean([3,5,2])`], definitions: [ makeNumberArrayToNumberDefinition((arr) => E_A_Floats.mean(arr)), @@ -145,6 +215,7 @@ export const library = [ name: "quantile", output: "Number", examples: [`quantile([1,5,10,40,2,4], 0.3)`], + displaySection: "Functions (List)", definitions: [ makeDefinition([frArray(frNumber), frNumber], frNumber, ([arr, i]) => { assertIsNotEmpty(arr); @@ -156,6 +227,7 @@ export const library = [ name: "median", output: "Number", examples: [`median([1,5,10,40,2,4])`], + displaySection: "Functions (List)", definitions: [ makeDefinition([frArray(frNumber)], frNumber, ([arr]) => { assertIsNotEmpty(arr); @@ -168,6 +240,7 @@ export const library = [ description: "geometric mean", output: "Number", examples: [`geomean([3,5,2])`], + displaySection: "Functions (List)", definitions: [ makeNumberArrayToNumberDefinition((arr) => E_A_Floats.geomean(arr)), ], @@ -177,6 +250,7 @@ export const library = [ description: "standard deviation", output: "Number", examples: [`stdev([3,5,2,3,5])`], + displaySection: "Functions (List)", definitions: [ makeNumberArrayToNumberDefinition((arr) => E_A_Floats.stdev(arr)), ], @@ -185,6 +259,7 @@ export const library = [ name: "variance", output: "Number", examples: [`variance([3,5,2,3,5])`], + displaySection: "Functions (List)", definitions: [ makeNumberArrayToNumberDefinition((arr) => E_A_Floats.variance(arr)), ], @@ -193,6 +268,7 @@ export const library = [ name: "sort", output: "Array", examples: [`sort([3,5,2,3,5])`], + displaySection: "Functions (List)", definitions: [ makeNumberArrayToNumberArrayDefinition( (arr) => E_A_Floats.sort(arr), @@ -204,6 +280,7 @@ export const library = [ name: "cumsum", output: "Array", description: "cumulative sum", + displaySection: "Algegra (List)", examples: [`cumsum([3,5,2,3,5])`], definitions: [ makeNumberArrayToNumberArrayDefinition(E_A_Floats.cumSum, false), @@ -213,6 +290,7 @@ export const library = [ name: "cumprod", description: "cumulative product", output: "Array", + displaySection: "Algebra (List)", examples: [`cumprod([3,5,2,3,5])`], definitions: [ makeNumberArrayToNumberArrayDefinition(E_A_Floats.cumProd, false), @@ -221,6 +299,7 @@ export const library = [ maker.make({ name: "diff", output: "Array", + displaySection: "Algebra (List)", examples: [`diff([3,5,2,3,5])`], definitions: [makeNumberArrayToNumberArrayDefinition(E_A_Floats.diff)], }), @@ -228,6 +307,7 @@ export const library = [ name: "rangeDomain", requiresNamespace: true, output: "Domain", + displaySection: "Utils", examples: ["Number.rangeDomain(5, 10)"], definitions: [ makeDefinition( diff --git a/packages/squiggle-lang/src/fr/string.ts b/packages/squiggle-lang/src/fr/string.ts index daff67205d..e25dbb8767 100644 --- a/packages/squiggle-lang/src/fr/string.ts +++ b/packages/squiggle-lang/src/fr/string.ts @@ -16,8 +16,32 @@ export const library = [ maker.make({ name: "make", output: "String", + description: + "Converts any value to a string. Some information is often lost.", definitions: [makeDefinition([frAny()], frString, ([x]) => x.toString())], }), + maker.ss2s({ name: "add", requiresNamespace: false, fn: (x, y) => x + y }), // infix + on strings + maker.make({ + name: "concat", + requiresNamespace: false, + definitions: [ + makeDefinition([frString, frString], frString, ([a, b]) => { + return a + b; + }), + makeDefinition([frString, frAny()], frString, ([a, b]) => { + return a + b.toString(); + }), + ], + }), + maker.make({ + name: "add", + requiresNamespace: false, + definitions: [ + makeDefinition([frString, frAny()], frString, ([a, b]) => { + return a + b.toString(); + }), + ], + }), maker.make({ name: "split", definitions: [ diff --git a/packages/squiggle-lang/src/library/registry/index.ts b/packages/squiggle-lang/src/library/registry/index.ts index f63982221c..da309d1028 100644 --- a/packages/squiggle-lang/src/library/registry/index.ts +++ b/packages/squiggle-lang/src/library/registry/index.ts @@ -1,3 +1,4 @@ +import { library as booleanLibrary } from "../../fr/boolean.js"; import { library as builtinLibrary } from "../../fr/builtin.js"; import { library as calculatorLibrary } from "../../fr/calculator.js"; import { library as dangerLibrary } from "../../fr/danger.js"; @@ -29,7 +30,7 @@ import { ImmutableMap } from "../../utility/immutableMap.js"; import { FRFunction, Registry } from "./core.js"; const fnList: FRFunction[] = [ - ...builtinLibrary, + ...booleanLibrary, ...dangerLibrary, ...dateLibrary, ...dictLibrary, @@ -53,6 +54,7 @@ const fnList: FRFunction[] = [ ...unitsLibrary, ...calculatorLibrary, ...inputLibrary, + ...builtinLibrary, // should go last, because has some catch-all functions ]; export const registry = Registry.make(fnList); diff --git a/packages/website/.gitignore b/packages/website/.gitignore index 6f737c587e..279ee9d204 100644 --- a/packages/website/.gitignore +++ b/packages/website/.gitignore @@ -15,5 +15,7 @@ /src/pages/docs/Api/List.mdx /src/pages/docs/Api/Danger.mdx /src/pages/docs/Api/Dist.mdx +/src/pages/docs/Api/Number.mdx +/src/pages/docs/Api/String.mdx /src/pages/docs/Ecosystem/LLMPrompt.md /public/llms/documentationBundle.txt diff --git a/packages/website/src/pages/docs/Api/Number.mdx b/packages/website/src/pages/docs/Api/Number.mdx deleted file mode 100644 index 5fa5f353a7..0000000000 --- a/packages/website/src/pages/docs/Api/Number.mdx +++ /dev/null @@ -1,177 +0,0 @@ ---- -description: Squiggle numbers are Javascript floats. ---- - -# Number - -Squiggle `numbers` are Javascript floats. - -Many of the functions below work on lists or pairs of numbers. - -### ceil - -``` -ceil: (number) => number -``` - -### floor - -``` -floor: (number) => number -``` - -### abs - -``` -abs: (number) => number -``` - -### round - -``` -round: (number) => number -``` - -## Statistics - -### max - -``` -max: (list) => number -max: (number, number) => number -``` - -### min - -``` -min: (list) => number -min: (number, number) => number -``` - -### mean - -``` -mean: (list) => number -``` - -### geometric mean - -``` -geomean: (list) => number -``` - -### stdev - -``` -stdev: (list) => number -``` - -### variance - -``` -variance: (list) => number -``` - -### median - -``` -median: (list) => number -``` - -### quantile - -``` -quantile: (list, number) => number -``` - -## Algebra - -### unaryMinus - -``` -unaryMinus: (number) => number -``` - -### equal - -``` -equal: (number, number) => boolean -``` - -### add - -``` -add: (number, number) => number -``` - -### sum - -``` -sum: (list) => number -``` - -### cumulative sum - -``` -cumsum: (list) => list -``` - -### multiply - -``` -multiply: (number, number) => number -``` - -### product - -``` -product: (list) => number -``` - -### cumulative product - -``` -cumprod: (list) => list -``` - -### diff - -``` -diff: (list) => list -``` - -### sort - -``` -sort: (list) => list -``` - -### subtract - -``` -subtract: (number, number) => number -``` - -### divide - -``` -divide: (number, number) => number -``` - -### pow - -``` -pow: (number, number) => number -``` - -### exp - -``` -exp: (number) => number -``` - -### log - -``` -log: (number) => number -``` diff --git a/packages/website/src/pages/docs/Api/String.md b/packages/website/src/pages/docs/Api/String.md deleted file mode 100644 index 085f69b724..0000000000 --- a/packages/website/src/pages/docs/Api/String.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -description: Functions for working with strings in Squiggle ---- - -# String - -Strings support all JSON escape sequences, with addition of escaped single-quotes (for single-quoted strings) - -```js -a = "'\" NUL:\u0000" -b = '\'" NUL:\u0000' -``` - -### make - -Converts any type to a simple string. Note that information is typically lost in this process. - -``` -make: (any) => string -``` - -```squiggle -String.make(5 to 40) -String.make([3,4,5,2]) -``` -### concat - -``` -concat: (string, string) => string -``` - -```squiggle -s1 = concat("foo", "bar") // foobar -s2 = "foo" + "bar" // foobar -s3 = "foo" + 3 // foo3 -``` - -### split - -``` -split: (string, string) => list -``` - -```squiggle -foo = "this_is_a_sentence" -bar = String.split(foo, "_") -``` \ No newline at end of file diff --git a/packages/website/templates.mjs b/packages/website/templates.mjs index c46147abf7..1230f2abbd 100644 --- a/packages/website/templates.mjs +++ b/packages/website/templates.mjs @@ -86,6 +86,29 @@ Calculators can be useful for debugging functions or to present functions to end "Squiggle dictionaries work similar to Python dictionaries. The syntax is similar to objects in Javascript.", intro: ` `, + }, + { + name: "Number", + sections: [ + { name: "Comparison" }, + { name: "Algebra (Number)" }, + { name: "Functions (Number)" }, + { name: "Algebra (List)" }, + { name: "Functions (List)" }, + { name: "Utils" }, + ], + description: "Squiggle numbers are Javascript floats.", + intro: "Squiggle numbers are Javascript floats.", + }, + { + name: "String", + description: "Functions for working with strings in Squiggle", + intro: `Strings support all JSON escape sequences, with addition of escaped single-quotes (for single-quoted strings) + +~~~squiggle +a = "'\" NUL:\u0000" +b = '\'" NUL:\u0000' +~~~`, }, { name: "Input", diff --git a/packages/website/turbo.json b/packages/website/turbo.json index 109342e54b..b64e4d9ebe 100644 --- a/packages/website/turbo.json +++ b/packages/website/turbo.json @@ -22,6 +22,8 @@ "/src/pages/docs/Api/List.mdx", "/src/pages/docs/Api/Danger.mdx", "/src/pages/docs/Api/Dist.mdx", + "/src/pages/docs/Api/Number.mdx", + "/src/pages/docs/Api/String.mdx", "src/pages/docs/Ecosystem/LLMPrompt.md" ] }, From 65d76de1b0f8451ed02bf654e4ced614cf2902ae Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 3 Jan 2024 22:16:56 -0800 Subject: [PATCH 02/16] Autogenerate RelativeValues, Boolean. Changed BuiltIn to Common --- packages/squiggle-lang/src/fr/builtin.ts | 5 +++- .../squiggle-lang/src/fr/relativeValues.ts | 6 ++-- packages/website/.gitignore | 3 ++ .../website/src/pages/docs/Api/BuiltIn.mdx | 30 ------------------- .../src/pages/docs/Api/RelativeValues.mdx | 13 -------- .../website/src/pages/docs/Api/_meta.json | 3 +- packages/website/templates.mjs | 17 +++++++++++ packages/website/turbo.json | 3 ++ 8 files changed, 32 insertions(+), 48 deletions(-) delete mode 100644 packages/website/src/pages/docs/Api/BuiltIn.mdx delete mode 100644 packages/website/src/pages/docs/Api/RelativeValues.mdx diff --git a/packages/squiggle-lang/src/fr/builtin.ts b/packages/squiggle-lang/src/fr/builtin.ts index 8537be71fb..40d479fb50 100644 --- a/packages/squiggle-lang/src/fr/builtin.ts +++ b/packages/squiggle-lang/src/fr/builtin.ts @@ -10,7 +10,7 @@ import { FnFactory } from "../library/registry/helpers.js"; import { isEqual } from "../value/index.js"; const maker = new FnFactory({ - nameSpace: "", // no namespaced versions + nameSpace: "Common", // no namespaced versions requiresNamespace: false, }); @@ -33,6 +33,8 @@ export const library = [ }), maker.make({ name: "typeOf", + description: + "Returns the type of the value passed in as a string. This is useful when you want to treat a value differently depending on its type.", definitions: [ makeDefinition([frAny()], frString, ([value]) => { return value.publicName; @@ -41,6 +43,7 @@ export const library = [ }), maker.make({ name: "inspect", + description: `Runs Console.log() in the [Javascript developer console](https://www.digitalocean.com/community/tutorials/how-to-use-the-javascript-developer-console) and returns the value passed in.`, definitions: [ makeDefinition( [frAny({ genericName: "A" }), frNamed("message", frOptional(frString))], diff --git a/packages/squiggle-lang/src/fr/relativeValues.ts b/packages/squiggle-lang/src/fr/relativeValues.ts index 16b51a2aee..57632b46f4 100644 --- a/packages/squiggle-lang/src/fr/relativeValues.ts +++ b/packages/squiggle-lang/src/fr/relativeValues.ts @@ -30,9 +30,9 @@ export const library = [ output: "Plot", examples: [ `RelativeValues.gridPlot({ - ids: ["foo", "bar"], - fn: {|id1, id2| [SampleSet.fromDist(2 to 5), SampleSet.fromDist(3 to 6)]}, - })`, + ids: ["foo", "bar"], + fn: {|id1, id2| [SampleSet.fromDist(2 to 5), SampleSet.fromDist(3 to 6)]}, +})`, ], definitions: [ makeDefinition([relativeValuesShape], frPlot, ([{ ids, fn, title }]) => { diff --git a/packages/website/.gitignore b/packages/website/.gitignore index 279ee9d204..1b07693df7 100644 --- a/packages/website/.gitignore +++ b/packages/website/.gitignore @@ -17,5 +17,8 @@ /src/pages/docs/Api/Dist.mdx /src/pages/docs/Api/Number.mdx /src/pages/docs/Api/String.mdx +/src/pages/docs/Api/Common.mdx +/src/pages/docs/Api/Boolean.mdx +/src/pages/docs/Api/RelativeValues.mdx /src/pages/docs/Ecosystem/LLMPrompt.md /public/llms/documentationBundle.txt diff --git a/packages/website/src/pages/docs/Api/BuiltIn.mdx b/packages/website/src/pages/docs/Api/BuiltIn.mdx deleted file mode 100644 index 6c2693c74f..0000000000 --- a/packages/website/src/pages/docs/Api/BuiltIn.mdx +++ /dev/null @@ -1,30 +0,0 @@ ---- -description: Builtin functions that work on many types. ---- - -### typeOf - -Returns the type of the value passed in as a string. This is useful when you want to treat a value differently depending on its type. - -``` -typeOf: (any) => string -``` - -```squiggle -fn(v) = if typeOf(v) == "String" then v else if typeOf(v) == - "Number" then "the number: " + v else "other" -``` - -### inspect - -Runs Console.log() in the [Javascript developer console](https://www.digitalocean.com/community/tutorials/how-to-use-the-javascript-developer-console) and returns the value passed in. - -``` -inspect: (`a) => `a -inspect: (`a, string) => `a -``` - -```squiggle -foo = inspect(5 to 10) // sets foo to (5 to 10) and logs it to the console -foo = inspect(5 to 10, "my range") -``` \ No newline at end of file diff --git a/packages/website/src/pages/docs/Api/RelativeValues.mdx b/packages/website/src/pages/docs/Api/RelativeValues.mdx deleted file mode 100644 index fbe98c7a82..0000000000 --- a/packages/website/src/pages/docs/Api/RelativeValues.mdx +++ /dev/null @@ -1,13 +0,0 @@ -# Relative Values - -Warning: Relative value functions are experimental and subject to change. - -### RelativeValues.gridPlot - -``` -RelativeValues.gridPlot: ({ - ids: list, - fn: (string, string) => [distribution, distribution], - title?: string -}) => plot -``` diff --git a/packages/website/src/pages/docs/Api/_meta.json b/packages/website/src/pages/docs/Api/_meta.json index 3c014d7438..0a536d6521 100644 --- a/packages/website/src/pages/docs/Api/_meta.json +++ b/packages/website/src/pages/docs/Api/_meta.json @@ -1,5 +1,6 @@ { - "BuiltIn": "Built In", + "Common": "Common", + "Boolean": "Boolean", "Date": "Date", "Dict": "Dictionary", "Dist": "Distribution", diff --git a/packages/website/templates.mjs b/packages/website/templates.mjs index 1230f2abbd..915d774eef 100644 --- a/packages/website/templates.mjs +++ b/packages/website/templates.mjs @@ -87,6 +87,17 @@ Calculators can be useful for debugging functions or to present functions to end intro: ` `, }, + { + name: "Boolean", + description: "", + intro: ` +`, + }, + { + name: "Common", + description: "", + intro: `Functions that work on many different types of values.`, + }, { name: "Number", sections: [ @@ -100,6 +111,12 @@ Calculators can be useful for debugging functions or to present functions to end description: "Squiggle numbers are Javascript floats.", intro: "Squiggle numbers are Javascript floats.", }, + { + name: "RelativeValues", + description: "", + intro: + "*Warning: Relative value functions are particularly experimental and subject to change.*", + }, { name: "String", description: "Functions for working with strings in Squiggle", diff --git a/packages/website/turbo.json b/packages/website/turbo.json index b64e4d9ebe..60d719a817 100644 --- a/packages/website/turbo.json +++ b/packages/website/turbo.json @@ -24,6 +24,9 @@ "/src/pages/docs/Api/Dist.mdx", "/src/pages/docs/Api/Number.mdx", "/src/pages/docs/Api/String.mdx", + "/src/pages/docs/Api/Common.mdx", + "/src/pages/docs/Api/Boolean.mdx", + "/src/pages/docs/Api/RelativeValues.mdx", "src/pages/docs/Ecosystem/LLMPrompt.md" ] }, From 5dfba1791bec8928dacd2ffd9834991f44aec3f2 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 5 Jan 2024 11:38:44 -0800 Subject: [PATCH 03/16] Added interactive examples and tests for Plots --- .../__tests__/library/examples_test.ts | 5 +- packages/squiggle-lang/src/fr/plot.ts | 63 ++++++++++++++++--- .../squiggle-lang/src/fr/relativeValues.ts | 2 +- .../src/library/registry/core.ts | 14 +++-- 4 files changed, 68 insertions(+), 16 deletions(-) diff --git a/packages/squiggle-lang/__tests__/library/examples_test.ts b/packages/squiggle-lang/__tests__/library/examples_test.ts index 67c8c83fc3..f72432a573 100644 --- a/packages/squiggle-lang/__tests__/library/examples_test.ts +++ b/packages/squiggle-lang/__tests__/library/examples_test.ts @@ -5,14 +5,15 @@ test.each(registry.allExamplesWithFns())( "tests of example $example", async ({ fn, example }) => { const result = await evaluateStringToResult(example); - expect(result.ok).toBe(true); if (!result.ok) { - throw new Error("Can't test type"); + throw new Error(`Can't test type, with error: ${result.value}`); } if (fn.output !== undefined) { expect(result.value.type).toEqual(fn.output); } + + expect(result.ok).toBe(true); } ); diff --git a/packages/squiggle-lang/src/fr/plot.ts b/packages/squiggle-lang/src/fr/plot.ts index 50ee97c9b2..df16b56672 100644 --- a/packages/squiggle-lang/src/fr/plot.ts +++ b/packages/squiggle-lang/src/fr/plot.ts @@ -167,8 +167,11 @@ const numericFnDef = () => { return maker.make({ name: "numericFn", output: "Plot", - examples: [ - `Plot.numericFn({|x|x*x}, {xScale: Scale.linear({ min: 3, max: 5 }), yScale: Scale.log({ tickFormat: ".2s" }) })`, + interactiveExamples: [ + `Plot.numericFn( + {|t|t ^ 2}, + { xScale: Scale.log({ min: 1, max: 100 }), points: 10 } +)`, ], definitions: [ makeDefinition( @@ -228,11 +231,16 @@ export const library = [ maker.make({ name: "dists", output: "Plot", - examples: [ - `Plot.dists({ - dists: [{ name: "dist", value: normal(0, 1) }], - xScale: Scale.symlog() -})`, + interactiveExamples: [ + `Plot.distFn( + {|t|normal(t, 2) * normal(5, 3)}, + { + 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" }), + } +)`, ], definitions: [ makeDefinition( @@ -333,6 +341,17 @@ export const library = [ xScale: Scale.symlog() })`, ], + 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( [ @@ -392,8 +411,16 @@ export const library = [ maker.make({ name: "distFn", output: "Plot", - examples: [ - `Plot.distFn({|x| uniform(x, x+1)}, {xScale: Scale.linear({ min: 3, max: 5}), yScale: Scale.log({ tickFormat: ".2s" })})`, + interactiveExamples: [ + `Plot.distFn( + {|t|normal(t, 2) * normal(5, 3)}, + { + 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" }), + } +)`, ], definitions: [ makeDefinition( @@ -466,6 +493,24 @@ export const library = [ `Plot.scatter({ xDist: 2 to 5, yDist: SampleSet.fromDist(1 to 3) })`, `Plot.scatter({ xDist: 2 to 5, yDist: SampleSet.fromDist(1 to 3), xScale: Scale.symlog(), yScale: Scale.symlog() })`, ], + interactiveExamples: [ + `xDist = SampleSet.fromDist(2 to 5) +yDist = normal({p5:-3, p95:3}) * 5 - xDist ^ 2 +Plot.scatter({ + xDist: xDist, + yDist: yDist, + xScale: Scale.log({min: 1.5}), +})`, + `xDist = SampleSet.fromDist(normal({p5:-2, p95:5})) +yDist = normal({p5:-3, p95:3}) * 5 - xDist +Plot.scatter({ + title: "A Scatterplot", + xDist: xDist, + yDist: yDist, + xScale: Scale.symlog({title: "X Axis Title"}), + yScale: Scale.symlog({title: "Y Axis Title"}), +})`, + ], definitions: [ makeDefinition( [ diff --git a/packages/squiggle-lang/src/fr/relativeValues.ts b/packages/squiggle-lang/src/fr/relativeValues.ts index 57632b46f4..1c4e004bdb 100644 --- a/packages/squiggle-lang/src/fr/relativeValues.ts +++ b/packages/squiggle-lang/src/fr/relativeValues.ts @@ -28,7 +28,7 @@ export const library = [ maker.make({ name: "gridPlot", output: "Plot", - examples: [ + interactiveExamples: [ `RelativeValues.gridPlot({ ids: ["foo", "bar"], fn: {|id1, id2| [SampleSet.fromDist(2 to 5), SampleSet.fromDist(3 to 6)]}, diff --git a/packages/squiggle-lang/src/library/registry/core.ts b/packages/squiggle-lang/src/library/registry/core.ts index 0e08d07e09..a7d6377d47 100644 --- a/packages/squiggle-lang/src/library/registry/core.ts +++ b/packages/squiggle-lang/src/library/registry/core.ts @@ -19,6 +19,7 @@ export type FRFunction = { definitions: FnDefinition[]; output?: Value["type"]; examples?: string[]; + interactiveExamples?: string[]; description?: string; isExperimental?: boolean; isUnit?: boolean; @@ -36,6 +37,7 @@ export type FnDocumentation = Pick< | "definitions" | "name" | "examples" + | "interactiveExamples" | "isExperimental" | "isUnit" | "shorthand" @@ -78,13 +80,16 @@ export class Registry { allExamplesWithFns(): { fn: FRFunction; example: string }[] { return this.functions - .map( - (fn) => + .map((fn) => { + const regularExamples = fn.examples?.map((example) => ({ fn, example, - })) ?? [] - ) + })) ?? []; + const interactiveExamples = + fn.interactiveExamples?.map((example) => ({ fn, example })) ?? []; + return [...regularExamples, ...interactiveExamples]; + }) .flat(); } @@ -134,6 +139,7 @@ export class Registry { description: fn.description, definitions: fn.definitions, examples: fn.examples, + interactiveExamples: fn.interactiveExamples, signatures: fn.definitions .filter((d) => showInDocumentation(d)) .map(fnDefinitionToString), From 02db0ce48794d575996f11c46ead84621efecd1b Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 5 Jan 2024 13:11:36 -0800 Subject: [PATCH 04/16] Improving FnDocumentation to have SquiggleEditor work well in docs --- .../src/components/CodeEditor/index.tsx | 5 +- .../src/components/SquiggleEditor.tsx | 5 +- .../src/components/ui/FnDocumentation.tsx | 48 ++++++++++++++----- .../FnDocumentation.stories.tsx | 47 ++++++++++++++++-- .../DistributionSizes.stories.tsx | 14 ++++++ packages/squiggle-lang/src/fr/plot.ts | 10 +++- 6 files changed, 109 insertions(+), 20 deletions(-) diff --git a/packages/components/src/components/CodeEditor/index.tsx b/packages/components/src/components/CodeEditor/index.tsx index 38d942fe00..8f213f5a71 100644 --- a/packages/components/src/components/CodeEditor/index.tsx +++ b/packages/components/src/components/CodeEditor/index.tsx @@ -16,6 +16,7 @@ export type CodeEditorProps = { lineWrapping?: boolean; errors?: SqError[]; sourceId?: string; + fontSize?: number; project: SqProject; }; @@ -42,6 +43,8 @@ export const CodeEditor = forwardRef( scrollTo, })); - return
; + return ( +
+ ); } ); diff --git a/packages/components/src/components/SquiggleEditor.tsx b/packages/components/src/components/SquiggleEditor.tsx index ea99d6714b..edef0d373b 100644 --- a/packages/components/src/components/SquiggleEditor.tsx +++ b/packages/components/src/components/SquiggleEditor.tsx @@ -11,6 +11,7 @@ import { SquiggleCodeProps } from "./types.js"; export type SquiggleEditorProps = SquiggleCodeProps & { hideViewer?: boolean; + editorFontSize?: number; // environment comes from SquiggleCodeProps } & Omit; @@ -21,6 +22,7 @@ export const SquiggleEditor: FC = ({ continues, environment, hideViewer, + editorFontSize, ...settings }) => { const { code, setCode, defaultCode } = useUncontrolledCode({ @@ -48,12 +50,13 @@ export const SquiggleEditor: FC = ({ return (
@@ -81,11 +87,16 @@ export const FnDocumentation: FC<{ href={`${SQUIGGLE_DOCS_URL}/${nameSpace}#${name}`} target="_blank" rel="noreferrer" - className="text-blue-500 hover:underline text-sm leading-none" + className={clsx( + "text-blue-500 hover:underline leading-none", + size === "small" ? "text-sm" : "text-md" + )} > {fullName} -
+
Stdlib
@@ -93,7 +104,7 @@ export const FnDocumentation: FC<{ )} {(isUnit || shorthand || isExperimental || !requiresNamespace) && (
-
+
{isUnit && (
Unit @@ -147,19 +158,30 @@ export const FnDocumentation: FC<{
) : null} - {examples?.length ? ( + {examples?.length ?? interactiveExamples?.length ? (
Examples
- {examples.map((example, i) => ( - + {examples && + examples.map((example, i) => ( + + ))} + {(interactiveExamples ?? []).map((example, i) => ( +
+ +
))}
) : null} diff --git a/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx b/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx index 0eda7e1723..099ac0ff51 100644 --- a/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx +++ b/packages/components/src/stories/InternalComponents/FnDocumentation.stories.tsx @@ -40,12 +40,43 @@ FnStory.story = { name: "All", }; -const documentation: FnDocumentationType = { +const fnDocumentation = getFunctionDocumentation("Plot.dist"); +if (!fnDocumentation) { + throw new Error("fnDocumentation is undefined"); +} + +const exampleDocumentation: FnDocumentationType = { name: "add", nameSpace: "Number", requiresNamespace: false, signatures: ["(number, number) => number"], - examples: ["add(5,2)"], + examples: [ + `xDist = SampleSet.fromDist(2 to 5) +yDist = normal({p5:-3, p95:3}) * 5 - xDist ^ 2 +Plot.scatter({ + xDist: xDist, + yDist: yDist, + xScale: Scale.log({min: 1.5}), +})`, + ], + interactiveExamples: [ + `xDist = SampleSet.fromDist(2 to 5) +yDist = normal({p5:-3, p95:3}) * 5 - xDist ^ 2 +Plot.scatter({ + xDist: xDist, + yDist: yDist, + xScale: Scale.log({min: 1.5}), +})`, + `xDist = SampleSet.fromDist(normal({p5:-2, p95:5})) +yDist = normal({p5:-3, p95:3}) * 5 - xDist +Plot.scatter({ + title: "A Scatterplot", + xDist: xDist, + yDist: yDist, + xScale: Scale.symlog({title: "X Axis Title"}), + yScale: Scale.symlog({title: "Y Axis Title"}), +})`, + ], isExperimental: true, definitions: [], isUnit: true, @@ -57,7 +88,17 @@ More content *here*`, export const Simple: Story = { name: "Normal", args: { - documentation, + documentation: exampleDocumentation, + showNameAndDescription: true, + size: "normal", + }, +}; + +export const Existing: Story = { + name: "Existing", + args: { + documentation: fnDocumentation, showNameAndDescription: true, + size: "small", }, }; diff --git a/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx b/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx index 9e4270a09e..33f9ed651e 100644 --- a/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx +++ b/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx @@ -31,6 +31,20 @@ export const Height40: Story = { code, }, }; +export const Height40WithLabels: Story = { + name: "Height 40 with labels", + args: { + chartHeight: 50, + code: `Plot.dist( + normal(5, 2), + { + xScale: Scale.linear({ min: -2, max: 6, title: "X Axis Title" }), + title: "A Simple Normal Distribution", + showSummary: true, + } + )`, + }, +}; export const Height100: Story = { name: "Height 100", diff --git a/packages/squiggle-lang/src/fr/plot.ts b/packages/squiggle-lang/src/fr/plot.ts index df16b56672..c0f376d9b0 100644 --- a/packages/squiggle-lang/src/fr/plot.ts +++ b/packages/squiggle-lang/src/fr/plot.ts @@ -490,8 +490,14 @@ export const library = [ name: "scatter", output: "Plot", examples: [ - `Plot.scatter({ xDist: 2 to 5, yDist: SampleSet.fromDist(1 to 3) })`, - `Plot.scatter({ xDist: 2 to 5, yDist: SampleSet.fromDist(1 to 3), xScale: Scale.symlog(), yScale: Scale.symlog() })`, + `Plot.scatter( + { + xDist: 2 to 5, + yDist: SampleSet.fromDist(1 to 3), + xScale: Scale.symlog(), + yScale: Scale.symlog(), + } +)`, ], interactiveExamples: [ `xDist = SampleSet.fromDist(2 to 5) From 944675f22e60b88bd02f937ec44a9e6feeef772b Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 5 Jan 2024 20:59:37 -0800 Subject: [PATCH 05/16] Improved chart x-titles to work decently on small charts --- .../DistributionSizes.stories.tsx | 14 ++--- .../widgets/DistWidget/DistributionsChart.tsx | 53 +++++++++++-------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx b/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx index 33f9ed651e..37e4273fac 100644 --- a/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx +++ b/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx @@ -9,17 +9,19 @@ export default meta; type Story = StoryObj; const code = "mx(5 to 100, uniform(100, 180), 30, 60, 80, [5,5,0.3,0.3,0.3])"; +const multiplier = 2; + export const Height7: Story = { name: "Height14", args: { - chartHeight: 7, + chartHeight: 14 * multiplier, code, }, }; export const Height15: Story = { name: "Height20", args: { - chartHeight: 10, + chartHeight: 20 * multiplier, code, }, }; @@ -27,14 +29,14 @@ export const Height15: Story = { export const Height40: Story = { name: "Height40", args: { - chartHeight: 20, + chartHeight: 40 * multiplier, code, }, }; export const Height40WithLabels: Story = { name: "Height 40 with labels", args: { - chartHeight: 50, + chartHeight: 40 * multiplier, code: `Plot.dist( normal(5, 2), { @@ -49,7 +51,7 @@ export const Height40WithLabels: Story = { export const Height100: Story = { name: "Height 100", args: { - chartHeight: 50, + chartHeight: 100 * multiplier, code, }, }; @@ -57,7 +59,7 @@ export const Height100: Story = { export const ContinuousSampleSetBig: Story = { name: "Height 400", args: { - chartHeight: 200, + chartHeight: 400 * multiplier, code, }, }; diff --git a/packages/components/src/widgets/DistWidget/DistributionsChart.tsx b/packages/components/src/widgets/DistWidget/DistributionsChart.tsx index deefadfdac..1904f7199d 100644 --- a/packages/components/src/widgets/DistWidget/DistributionsChart.tsx +++ b/packages/components/src/widgets/DistWidget/DistributionsChart.tsx @@ -94,6 +94,7 @@ const InnerDistributionsChart: FC<{ samplesBarSetting: SampleBarSetting; showCursorLine: boolean; showPercentileLines: boolean; + showAxisTitles: boolean; showXAxis: boolean; }> = ({ shapes: unAdjustedShapes, @@ -102,6 +103,7 @@ const InnerDistributionsChart: FC<{ height: innerHeight, isMulti, samplesBarSetting, + showAxisTitles, showCursorLine, showPercentileLines, showXAxis, @@ -134,11 +136,11 @@ const InnerDistributionsChart: FC<{ : 0; const samplesFooterHeight = samplesBarSetting === "bottom" ? 20 : 0; - const bottomPadding = (!showXAxis ? 0 : 14) + samplesFooterHeight; + const bottomPadding = (showXAxis ? 16 : 0) + samplesFooterHeight; // full height of canvas const height = Math.max( - innerHeight + samplesFooterHeight, + innerHeight + bottomPadding, legendHeight + bottomPadding ); @@ -159,7 +161,7 @@ const InnerDistributionsChart: FC<{ const yScale = sqScaleToD3(plot.yScale); yScale.domain([ - Math.min(...domain.map((p) => p.y), 0), // min value, but at least 0 + Math.max(Math.min(...domain.map((p) => p.y)), 0), // min value, but at least 0 Math.max(...domain.map((p) => p.y)), ]); @@ -197,7 +199,7 @@ const InnerDistributionsChart: FC<{ showYAxis: false, showXAxis, xTickFormat: plot.xScale.tickFormat, - xAxisTitle: plot.xScale.title, + xAxisTitle: showAxisTitles ? plot.xScale.title : undefined, showAxisLines: false, }); @@ -403,6 +405,7 @@ const InnerDistributionsChart: FC<{ showCursorLine, showPercentileLines, showXAxis, + showAxisTitles, ] ); @@ -497,6 +500,11 @@ export const DistributionsChart: FC = ({ isNormalized: distribution.isNormalized(), })); + const showAxisTitles = height > 30; + const shownXAxisTitle = showAxisTitles && !!plot.xScale.title; + const showXAxis = height > 15; + const nonTitleHeight = Math.max(height - (showXAxis ? 20 : 0), 0); + const anyAreNonnormalized = normalizedStatus.some( ({ isNormalized }) => !isNormalized ); @@ -526,16 +534,16 @@ export const DistributionsChart: FC = ({ let samplesState: SampleBarSetting = "none"; - const size = height > 150 ? "large" : "small"; + const size = nonTitleHeight > 150 ? "large" : "small"; if ( samples.length < 10 || samples.length > CUTOFF_TO_SHOW_SAMPLES_BAR || isMulti || - height <= 30 + nonTitleHeight <= 15 ) { samplesState = "none"; - } else if (size == "small") { + } else if (size == "small" && !shownXAxisTitle) { samplesState = "behind"; } else { samplesState = "bottom"; @@ -564,23 +572,26 @@ export const DistributionsChart: FC = ({ plot={plot} height={height} samplesBarSetting={samplesState} - showCursorLine={height > 30} - showPercentileLines={height > 30} - showXAxis={height > 20} + showCursorLine={nonTitleHeight > 30} + showPercentileLines={nonTitleHeight > 30} + showXAxis={showXAxis} + showAxisTitles={showAxisTitles} />
- {!anyAreNonnormalized && plot.showSummary && ( -
- -
- )} + {!anyAreNonnormalized && + plot.showSummary && + nonTitleHeight > 30 && ( +
+ +
+ )} {anyAreNonnormalized && height > 20 && (
{nonNormalizedError()}
)} From e47d79a908f9bc43c0a8ea628b459c228be23d7b Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 6 Jan 2024 07:10:55 -0800 Subject: [PATCH 06/16] Added Plot and Table to autogenerated docs --- .../widgets/DistWidget/DistributionsChart.tsx | 2 +- packages/squiggle-lang/src/fr/plot.ts | 15 -- packages/squiggle-lang/src/fr/table.ts | 43 ++++- packages/website/.gitignore | 2 + packages/website/src/pages/docs/Api/Plot.mdx | 163 ------------------ packages/website/src/pages/docs/Api/Table.mdx | 73 -------- packages/website/templates.mts | 5 + packages/website/turbo.json | 1 + 8 files changed, 51 insertions(+), 253 deletions(-) delete mode 100644 packages/website/src/pages/docs/Api/Plot.mdx delete mode 100644 packages/website/src/pages/docs/Api/Table.mdx diff --git a/packages/components/src/widgets/DistWidget/DistributionsChart.tsx b/packages/components/src/widgets/DistWidget/DistributionsChart.tsx index 1904f7199d..fb6c452f95 100644 --- a/packages/components/src/widgets/DistWidget/DistributionsChart.tsx +++ b/packages/components/src/widgets/DistWidget/DistributionsChart.tsx @@ -138,7 +138,6 @@ const InnerDistributionsChart: FC<{ const bottomPadding = (showXAxis ? 16 : 0) + samplesFooterHeight; - // full height of canvas const height = Math.max( innerHeight + bottomPadding, legendHeight + bottomPadding @@ -536,6 +535,7 @@ export const DistributionsChart: FC = ({ const size = nonTitleHeight > 150 ? "large" : "small"; + //It probably would be nices to show samples behind, if its small and there's an xAxisTitle, but that would require messing more with the yPadding in the draw/index file. if ( samples.length < 10 || samples.length > CUTOFF_TO_SHOW_SAMPLES_BAR || diff --git a/packages/squiggle-lang/src/fr/plot.ts b/packages/squiggle-lang/src/fr/plot.ts index c0f376d9b0..6693496710 100644 --- a/packages/squiggle-lang/src/fr/plot.ts +++ b/packages/squiggle-lang/src/fr/plot.ts @@ -336,11 +336,6 @@ export const library = [ maker.make({ name: "dist", output: "Plot", - examples: [ - `Plot.dist(normal(0,1), { - xScale: Scale.symlog() -})`, - ], interactiveExamples: [ `Plot.dist( normal(5, 2), @@ -489,16 +484,6 @@ export const library = [ maker.make({ name: "scatter", output: "Plot", - examples: [ - `Plot.scatter( - { - xDist: 2 to 5, - yDist: SampleSet.fromDist(1 to 3), - xScale: Scale.symlog(), - yScale: Scale.symlog(), - } -)`, - ], interactiveExamples: [ `xDist = SampleSet.fromDist(2 to 5) yDist = normal({p5:-3, p95:3}) * 5 - xDist ^ 2 diff --git a/packages/squiggle-lang/src/fr/table.ts b/packages/squiggle-lang/src/fr/table.ts index 6f853e6520..3b20058778 100644 --- a/packages/squiggle-lang/src/fr/table.ts +++ b/packages/squiggle-lang/src/fr/table.ts @@ -20,7 +20,48 @@ export const library = [ maker.make({ name: "make", output: "Plot", - examples: [], + interactiveExamples: [ + `Table.make( + [ + { name: "First Dist", value: normal(0, 1) }, + { name: "Second Dist", value: uniform(2, 4) }, + { name: "Third Dist", value: uniform(5, 6) }, + ], + { + columns: [ + { name: "Name", fn: {|d|d.name} }, + { name: "Mean", fn: {|d|mean(d.value)} }, + { name: "Std Dev", fn: {|d|variance(d.value)} }, + { name: "Dist", fn: {|d|d.value} }, + ], + } +)`, + `Table.make( + [ + { name: "First Dist", value: Sym.lognormal({ p5: 1, p95: 10 }) }, + { name: "Second Dist", value: Sym.lognormal({ p5: 5, p95: 30 }) }, + { name: "Third Dist", value: Sym.lognormal({ p5: 50, p95: 90 }) }, + ], + { + columns: [ + { name: "Name", fn: {|d|d.name} }, + { + name: "Plot", + fn: { + |d| + Plot.dist( + { + dist: d.value, + xScale: Scale.log({ min: 0.5, max: 100 }), + showSummary: false, + } + ) + }, + }, + ], + } +)`, + ], definitions: [ makeDefinition( [ diff --git a/packages/website/.gitignore b/packages/website/.gitignore index 1b07693df7..47b1a89486 100644 --- a/packages/website/.gitignore +++ b/packages/website/.gitignore @@ -19,6 +19,8 @@ /src/pages/docs/Api/String.mdx /src/pages/docs/Api/Common.mdx /src/pages/docs/Api/Boolean.mdx +/src/pages/docs/Api/Table.mdx +/src/pages/docs/Api/Plot.mdx /src/pages/docs/Api/RelativeValues.mdx /src/pages/docs/Ecosystem/LLMPrompt.md /public/llms/documentationBundle.txt diff --git a/packages/website/src/pages/docs/Api/Plot.mdx b/packages/website/src/pages/docs/Api/Plot.mdx deleted file mode 100644 index 2f60a3bcc5..0000000000 --- a/packages/website/src/pages/docs/Api/Plot.mdx +++ /dev/null @@ -1,163 +0,0 @@ ---- -description: The Plot module provides functions to create plots of distributions and functions. ---- - -import { SquiggleEditor } from "@quri/squiggle-components"; - -# Plot - -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. - -### Plot.dists - -Plots one or more labeled distributions on the same plot. Distributions can be either continuous, discrete, or a single number. - -``` -Plot.dists: ({ - dists: list<{ - name: string, - value: distribution | number - }>, - xScale: scale, - yScale: scale, - title: string, - showSummary: bool -}) => plot -``` - -Examples: - - - -### Plot.dist - -Like `Plot.dists`, but plots a single distribution. - -``` -Plot.dist: ( - dist, - { - xScale: scale, - yScale: scale, - title: string, - showSummary: bool - } -) => plot -``` - -Examples: - - - -### Plot.numericFn - -Plots a function that outputs numeric values. This works by sampling the function at a fixed number of points. The number of points is adjustable with the `points` parameter. - -``` -Plot.numericFn: ( - fn: (number => number), - { - xScale: scale, - yScale: scale, - title: string, - points: number - } -) => plot -``` - -Examples: - - - -### Plot.distFn - -``` -Plot.distFn: ( - fn: (number => dist), - { - xScale: scale, - yScale: scale, - title: string, - distXScale: scale, - points: number - } -) => plot -``` - - - -### Plot.scatter - -Plots a scatterplot. Requires two sample set distributions. - -``` -Plot.scatter: ({ - yDist: sampleSetDist, - xDist: sampleSetDist, - xScale: Scale, - yScale: Scale, - title: string, -}) => plot -``` - - - - - -### Scales - -Chart axes can be scaled using the following functions from [Scale](./Scale.mdx) module. diff --git a/packages/website/src/pages/docs/Api/Table.mdx b/packages/website/src/pages/docs/Api/Table.mdx deleted file mode 100644 index 5738f18ece..0000000000 --- a/packages/website/src/pages/docs/Api/Table.mdx +++ /dev/null @@ -1,73 +0,0 @@ ---- -description: The table module helps you create tables of data. ---- - -import { SquiggleEditor } from "@quri/squiggle-components"; - -# Table - -The Table module allows you to make tables of data. - -### Table.make - -``` -Table.make: ( - data: list<'a>, - { - columns: list<{ - name?: string, - fn: 'a => any - }> - } -) => table -``` - -Examples: - - - -You can hardcode the scales to make the xAxis consistent between rows. - - diff --git a/packages/website/templates.mts b/packages/website/templates.mts index b510a2cf8e..eab6e0d739 100644 --- a/packages/website/templates.mts +++ b/packages/website/templates.mts @@ -52,6 +52,11 @@ helperFn(f) = f \`}/> { name: "Other" }, ], }, + { + description: "Tables are a simple date time type.", + name: "Table", + intro: `The Table module allows you to make simple tables for displaying data.`, + }, { name: "Duration", description: diff --git a/packages/website/turbo.json b/packages/website/turbo.json index ef22350110..2f722c9726 100644 --- a/packages/website/turbo.json +++ b/packages/website/turbo.json @@ -27,6 +27,7 @@ "/src/pages/docs/Api/Common.mdx", "/src/pages/docs/Api/Boolean.mdx", "/src/pages/docs/Api/RelativeValues.mdx", + "/src/pages/docs/Api/Table.mdx", "src/pages/docs/Ecosystem/LLMPrompt.md" ] }, From efd84905d4947132230f7be1f70a180603b1bb46 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 6 Jan 2024 09:46:22 -0800 Subject: [PATCH 07/16] Added Math to generated pages --- packages/squiggle-lang/src/fr/list.ts | 8 +- packages/website/.gitignore | 1 + .../website/scripts/generateModulePages.mts | 2 +- packages/website/src/pages/docs/Api/Math.md | 97 ------------------- packages/website/templates.mts | 26 ++++- packages/website/turbo.json | 1 + 6 files changed, 34 insertions(+), 101 deletions(-) delete mode 100644 packages/website/src/pages/docs/Api/Math.md diff --git a/packages/squiggle-lang/src/fr/list.ts b/packages/squiggle-lang/src/fr/list.ts index 5116d3bf3f..dd32648c7e 100644 --- a/packages/squiggle-lang/src/fr/list.ts +++ b/packages/squiggle-lang/src/fr/list.ts @@ -551,7 +551,13 @@ export const library = [ List.reduceWhile([5, 6, 7], 0, {|acc, curr| acc + curr}, {|acc| acc < 15}) `, `// Adds first two elements, returns \`{ x: 11 }\`. -List.reduceWhile([5, 6, 7], { x: 0 }, {|acc, curr| { x: acc.x + curr }}, {|acc| acc.x < 15})`, +List.reduceWhile( + [5, 6, 7], + { x: 0 }, + {|acc, curr| { x: acc.x + curr }}, + {|acc| acc.x < 15} +) +`, ], description: `Works like \`reduce\`, but stops when the condition is no longer met. This is useful, in part, for simulating processes that need to stop based on the process state. `, diff --git a/packages/website/.gitignore b/packages/website/.gitignore index 47b1a89486..198ab6a1e5 100644 --- a/packages/website/.gitignore +++ b/packages/website/.gitignore @@ -22,5 +22,6 @@ /src/pages/docs/Api/Table.mdx /src/pages/docs/Api/Plot.mdx /src/pages/docs/Api/RelativeValues.mdx +/src/pages/docs/Api/Math.mdx /src/pages/docs/Ecosystem/LLMPrompt.md /public/llms/documentationBundle.txt diff --git a/packages/website/scripts/generateModulePages.mts b/packages/website/scripts/generateModulePages.mts index a53d2b463d..13df7974ae 100644 --- a/packages/website/scripts/generateModulePages.mts +++ b/packages/website/scripts/generateModulePages.mts @@ -15,7 +15,7 @@ function escapedStr(str: string) { function toMarkdown(documentation: FnDocumentation) { const fullName = documentation.nameSpace + "." + documentation.name; - return `### ${documentation.name}${escapedStr( + return `### ${documentation.name}\n${escapedStr( documentation.description || "" )} diff --git a/packages/website/src/pages/docs/Api/Math.md b/packages/website/src/pages/docs/Api/Math.md deleted file mode 100644 index 392b3aa9de..0000000000 --- a/packages/website/src/pages/docs/Api/Math.md +++ /dev/null @@ -1,97 +0,0 @@ ---- -description: Math functions and constants ---- - -# Math - -### E - -``` -Math.e: -``` - -Euler's number; ≈ 2.718281828459045 - -### LN2 - -``` -Math.ln2: -``` - -Natural logarithm of 2; ≈ 0.6931471805599453 - -### LN10 - -``` -Math.ln10: -``` - -Natural logarithm of 10; ≈ 2.302585092994046 - -### LOG2E - -``` -Math.log2e: -``` - -Base 2 logarithm of E; ≈ 1.4426950408889634Base 2 logarithm of E; ≈ 1.4426950408889634 - -### LOG10E - -``` -Math.log10e: -``` - -Base 10 logarithm of E; ≈ 0.4342944819032518 - -### PI - -``` -Math.pi: -``` - -Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793 - -### SQRT1_2 - -``` -Math.sqrt1_2: -``` - -Square root of 1/2; ≈ 0.7071067811865476 - -### SQRT2 - -``` -Math.sqrt2: -``` - -Square root of 2; ≈ 1.4142135623730951 - -### PHI - -``` -Math.phi: -``` - -Phi is the golden ratio. 1.618033988749895 - -### TAU - -``` -Math.tau: -``` - -Tau is the ratio constant of a circle's circumference to radius, equal to 2 \* pi. 6.283185307179586 - -### Math functions - -``` -Math.sqrt(x) // Square root -Math.sin(x) // Sine -Math.cos(x) // Cosine -Math.tan(x) // Tangent -Math.asin(x) // Arcsine (inverse sine) -Math.acos(x) // Arccosine (invers cosine) -Math.atan(x) // Acrtangent (inverse tangent) -``` diff --git a/packages/website/templates.mts b/packages/website/templates.mts index eab6e0d739..d42723ce70 100644 --- a/packages/website/templates.mts +++ b/packages/website/templates.mts @@ -131,14 +131,36 @@ Calculators can be useful for debugging functions or to present functions to end intro: "*Warning: Relative value functions are particularly experimental and subject to change.*", }, + { + name: "Math", + description: "Simple constants and functions for math in Squiggle.", + intro: ` +## Constants + +| Variable Name | Number Name | Value | +|------------------|----------------------------------------------------------------------------------|----------------------| +| \`Math.e\` | Euler's number | ≈ 2.718281828459045 | +| \`Math.ln2\` | Natural logarithm of 2 | ≈ 0.6931471805599453 | +| \`Math.ln10\` | Natural logarithm of 10 | ≈ 2.302585092994046 | +| \`Math.log2e\` | Base 2 logarithm of E | ≈ 1.4426950408889634 | +| \`Math.log10e\` | Base 10 logarithm of E | ≈ 0.4342944819032518 | +| \`Math.pi\` | Pi - ratio of the circumference to the diameter of a circle | ≈ 3.141592653589793 | +| \`Math.sqrt1_2\` | Square root of 1/2 | ≈ 0.7071067811865476 | +| \`Math.sqrt2\` | Square root of 2 | ≈ 1.4142135623730951 | +| \`Math.phi\` | Phi is the golden ratio. | 1.618033988749895 | +| \`Math.tau\` | Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi | 6.283185307179586 | + +## Functions + `, + }, { name: "String", description: "Functions for working with strings in Squiggle", intro: `Strings support all JSON escape sequences, with addition of escaped single-quotes (for single-quoted strings) ~~~squiggle -a = "'\" NUL:\u0000" -b = '\'" NUL:\u0000' +a = "'\\" NUL:\\u0000" +b = '\\'" NUL:\\u0000' ~~~`, }, { diff --git a/packages/website/turbo.json b/packages/website/turbo.json index 2f722c9726..d69fce757e 100644 --- a/packages/website/turbo.json +++ b/packages/website/turbo.json @@ -28,6 +28,7 @@ "/src/pages/docs/Api/Boolean.mdx", "/src/pages/docs/Api/RelativeValues.mdx", "/src/pages/docs/Api/Table.mdx", + "/src/pages/docs/Api/Math.mdx", "src/pages/docs/Ecosystem/LLMPrompt.md" ] }, From c39c726fd39269479b07bed4b8801bf6d7292dd3 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 6 Jan 2024 10:05:38 -0800 Subject: [PATCH 08/16] Autogenerate _meta page --- packages/website/.gitignore | 22 +- .../website/scripts/generateModulePages.mts | 30 +- .../website/src/pages/docs/Api/_meta.json | 23 -- packages/website/templates.mts | 332 +++++++++--------- packages/website/turbo.json | 21 +- 5 files changed, 197 insertions(+), 231 deletions(-) delete mode 100644 packages/website/src/pages/docs/Api/_meta.json diff --git a/packages/website/.gitignore b/packages/website/.gitignore index 198ab6a1e5..387b559974 100644 --- a/packages/website/.gitignore +++ b/packages/website/.gitignore @@ -2,26 +2,6 @@ # These files are generated. # They must be also listed in ./turbo.json build outputs. -/src/pages/docs/Api/Date.mdx -/src/pages/docs/Api/Duration.mdx -/src/pages/docs/Api/Tag.mdx -/src/pages/docs/Api/Calculator.mdx -/src/pages/docs/Api/Input.mdx -/src/pages/docs/Api/Dict.mdx -/src/pages/docs/Api/SampleSet.mdx -/src/pages/docs/Api/PointSet.mdx -/src/pages/docs/Api/Sym.mdx -/src/pages/docs/Api/Scale.mdx -/src/pages/docs/Api/List.mdx -/src/pages/docs/Api/Danger.mdx -/src/pages/docs/Api/Dist.mdx -/src/pages/docs/Api/Number.mdx -/src/pages/docs/Api/String.mdx -/src/pages/docs/Api/Common.mdx -/src/pages/docs/Api/Boolean.mdx -/src/pages/docs/Api/Table.mdx -/src/pages/docs/Api/Plot.mdx -/src/pages/docs/Api/RelativeValues.mdx -/src/pages/docs/Api/Math.mdx +/src/pages/docs/Api/* /src/pages/docs/Ecosystem/LLMPrompt.md /public/llms/documentationBundle.txt diff --git a/packages/website/scripts/generateModulePages.mts b/packages/website/scripts/generateModulePages.mts index 13df7974ae..ddf2a9a2c5 100644 --- a/packages/website/scripts/generateModulePages.mts +++ b/packages/website/scripts/generateModulePages.mts @@ -40,7 +40,31 @@ const generateModulePage = async ( }); }; +const generateMetaPage = async ({ pages }: { pages: ModulePage[] }) => { + function convertToKeyValuePairs(names: string[]): { [key: string]: string } { + const keyValuePairs: { [key: string]: string } = {}; + names.forEach((name) => { + keyValuePairs[name] = name; + }); + return keyValuePairs; + } + + const names = pages.map((p) => p.name); + const fileName = `./src/pages/docs/Api/_meta.json`; + const content = JSON.stringify(convertToKeyValuePairs(names), null, 2); + + fs.writeFile(fileName, content, (err) => { + if (err) { + console.error(err); + return; + } + console.log(`Content written to ${targetFilename(fileName)}`); + }); +}; + //Remember to add any new Modules to .gitignore -for (const modulePage of modulePages) { - await generateModulePage(modulePage, toMarkdown); -} +// for (const modulePage of modulePages) { +// await generateModulePage(modulePage, toMarkdown); +// } + +await generateMetaPage({ pages: modulePages }); diff --git a/packages/website/src/pages/docs/Api/_meta.json b/packages/website/src/pages/docs/Api/_meta.json deleted file mode 100644 index 0a536d6521..0000000000 --- a/packages/website/src/pages/docs/Api/_meta.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "Common": "Common", - "Boolean": "Boolean", - "Date": "Date", - "Dict": "Dictionary", - "Dist": "Distribution", - "Duration": "Duration", - "Sym": "Symbolic Distribution", - "SampleSet": "Sample Set Distribution", - "PointSet": "Point Set Distribution", - "List": "List", - "Math": "Math", - "Number": "Number", - "Plot": "Plot", - "Scale": "Scale", - "String": "String", - "Table": "Table", - "Tag": "Tag", - "Calculator": "Calculator", - "Input": "Input", - "RelativeValues": "Relative Values", - "Danger": "Danger" -} diff --git a/packages/website/templates.mts b/packages/website/templates.mts index d42723ce70..195cea7527 100644 --- a/packages/website/templates.mts +++ b/packages/website/templates.mts @@ -9,35 +9,14 @@ export type ModulePage = { export const modulePages: ModulePage[] = [ { - name: "Tag", - description: - "The Tag module handles tags, which allow the additions of metadata to Squiggle variables.", - sections: [{ name: "Tags" }, { name: "Functions" }], - intro: `Tags are metadata that can be added to Squiggle variables. They are used to add additional information to variables, such as names, descriptions, and visualization options. While tags can be accessed at runtime, they are primarily meant for use with the Squiggle Playground and other visualizations. -Tags can be added to variables either by using their name \`Tag.[name]\` or by using decorators. - -## List of Tags -| Tag Name | Description | -| --------- | ----------- | -| \`name\` | Change the default display name for the variable, in the playground. | -| \`doc\` | Adds documentation to the variable in the playground. | -| \`showAs\` | Change the default view for the value when displayed. | -| \`format\` | Format a number, date, or duration when displayed. | -| \`hide\` | Don't show the variable in the playground | - -## Examples - + name: "Common", + description: "", + intro: `Functions that work on many different types of values.`, + }, + { + name: "Boolean", + description: "", + intro: ` `, }, { @@ -53,9 +32,85 @@ helperFn(f) = f \`}/> ], }, { - description: "Tables are a simple date time type.", - name: "Table", - intro: `The Table module allows you to make simple tables for displaying data.`, + name: "Dict", + sections: [ + { name: "Conversions" }, + { name: "Transformations" }, + { name: "Queries" }, + ], + description: + "Squiggle dictionaries work similar to Python dictionaries. The syntax is similar to objects in Javascript.", + intro: ` +`, + }, + { + name: "Dist", + sections: [ + { + name: "Distributions", + description: `These are functions for creating primitive distributions. Many of these could optionally take in distributions as inputs. In these cases, Monte Carlo Sampling will be used to generate the greater distribution. This can be used for simple hierarchical models. + +See a longer tutorial on creating distributions [here](/docs/Guides/DistributionCreation).`, + }, + { name: "Basic Functions" }, + { name: "Algebra (Dist)" }, + { name: "Algebra (List)" }, + { + name: "Pointwise Algebra", + description: `Pointwise arithmetic operations cover the standard arithmetic operations, but work in a different way than the regular operations. These operate on the y-values of the distributions instead of the x-values. A pointwise addition would add the y-values of two distributions. + +The infixes \`.+\`,\`.-\`, \`.*\`, \`./\`, \`.^\` are supported for their respective operations. \`Mixture\` works using pointwise addition. + +Pointwise operations work on Point Set distributions, so will convert other distributions to Point Set ones first. Pointwise arithmetic operations typically return unnormalized or completely invalid distributions. For example, the operation{" "} normal(5,2) .- uniform(10,12) results in a distribution-like object with negative probability mass.`, + }, + { + name: "Normalization", + description: `There are some situations where computation will return unnormalized distributions. This means that their cumulative sums are not equal to 1.0. Unnormalized distributions are not valid for many relevant functions; for example, klDivergence and scoring. + +The only functions that do not return normalized distributions are the pointwise arithmetic operations and the scalewise arithmetic operations. If you use these functions, it is recommended that you consider normalizing the resulting distributions.`, + }, + { name: "Utility" }, + { name: "Scoring" }, + ], + description: + "Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions.", + intro: `Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions. + +One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.`, + }, + { + name: "Sym", + description: + "The Sym module provides functions to create some common symbolic distributions.", + intro: `Symbolic Distributions. All these functions match the functions for creating sample set distributions, but produce symbolic distributions instead. Symbolic distributions won't capture correlations, but are more performant than sample distributions.`, + }, + { + name: "SampleSet", + sections: [ + { name: "Constructors" }, + { name: "Conversions" }, + { name: "Transformations" }, + ], + description: + "Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers.", + intro: `Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers. It's useful to distinguish point set distributions from arbitrary lists of numbers to make it clear which functions are applicable. + +Monte Carlo calculations typically result in sample set distributions. + +All regular distribution function work on sample set distributions. In addition, there are several functions that only work on sample set distributions..`, + }, + { + name: "PointSet", + sections: [ + { name: "Constructors" }, + { name: "Conversions" }, + { name: "Transformations" }, + ], + description: + "Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions.", + intro: `Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions. + +One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.`, }, { name: "Duration", @@ -81,56 +136,25 @@ This table now presents the information in a clear and concise manner, focusing `, }, { - name: "Calculator", - description: "The Calculator module helps you create custom calculators", - intro: ` -The Calculator module allows you to make custom calculators for functions. This is a form that's tied to a specific Squiggle function, where the inputs to the form are passed to that function, and the output of the function gets shown on the bottom. - -Calculators can be useful for debugging functions or to present functions to end users. -`, - }, - { - name: "Dict", - sections: [ - { name: "Conversions" }, - { name: "Transformations" }, - { name: "Queries" }, - ], + name: "List", description: - "Squiggle dictionaries work similar to Python dictionaries. The syntax is similar to objects in Javascript.", - intro: ` -`, - }, - { - name: "Boolean", - description: "", - intro: ` -`, - }, - { - name: "Common", - description: "", - intro: `Functions that work on many different types of values.`, - }, - { - name: "Number", + "Lists are a simple data structure that can hold any type of value. They are similar to arrays in Javascript or lists in Python.", sections: [ - { name: "Comparison" }, - { name: "Algebra (Number)" }, - { name: "Functions (Number)" }, - { name: "Algebra (List)" }, - { name: "Functions (List)" }, - { name: "Utils" }, + { name: "Constructors" }, + { name: "Modifications" }, + { name: "Filtering" }, + { name: "Queries" }, + { name: "Functional Transformations" }, ], - description: "Squiggle numbers are Javascript floats.", - intro: "Squiggle numbers are Javascript floats.", - }, - { - name: "RelativeValues", - description: "", - intro: - "*Warning: Relative value functions are particularly experimental and subject to change.*", + intro: `Lists are a simple data structure that can hold any type of value. They are similar to arrays in Javascript or lists in Python. + +\`\`\`squiggle +myList = [1, 2, 3, normal(5,2), "hello"] +\`\`\` + +Lists are immutable, meaning that they cannot be modified. Instead, all list functions return a new list.`, }, + { name: "Math", description: "Simple constants and functions for math in Squiggle.", @@ -152,6 +176,27 @@ Calculators can be useful for debugging functions or to present functions to end ## Functions `, + }, + { + name: "Number", + sections: [ + { name: "Comparison" }, + { name: "Algebra (Number)" }, + { name: "Functions (Number)" }, + { name: "Algebra (List)" }, + { name: "Functions (List)" }, + { name: "Utils" }, + ], + description: "Squiggle numbers are Javascript floats.", + intro: "Squiggle numbers are Javascript floats.", + }, + { + name: "Scale", + description: "Scales for plots.", + sections: [{ name: "Numeric Scales" }, { name: "Date Scales" }], + intro: `Chart axes in [plots](./Plot.mdx) can be scaled using the following functions. Each scale function accepts optional min and max value. Power scale accepts an extra exponent parameter. + +Squiggle uses D3 for the tick formats. You can read about d3 tick formats [here](https://github.com/d3/d3-format).`, }, { name: "String", @@ -164,72 +209,66 @@ b = '\\'" NUL:\\u0000' ~~~`, }, { - name: "Input", - description: - "Inputs are now only used for describing forms for calculators.", - intro: `Inputs are now only used for describing forms for [calculators](./Calculator.mdx).`, + description: "Tables are a simple date time type.", + name: "Table", + intro: `The Table module allows you to make simple tables for displaying data.`, }, { - name: "SampleSet", - sections: [ - { name: "Constructors" }, - { name: "Conversions" }, - { name: "Transformations" }, - ], + name: "Tag", description: - "Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers.", - intro: `Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers. It's useful to distinguish point set distributions from arbitrary lists of numbers to make it clear which functions are applicable. + "The Tag module handles tags, which allow the additions of metadata to Squiggle variables.", + sections: [{ name: "Tags" }, { name: "Functions" }], + intro: `Tags are metadata that can be added to Squiggle variables. They are used to add additional information to variables, such as names, descriptions, and visualization options. While tags can be accessed at runtime, they are primarily meant for use with the Squiggle Playground and other visualizations. +Tags can be added to variables either by using their name \`Tag.[name]\` or by using decorators. -Monte Carlo calculations typically result in sample set distributions. +## List of Tags +| Tag Name | Description | +| --------- | ----------- | +| \`name\` | Change the default display name for the variable, in the playground. | +| \`doc\` | Adds documentation to the variable in the playground. | +| \`showAs\` | Change the default view for the value when displayed. | +| \`format\` | Format a number, date, or duration when displayed. | +| \`hide\` | Don't show the variable in the playground | -All regular distribution function work on sample set distributions. In addition, there are several functions that only work on sample set distributions..`, +## Examples + +`, }, + { - name: "PointSet", - sections: [ - { name: "Constructors" }, - { name: "Conversions" }, - { name: "Transformations" }, - ], - description: - "Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions.", - intro: `Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions. + name: "Calculator", + description: "The Calculator module helps you create custom calculators", + intro: ` +The Calculator module allows you to make custom calculators for functions. This is a form that's tied to a specific Squiggle function, where the inputs to the form are passed to that function, and the output of the function gets shown on the bottom. -One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.`, +Calculators can be useful for debugging functions or to present functions to end users. +`, }, { - name: "Sym", + name: "Input", description: - "The Sym module provides functions to create some common symbolic distributions.", - intro: `Symbolic Distributions. All these functions match the functions for creating sample set distributions, but produce symbolic distributions instead. Symbolic distributions won't capture correlations, but are more performant than sample distributions.`, + "Inputs are now only used for describing forms for calculators.", + intro: `Inputs are now only used for describing forms for [calculators](./Calculator.mdx).`, }, - { - name: "Scale", - description: "Scales for plots.", - sections: [{ name: "Numeric Scales" }, { name: "Date Scales" }], - intro: `Chart axes in [plots](./Plot.mdx) can be scaled using the following functions. Each scale function accepts optional min and max value. Power scale accepts an extra exponent parameter. -Squiggle uses D3 for the tick formats. You can read about d3 tick formats [here](https://github.com/d3/d3-format).`, - }, { - name: "List", - description: - "Lists are a simple data structure that can hold any type of value. They are similar to arrays in Javascript or lists in Python.", - sections: [ - { name: "Constructors" }, - { name: "Modifications" }, - { name: "Filtering" }, - { name: "Queries" }, - { name: "Functional Transformations" }, - ], - intro: `Lists are a simple data structure that can hold any type of value. They are similar to arrays in Javascript or lists in Python. - -\`\`\`squiggle -myList = [1, 2, 3, normal(5,2), "hello"] -\`\`\` - -Lists are immutable, meaning that they cannot be modified. Instead, all list functions return a new list.`, + name: "RelativeValues", + description: "", + intro: + "*Warning: Relative value functions are particularly experimental and subject to change.*", }, + { name: "Danger", description: @@ -246,39 +285,4 @@ Lists are immutable, meaning that they cannot be modified. Instead, all list fun intro: `The Danger library contains newer experimental functions which are less stable than Squiggle as a whole. They are not recommended for production use, but are useful for testing out new ideas., `, }, - { - name: "Dist", - sections: [ - { - name: "Distributions", - description: `These are functions for creating primitive distributions. Many of these could optionally take in distributions as inputs. In these cases, Monte Carlo Sampling will be used to generate the greater distribution. This can be used for simple hierarchical models. - -See a longer tutorial on creating distributions [here](/docs/Guides/DistributionCreation).`, - }, - { name: "Basic Functions" }, - { name: "Algebra (Dist)" }, - { name: "Algebra (List)" }, - { - name: "Pointwise Algebra", - description: `Pointwise arithmetic operations cover the standard arithmetic operations, but work in a different way than the regular operations. These operate on the y-values of the distributions instead of the x-values. A pointwise addition would add the y-values of two distributions. - -The infixes \`.+\`,\`.-\`, \`.*\`, \`./\`, \`.^\` are supported for their respective operations. \`Mixture\` works using pointwise addition. - -Pointwise operations work on Point Set distributions, so will convert other distributions to Point Set ones first. Pointwise arithmetic operations typically return unnormalized or completely invalid distributions. For example, the operation{" "} normal(5,2) .- uniform(10,12) results in a distribution-like object with negative probability mass.`, - }, - { - name: "Normalization", - description: `There are some situations where computation will return unnormalized distributions. This means that their cumulative sums are not equal to 1.0. Unnormalized distributions are not valid for many relevant functions; for example, klDivergence and scoring. - -The only functions that do not return normalized distributions are the pointwise arithmetic operations and the scalewise arithmetic operations. If you use these functions, it is recommended that you consider normalizing the resulting distributions.`, - }, - { name: "Utility" }, - { name: "Scoring" }, - ], - description: - "Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions.", - intro: `Point set distributions are one of the three distribution formats. They are stored as a list of x-y coordinates representing both discrete and continuous distributions. - -One complication is that it's possible to represent invalid probability distributions in the point set format. For example, you can represent shapes with negative values, or shapes that are not normalized.`, - }, ]; diff --git a/packages/website/turbo.json b/packages/website/turbo.json index d69fce757e..6eb79a0d92 100644 --- a/packages/website/turbo.json +++ b/packages/website/turbo.json @@ -9,26 +9,7 @@ "!.next/cache/**", "public/llms/documentationBundle.txt", "src/pages/docs/Ecosystem/LLMPrompt.md", - "src/pages/docs/Api/Date.mdx", - "src/pages/docs/Api/Duration.mdx", - "src/pages/docs/Api/Tag.mdx", - "src/pages/docs/Api/Calculator.mdx", - "src/pages/docs/Api/Input.mdx", - "src/pages/docs/Api/Dict.mdx", - "src/pages/docs/Api/SampleSet.mdx", - "src/pages/docs/Api/PointSet.mdx", - "src/pages/docs/Api/Sym.mdx", - "src/pages/docs/Api/Scale.mdx", - "src/pages/docs/Api/List.mdx", - "src/pages/docs/Api/Danger.mdx", - "src/pages/docs/Api/Dist.mdx", - "/src/pages/docs/Api/Number.mdx", - "/src/pages/docs/Api/String.mdx", - "/src/pages/docs/Api/Common.mdx", - "/src/pages/docs/Api/Boolean.mdx", - "/src/pages/docs/Api/RelativeValues.mdx", - "/src/pages/docs/Api/Table.mdx", - "/src/pages/docs/Api/Math.mdx", + "src/pages/docs/Api/*", "src/pages/docs/Ecosystem/LLMPrompt.md" ] }, From d8a3de5943aa7d36a567fc9a4a45d50a46d81c7c Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 6 Jan 2024 10:08:06 -0800 Subject: [PATCH 09/16] Test fix --- packages/squiggle-lang/src/fr/table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/squiggle-lang/src/fr/table.ts b/packages/squiggle-lang/src/fr/table.ts index 3b20058778..619bad0bec 100644 --- a/packages/squiggle-lang/src/fr/table.ts +++ b/packages/squiggle-lang/src/fr/table.ts @@ -19,7 +19,7 @@ const maker = new FnFactory({ export const library = [ maker.make({ name: "make", - output: "Plot", + output: "TableChart", interactiveExamples: [ `Table.make( [ From 0ffbd187a5af404428dbe5a2a8a3573fae50ab9b Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sat, 6 Jan 2024 12:03:00 -0800 Subject: [PATCH 10/16] Tiny fix --- .../src/widgets/DistWidget/DistributionsChart.tsx | 2 +- packages/website/scripts/generateModulePages.mts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/components/src/widgets/DistWidget/DistributionsChart.tsx b/packages/components/src/widgets/DistWidget/DistributionsChart.tsx index fb6c452f95..9578b77b98 100644 --- a/packages/components/src/widgets/DistWidget/DistributionsChart.tsx +++ b/packages/components/src/widgets/DistWidget/DistributionsChart.tsx @@ -136,7 +136,7 @@ const InnerDistributionsChart: FC<{ : 0; const samplesFooterHeight = samplesBarSetting === "bottom" ? 20 : 0; - const bottomPadding = (showXAxis ? 16 : 0) + samplesFooterHeight; + const bottomPadding = (showXAxis ? 14 : 0) + samplesFooterHeight; const height = Math.max( innerHeight + bottomPadding, diff --git a/packages/website/scripts/generateModulePages.mts b/packages/website/scripts/generateModulePages.mts index ddf2a9a2c5..c2870d3a44 100644 --- a/packages/website/scripts/generateModulePages.mts +++ b/packages/website/scripts/generateModulePages.mts @@ -62,9 +62,8 @@ const generateMetaPage = async ({ pages }: { pages: ModulePage[] }) => { }); }; -//Remember to add any new Modules to .gitignore -// for (const modulePage of modulePages) { -// await generateModulePage(modulePage, toMarkdown); -// } +for (const modulePage of modulePages) { + await generateModulePage(modulePage, toMarkdown); +} await generateMetaPage({ pages: modulePages }); From 2e8591cd4732c99347a90932efadbc79db6469f9 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:02:10 -0800 Subject: [PATCH 11/16] First changes for CR --- .../src/components/ui/FnDocumentation.tsx | 2 +- .../SquiggleChart/DistributionSizes.stories.tsx | 2 +- packages/squiggle-lang/src/fr/list.ts | 13 ------------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/packages/components/src/components/ui/FnDocumentation.tsx b/packages/components/src/components/ui/FnDocumentation.tsx index b4cc3bd924..ab00aad9cc 100644 --- a/packages/components/src/components/ui/FnDocumentation.tsx +++ b/packages/components/src/components/ui/FnDocumentation.tsx @@ -104,7 +104,7 @@ export const FnDocumentation: FC<{ )} {(isUnit || shorthand || isExperimental || !requiresNamespace) && (
-
+
{isUnit && (
Unit diff --git a/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx b/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx index 37e4273fac..d05c41ac50 100644 --- a/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx +++ b/packages/components/src/stories/SquiggleChart/DistributionSizes.stories.tsx @@ -9,7 +9,7 @@ export default meta; type Story = StoryObj; const code = "mx(5 to 100, uniform(100, 180), 30, 60, 80, [5,5,0.3,0.3,0.3])"; -const multiplier = 2; +const multiplier = 0.5; export const Height7: Story = { name: "Height14", diff --git a/packages/squiggle-lang/src/fr/list.ts b/packages/squiggle-lang/src/fr/list.ts index dd32648c7e..28181abe02 100644 --- a/packages/squiggle-lang/src/fr/list.ts +++ b/packages/squiggle-lang/src/fr/list.ts @@ -694,19 +694,6 @@ List.reduceWhile( makeDefinition([frArray(frString)], frString, ([array]) => array.join()), ], }), - maker.make({ - name: "concat", - displaySection: "Modifications", - definitions: [ - makeDefinition( - [frArray(frAny()), frArray(frAny())], - frArray(frAny()), - ([a, b]) => { - return [...a, ...b]; - } - ), - ], - }), maker.make({ name: "flatten", requiresNamespace: true, From a7be13af667be576f6f0b9fd966bd258f245afe0 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:26:35 -0800 Subject: [PATCH 12/16] Changed SquiggleEditor in docs --- packages/website/scripts/generateModuleContent.mts | 4 +++- packages/website/src/components/SquiggleEditor.tsx | 10 ++++++++++ packages/website/src/pages/docs/Guides/BasicTypes.mdx | 3 ++- packages/website/src/pages/docs/Guides/Bugs.mdx | 3 ++- packages/website/src/pages/docs/Guides/ControlFlow.mdx | 3 ++- .../src/pages/docs/Guides/DistributionCreation.mdx | 2 +- .../src/pages/docs/Guides/DistributionFunctions.mdx | 3 ++- packages/website/src/pages/docs/Guides/Functions.mdx | 3 ++- packages/website/src/pages/docs/Guides/Gotchas.mdx | 3 ++- .../website/src/pages/docs/Guides/LanguageFeatures.mdx | 3 ++- packages/website/src/pages/docs/index.mdx | 2 +- packages/website/tsconfig.json | 6 +++++- 12 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 packages/website/src/components/SquiggleEditor.tsx diff --git a/packages/website/scripts/generateModuleContent.mts b/packages/website/scripts/generateModuleContent.mts index 3e3fe72dce..1bf530dea6 100644 --- a/packages/website/scripts/generateModuleContent.mts +++ b/packages/website/scripts/generateModuleContent.mts @@ -57,7 +57,9 @@ export function generateModuleContent( const content = `--- description: ${description} --- -import { SquiggleEditor, FnDocumentationFromName } from "@quri/squiggle-components"; +import { FnDocumentationFromName } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # ${name} ${intro} diff --git a/packages/website/src/components/SquiggleEditor.tsx b/packages/website/src/components/SquiggleEditor.tsx new file mode 100644 index 0000000000..c996ca3627 --- /dev/null +++ b/packages/website/src/components/SquiggleEditor.tsx @@ -0,0 +1,10 @@ +import { SquiggleEditor as OriginalSquiggleEditor } from "@quri/squiggle-components"; +import { FC } from "react"; + +export const SquiggleEditor: FC< + Parameters[0] +> = (props) => ( +
+ +
+); diff --git a/packages/website/src/pages/docs/Guides/BasicTypes.mdx b/packages/website/src/pages/docs/Guides/BasicTypes.mdx index 38a75107f2..39ae85407e 100644 --- a/packages/website/src/pages/docs/Guides/BasicTypes.mdx +++ b/packages/website/src/pages/docs/Guides/BasicTypes.mdx @@ -2,7 +2,8 @@ description: "Basic Types" --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Basic Types diff --git a/packages/website/src/pages/docs/Guides/Bugs.mdx b/packages/website/src/pages/docs/Guides/Bugs.mdx index f6360da3c9..35ee650017 100644 --- a/packages/website/src/pages/docs/Guides/Bugs.mdx +++ b/packages/website/src/pages/docs/Guides/Bugs.mdx @@ -2,7 +2,8 @@ description: Much of the Squiggle math is imprecise. This can cause significant errors, so watch out. --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Known Bugs diff --git a/packages/website/src/pages/docs/Guides/ControlFlow.mdx b/packages/website/src/pages/docs/Guides/ControlFlow.mdx index 292047bb21..c222bd05fa 100644 --- a/packages/website/src/pages/docs/Guides/ControlFlow.mdx +++ b/packages/website/src/pages/docs/Guides/ControlFlow.mdx @@ -2,7 +2,8 @@ description: This page documents control flow. Squiggle has if/else statements, but not for loops. --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Control Flow diff --git a/packages/website/src/pages/docs/Guides/DistributionCreation.mdx b/packages/website/src/pages/docs/Guides/DistributionCreation.mdx index 6bf09c29c6..bc25f55e34 100644 --- a/packages/website/src/pages/docs/Guides/DistributionCreation.mdx +++ b/packages/website/src/pages/docs/Guides/DistributionCreation.mdx @@ -4,7 +4,7 @@ description: Various ways to create Squiggle distributions import { Callout, Tabs, Tab } from "nextra/components"; -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; # Distribution Creation diff --git a/packages/website/src/pages/docs/Guides/DistributionFunctions.mdx b/packages/website/src/pages/docs/Guides/DistributionFunctions.mdx index ee0f7d135b..05510a1f79 100644 --- a/packages/website/src/pages/docs/Guides/DistributionFunctions.mdx +++ b/packages/website/src/pages/docs/Guides/DistributionFunctions.mdx @@ -2,7 +2,8 @@ description: Various functions for operating on distributions --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Distribution Functions diff --git a/packages/website/src/pages/docs/Guides/Functions.mdx b/packages/website/src/pages/docs/Guides/Functions.mdx index e8c3637a2f..c2a37bbd9a 100644 --- a/packages/website/src/pages/docs/Guides/Functions.mdx +++ b/packages/website/src/pages/docs/Guides/Functions.mdx @@ -1,7 +1,8 @@ --- description: "Squiggle Function Overview" --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Functions diff --git a/packages/website/src/pages/docs/Guides/Gotchas.mdx b/packages/website/src/pages/docs/Guides/Gotchas.mdx index 19b6264943..4df0df7623 100644 --- a/packages/website/src/pages/docs/Guides/Gotchas.mdx +++ b/packages/website/src/pages/docs/Guides/Gotchas.mdx @@ -2,7 +2,8 @@ description: Explore common pitfalls and misunderstandings in Squiggle's handling of distributions --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Gotchas diff --git a/packages/website/src/pages/docs/Guides/LanguageFeatures.mdx b/packages/website/src/pages/docs/Guides/LanguageFeatures.mdx index 323f8f1af3..cea19c888f 100644 --- a/packages/website/src/pages/docs/Guides/LanguageFeatures.mdx +++ b/packages/website/src/pages/docs/Guides/LanguageFeatures.mdx @@ -2,7 +2,8 @@ description: "Language features: an overview of syntax, operators, functions, and more" --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../../components/SquiggleEditor"; + # Language Features diff --git a/packages/website/src/pages/docs/index.mdx b/packages/website/src/pages/docs/index.mdx index 5769cd77a8..eab8e85cfd 100644 --- a/packages/website/src/pages/docs/index.mdx +++ b/packages/website/src/pages/docs/index.mdx @@ -1,7 +1,7 @@ --- description: Squiggle is a minimalist programming language for probabilistic estimation. It's meant for intuitively-driven quantitative estimation instead of data analysis or data-driven statistical techniques. --- -import { SquiggleEditor } from "@quri/squiggle-components"; +import { SquiggleEditor } from "../../components/SquiggleEditor"; import { Callout, Tabs, Tab } from "nextra/components"; # Introduction diff --git a/packages/website/tsconfig.json b/packages/website/tsconfig.json index dc5e22e26e..d2c7c6a5cb 100644 --- a/packages/website/tsconfig.json +++ b/packages/website/tsconfig.json @@ -13,7 +13,11 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", - "allowJs": true + "allowJs": true, + "baseUrl": ".", + "paths": { + "@/components/*": ["src/components/*"] + } }, "include": [ "next-env.d.ts", From 788a9b2092591637cf37c5fe7f3ffe7dd75514a2 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:37:40 -0800 Subject: [PATCH 13/16] 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", From a87765453ff65737974a207d684fd23bd3e3dfc4 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:40:00 -0800 Subject: [PATCH 14/16] Removes Plot titles from examples --- packages/squiggle-lang/src/fr/plot.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/squiggle-lang/src/fr/plot.ts b/packages/squiggle-lang/src/fr/plot.ts index 6893623a60..312b396444 100644 --- a/packages/squiggle-lang/src/fr/plot.ts +++ b/packages/squiggle-lang/src/fr/plot.ts @@ -236,7 +236,6 @@ export const library = [ normal(5, 2), { xScale: Scale.linear({ min: -2, max: 6, title: "X Axis Title" }), - title: "A Simple Normal Distribution", showSummary: true, } )`, @@ -410,7 +409,6 @@ export const library = [ `Plot.distFn( {|t|normal(t, 2) * normal(5, 3)}, { - 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" }), @@ -495,7 +493,6 @@ Plot.scatter({ `xDist = SampleSet.fromDist(normal({p5:-2, p95:5})) yDist = normal({p5:-3, p95:3}) * 5 - xDist Plot.scatter({ - title: "A Scatterplot", xDist: xDist, yDist: yDist, xScale: Scale.symlog({title: "X Axis Title"}), From 5b1a059cf2af70ddbe8ed8a2e8fb274e74a72c73 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:47:50 -0800 Subject: [PATCH 15/16] TsConfig fix --- packages/website/tsconfig.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/website/tsconfig.json b/packages/website/tsconfig.json index d2c7c6a5cb..cd4e0a4d40 100644 --- a/packages/website/tsconfig.json +++ b/packages/website/tsconfig.json @@ -14,10 +14,6 @@ "isolatedModules": true, "jsx": "preserve", "allowJs": true, - "baseUrl": ".", - "paths": { - "@/components/*": ["src/components/*"] - } }, "include": [ "next-env.d.ts", From d19e9d41dccfb25305c15e7ff804908b1093b155 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 7 Jan 2024 08:49:17 -0800 Subject: [PATCH 16/16] Fixed tsconfig.json comma issue --- packages/website/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/website/tsconfig.json b/packages/website/tsconfig.json index cd4e0a4d40..dc5e22e26e 100644 --- a/packages/website/tsconfig.json +++ b/packages/website/tsconfig.json @@ -13,7 +13,7 @@ "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", - "allowJs": true, + "allowJs": true }, "include": [ "next-env.d.ts",