Skip to content

Commit

Permalink
Add documentation, comments, rename to DotRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamsharma committed Feb 28, 2017
1 parent 67bfa60 commit 8f0da80
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ import scala.collection.immutable.Queue

val renderer = Renderer(
renderingOptions = RenderingOptions(density = 75),
directory = Paths.get("images", "usage"),
format = "png" // Or "svg", "ps" and others supported by dot
directory = Paths.get("images", "usage")
)
```

You can also pass a `format` parameter as a String to the `Renderer` constructor
to specify the format you require. The default is `png`. You can specify any
file type supported by `dot -T`.

There are two ways to use it:

```scala
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import uk.co.turingatemyhamster.graphvizs.exec._

import scala.sys.process.{Process, BasicIO}

object ImageRenderer {
object DotRenderer {
def render(graph: Graph, output: Path,
options: RenderingOptions, format: String): Unit = {
options: RenderingOptions, format: String
): Unit = {
val args = Seq(
"-K", "dot",
"-T", format,
Expand Down
13 changes: 10 additions & 3 deletions core/src/main/scala/reftree/render/Renderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ import reftree.svg.SvgGraphAnimation
*
* val renderer = Renderer(
* renderingOptions = RenderingOptions(density = 75),
* directory = Paths.get("images", "usage")
* )
*
* // With custom output format
* val renderer = Renderer(
* renderingOptions = RenderingOptions(density = 75),
* directory = Paths.get("images", "usage"),
* format = "jpg"
* format = "ps" // Or any other format that compatible with dot -T
* )
*
* // Conventional usage
Expand Down Expand Up @@ -52,11 +58,12 @@ case class Renderer(
/** Render a diagram to a file with the given name (do not include the extension) */
def render(name: String, diagram: Diagram): Unit = {
val graph = Graphs.graph(renderingOptions)(diagram)
ImageRenderer.render(
DotRenderer.render(
graph,
directory.resolve(s"$name.$format"),
renderingOptions,
format)
format
)
}

/** Render an animation to a GIF file with the given name (do not include the extension) */
Expand Down
4 changes: 4 additions & 0 deletions demo/src/main/tut/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ val renderer = Renderer(
)
```

You can also pass a `format` parameter as a String to the `Renderer` constructor
to specify the format you require. The default is `png`. You can specify any
file type supported by `dot -T`.

There are two ways to use it:

```tut:silent
Expand Down

0 comments on commit 8f0da80

Please sign in to comment.