PlotlyJS with ScalaJS: Problem with 3D graph / WebGL

176 Views Asked by At

With plain Javascript it works:

 var data = [{
          "z": [[8.83, 8.89, 8.81, 8.87, 8.9, 8.87], [8.89, 8.94, 8.85, 8.94, 8.96, 8.92], ..., [8.93, 8.97, 8.97, 9.18, 9.2, 9.18]],
          "type": "surface"
        }];
 var layout = {};
 var TESTER = document.getElementById('example');
 Plotly.newPlot(TESTER, data, layout);

With ScalaJS it does not work (it shows: WebGL is not supported by your browser). I took the generated code and the only difference is this line:

$i_plotly$002ejs.newPlot(TESTER, data, layout)

Also the version should be identical:

// JavaScript
<script src="https://cdn.plot.ly/plotly-1.47.2.min.js"></script>

// build.sbt
libraryDependencies ++= Seq(ScalablyTyped.P.`plotly_dot_js`)
npmDependencies in Compile ++= Seq("plotly.js" -> "1.47.2")

Here the Scala code, how I use Plotly:

import typings.plotlyDotJsLib.plotlyDotJsMod.{Data, Layout, ^ => Plotly}
...

   val data: js.Array[Data] = js.Array(
  dynLit(
    z =  js.Array(
      js.Array(8.83,8.89,8.81,8.87,8.9,8.87),
      ...
      js.Array(9,9.01,9,9.2,9.23,9.2),
      js.Array(8.99,8.99,8.98,9.18,9.2,9.19),
      js.Array(8.93,8.97,8.97,9.18,9.2,9.18)
  ),
    `type` = "surface"
  ).asInstanceOf[Partial[Data]]
)
...
  Plotly.newPlot("plotCube", data, layout)
0

There are 0 best solutions below