I want you to learn what Graph Style Script looks like so you can help generate GSS code on user request. Let's start with the introduction:
GSS (Graph Style Script) is a language for customizing the visual display of graphs.
The main building blocks of Graph Style Script (GSS) are expressions and directives. GSS files are a sequence of expressions and directives.
Expressions are used to combine values to create new values using functions. For example, the expression:
Add(2, 5)
creates a new value 7 from values 2 and 5. There are a lot of functions built into Graph Style Script so there are even more ways to combine values. There is even a function to create new functions.
When expressions are evaluated, values are created. There are several types of Graph Style Script values: Boolean
, Color
, Number
, String
, Array
, Dictionary
, Function
and Null
.
An expression can be either literal expressions, name expressions or function applications. Literal expressions exist for Color
, Number
and String
.
This is a literal expression for String: "Hello"
. It evaluates to the value "Hello" of the type String. The newline character and double quotes can be escaped in strings using \
(backslash), e.g.
"In the end he said: \"I am Iron Man!\""
This is a literal expression for Number: 1
or 12.100
.
This is a literal expression for Color: red
or #FF0000
or #FF000010
. Literal expressions for colors are hex strings starting with '#'.
Name expressions are names that can be evaluated if there are values bound to them in the environment (lexical scope). Names can start with any of the lower case or upper case letters of the English alphabet and apart from those can contain digits and the following characters: -
, _
. Names can be defined using the Define
function:
Define(superhero, "Iron Man")
In the previous example the value "Iron Man" was bound to the name superhero. After that name expression superhero evaluates the value "Iron Man" to type String.
There are many built-in names that are bound to useful values. Most used are boolean values which are bound to True
and False
and null value which is bound to Null
. Also, all the CSS web colors are bound to their names:
dodgerblue -> evaluates to #1e90ff
forestgreen -> evaluates to #228b22
Another type of expressions are function application expressions. A function can be applied to the list of expressions (arguments) in the following way.
Concat("Agents", " ", "of", " ", "S.H.I.E.L.D.") -> evaluates to "Agents of S.H.I.E.L.D."
Here the function Concat
was applied to the list of string literal expressions to produce their concatenation. Any expression can be an argument.
Not all expressions have to be evaluated. For example, when calling If
function one argument will not be evaluated.
Define(mood, "happy")
Define(name, "Happy Hogan")
If(Equals(mood, "happy"),
Format("{} is happy today.", name),
Format("{} is not happy today.", name))
-> evaluates to "Happy Hogan is happy today."
In the previous example expression Format("{} is not happy today", name)
will not be evaluated because its value is not needed.
Some other function will not evaluate their arguments because they are interested in their names and not values. For example, when creating a new function argument names aren't evaluated, but are remembered to be later bound to the function arguments when the function is called.
Define(square, Function(x, Mul(x, x)))
square(2) -> evaluates to 4
In the previous example the name x
isn't evaluated in the first line, and neither is the expression Mul(x, x)
. In the second line when the function square
is called number 2 will be bound to the name x
and only then will Mul(x, x)
be evaluated.