Skip to content

Cleanups to webagg & friends. #19127

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
Dec 16, 2020
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
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def remove_comm(self, comm_id):


class FigureCanvasNbAgg(FigureCanvasWebAggCore):
_timer_cls = TimerTornado
pass


class CommSocket:
Expand Down
7 changes: 1 addition & 6 deletions lib/matplotlib/backends/backend_webagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ def run(self):


class FigureCanvasWebAgg(core.FigureCanvasWebAggCore):
_timer_cls = TimerTornado

def show(self):
# show the figure window
global show # placates pyflakes: created by @_Backend.export below
show()
pass


class WebAggApplication(tornado.web.Application):
Expand Down
75 changes: 37 additions & 38 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,43 @@ def _handle_key(key):
return key


class TimerTornado(backend_bases.TimerBase):
def __init__(self, *args, **kwargs):
self._timer = None
super().__init__(*args, **kwargs)

def _timer_start(self):
self._timer_stop()
if self._single:
ioloop = tornado.ioloop.IOLoop.instance()
self._timer = ioloop.add_timeout(
datetime.timedelta(milliseconds=self.interval),
self._on_timer)
else:
self._timer = tornado.ioloop.PeriodicCallback(
self._on_timer,
max(self.interval, 1e-6))
self._timer.start()

def _timer_stop(self):
if self._timer is None:
return
elif self._single:
ioloop = tornado.ioloop.IOLoop.instance()
ioloop.remove_timeout(self._timer)
else:
self._timer.stop()
self._timer = None

def _timer_set_interval(self):
# Only stop and restart it if the timer has already been started
if self._timer is not None:
self._timer_stop()
self._timer_start()


class FigureCanvasWebAggCore(backend_agg.FigureCanvasAgg):
supports_blit = True
_timer_cls = TimerTornado

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -478,8 +513,7 @@ def get_javascript(cls, stream=None):
for filetype, ext in sorted(FigureCanvasWebAggCore.
get_supported_filetypes_grouped().
items()):
if ext[0] != 'pgf': # pgf does not support BytesIO
extensions.append(ext[0])
extensions.append(ext[0])
output.write("mpl.extensions = {0};\n\n".format(
json.dumps(extensions)))

Expand All @@ -499,41 +533,6 @@ def _send_event(self, event_type, **kwargs):
s.send_json(payload)


class TimerTornado(backend_bases.TimerBase):
def __init__(self, *args, **kwargs):
self._timer = None
super().__init__(*args, **kwargs)

def _timer_start(self):
self._timer_stop()
if self._single:
ioloop = tornado.ioloop.IOLoop.instance()
self._timer = ioloop.add_timeout(
datetime.timedelta(milliseconds=self.interval),
self._on_timer)
else:
self._timer = tornado.ioloop.PeriodicCallback(
self._on_timer,
max(self.interval, 1e-6))
self._timer.start()

def _timer_stop(self):
if self._timer is None:
return
elif self._single:
ioloop = tornado.ioloop.IOLoop.instance()
ioloop.remove_timeout(self._timer)
else:
self._timer.stop()
self._timer = None

def _timer_set_interval(self):
# Only stop and restart it if the timer has already been started
if self._timer is not None:
self._timer_stop()
self._timer_start()


@_Backend.export
class _BackendWebAggCoreAgg(_Backend):
FigureCanvas = FigureCanvasWebAggCore
Expand Down