From: Vladimír Vondruš Date: Tue, 9 Jun 2020 16:13:30 +0000 (+0200) Subject: m.plots: change :labels_extra: and :bar_height: to dashes also. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=bb0a7b1757b7edda6725409edb032497109a1984;p=blog.git m.plots: change :labels_extra: and :bar_height: to dashes also. It was UGHLY also. The previous option name is still recognized, of course. --- diff --git a/doc/plugins/plots-and-graphs.rst b/doc/plugins/plots-and-graphs.rst index 9df4345a..9d8a97a6 100644 --- a/doc/plugins/plots-and-graphs.rst +++ b/doc/plugins/plots-and-graphs.rst @@ -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 ` 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 .. diff --git a/plugins/m/plots.py b/plugins/m/plots.py index a2d861f4..c3072a1f 100644 --- a/plugins/m/plots.py +++ b/plugins/m/plots.py @@ -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