I need some help with d3 in scala js please. Not sure how to go about using d3.json function.
I have this:
val rectXFunVpc = (d: Vpcs,
i: Int) => {
println(s"rectXFunVpc i:$i")
i * 30
}
d3.json(
"json-file.json", callback = (e: Any, json: Any) => {
val jsonAsString: String = JSON.stringify(json.asInstanceOf[js.Any])
println(s"jsonAsString: $jsonAsString")
val pickledJson = read[domain.DescribeVpcsObject](jsonAsString)
println(s"pickledJson:$pickledJson")
val dataArray: js.Array[Vpcs] = pickledJson.Vpcs.asInstanceOf[js.Array[Vpcs]]
println(s"dataArray:$dataArray")
val sel: Update[Vpcs] = svg.selectAll("rect").data(dataArray)
sel.enter()
.append("rect")
.attr("x", rectXFunVpc)
.attr("y", 20)
.attr("width", 20)
.attr("height", 10)
.style("fill", rectColorFun)
print()
}
)
couple of issues:
- The rects are not drawn so it looks like the dataArray is not right but when I console.log it I think I am getting a proper js.Array[Vpcs]
- The rectXFuncVpc is never called (my printlns in there are not printed in browser console)
- the return type of Unit is forcing me to put the print() as the last statement of the function
Is there a chance someone could provide me an example please?