[Python-modules-commits] [python-mplexporter] 96/135: Changed logic for legends.

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-mplexporter.

commit 26c66286b9a8a6979901cd66e2ba83ee20171323
Author: theengineear <andseier at gmail.com>
Date:   Sat Mar 15 12:48:39 2014 -0700

    Changed logic for legends.
    
    Files Effected:
    ===============
    
    exporter.py
    -----------
    
    - Legend context only opened if `legend is not None`
    - Legend contents drawn only if `legend.get_visible()`
    
    test_basic.py
    -------------
    
    - Added legend test where legend is not visible. This causes the legend
    context to open and information to be passed to renderers. However, no
    SVG draw commands are issued because nothing should be drawn.
    
    utils.py
    --------
    
    - Passes both `ax` and `legend` to `get_legend_properties` and now
    includes a `visible` key in the `props` dict.
---
 mplexporter/exporter.py         | 10 +++++-----
 mplexporter/tests/test_basic.py | 35 +++++++++++++++--------------------
 mplexporter/utils.py            |  5 +++--
 3 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index 509e714..515c6af 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -140,11 +140,11 @@ class Exporter(object):
                 self.draw_image(ax, image)
 
             legend = ax.get_legend()
-            with self.renderer.draw_legend(
-                    legend=legend,
-                    props=utils.get_legend_properties(ax)):
-                if legend is not None:
-                    self.crawl_legend(ax, legend)
+            if legend is not None:
+                props = utils.get_legend_properties(ax, legend)
+                with self.renderer.draw_legend(legend=legend, props=props):
+                    if props['visible']:
+                        self.crawl_legend(ax, legend)
 
     def crawl_legend(self, ax, legend):
         for child in legend.get_children():
diff --git a/mplexporter/tests/test_basic.py b/mplexporter/tests/test_basic.py
index d36844f..9c90d66 100644
--- a/mplexporter/tests/test_basic.py
+++ b/mplexporter/tests/test_basic.py
@@ -30,8 +30,6 @@ def test_lines():
                          opening figure
                          opening axes
                          draw path with 20 vertices
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -41,8 +39,6 @@ def test_lines():
                          opening figure
                          opening axes
                          draw line with 20 points
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -58,8 +54,6 @@ def test_markers():
                          opening axes
                          draw path with 25 vertices
                          draw path with 25 vertices
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -69,8 +63,6 @@ def test_markers():
                          opening figure
                          opening axes
                          draw 2 markers
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -87,8 +79,6 @@ def test_path_collection():
                          draw path with 25 vertices
                          draw path with 25 vertices
                          draw path with 25 vertices
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -98,8 +88,6 @@ def test_path_collection():
                          opening figure
                          opening axes
                          draw path collection with 3 offsets
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -120,8 +108,6 @@ def test_text():
                          draw text 'my x label' xlabel
                          draw text 'my y label' ylabel
                          draw text 'my title' title
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -138,8 +124,6 @@ def test_path():
                          opening axes
                          draw path with 25 vertices
                          draw path with 4 vertices
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -155,13 +139,9 @@ def test_multiaxes():
                          opening figure
                          opening axes
                          draw path with 4 vertices
-                         opening legend
-                         closing legend
                          closing axes
                          opening axes
                          draw path with 10 vertices
-                         opening legend
-                         closing legend
                          closing axes
                          closing figure
                          """)
@@ -178,8 +158,23 @@ def test_image():
                          opening figure
                          opening axes
                          draw image of size 2848
+                         closing axes
+                         closing figure
+                         """)
+
+
+def test_legend():
+    fig, ax = plt.subplots()
+    ax.plot([1,2,3], label='label')
+    ax.legend().set_visible(False)
+    _assert_output_equal(fake_renderer_output(fig, FakeRenderer),
+                         """
+                         opening figure
+                         opening axes
+                         draw path with 3 vertices
                          opening legend
                          closing legend
                          closing axes
                          closing figure
                          """)
+
diff --git a/mplexporter/utils.py b/mplexporter/utils.py
index 4bd1926..78e9492 100644
--- a/mplexporter/utils.py
+++ b/mplexporter/utils.py
@@ -298,9 +298,10 @@ def get_axes_properties(ax):
     return props
 
 
-def get_legend_properties(ax):
+def get_legend_properties(ax, legend):
     handles, labels = ax.get_legend_handles_labels()
-    return {'handles': handles, 'labels': labels}
+    visible = legend.get_visible()
+    return {'handles': handles, 'labels': labels, 'visible': visible}
     
 
 def image_to_base64(image):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mplexporter.git



More information about the Python-modules-commits mailing list