Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 39737b8

Browse files
authored
Merge pull request #19127 from anntzer/webagg
Cleanups to webagg & friends.
2 parents 27aaf0c + 25ee876 commit 39737b8

File tree

3 files changed

+39
-45
lines changed

3 files changed

+39
-45
lines changed

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def remove_comm(self, comm_id):
142142

143143

144144
class FigureCanvasNbAgg(FigureCanvasWebAggCore):
145-
_timer_cls = TimerTornado
145+
pass
146146

147147

148148
class CommSocket:

lib/matplotlib/backends/backend_webagg.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ def run(self):
4848

4949

5050
class FigureCanvasWebAgg(core.FigureCanvasWebAggCore):
51-
_timer_cls = TimerTornado
52-
53-
def show(self):
54-
# show the figure window
55-
global show # placates pyflakes: created by @_Backend.export below
56-
show()
51+
pass
5752

5853

5954
class WebAggApplication(tornado.web.Application):

lib/matplotlib/backends/backend_webagg_core.py

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,43 @@ def _handle_key(key):
117117
return key
118118

119119

120+
class TimerTornado(backend_bases.TimerBase):
121+
def __init__(self, *args, **kwargs):
122+
self._timer = None
123+
super().__init__(*args, **kwargs)
124+
125+
def _timer_start(self):
126+
self._timer_stop()
127+
if self._single:
128+
ioloop = tornado.ioloop.IOLoop.instance()
129+
self._timer = ioloop.add_timeout(
130+
datetime.timedelta(milliseconds=self.interval),
131+
self._on_timer)
132+
else:
133+
self._timer = tornado.ioloop.PeriodicCallback(
134+
self._on_timer,
135+
max(self.interval, 1e-6))
136+
self._timer.start()
137+
138+
def _timer_stop(self):
139+
if self._timer is None:
140+
return
141+
elif self._single:
142+
ioloop = tornado.ioloop.IOLoop.instance()
143+
ioloop.remove_timeout(self._timer)
144+
else:
145+
self._timer.stop()
146+
self._timer = None
147+
148+
def _timer_set_interval(self):
149+
# Only stop and restart it if the timer has already been started
150+
if self._timer is not None:
151+
self._timer_stop()
152+
self._timer_start()
153+
154+
120155
class FigureCanvasWebAggCore(backend_agg.FigureCanvasAgg):
121-
supports_blit = True
156+
_timer_cls = TimerTornado
122157

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

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

501535

502-
class TimerTornado(backend_bases.TimerBase):
503-
def __init__(self, *args, **kwargs):
504-
self._timer = None
505-
super().__init__(*args, **kwargs)
506-
507-
def _timer_start(self):
508-
self._timer_stop()
509-
if self._single:
510-
ioloop = tornado.ioloop.IOLoop.instance()
511-
self._timer = ioloop.add_timeout(
512-
datetime.timedelta(milliseconds=self.interval),
513-
self._on_timer)
514-
else:
515-
self._timer = tornado.ioloop.PeriodicCallback(
516-
self._on_timer,
517-
max(self.interval, 1e-6))
518-
self._timer.start()
519-
520-
def _timer_stop(self):
521-
if self._timer is None:
522-
return
523-
elif self._single:
524-
ioloop = tornado.ioloop.IOLoop.instance()
525-
ioloop.remove_timeout(self._timer)
526-
else:
527-
self._timer.stop()
528-
self._timer = None
529-
530-
def _timer_set_interval(self):
531-
# Only stop and restart it if the timer has already been started
532-
if self._timer is not None:
533-
self._timer_stop()
534-
self._timer_start()
535-
536-
537536
@_Backend.export
538537
class _BackendWebAggCoreAgg(_Backend):
539538
FigureCanvas = FigureCanvasWebAggCore

0 commit comments

Comments
 (0)