[IPython-dev] _repr_javascript_ code samples for D3
Matthias BUSSONNIER
bussonniermatthias at gmail.com
Tue May 14 09:54:56 EDT 2013
Hi stephan,
Right now we are focusing on polishing IPython for the 1.0 around mid July,
we plan on having meeting after to start discussing interactivity and dynamic
graph (For example d3js) after that. There are some prototype and hack around,
but none of them completely satisfy us.
So right now, there are no "right way" to do it. I don't want to promise you too much,
nor go too much into detail about something that would change, but we will probably define
a way to tell o the notebook interface,
"here are some javascrit plugin that know how to represent data"
then on your object you would probably define a _json_repr_ that say
"I hold the data of such type"
And the js plugin will then be given the data and the container in which to do it's stuff.
tricky part is that some plugin might want to have interaction with kernel, and that you also need to store
the data for later convert ion (by nbviewer for example).
In my vision of things, we could inspire on vega[1],
and I already have some idea to integrate it with nbviewer to also have some dynamic representation with it.
As for you problem, if you are on dev, you could simplify things by using custom.js
and using a $.getScript(''http://d3js.org/d3.v3.min.js") in it, that will inject d3 library on all your notebooks,
it will help.
You can have a look at https://github.com/ipython/ipython/pull/2518 if you want some more place to start to
know what where the issues with fist prototyping.
[1] http://trifacta.github.io/vega/
--
Matthias
Le 14 mai 2013 à 15:36, Stefan Krastanov a écrit :
> I was able to hack together something that uses `publish_html` and
> `publish_javascript` in order to create a D3 graphic from within the
> ipython notebook:
>
>
> Prepare a container:
>
> publish_html("""
> <div id="sympy_d3_plot_%d"></div
> """%_ipython_div_counter)
>
> Load the library
>
> publish_javascript("""
> var script = document.createElement("script");
> script.src = "http://d3js.org/d3.v3.min.js";
> document.body.appendChild(script);
> """)
>
> And after that another `publish_javascript` for doing the D3.js specific stuff.
>
> However I do not believe this is the correct way to create objects
> that visualize nicely in IPython. Is there a guide how to do this The
> Right Way(TM)?
>
>
> On 8 May 2013 11:02, Stefan Krastanov <krastanov.stefan at gmail.com> wrote:
>> Hi all,
>>
>> I have seen a nice visualization of networkx graph through d3.js in
>> the notebook. I want to use D3 to visualize some other objects. I
>> guess I should use `_repr_javascript_` but I do not know how the
>> scoping of javascript libraries works, how much is sandboxed by the
>> notebook, where to include the library, etc. I was hoping that you can
>> point me to a code sample that does it The Right Way(TM).
>>
>> A quick code search on github did not return anything useful.
>>
>> Regards
>> Stefan
> _______________________________________________
> 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/20130514/0bd6484c/attachment.html>
More information about the IPython-dev
mailing list