Skip to main content

Getting started

To use this library you will need to have GraphViz installed (and have dot on your PATH). I also recommend to install the Source Code Pro fonts (regular and italic), as I find they look the best among the free options and therefore are used by default.

For viewing PNG and animated GIF on Linux I recommend eog and gifview respectively.

Interactive usage

To jump into an interactive session:

$ git clone https://github.com/stanch/reftree
$ cd reftree
$ sbt demo
@ render(List(1, 2, 3))
// display diagram.png with your favorite image viewer

Including in your project

reftree is available for Scala 2.12 and 2.13. You can depend on the library by adding these lines to your build.sbt:

libraryDependencies += "io.github.stanch" %% "reftree" % "1.5.0"

Minimal example

import reftree.render.{Renderer, RenderingOptions}
import reftree.diagram.Diagram
import java.nio.file.Paths
val ImagePath = "images"
val renderer = Renderer(
renderingOptions = RenderingOptions(density = 100),
directory = Paths.get(ImagePath, "overview")
)
import renderer._

case class Person(firstName: String, age: Int)

Diagram.sourceCodeCaption(Person("Bob", 42)).render("example")

This generates images/overview/example.png with the following image:

bob

For more details, please refer to the guide.