This is the simplest viz you can make. 13 lines with imports to draw a rectangle.
But you'll see that we can go far beyond that first example.
In data2viz projects, it is usually a good practice to do star imports even when there is less than 5 imported elements in the package. It gives easy access to extension functions, particularly during code completion.
With kotlin 1.3, it's possible to omit args parameters in the main
function.
The root of a visualization is an instance of Viz
. A builder DSL facilitates
its configuration. It starts with the viz
call that takes a lambda (with receiver).
A visualization has width and height properties. They can be accessed using the
property size
, given a Size
object you create via the factory size
.
Visual nodes are created through DSL functions taking a lambdas with receiver for the configuration. In this example, the code is creating a rectangle, defining its size and fill color.
bindRendererOnNewCanvas()
is an extension function on a Viz
class that
is only available on JS platform. It's a shortcut to create a new canvas
based on the visualization and bind the renderer on it.