File: needbar.rst

package info (click to toggle)
sphinx-needs 5.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 11,924 kB
  • sloc: python: 21,132; javascript: 187; makefile: 89; sh: 29; xml: 10
file content (443 lines) | stat: -rw-r--r-- 10,910 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
.. _needbar:

needbar
========

.. versionadded:: 0.7.5

``needbar`` adds a bar-chart to your documentation:

.. need-example::

   .. needbar::

      5,20,15
      10,15,10
      15,10,20
      20,15,10

Each content value gets interpreted either as static float/int value or as a :ref:`filter_string`.
The amount of found needs by the filter string is then used as value.

.. note::

    This generates multiple image files per ``needbar`` and allows
    the document engine to pick the appropriate image type (vector or raster).

Options
-------

Example with all options used:

.. need-example::

   .. needbar:: Full bar chart
      :legend:
      :colors: #ffcc88, #ffcc00, #444444
      :text_color: crimson
      :style: dark_background
      :x_axis_title: x_axis_title
      :xlabels_rotation: 90
      :xlabels: a, b, c
      :y_axis_title: y_axis_title
      :ylabels: FROM_DATA
      :ylabels_rotation: 45
      :separator: ;
      :stacked:
      :show_top_sum:
      :show_sum:
      :sum_rotation: 90
      :transpose:
      :horizontal:

      Z; 5;20;15
      Y;10;15;10
      X;15;10;20
      W;20;15;10

title
~~~~~

You can specify the headline of the bar chart using the ``title`` argument.

.. need-example::

   .. needbar:: Title example

      5,20,15
      10,15,10
      15,10,20
      20,15,10

It is possible to create bar charts without title.

.. need-example::

   .. needbar::

      5,20,15
      10,15,10
      15,10,20
      20,15,10

content
~~~~~~~

In the example below, we fetch the ``:xlabels:`` and ``:ylabels:`` options from the content using ``FROM_DATA`` with the `labels`_.
You can use white spaces to format the table to improve readability.

From the content, we interpret each value either as a static float/int value or as a :ref:`filter_string`.
We get the bar chart's data (values) from the amount of **need** objects found by the filter string.

Below is a more realistic example with data fetched from filters, together with hardcoded data:

.. need-example::

   .. needbar:: A more real bar chart
      :legend:
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

                   ,                           open ,                          in progress ,                          closed ,                          done ,                          implemented , number
        Requirement, type=='req' and status=='open', type=='req' and status=='in progress', type=='req' and status=='closed', type=='req' and status=='done', type=='req' and status=='implemented', 5
               Test, type=='test' and status=='open', type=='test' and status=='in progress', type=='test' and status=='closed', type=='test' and status=='done', type=='test' and status=='implemented', 7
      Specification, type=='spec' and status=='open', type=='spec' and status=='in progress', type=='spec' and status=='closed', type=='spec' and status=='done', type=='spec' and status=='implemented', 9

legend
~~~~~~

You can place a legend on the barchart by setting the ``:legend:`` flag.

The ``:legend:`` flag does not support any values.

.. need-example::

   .. needbar:: Legend example
      :legend:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

axis title
~~~~~~~~~~

You can enable axis titles on the barchart by setting the ``:x_axis_title:`` or ``:y_axis_title:`` options.

.. hint::
   If you use `horizontal`_ or `transpose`_, the meaning of ``:x_axis_title:`` and ``:y_axis_title:`` must be understandable.
   So you have to change the description accordingly.

.. need-example::

   .. needbar:: Axis title example
      :x_axis_title: types
      :y_axis_title: numbers

      5,20,15
      10,15,10
      15,10,20
      20,15,10

labels
~~~~~~

| Use ``:xlabels:`` to set labels for columns of the data.
| Use ``:ylabels:`` to set labels for row of the data.

You can define the ``:xlabels:`` and/or ``:ylabels:`` by setting a comma separated string.
The amount of labels must match the amount of values/lines from content. |br|
Also, you can set the ``:xlabels:`` and/or ``:ylabels:`` value to ``FROM_DATA`` to fetch the labels from the content.

.. hint::
   In a normal bar chart, we use the ``:xlabels:`` as the labels of the x-axis on the chart and the ``:ylabels:`` as the labels of legend.

   But if you use `horizontal`_ or `transpose`_, the meaning of ``:x_axis_title:`` and ``:y_axis_title:`` will change automatically.

.. need-example::

   .. needbar:: Labels example 1
      :legend:
      :xlabels: a, b, c
      :ylabels: Z, Y, X, W

       5,20,15
      10,15,10
      15,10,20
      20,15,10

   .. needbar:: Labels example 2
      :legend:
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

       , a, b, c
      Z, 5,20,15
      Y,10,15,10
      X,15,10,20
      W,20,15,10


stacked
~~~~~~~

You can render the barchart in a stacked design by setting ``:stacked:`` flag.

The ``:stacked:`` flag does not support any values.

.. need-example::

   .. needbar:: stacked example
      :stacked:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

show_sum
~~~~~~~~

You can render the barchart with detailed information of the height of each bar by setting the ``:show_sum:`` flag.

The ``:show_sum:`` flag does not support any values and it's useful with the ``stacked`` option  enabled.

