That looks very interesting. I am still looking for ways to do this for a 
more complex class. My problem is that 
I havent managed to penetrate into javascript very well and all the 
concepts and especially the multitude of frameworks 
still confuses. 

On Sunday, January 14, 2018 at 4:25:43 PM UTC, Tony Hirst wrote:
>
> Loosely related to this, a simple cell magic for writing to an HTML 2D 
> canvas element: https://github.com/psychemedia/ipython_magic_canvas
>
> --tony
>
> On Friday, 20 January 2017 13:38:46 UTC, Steven Silvester wrote:
>>
>> Right, I meant that a subset of HTML could be used in the html_repr as a 
>> fallback display in an untrusted notebook.
>>
>>
>> On Sunday, January 15, 2017 at 10:28:32 AM UTC-6, Björn Johansson wrote:
>>>
>>> Hi, I would like to add a javascript representation to the class below. 
>>> I would like to have a circle drawn on a HTML5 canvas. Is this even 
>>> possible? The code below does not work and I do not know very much 
>>> javascript. I would be grateful for help. The code below executes, but 
>>> nothing is drawn in the cell. I have looked at the ipywidgets 
>>> <https://github.com/ipython/ipywidgets>, but it is not clear to me how 
>>> to modify the code below.
>>>
>>> *class MyCircle(object):*
>>>
>>> *    def __init__(self, center=(0.0,0.0), radius=1.0, color='blue'):*
>>> *        self.center = center*
>>> *        self.radius = radius*
>>> *        self.color = color*
>>>
>>> *    def _repr_html_(self):*
>>> *        return "&#x25CB; (<b>html</b>)"*
>>>
>>> *    def _repr_svg_(self):*
>>> *        return """<svg width="100px" height="100px">*
>>> *           <circle cx="50" cy="50" r="20" stroke="black" 
>>> stroke-width="1" fill="blue"/>*
>>> *        </svg>"""*
>>>     
>>> *    def _repr_latex_(self):*
>>> *        return r"$\bigcirc \LaTeX$"*
>>>
>>> *    def _repr_javascript_(self):            *
>>> *        s=(    'var canvas = document.createElement("canvas");'    *
>>> *               'canvas.height= 400;'*
>>> *               'canvas.width = 400;'*
>>> *               'var context = canvas.getContext("2d");'*
>>> *               'document.body.appendChild(canvas);')*
>>> *        return s*
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/c409215d-2b7e-4339-8cab-f4138fe2d5f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to