我在尝试绘制" Diagonal"使用ScalaJS D3库的行:https://github.com/spaced/scala-js-d3
我从这里的原始JS示例开始:http://jsfiddle.net/MetalMonkey/JnNwu/
// root is a js.Dynamic holding JSON data
val nodes =
tree
.nodes(root)
.reverse
val svg = d3.select("#tree").append("svg")
val links = tree.links(nodes)
val projector = (d: Node, num: Double) => { js.Tuple2(d.x, d.y) }
val diagonal = d3.svg.diagonal()
.projection(projector)
val link =
svg
.data(links)
.append("line")
.attr("class", "link")
.style("stroke-width", 5)
.attr("d", diagonal)
试图通过"对角线"功能让我:
[error] found : (scala.scalajs.js.Dynamic, Int, scala.scalajs.js.UndefOr[Int]) => String
[error] required: scala.scalajs.js.Function3[org.singlespaced.d3js.Link[scala.scalajs.js.Dynamic],Int,scala.scalajs.js.UndefOr[Int],scala.scalajs.js.|[scala.scalajs.js.|[Double,String],Boolean]]
[error] .attr("d", (value: Dynamic, x: Int,y: js.UndefOr[Int]) => "Completely lost.")
[error] ^
[error] one error found
不知所措,我试图传递符合所需签名的任何函数:
val link =
svg
.data(tree.links(nodes))
.append("line")
.attr("class", "link")
.style("stroke-width", 5)
.attr("d", (value: Link[Dynamic], x: Int,y: js.UndefOr[Int]) => "Totally lost": Primitive)
编译,只会导致在浏览器中抛出此错误:
uncaught exception: scala.scalajs.runtime.UndefinedBehaviorError: An undefined
behavior was detected: [object Object] is not an instance of org.singlespaced.d3js.Link
我没有真正认识到
scala.scalajs.js.|[scala.scalajs.js.|[Double,String],Boolean]
类型,我还没有找到任何结果来解释它是否是ScalaJS disjunction / etc / etc或者甚至是相关的。我是ScalaJS和D3的新手,所以任何指针都很有帮助。