Skip to content

Py3fy webagg/nbagg. #10708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# lib/matplotlib/backends/web_backend/nbagg_uat.ipynb to help verify
# that changes made maintain expected behaviour.

import six

from base64 import b64encode
import io
import json
Expand Down Expand Up @@ -204,9 +202,7 @@ def send_json(self, content):
def send_binary(self, blob):
# The comm is ascii, so we always send the image in base64
# encoded data URL form.
data = b64encode(blob)
if six.PY3:
data = data.decode('ascii')
data = b64encode(blob).decode('ascii')
data_uri = "data:image/png;base64,{0}".format(data)
self.comm.send({'data': data_uri})

Expand Down
18 changes: 3 additions & 15 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
# - `backend_webagg.py` contains a concrete implementation of a basic
# application, implemented with tornado.

from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six

import datetime
import io
import json
Expand All @@ -26,8 +21,7 @@

from matplotlib.backends import backend_agg
from matplotlib.backend_bases import _Backend
from matplotlib import backend_bases
from matplotlib import _png
from matplotlib import backend_bases, _png


# http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
Expand Down Expand Up @@ -150,17 +144,11 @@ def show(self):
show()

def draw(self):
renderer = self.get_renderer(cleared=True)

self._png_is_old = True

backend_agg.RendererAgg.lock.acquire()
try:
self.figure.draw(renderer)
super().draw()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... this is pretty different. Does it do the same thing? Why just call super draw instead of the figure? Just trying to understand, not saying its wrong....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using Agg, this resolves to https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_agg.py#L414 which gets a cleared renderer, handles the locking and calls self.figure.draw(self.renderer).

Of course the not-so-secret objective here is to make it possible to swap in mplcairo's renderer. For that, the idea is as usual to push as much the renderer-specific code back to the super-class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I did find super().draw() a bit opaque.; ie. why not just self.draw()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well that would be an infinite loop...
super().draw() means (approximately) "call the draw method but don't look it up on this class, look it up on the base class [in this case, FigureCanvasAgg] instead" (check up e.g. "python super mro" for details)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooops. duh.

finally:
backend_agg.RendererAgg.lock.release()
# Swap the frames
self.manager.refresh_all()
self.manager.refresh_all() # Swap the frames.

def draw_idle(self):
self.send_event("draw")
Expand Down