Commit f3fcf034 authored by Michael Droettboom's avatar Michael Droettboom Committed by GitHub

Merge pull request #323 from mdboom/fix-matplotlib

Fix matplotlib wasm backend after undefined attribute behavior changed
parents 8da4b1f5 2f3a727e
...@@ -90,21 +90,24 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg): ...@@ -90,21 +90,24 @@ class FigureCanvasWasm(backend_agg.FigureCanvasAgg):
This is typically 2 on a HiDPI ("Retina") display, and 1 otherwise. This is typically 2 on a HiDPI ("Retina") display, and 1 otherwise.
""" """
backing_store = ( backing_store = (
context.backingStorePixelRatio or getattr(context, 'backingStorePixelRatio', 0) or
context.webkitBackingStorePixel or getattr(context, 'webkitBackingStorePixel', 0) or
context.mozBackingStorePixelRatio or getattr(context, 'mozBackingStorePixelRatio', 0) or
context.msBackingStorePixelRatio or getattr(context, 'msBackingStorePixelRatio', 0) or
context.oBackingStorePixelRatio or getattr(context, 'oBackingStorePixelRatio', 0) or
context.backendStorePixelRatio or getattr(context, 'backendStorePixelRatio', 0) or
1 1
) )
return (window.devicePixelRatio or 1) / backing_store return (getattr(window, 'devicePixelRatio', 0) or 1) / backing_store
def create_root_element(self): def create_root_element(self):
# Designed to be overridden by subclasses for use in contexts other # Designed to be overridden by subclasses for use in contexts other
# than iodide. # than iodide.
from js import iodide from js import iodide
return iodide.output.element('div') if iodide is not None:
return iodide.output.element('div')
else:
return document.createElement('div')
def show(self): def show(self):
# If we've already shown this canvas elsewhere, don't create a new one, # If we've already shown this canvas elsewhere, don't create a new one,
......
def test_matplotlib(selenium): def test_matplotlib(selenium_standalone):
selenium = selenium_standalone
selenium.load_package("matplotlib") selenium.load_package("matplotlib")
selenium.run("from matplotlib import pyplot as plt") selenium.run("from matplotlib import pyplot as plt")
selenium.run("plt.figure()") selenium.run("plt.figure()")
selenium.run("x = plt.plot([1,2,3])") selenium.run("plt.plot([1,2,3])")
selenium.run("plt.show()")
def test_svg(selenium): def test_svg(selenium):
...@@ -26,5 +28,3 @@ def test_pdf(selenium): ...@@ -26,5 +28,3 @@ def test_pdf(selenium):
selenium.run("import io") selenium.run("import io")
selenium.run("fd = io.BytesIO()") selenium.run("fd = io.BytesIO()")
selenium.run("plt.savefig(fd, format='pdf')") selenium.run("plt.savefig(fd, format='pdf')")
content = selenium.run("fd.getvalue()")
assert len(content) == 5559
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment