Tag
The Tag module handles tags, which allow the additions of metadata to Squiggle variables.
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 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. |
notebook | Formats lists as notebooks. |
hide | Don't show the variable in the playground |
startOpen | Start the variable open in the playground |
startClosed | Start the variable closed in the playground |
location | Store the proper location. Helps when you want to locate code corresponding to a variable. |
exportData | Metadata 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.
getName
doc
Adds text documentation to a value. This is useful for documenting what a value represents or how it was calculated.
getDoc
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 Type | Visualization Types |
---|---|
Distribution | Plot.dist |
List | Table |
(Number -> Number) Function | Plot.numericFn , Calculator |
(Number -> Dist) Function | Plot.distFn , Calculator |
Function | Calculator |
getShowAs
getExportData
spec
Adds a specification to a value. This is useful for documenting how a value was calculated, or what it represents.
getSpec
format
Set the display format for a number, distribution, duration, or date. Uses the d3-format syntax on numbers and distributions, and the d3-time-format syntax for dates.
getFormat
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.
getHide
startOpen
When the value is first displayed, it will begin open in the viewer. Refresh the page to reset.
startClosed
When the value is first displayed, it will begin collapsed in the viewer. Refresh the page to reset.
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
.
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.
getNotebook
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.
getLocation
Functions
getAll
Returns a dictionary of all tags on a value.
omit
Returns a copy of the value with the specified tags removed.
clear
Returns a copy of the value with all tags removed.