openmole / scala-js-plotlyjs   1.8.1

GNU Affero General Public License v3.0 GitHub

Scala.js facades for plotly.js .

Scala versions: 3.x 2.13 2.12
Scala.js versions: 1.x

scala-js-plotlyjs

Scala.js

Scala.js facades for plotly.js.

Usage

First, add the JCenter resolver to your build file:

resolvers += Resolver.jcenterRepo,

Then, add it to your SBT dependencies:

libraryDependencies += "org.openmole" %%% "scala-js-plotlyjs" % "1.6.2"

This project provides Scala.js facades. The plotly.js (2.8.2) file resources is embedd in the jars through the jsDependency sbt plugin.

Demo

Plotly demo

Sources: https://github.com/openmole/scala-js-plotlyjs-demo

Example

    val plotDiv = div()

val layout = Layout
  .title("My line plot")
  .showlegend(true)
  .xaxis(axis.title("Time"))
  .yaxis(axis.title("Production"))

val data = linechart.lines

val ref = Utils.randomDoubles(15, 10)

val dataRef = data
  .x((0 to 14).toJSArray)
  .y(ref)
  .marker(marker.symbol(square).color(all.color.rgb(180, 0, 0)).size(12.0))
  .name("Reds")


val dataN = (for (i <- 1 to 6) yield {
  data
    .x((0 to 14).toJSArray)
    .y(ref.map { x => x + Utils.rng.nextDouble * 2 - 1 }.toJSArray)
    .marker(marker.size(10.0).color(all.color.rgb(200, 136, 170)))
    ._result
}).toJSArray


val config = Config.displayModeBar(false)

Plotly.newPlot(plotDiv.ref,
  dataN :+ dataRef._result,
  layout,
  config)

plotDiv