SciNim / nim-plotly

plotly wrapper for nim-lang
https://scinim.github.io/nim-plotly/
MIT License
179 stars 15 forks source link

Compiling JS example #57

Closed moukle closed 4 years ago

moukle commented 4 years ago

Hey there!

Am new to Nim, thus I am not sure if the fault is on my side but trying to compile the js example (nim js fig8_js_interactive.nim) yields following error for me:

/home/ritzo/Documents/moukle.github.io/assets/js/nim_plots/fig8_js_interactive.nim(56, 4) template/generic instantiation of `animate` from here
/home/ritzo/Documents/moukle.github.io/assets/js/nim_plots/fig8_js_interactive.nim(15, 39) template/generic instantiation of `parseTraces` from here
/home/ritzo/.nimble/pkgs/plotly-0.2.0/plotly/plotly_js.nim(24, 17) Error: type mismatch: got <seq[Trace[system.int]]>
but expected one of: 
proc `%`(x, y: JsObject): JsObject
  first type mismatch at position: 1
  required type for x: JsObject
  but expression 'traces' is of type: seq[Trace[system.int]]

System:

brentp commented 4 years ago

looks like that has some bit rot as it's not tested. I think this change fixes:

diff --git a/src/plotly/plotly_js.nim b/src/plotly/plotly_js.nim
index 454d707..e62b7e1 100644
--- a/src/plotly/plotly_js.nim
+++ b/src/plotly/plotly_js.nim
@@ -1,7 +1,8 @@
 import jsbind
 import jsffi
 import dom
-import plotly_types
+import ./plotly_types
+import ./api

maybe @Vindaar can verify?

Vindaar commented 4 years ago

Yep, that's almost all that's needed. Thanks for the hint though, because in my current state I wouldn't have figured out quickly that this is due to the % missing for one of the types. :)

And the resulting js file is apparently not put into the nimcache directory anymore, so the html template has to be changed. I'll open a PR.

moukle commented 4 years ago

Thanks for the fast response! :)