.. need-example::

   .. needbar:: show_sum example 1
      :show_sum:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

   .. needbar:: show_sum example 2
      :stacked:
      :show_sum:

      5,20,15
      10,15,10
      15,10,20
      20,15,10


show_top_sum
~~~~~~~~~~~~

You can render the barchart with detailed information of the height of each bar above by setting the ``:show_top_sum:`` flag.

The ``:show_sum:`` flag does not support any values and it's useful with the ``stacked`` option  enabled.

.. need-example::

   .. needbar:: show_top_sum example 1
      :show_top_sum:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

   .. needbar:: show_top_sum example 2
      :stacked:
      :show_sum:
      :show_top_sum:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

horizontal
~~~~~~~~~~

You can render the bar chart with horizontal bars by setting the ``:horizontal:`` flag.

The ``:horizontal:`` flag does not support any values and it's useful with the ``stacked`` option  enabled.

.. hint::
   The meaning of `labels`_ will change automatically with the usage of ``:horizontal:``. We will use the
   ``:x_axis_title:`` as labels for the y-axis and use the ``:y_axis_title:`` as the values in the `legend`_.

.. need-example::

   .. needbar:: horizontal example 1
      :horizontal:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

   .. needbar:: horizontal example 2
      :stacked:
      :legend:
      :show_sum:
      :horizontal:
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

       , a, b, c
      Z, 5,20,15
      Y,10,15,10
      X,15,10,20
      W,20,15,10

transpose
~~~~~~~~~

You can `transpose <https://en.wikipedia.org/wiki/Transpose>`_ the data in the content by setting the ``:transpose:`` flag.
The idea is, you can try to see the data from different point of view, without refactoring.

The ``:transpose:`` flag does not support any values and it's useful with big content tables.

.. hint::
   * Using the ``:transpose:`` flag, transposes the ``:x_axis_title:`` and ``:y_axis_title:`` fetched from the content data or specified with `labels`_ but does not transpose the extra `axis title`_.
   * Remember that with the ``:transpose:`` flag, the length and height of the content data changes, not to think about the width of matching elements, like `colors`_. Please review the impact of ``:transpose:`` before using it.

.. need-example::

   .. needbar:: transpose example 1
      :transpose:

      5,20,15
      10,15,10
      15,10,20
      20,15,10

   .. needbar:: transpose example 2
      :legend:
      :stacked:
      :show_sum:
      :transpose:
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

       , a, b, c
      Z, 5,20,15
      Y,10,15,10
      X,15,10,20
      W,20,15,10


rotation
~~~~~~~~

| Use ``:xlabels_rotation:`` to set rotation of labels for x-axis on the diagram.
| Use ``:ylabels_rotation:`` to set rotation of labels for y-axis on the diagram.
| Use ``:sum_rotation:`` to set rotation of labels for bars on the diagram.


.. need-example::

   .. needbar:: rotation example
      :legend:
      :xlabels: a, b, c
      :xlabels_rotation: 90
      :ylabels: Z, Y, X, W
      :ylabels_rotation: 40
      :show_top_sum:
      :show_sum:
      :sum_rotation: 90

       5,20,15
      10,15,10
      15,10,20
      20,15,10

separator
~~~~~~~~~

You can specify a custom separator between the values in the content by setting the ``:separator:`` flag.
This ensures the use of ``,`` (the default separator) in a filter rule. Other options will be processed as defined there.

The ``:separator:`` is a string that supports any symbols.

.. need-example::

   .. needbar:: separator example
      :separator: -

      5-20-15
      10-15-10
      15-10-20
      20-15-10

colors
~~~~~~

``:colors:`` takes a comma separated list of color names and uses them for the bar charts.

See `Matplotlib documentation of supported colors <https://matplotlib.org/stable/gallery/color/named_colors.html>`_
for a complete list of color names.

But besides names, ``:colors:`` options also supports hex-values like ``#ffcc00``.

.. hint::
   In a normal bar chart, we use the ``:colors:`` for the legend and bars itself.
   When you use `horizontal`_ or `transpose`_, the bar's length must be equal to ``:xlabels:`` or ``:ylabels:``.
   If the length does not fit, it will fill the bar with the colors again and you will get a warning.

.. need-example::

   .. needbar:: colors example
      :legend:
      :colors: lightcoral, gold, #555555, #888888
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

       , a, b, c
      Z, 5,20,15
      Y,10,15,10
      X,15,10,20
      W,20,15,10

text_color
~~~~~~~~~~

``:text_color:`` defines the color for text inside the bar chart and the labels.

.. need-example::

   .. needbar:: text_color example
      :legend:
      :text_color: green
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

       , a, b, c
      Z, 5,20,15
      Y,10,15,10
      X,15,10,20
      W,20,15,10

style
~~~~~

``:style:`` activates a complete style (colors, font, sizes) for a bar chart.
It takes a string, which must match the
`supported Matplotlib style names <https://matplotlib.org/3.1.1/gallery/style_sheets/style_sheets_reference.html>`_.

Useful styles are for example:

* default
* classic
* Solarize_Light2
* dark_background
* grayscale

.. need-example::

   .. needbar:: style example
      :legend:
      :style: Solarize_Light2
      :xlabels: FROM_DATA
      :ylabels: FROM_DATA

       , a, b, c
      Z, 5,20,15
      Y,10,15,10
      X,15,10,20
      W,20,15,10