stanch / reftree Goto Github PK
View Code? Open in Web Editor NEWAutomatically generated diagrams and animations for Scala data structures
Home Page: http://stanch.github.io/reftree/
License: GNU General Public License v3.0
Automatically generated diagrams and animations for Scala data structures
Home Page: http://stanch.github.io/reftree/
License: GNU General Public License v3.0
While trying to print an AST of a program, I tried renaming a node to <
for instance.
Reftree does not fail on that, but when it tries to render the resulting dotfile using dot, the error is thrown by dot. Oh, and no, it isn't a clear error.
Perhaps special characters needed by dot should be escaped somehow?
Can we have an implicit for drawing a vertical sequential list?
Something like:
abcd
|
efgh
|
ijkl
|
end
I was using something like this, but it crashes on some very simple inputs (flowName is a string)
implicit def cfListDrawer: ToRefTree[List[CFEnum]] = ToRefTree[List[CFEnum]] {
case x::xs => RefTree.Ref(x, Seq(xs.refTree)).rename(x.flowName)
case Nil => RefTree.Ref("", Seq()).rename("End")
}
Would be useful for vertical flow diagrams.
So I'm generating these two images from the code below:
In the first case, my integer case class is correctly renamed to bob. In the second case, no renaming happens.
implicit val tint: ToRefTree.DerivationConfig[Integer] =
ToRefTree
.DerivationConfig[Integer]
.rename("bob")
.omitField("i")
val renderer = Renderer(
renderingOptions = RenderingOptions(density = 75),
animationOptions = AnimationOptions(interpolationDuration = 3.seconds, framesPerSecond = 1),
directory = Paths.get("images")
)
renderer.render("application_with_integer", Diagram(Application(Integer(42), Identifier("x"))))
renderer.render("integer", Diagram(Integer(42)))
I am not sure if I am using the API correctly, but I can see that the "i" field is omitted in both cases, i.e. some of the options must be picked up in both cases.
I was going to give it a spin, but no 2.12 support stopped me. 2.12 has been our for a long time, how come it's only released as 2.11?
$ coursier launch com.lihaoyi:ammonite_2.12.7:1.4.2 --main ammonite.Main
Loading...
Welcome to the Ammonite Repl 1.4.2
(Scala 2.12.7 Java 1.8.0_181)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ import $ivy.`io.github.stanch::reftree:1.2.1`
import $ivy.$
@ import reftree.render.{Renderer, RenderingOptions}
import reftree.render.{Renderer, RenderingOptions}
@ val renderer = Renderer(
renderingOptions = RenderingOptions(density = 75),
)
java.lang.NoClassDefFoundError: fastparse/all$
reftree.geometry.Color$.<init>(Color.scala:100)
reftree.geometry.Color$.<clinit>(Color.scala)
reftree.render.RenderingOptions$.apply$default$2(Options.scala:19)
ammonite.$sess.cmd2$.<init>(cmd2.sc:2)
ammonite.$sess.cmd2$.<clinit>(cmd2.sc)
java.lang.ClassNotFoundException: fastparse.all$
java.net.URLClassLoader.findClass(URLClassLoader.java:382)
ammonite.runtime.SpecialClassLoader.findClass(ClassLoaders.scala:215)
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
reftree.geometry.Color$.<init>(Color.scala:100)
reftree.geometry.Color$.<clinit>(Color.scala)
reftree.render.RenderingOptions$.apply$default$2(Options.scala:19)
ammonite.$sess.cmd2$.<init>(cmd2.sc:2)
ammonite.$sess.cmd2$.<clinit>(cmd2.sc)
First guess: Ammonite depends on fastparse 2.0.5 (via scalaparse), so perhaps that's on the classpath instead of the older version required by reftree.
Please update the monocle-macro from version 1.4.0 to 2.0.0
I am trying the project out but I cannot run sbt demo
if always fails. Any ideas?
update the below dependencies
Color.fromRgbaString( "#F44336" )
yields the following error:
[error] (run-main-18) java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
at com.liefery.courier_android_app.reftree.Render.main(Render.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Caused by: fastparse.core.ParseError: found "#F44336", expected transparent | white | rgba at index 0
#F44336
^
at fastparse.core.Parsed$class.get(Parsing.scala:32)
at fastparse.core.Parsed$Failure.get(Parsing.scala:74)
at reftree.geometry.Color$.fromRgbaString(Color.scala:95)
at com.liefery.courier_android_app.reftree.Render$.<init>(Render.scala:18)
at com.liefery.courier_android_app.reftree.Render$.<clinit>(Render.scala:12)
at com.liefery.courier_android_app.reftree.Render.main(Render.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Changing the color hex to lower case fixes the error.
The line which is causing this is val x = CharIn(('0' to '9') ++ ('a' to 'f'))
here
I have the following image generated:
This is the code I am using:
implicit def `ArrayDeque RefTree`: ToRefTree[mutable.ArrayDeque[Char]] = ToRefTree {ds =>
val array = ds.privateField[Array[AnyRef]]("array").map(c => Option(c).getOrElse('␀').asInstanceOf[Char])
val start = ds.privateField[Int]("start")
val end = ds.privateField[Int]("end")
val arrayRef = {
val arrayFields = array.zipWithIndex map { case (a, i) =>
val name = i match {
case `start` if start == end => s"start=end=$i"
case `start` => s"start=$i"
case `end` => s"end=$i"
case _ => i.toString
}
a.refTree.withHighlight(i == start || i == end).toField.withName(name)
}
RefTree.Ref(array, arrayFields).rename(s"char[${array.length}]")
}
RefTree.Ref(ds, Seq(
start.refTree.withHighlight(true).toField.withName("start"),
end.refTree.withHighlight(true).toField.withName("end"),
arrayRef.toField.withName("array")
) ++ ds.toArray.zipWithIndex.map({case (a, i) => a.refTree.toField.withName(i.toString)}))
}
But, it would be nice to have start
and end
have arrows into the array. Is it possible?
In https://stanch.github.io/reftree/#minimal-example the example uses ImagePath
but does not define it.
It would be easier if a URL was provided:
import java.nio.file.Paths
import reftree.diagram.Diagram
import reftree.render.{Renderer, RenderingOptions}
object Main {
def main(args: Array[String]): Unit = {
val imagePath = Paths.get("images") // current relative path + "images"
val renderer = Renderer(
renderingOptions = RenderingOptions(density = 75),
directory = imagePath.resolve("overview")
)
import renderer._
case class Person(firstName: String, age: Int)
Diagram.sourceCodeCaption(Person("Bob", 42)).render("example")
val file = directory.resolve("example.png")
println(s"Open with Browser ${file.toUri}")
println(s"Open with IntelliJ IDEA http://localhost:63342/api/file/${file.toString}")
}
}
For SVG output, the dot language supports specifying a URL link for a node.
See: https://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:URL
Since the node label is a table, the tooltip shows "
" if there is no anchor.Currently this project is only published for Scala 2.11. I would love to use it for generating some documentation in Scala 2.12.
In some cases, the predefined options for formatting value fields are insufficient. E.g.
00010100111xxxx
In these cases it would be useful to be able to provide a custom toString method or have another method to customise display of inline fields.
Char nullSymbol = '␀'
I don't see the 2.12 artifacts on Jcenter, and depending on "org.stanch" %% "reftree" % "1.1.3"
fails as well. Is there a different repo I should be using?
Exception building diagram (on scala 2.12.5)
[info] Compiling 1 Scala source to /home/wsargent/work/scala-capabilities/images/target/scala-2.12/classes ...
[error] /home/wsargent/work/scala-capabilities/images/src/main/scala/Main.scala:90:44: Internal error: unable to find the outer accessor symbol of class anon$Generic Coproduct RefTree$macro$14
[error] val diagram = Diagram(nameChanger)
[error] ^
[error] ## Exception when compiling 1 sources to /home/wsargent/work/scala-capabilities/images/target/scala-2.12/classes
[error] null
[error] java.lang.String.valueOf(String.java:2994)
code is as follows
import java.nio.file.{Path, Paths}
import reftree.diagram.Diagram
import reftree.render.{Renderer, RenderingOptions}
object Main {
// #definition
final class Document(private var name: String) {
private object capabilities {
val nameChanger = new Document.NameChanger {
override def changeName(newName: String): Unit = {
name = newName
}
}
}
override def toString: String = s"Document($name)"
}
// #definition
// #access
object Document {
sealed trait NameChanger {
def changeName(name: String): Unit
}
// Policy controls who has access to what
class Access private {
def nameChanger(doc: Document): NameChanger = {
doc.capabilities.nameChanger
}
}
object Access {
def apply(): Access = new Access
}
}
// #access
// https://www.youtube.com/watch?v=6mWaqGHeg3g
def main(args: Array[String]): Unit = {
val imagePath = Paths.get("images") // current relative path + "images"
implicit val renderer = Renderer(
renderingOptions = RenderingOptions(),
directory = imagePath.resolve("overview")
)
import renderer._
def render(name: String, diagram: Diagram): Path = {
diagram.render(name)
directory.resolve(s"$name.${renderer.format}")
}
def display(path: Path) = {
println(s"Open with Browser ${path.toUri}")
println(s"Open with IntelliJ IDEA http://localhost:63342/api/file/${path.toString}")
}
val document = new Document("will")
val access = Document.Access()
val nameChanger = access.nameChanger(document)
println(s"result = $document")
val diagram = Diagram(nameChanger)
display(render("nameChanger", diagram))
}
}
When I look at the https://stanch.github.io/reftree/#including-in-your-project it says 1.2.0 is the latest.
In addition, the documentation does not specify that you are using bintray and so need to add a bintray resolver:
resolvers += Resolver.bintrayRepo("stanch", "reftree"),
The latest version on mvnrepository is 1.1.3:
https://mvnrepository.com/artifact/org.stanch/reftree
If I go to bintray directly then it does tell me it's 1.2.0:
https://bintray.com/stanch/maven/reftree/1.2.0
But it appears that 1.2.0 was only published for Scala 2.11, not 2.12 (it was not cross-published):
Finally, the gitbook demo is flaky -- if I type "makeSite" twice in a row then it fails with some npm exception. Not sure what's up with that.
Hey there! Is there any chance to publish this library for Scala 2.13? Or maybe if there is a PR from the community, would it be possible to merge it (asking for a friend 😄)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.