Skip to content

Commit

Permalink
Make ImagePath visible in minimal example (close #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
stanch committed Jul 10, 2024
1 parent fc11bc1 commit 4190d1a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
26 changes: 24 additions & 2 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@ $ sbt demo

You can depend on the library by adding these lines to your `build.sbt`:

```mdx-code-block
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```

<Tabs groupId="platform">
<TabItem value="jvm" label="JVM" default>

```scala
// JVM
libraryDependencies += "io.github.stanch" %% "reftree" % "@VERSION@"
```

// Scala.js
</TabItem>
<TabItem value="js" label="Scala.js">

```scala
libraryDependencies += "io.github.stanch" %%% "reftree" % "@VERSION@"
```

</TabItem>
</Tabs>

## Minimal example

```scala mdoc:invisible
Expand All @@ -44,7 +58,13 @@ val ImagePath = "site-gen/target/mdoc/images"
import reftree.render.{Renderer, RenderingOptions}
import reftree.diagram.Diagram
import java.nio.file.Paths
```

```scala
val ImagePath = "images"
```

```scala mdoc:silent
val renderer = Renderer(
renderingOptions = RenderingOptions(density = 100),
directory = Paths.get(ImagePath, "overview")
Expand All @@ -56,6 +76,8 @@ 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](images/overview/example.png)

For more details, please refer to the [guide](Guide.md).
29 changes: 25 additions & 4 deletions docs/Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,29 @@ implicit def treeInstance: ToRefTree[Tree] = ToRefTree[Tree] { tree =>

To render diagrams and animations, you will need a `Renderer`.

**For JVM:**
```mdx-code-block
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```

```scala mdoc:invisible
val ImagePath = "site-gen/target/mdoc/images"
```

<Tabs groupId="platform">
<TabItem value="jvm" label="JVM" default>

```scala mdoc:silent
import reftree.render._
import reftree.diagram._
import java.nio.file.Paths
```

```scala
val ImagePath = "images"
```

```scala mdoc:silent
val renderer = Renderer(
renderingOptions = RenderingOptions(density = 75),
directory = Paths.get(ImagePath, "guide")
Expand All @@ -74,7 +86,8 @@ 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`.

**For Scala.js:**
</TabItem>
<TabItem value="js" label="Scala.js">

```scala
import reftree.render._
Expand All @@ -85,9 +98,13 @@ val renderer = Renderer(
)
```

</TabItem>
</Tabs>

There are two ways to use renderers:

**JVM**
<Tabs groupId="platform">
<TabItem value="jvm" label="JVM" default>

```scala mdoc:silent
import scala.collection.immutable.Queue
Expand All @@ -100,7 +117,8 @@ import renderer._
Diagram(Queue(1)).render("queue")
```

**Scala.js**
</TabItem>
<TabItem value="js" label="Scala.js">

```scala
import org.scalajs.dom
Expand All @@ -113,6 +131,9 @@ import renderer._
Diagram(List(1)).render(dom.document.getElementById("diagram"))
```

</TabItem>
</Tabs>

You can set various options, for example:

```scala mdoc:silent
Expand Down

0 comments on commit 4190d1a

Please sign in to comment.