chiark / gitweb /
m.plots: update the regex hell for matplotlib 3.3.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 8 Oct 2020 14:27:21 +0000 (16:27 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 8 Oct 2020 14:35:36 +0000 (16:35 +0200)
documentation/test_python/page_plugins/plots.html
plugins/m/plots.py
plugins/m/test/plots/page-22.html
plugins/m/test/plots/page-30.html
plugins/m/test/plots/page-py35.html
plugins/m/test/plots/page.html

index f60ed497203e42f54b52bbc9e795970bc895316e..c1f9746cfbf89066eac3d13d77aa5fe6c7632b79 100644 (file)
@@ -27,9 +27,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 </style><div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
index 834299052bdd5eaee302caaa5e0200c954da1374..df8fea467e7ba0f27c93bf6e2876483e4b11ee99 100644 (file)
@@ -72,14 +72,25 @@ style_mapping = {
 }
 
 # Patch to remove preamble and hardcoded sizes. Matplotlib 2.2 has a http URL
-# while matplotlib 3 has a https URL, check for both.
+# while matplotlib 3 has a https URL, check for both. Matplotlib 3.3 has a new
+# <metadata> field (which we're not interested in) and slightly different
+# formatting of the global style after (which we unify to the compact version).
 _patch_src = re.compile(r"""<\?xml version="1\.0" encoding="utf-8" standalone="no"\?>
 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1\.1//EN"
   "http://www\.w3\.org/Graphics/SVG/1\.1/DTD/svg11\.dtd">
 <!-- Created with matplotlib \(https?://matplotlib.org/\) -->
-<svg height="\d+(\.\d+)?pt" version="1.1" (?P<viewBox>viewBox="0 0 \d+ \d+(\.\d+)?") width="\d+(\.\d+)?pt" xmlns="http://www\.w3\.org/2000/svg" xmlns:xlink="http://www\.w3\.org/1999/xlink">
-""")
+<svg height="\d+(\.\d+)?pt" version="1.1" (?P<viewBox>viewBox="0 0 \d+ \d+(\.\d+)?") width="\d+(\.\d+)?pt" xmlns="http://www\.w3\.org/2000/svg" xmlns:xlink="http://www\.w3\.org/1999/xlink">(
+ <metadata>.+</metadata>)?
+ <defs>
+  <style type="text/css">
+?\*{stroke-linecap:butt;stroke-linejoin:round;}(
+  )?</style>
+ </defs>
+""", re.DOTALL)
 _patch_dst = r"""<svg \g<viewBox>>
+ <defs>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
+ </defs>
 """
 
 # Remove needless newlines and trailing space in path data
@@ -98,14 +109,21 @@ _class_mapping = [
     # <use>, everything is defined in <defs>, no need to repeat
     ('<use style="fill:#cafe02;stroke:#cafe02;stroke-width:0.8;"', '<use'),
 
+    # Text styles have `font-stretch:normal;` added in matplotlib 3.3, so
+    # all of them are duplicated to handle this
+
     # Label text on left
     ('style="fill:#cafe02;font-family:{font};font-size:11px;font-style:normal;font-weight:normal;"', 'class="m-label"'),
+    ('style="fill:#cafe02;font-family:{font};font-size:11px;font-stretch:normal;font-style:normal;font-weight:normal;"', 'class="m-label"'),
     # Label text on bottom (has extra style params)
     ('style="fill:#cafe02;font-family:{font};font-size:11px;font-style:normal;font-weight:normal;', 'class="m-label" style="'),
+    ('style="fill:#cafe02;font-family:{font};font-size:11px;font-stretch:normal;font-style:normal;font-weight:normal;', 'class="m-label" style="'),
     # Secondary label text
     ('style="fill:#cafe0b;font-family:{font};font-size:11px;font-style:normal;font-weight:normal;"', 'class="m-label m-dim"'),
+    ('style="fill:#cafe0b;font-family:{font};font-size:11px;font-stretch:normal;font-style:normal;font-weight:normal;"', 'class="m-label m-dim"'),
     # Title text
     ('style="fill:#cafe02;font-family:{font};font-size:13px;font-style:normal;font-weight:normal;', 'class="m-title" style="'),
+    ('style="fill:#cafe02;font-family:{font};font-size:13px;font-stretch:normal;font-style:normal;font-weight:normal;', 'class="m-title" style="'),
 
     # Bar colors. Keep in sync with latex2svgextra.
     ('style="fill:#cafe03;"', 'class="m-bar m-default"'),
index e6598208de4feb2e2f1a29ac31bae3a9334f4981..989eff186a9b5fd498d4dcc456b7326514483c1c 100644 (file)
@@ -30,9 +30,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 </style><div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -163,9 +161,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 218.16">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -341,9 +337,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 142.56">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -516,9 +510,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
index 6939e60dc5805f3450bd8aeabe9943f2ffd1637b..2d6674edc2f74fdf76a73a71177e71e32f33619c 100644 (file)
@@ -30,9 +30,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 </style><div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -163,9 +161,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 218.16">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -341,9 +337,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 142.56">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -516,9 +510,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
index 3fa7caf924f0cca37cb8219252edd76f70ba4e24..0d64be21f2175e26261fb2f5247bd94d263f51ad 100644 (file)
@@ -30,9 +30,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 </style><div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -165,9 +163,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 324 218.16">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -344,9 +340,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 142.56">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -519,9 +513,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
index 4ece1575dff672eed5d86cf532f82968cb8d9dea..836e29664c0512881f70cab4b2298a00d27244a4 100644 (file)
@@ -30,9 +30,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 </style><div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -165,9 +163,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 324 218.16">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -344,9 +340,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 142.56">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">
@@ -519,9 +513,7 @@ div.m-plot svg { font-family: DejaVu Sans; }
 <div class="m-plot">
 <svg viewBox="0 0 576 113.76">
  <defs>
-  <style type="text/css">
-*{stroke-linecap:butt;stroke-linejoin:round;}
-  </style>
+  <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
  </defs>
  <g id="figure_1">
   <g id="axes_1">