Porting a JavaScript Library in Python

I am interested in porting the javacript protovis visualization library to python for use in scientific computing. I have a general question and a specific question.

General information. I have never migrated an entire library before. What are some good strategies? Should I first implement a user oriented API and then populate it in pythonic style? Or is it better to first try to transfer the internal structure / infrastructure, and then rebuild the API on top of it?

Specifically: this library seems to heavily use javascript prototype inheritance, which is slightly different from the python model. I found a person who made a fairly simple method for emulating prototype inheritance in python. However, from the point of view of porting the library, I would prefer not to twist python to be more like javascript. Any feedback on this would be greatly appreciated. Thanks!

Uri

+4
source share
3 answers

You might be better off looking at Prefuse (http://www.prefuse.org) or Flare (http://flare.prefuse.org). The first one is based on Java, the latest Flash.

The proto-release is slightly different in that regular Javascript works with the browser, using SVG as a canvas. You cannot easily use this in rewriting Python.

If you are using a graphical / network visualization package, you can check NetworkX: http://networkx.lanl.gov/

+1
source

If you want a port from C / C ++ to python, you probably want to use swig. I don't know about javascript for python, but you probably have to do it manually. I would consider prototype inheritance in python unpythonic. I would not recommend using the metaclass hack specified in the link. Python programmers are not used to prototype inheritance and probably will not want to use it, and you have to be very careful when using metaclasses. Therefore, I believe that it is best to revise the inheritance model. I also think that redesigning the API will not hurt to make it more pythonic.

+1
source

The Python ecosystem currently lacks a visualization tool like Protovis, go ahead and good luck with your rewriting!

+1
source

Source: https://habr.com/ru/post/1332640/


All Articles