I am following the tutorial here:
https://www.scala-js.org/doc/project/dependencies.html
- First things first, I have my project set up like this:
https://github.com/scala-js/scalajs-cross-compile-example
Without making any changes, this runs as expected when I pass in the following commands:
sbt> fooJS/run
sbt> fooJVM/run
Now I want to import this library:
I want to run the following function:
Plotly.newPlot('myDiv', data);
How can I do this?
My Main.scala file inside the js folder looks like this:
package example
object Main extends App {
println(s"Using Scala.js version ${System.getProperty("java.vm.version")}")
}
I know a facade for this library already exists, but I would like to be able to create my own facades for future projects, and am using this as an example. I read the tutorial here:
https://www.scala-js.org/doc/interoperability/facade-types.html
But in all honesty I do not follow those steps coming from a different language ecosystem.
“I do not follow those steps” is not a useful way to describe the problems you're having.
It looks fairly obvious what you need to do. There's a global Object called
Plotly, which has a method callednewPlot, which takes aStringand an array of objects containing the data. So you need something like this:Now that we have that, we also need to specify what
PlotDatais supposed to look like. Unlike the type of thePlotlyobject, where we merely specify the interface and the actual object is implemented in JS, this type is going to be implemented in Scala, so you need to follow this guide.For a
scattertype plot, it could look like so: