This is an excellent example (YMMV).
It raises a question: Is there a guide for JS development in Nim?
I looked in the "docs", and "learn" and came across Nim backend integration
Should an FAQ question be added, something like "How do I use Nim to write a JS App"?
Hi @Jipok,
Do you mean me adding gh-pages? I didn't want to put any docs up given that this is just a toy example. In any case, I added the output here .
My library code is tiny and looks like this:
import jsffi
import jsbind
type PlotlyObj = ref object of JsObject
proc newPlotly*(): PlotlyObj {.jsimportgWithName: "function(){return (Plotly)}" .}
let Plotly* = newPlotly()
proc newPlot*(p: PlotlyObj; divname: cstring; data: seq[JsObject]; layout: JsObject) {.jsimport.}
The examples are as follows:
import jsffi
import plotly
# Line plot
var trace1=newJsObject()
trace1.x = @[1, 2, 3, 4]
trace1.y = @[18, 15, 13, 12]
trace1.mode = "lines+markers"
var data1 = @[trace1]
var layout1 = newJsObject()
layout1.title = "Line plot".cstring
Plotly.newPlot("line-plot", data1, layout1)
# Bar plot
var trace2 = newJSObject()
trace2.x = @["giraffes".cstring,"orangutans".cstring,"monkeys".cstring]
trace2.y = @[20,14,23]
trace2.type = "bar".cstring
var data2 = @[trace2]
var layout2 = newJsObject()
layout2.title = "Bar plot".cstring
Plotly.newPlot("bar-plot", data2, layout2)
Some questions: