chiark / gitweb /
m.plots: change :labels_extra: and :bar_height: to dashes also.
authorVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jun 2020 16:13:30 +0000 (18:13 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Tue, 9 Jun 2020 16:26:46 +0000 (18:26 +0200)
It was UGHLY also. The previous option name is still recognized, of
course.

doc/plugins/plots-and-graphs.rst
plugins/m/plots.py

index 9df4345ad6437e3e2c2cf6e520eff19112226fc9..9d8a97a6cb0409d77955dda0501a65ace127e120 100644 (file)
@@ -126,9 +126,9 @@ configure bar colors using :rst:`:colors:`. The colors correspond to m.css
 `color classes <{filename}/css/components.rst#colors>`_ and you can either
 use one color for all or one for each value, separated by whitespace. Bar chart
 height is calculated automatically based on amount of values, you can adjust
-the bar height using :rst:`:bar_height:`. Default value is :py:`0.4`.
+the bar height using :rst:`:bar-height:`. Default value is :py:`0.4`.
 
-It's possible to add an extra line of labels using :rst:`:labels_extra:`.
+It's possible to add an extra line of labels using :rst:`:labels-extra:`.
 Again, there should be as many entries as primary labels and values. To omit an
 extra label for a value, specify it as the :abbr:`reST <reStructuredText>`
 comment :rst:`..`.
@@ -144,7 +144,7 @@ comment :rst:`..`.
                 Ours default
                 3rd party
                 Full setup
-            :labels_extra:
+            :labels-extra:
                 15 modules
                 60 modules
                 200 modules
@@ -153,7 +153,7 @@ comment :rst:`..`.
             :values: 15.09 84.98 197.13 934.27
             :errors: 0.74 3.65 9.45 25.66
             :colors: success info danger dim
-            :bar_height: 0.6
+            :bar-height: 0.6
 
     .. plot:: Runtime cost
         :type: barh
@@ -162,7 +162,7 @@ comment :rst:`..`.
             Ours default
             3rd party
             Full setup
-        :labels_extra:
+        :labels-extra:
             15 modules
             60 modules
             200 modules
@@ -171,7 +171,7 @@ comment :rst:`..`.
         :values: 15.09 84.98 197.13 934.27
         :errors: 0.74 3.65 9.45 25.66
         :colors: success info danger dim
-        :bar_height: 0.6
+        :bar-height: 0.6
 
 `Stacked values`_
 -----------------
@@ -197,7 +197,7 @@ per value like shown above.
                 Sdl2Application
                 Sdl2Application
                 EmscriptenApplication
-            :labels_extra:
+            :labels-extra:
                 -s USE_SDL=2
                 -s USE_SDL=1
                 ..
@@ -215,7 +215,7 @@ per value like shown above.
             Sdl2Application
             Sdl2Application
             EmscriptenApplication
-        :labels_extra:
+        :labels-extra:
             -s USE_SDL=2
             -s USE_SDL=1
             ..
index a2d861f4f487469ee47f0603420e4ca9ecc4a311..c3072a1f086beac47c52f1b51dc4e15d917e50c8 100644 (file)
@@ -137,11 +137,14 @@ class Plot(rst.Directive):
                    'name': directives.unchanged,
                    'type': directives.unchanged_required,
                    'labels': directives.unchanged_required,
-                   'labels_extra': directives.unchanged,
+                   'labels-extra': directives.unchanged,
                    'units': directives.unchanged_required,
                    'values': directives.unchanged_required,
                    'errors': directives.unchanged,
                    'colors': directives.unchanged,
+                   'bar-height': directives.unchanged,
+                   # Legacy options with ugly underscores instead of dashes
+                   'labels_extra': directives.unchanged,
                    'bar_height': directives.unchanged}
     has_content = False
 
@@ -156,9 +159,17 @@ class Plot(rst.Directive):
         units = self.options['units']
         labels = self.options['labels'].split('\n')
 
-        # Optional extra labels
+        # Legacy options, convert underscores to dashes
         if 'labels_extra' in self.options:
-            labels_extra = self.options['labels_extra'].split('\n')
+            self.options['labels-extra'] = self.options['labels_extra']
+            del self.options['labels_extra']
+        if 'bar_height' in self.options:
+            self.options['bar-height'] = self.options['bar_height']
+            del self.options['bar_height']
+
+        # Optional extra labels
+        if 'labels-extra' in self.options:
+            labels_extra = self.options['labels-extra'].split('\n')
             assert len(labels_extra) == len(labels)
         else:
             labels_extra = None
@@ -195,7 +206,7 @@ class Plot(rst.Directive):
             color_sets = [style_mapping['default']]*len(value_sets)
 
         # Bar height
-        bar_height = float(self.options.get('bar_height', '0.4'))
+        bar_height = float(self.options.get('bar-height', '0.4'))
 
         # Increase hashsalt for every plot to ensure (hopefully) unique SVG IDs
         mpl.rcParams['svg.hashsalt'] = int(mpl.rcParams['svg.hashsalt']) + 1