Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #25 #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/shared/src/main/scala/reftree/dot/DotEncoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ private[dot] sealed trait DotAttrEncoding extends LabelledProductTypeClassCompan
if (headEnc.encoded.isEmpty) {
ct.encoding(tail)
} else {
// The 'URL' attribute must remain in uppercase otherwise it will be ignored.
val encodedName = if (name == "URL") name else name.toLowerCase
Chunk.join(" ")(
Chunk.join("=")(Chunk(name.toLowerCase), headEnc),
Chunk.join("=")(Chunk(encodedName), headEnc),
ct.encoding(tail)
)
}
Expand Down
1 change: 1 addition & 0 deletions core/shared/src/main/scala/reftree/dot/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ object Node {
case class Attrs(
shape: Option[String] = None,
tooltip: Option[String] = None,
URL: Option[String] = None,
color: Option[Color] = None,
fontName: Option[String] = None,
fontColor: Option[Color] = None
Expand Down
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/reftree/graph/Graphs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ object Graphs {
depth: Int
): Seq[GraphStatement] = tree match {
case r @ RefTree.Ref(_, id, children, _) ⇒
Seq(Primitives.node(r, color, anchorId, namespace)) ++
Seq(Primitives.node(r, color, anchorId, namespace, options.nodeURLs.get(id), options.nodeTips.get(id))) ++
children.filterNot(_.elideRefs).flatMap(c ⇒ inner(c.value, color, None, namespace, depth + 1)) ++
children.zipWithIndex.flatMap { case (c, i) ⇒ Primitives.edge(id, c.value, i, color, namespace) }
case _ if depth == 0 ⇒
Seq(Primitives.node(tree, color, anchorId, namespace))
Seq(Primitives.node(tree, color, anchorId, namespace, None, None))
case _ ⇒
Seq.empty
}
Expand Down
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/reftree/graph/Primitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Primitives {
Seq(captionNode, captionEdge)
}

def node(tree: RefTree, color: Color, anchorId: Option[String], namespace: Seq[String]): Node = {
def node(tree: RefTree, color: Color, anchorId: Option[String], namespace: Seq[String], url: Option[String], tip: Option[String]): Node = {
val background = if (tree.highlight) color.opacify(0.2) else defaultBackground
val labelContent: Seq[Row] = tree match {
case ref: RefTree.Ref ⇒
Expand All @@ -51,9 +51,9 @@ object Primitives {
cellSpacing = Some(0), cellPadding = Some(6), cellBorder = Some(0), columns = Some("*"),
bgColor = Some(background), style = Some("rounded")
))
val tooltip = anchorId.map(a ⇒ s"anchor-$a")
val tooltip = tip.orElse(anchorId.map(a ⇒ s"anchor-$a"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this create extra anchors as a side effect and therefore affect alignment? Maybe if “pretty” tooltips are important, it would be better to use some other mechanism for anchors.

val id = namespaced(tree.id, namespace)
Node(id, label, Node.Attrs(fontColor = Some(color), color = Some(color), tooltip = tooltip))
Node(id, label, Node.Attrs(fontColor = Some(color), color = Some(color), tooltip = tooltip, URL = url))
}

private def cellLabel(tree: RefTree, elideRefs: Boolean = false): Html = tree match {
Expand Down
4 changes: 4 additions & 0 deletions core/shared/src/main/scala/reftree/render/Options.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import scala.concurrent.duration._
* Options for rendering static diagrams
*
* @param verticalSpacing vertical spacing to set for Graphviz
* @param nodeURLs map of node ID to a URL
* @param nodeTips map of node ID to a node tooltip overriding the anchor tooltip, if defined
* @param palette a sequence of colors to be used
* @param font the font for text rendering
* @param density the desired image density, in pixels per inch
*/
case class RenderingOptions(
verticalSpacing: Double = 0.8,
nodeURLs: Map[String, String] = Map.empty,
nodeTips: Map[String, String] = Map.empty,
palette: IndexedSeq[Color] = Array(
Color.fromRgbaString("#104e8b"),
Color.fromRgbaString("#228b22"),
Expand Down
20 changes: 20 additions & 0 deletions site/src/main/tut/Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ val renderer = Renderer(
)
```

**For SVG rendering (JVM, Scala.js):**

It is possible to specify for each `RefTree.Ref`
a hyperlink URL and a tooltip text
by providing associating to the `RefTree.Ref.id` a URL string
or a tooltip string respectively.

```scala
import reftree.render._
import reftree.diagram._

val renderer = Renderer(
renderingOptions = RenderingOptions(
density = 75,
nodeURLs = Map("1" -> "http://www.example.org", "2" -> "http://www.foobar.org"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give a real-life example of the URL you would use?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing, I am not sure I like the idea of attaching this to internal ids, because those ids are not guessable or even deterministic. Is it important to you to specify the tip explicitly? What if reftree generated tips automatically using toString or something like that? Or maybe it could just set all tooltips to an empty string.

nodeTips = Map("1" -> "example", "2" -> "foobar")),
format = "svg"
)
```

There are two ways to use renderers:

**JVM**
Expand Down