[IPython-dev] Wrap Javascript (D3.js) file into IPython Widget

Lucien Boillod lucienboillod at gmail.com
Mon Oct 13 03:53:53 EDT 2014

Really thank you for that !
I’ll explore all the way you gave me, and give you a feedback of my work !

Le 11 oct. 2014 à 20:23, Nicholas Bollweg <nick.bollweg at gmail.com> a écrit :

> You can stick the whole thing in an iframe, and it will work pretty much as it is right now... the crucial bit of magic will be keeping that link between those two documents. Here is a gist with an untested 20% solution:
> https://gist.github.com/bollwyvl/f0ba3e16a5a824d53dc8
> Now the widget and the d3 stuff will exist in two separate documents, with two different javascript contexts, but from the view you can touch the frame with view.frame... the other direction is trickier, and if you end up needing to do that, just rewrite the whole thing to be outside of a frame :)
> You may want to explore some patterns, like http://bost.ocks.org/mike/chart/, to encapsulate the relationship between data/drawing inside the iframe: right now, if a widget were to update
> You'll probably want to explore d3.dispatch, so that you can create custom events (like nodeAdd, nodeRemove, etc) that the widget can react to. This may be a cleaner way than trying to "share" data
> be careful of force layout changing your data (nodes, links) in-place, adding x, y, px, py, etc.
> when a user changes nodes/links form outside the visualization, you'll probably need to do some things to force... but you'll want to run them at the same time.
> look at  Backbone.Model.changed and Widget.hold_sync to make sure that this happens atomically... or get ready for a lot of svg errors.
> All that being said: a well-structured backbone view, which every widget must be, will be more maintainable in the long run. Just having evented get/set on the model, and maybe some custom collections, might be worth the price of admission. 
> Good luck!
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141013/b161a17f/attachment.html>

More information about the IPython-dev mailing list