Uri Laserson
Uri Laserson

Reputation: 2451

Porting a JavaScript library to Python

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

General: I have never ported a whole library before. What are some good strategies? Should I first just implement the user-facing API and then fill it in in a pythonic fashion? Or is it better to try to port over the internals/infrastructure first, and then rebuild the API on top of it?

Specific: This library appears to make heavy use of javascript's prototype-based inheritance, which is somewhat different from the python model. I found someone who made a pretty simple method to emulate prototypal-inheritance in python. However, from the perspective of porting a library, I'd rather not arm-twist python to be more like javascript. Any feedback on this issue would be greatly appreciated. Thanks!

Uri

Upvotes: 4

Views: 798

Answers (3)

fccoelho
fccoelho

Reputation: 6204

The Python ecosystem is currently lacking a visualization tool such as Protovis, go ahead and good luck with your rewrite!

Upvotes: 1

pyfex
pyfex

Reputation: 1205

If you want to port from C/C++ to python you probably want to use swig. I don't know about javascript to python, but you probably have to do by hand. I would consider prototype inheritance in python unpythonic. I wouldn't recommend using the metaclass hack given in the link. Python programmers are not used to prototype inheritance and will probably not want to use it and you should be very carful when using metaclasses. Therefore I think it is best when you redisgn the inheritance model. I also think a redesign on the API wouldn't hurt to make it more pythonic.

Upvotes: 1

axw
axw

Reputation: 7083

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

Protovis is a little different in that it's plain old Javascript running the browser, using SVG as the canvas. You're not going to be able to readily leverage that in a Python rewrite.

If you're after a graph/network visualisation package, you might want to check out NetworkX: http://networkx.lanl.gov/

Upvotes: 1

Related Questions