Documentation
API
Tag

Tag

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.get[Name] or by using decorators.

List of Tags

Tag NameDescription
nameChange the default display name for the variable, in the playground.
docAdds documentation to the variable in the playground.
showAsChange the default view for the value when displayed.
formatFormat a number, date, or duration when displayed.
notebookFormats lists as notebooks.
hideDon't show the variable in the playground
startOpenStart the variable open in the playground
startClosedStart the variable closed in the playground
locationStore the proper location. Helps when you want to locate code corresponding to a variable.
exportDataMetadata about exported variables. Cannot be added manually.

Example

Tags

name

Adds a user-facing name to a value. This is useful for documenting what a value represents, or how it was calculated.

Note: While names are shown in the sidebar, you still need to call variables by their regular variable names in code.

Signatures
Tag.name('A, String) => 'A

getName

Signatures
Tag.getName(any) => String

doc

Adds text documentation to a value. This is useful for documenting what a value represents or how it was calculated.

Signatures
Tag.doc('A, String) => 'A

getDoc

Signatures
Tag.getDoc(any) => String

showAs

Overrides the default visualization for a value. showAs() can take either a visualization, or a function that calls the value and returns a visualization.

Different types of values can be displayed in different ways. The following table shows the potential visualization types for each input type. In this table, Number can be used with Dates and Durations as well.

Input TypeVisualization Types
DistributionPlot.dist
ListTable
(Number -> Number) FunctionPlot.numericFn, Calculator
(Number -> Dist) FunctionPlot.distFn, Calculator
FunctionCalculator
Signatures
Tag.showAs(Dist, Plot|(Dist) => Plot) => Dist
Tag.showAs(List(any), Table|(List(any)) => Table) => List(any)
Tag.showAs((Number) => Dist|Number, Plot|Calculator|((Number) => Dist|Number) => Plot|Calculator) => (Number) => Dist|Number
Tag.showAs((Date) => Dist|Number, Plot|Calculator|((Date) => Dist|Number) => Plot|Calculator) => (Date) => Dist|Number
Tag.showAs((Duration) => Dist|Number, Plot|Calculator|((Duration) => Dist|Number) => Plot|Calculator) => (Duration) => Dist|Number
Tag.showAs(Function, Calculator|(Function) => Calculator) => Function
Examples

getShowAs

Signatures
Tag.getShowAs(any) => any

getExportData

Signatures
Tag.getExportData(any) => any

spec

Adds a specification to a value. This is useful for documenting how a value was calculated, or what it represents.

Signatures
Tag.spec('A, Specification) => 'A

getSpec

Signatures
Tag.getSpec(any) => any

format

Set the display format for a number, distribution, duration, or date. Uses the d3-format (opens in a new tab) syntax on numbers and distributions, and the d3-time-format (opens in a new tab) syntax for dates.

Signatures
Tag.format(Dist|Number, numberFormat: String) => Dist|Number
Tag.format(Duration, numberFormat: String) => Duration
Tag.format(Date, timeFormat: String) => Date

getFormat

Signatures
Tag.getFormat(Dist|Number) => String
Tag.getFormat(Duration) => String
Tag.getFormat(Date) => String

hide

Hides a value when displayed under Variables. This is useful for hiding intermediate values or helper functions that are used in calculations, but are not directly relevant to the user. Only hides top-level variables.

Signatures
Tag.hide('A, Bool) => 'A
Tag.hide('A) => 'A

getHide

Signatures
Tag.getHide(any) => Bool

startOpen

When the value is first displayed, it will begin open in the viewer. Refresh the page to reset.

Signatures
Tag.startOpen('A) => 'A

startClosed

When the value is first displayed, it will begin collapsed in the viewer. Refresh the page to reset.

Signatures
Tag.startClosed('A) => 'A

getStartOpenState

Returns the startOpenState of a value, which can be "open", "closed", or "" if no startOpenState is set. Set using Tag.startOpen and Tag.startClosed.

Signatures
Tag.getStartOpenState(any) => String

notebook

Displays the list of values as a notebook. This means that element indices are hidden, and the values are displayed in a vertical list. Useful for displaying combinations of text and values.

Signatures
Tag.notebook(List('A), Bool) => List('A)
Tag.notebook(List('A)) => List('A)
Examples

getNotebook

Signatures
Tag.getNotebook(any) => Bool

location

Saves the location of a value. Note that this must be called at the point where the location is to be saved. If you use it in a helper function, it will save the location of the helper function, not the location where the helper function is called.

Signatures
Tag.location('A) => 'A

getLocation

Signatures
Tag.getLocation(any) => any

Functions

getAll

Returns a dictionary of all tags on a value.

Signatures
Tag.getAll(any) => Dict(any)

omit

Returns a copy of the value with the specified tags removed.

Signatures
Tag.omit('A, List(String)) => 'A

clear

Returns a copy of the value with all tags removed.

Signatures
Tag.clear('A) => 'A