Drawing tree in OCaml GUI, best option?


#1

Hello,

I need to draw a knowledge tree of some form where the tree needs to be interactive. Basically just a tree of nodes that you can click on and do actions, hide, zoom in/out, move camera around etc.

My current plan is to convert the current core code, which is in OCaml, to ReasonML and offload the graphing part to some Javascript libraries.

Is this the best option in terms of time and ease of development?

The GUI does not have to be pretty, just needs to be prototype quality, which is why I don’t want to spend too much time on it as it shouldn’t be a big part of my project.

The GUI can also be in browser or in other UI or window of some form, as long as it can be opened on a computer.

Cheers,
Darren


#2

Reason is just a syntax, so you shouldn’t need to port to it in order to get access to new functionality like to-JavaScript compilation. The key question is whether you should use js_of_ocaml or Bucklescript to compile to JavaScript. If this is an ocaml-first project, I would use js_of_ocaml, since it’s fully up to date with recent compilers.

Lexifi’s vdom and Jane Street’s incr_dom both seem like plausible approaches to me.


#3

True, I just meant using refmt and so on. No manual porting or anything yep.

Thanks very much for your suggestion, I didn’t know about those two options at all, I’ll experiment with them later.


#4

I’ve also started playing with lablqml which is a set of OCaml bindings to the qtquick/qml part of Qt5, but it is too early for me to say if this is a viable approach to building UIs.


#5

Not sure if you’ve seen these or if this would match your use case, but there are also js_of_ocaml bindings to some charting libraries:


#6

Spiros’ ocaml-d3 is not actually typesafe, be warned. Modeling d3 properly in OCaml is tricky.

y


#7

One follow up question, if a project needs to rely on npm somewhat, is js_of_ocaml still a good option?

My understanding is bucklescript allows easier access to npm libraries, and deals with project management as well, while js_of_ocaml is still used inside dune etc. I have yet to find info on how easy it is to use npm stuff in js_of_ocaml.

Thanks very much!


#8

I’ve definitely used JavaScript libraries with js_of_ocaml, and that works fine. But npm integration as far as I know has only been put together with Bucklescript and bsb (the Bucklescript build system), and I don’t know much of the details. But it was pretty easy to grab a bundle off of npm, and then do the rest in js_of_ocaml. You can take a look at our virtual_dom package to see how it was done.


#9

Awesome! Thanks very much for the reply and the pointer.


#10

I only have experience with Bucklescript not with js_of_ocaml but my experience is quite good with it. If you have experience with js and the js ecosystem, I would probably check out Bucklescript.


#11

Yep I would agree, I have been toying with Reason and Bucklescript for past 1-2 days, and the experience has been very smooth.

My only concern is that being stuck with OCaml 4.02.3 might cause issues later down the road for the project that I can’t foresee right now. So I’ll proceed with js_of_ocaml for now.


#12

AFAIK, the work has started to move Bucklescript over to 4.06, these might be relevant: https://github.com/BuckleScript/bucklescript/issues/2755 and JS_of_OCaml vs Bucklescript


#13

Thanks for the info!

Yep I bumped into the GitHub issue today, but since my project is due in a few months, I can’t really wait on it.


#14

I have used it to make a UI used in the industry but it has a learning curve because aspects of it are not documented.


#15

Did you like using it? Would you use it again if you had to do an OCaml app with a GUI?


#16

I developed the binding method between QML with OCaml, so I’m probably biased, but I would use it again yes. I have had ideas to make it more straightforward but not the time, yet.


#17

@orbifx Can you advertise QML itself?


#18

Advertise QML itself? Qt project does a good job :yum:


#19

What’s the overall idea?


#20

QML objects emit parametrised signals for the various events they handle… During boot, we query the QML tree for objects of interest and we bind OCaml functions to these signals. There are some small things to watch out for. The cool thing with this approach is that it only requires QML + OCaml and generally no extra C++ code.