Styles
A style is a named set of properties, written like a config block:
style name { property: value; property: value }and use: name in a statement’s metadata applies it, as if its properties
had been written there. A style is resolved away when the file compiles, so
the graph only ever sees the properties themselves.
Styles live at the top level, and like macros they are in scope everywhere - above where they are written, and across every file an import brings in.
config { xmin: -8; xmax: 8; ymin: -6; ymax: 6 }
style guide { color: BLACK; lineOpacity: 0.3; lineStyle: DASHED }style marker { pointSize: 16; showLabel; labelOrientation: above }style knob { slider: -3..3 step 0.1 }
"Styles"
// The simplest use: a look shared by several statements, changed in one place.x = 0 @ use: guidey = 0 @ use: guide
folder "Composing styles" { "A style may use other styles, and add to them." "hot and cold are both a marker, in a colour of their own." (-5, 3) @ use: hot, label: "hot" (-3, 3) @ use: cold, label: "cold" "One clause may use several; they apply in the order written, so where two disagree the later wins." (-1, 3) @ use: hot, use: cold, label: "cold wins" (1, 3) @ use: cold, use: hot, label: "hot wins"}
// The style they compose, written below the statements that use it - which is// fine, since a style is in scope for the whole file.style hot { use: marker; color: RED }style cold { use: marker; color: BLUE }
folder "What a statement says wins" { "A property written in the clause itself beats every style it uses, wherever in the clause it is written." (3, 3) @ use: hot, color: GREEN, label: "green" (5, 3) @ color: GREEN, use: hot, label: "still green"}
folder "Any property" { "A style holds any property a statement may have - a slider's range too." a = 1 @ use: knob b = 0 @ use: knob "And an @{ } block uses one the same way, on a line of its own." y = a * sin(x - b) - 2 @{ use: guide lineStyle: SOLID lineOpacity: 1 lineWidth: 3 }}Open in playground →