Skip to content

Commit ac2d3e6

Browse files
authored
✨ Add border_color option for needflow (#1194)
The :border_color: option allows for setting per need border colors, based on the need data. The value should be written with the variant syntax, and each return value should be a hex (RGB) color.
1 parent 14fffc5 commit ac2d3e6

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

docs/directives/needflow.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,26 @@ sets the border for each need of the needflow to **red** if the need also passes
282282
:link_types: tests, blocks
283283
:highlight: id in ['spec_flow_002', 'subspec_2'] or type == 'req'
284284

285+
.. _needflow_border_color:
286+
287+
border_color
288+
~~~~~~~~~~~~
289+
290+
.. versionadded:: 3.0.0
291+
292+
The ``:border_color:`` allows for setting per need border colors, based on the need data.
293+
The value should be written with the :ref:`variant syntax <needs_variant_support>`, and each return value should be a hex (RGB) color.
294+
295+
.. need-example::
296+
297+
.. needflow:: Engineering plan to develop a car
298+
:tags: flow_example
299+
:link_types: tests, blocks
300+
:border_color:
301+
[type == 'req']:FF0000,
302+
[type == 'spec']:0000FF,
303+
[type == 'test']:00FF00
304+
285305
.. _needflow_align:
286306

287307
align

sphinx_needs/data.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ class NeedsFlowType(NeedsFilteredDiagramBaseType):
328328
root_depth: int | None
329329
"""How many levels to include from the root node (if set)."""
330330

331+
border_color: str | None
332+
"""Color of the outline of the needs, specified using the variant syntax."""
333+
331334

332335
class NeedsGanttType(NeedsFilteredDiagramBaseType):
333336
"""Data for a single (filtered) gantt chart."""

sphinx_needs/directives/needflow.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from sphinx_needs.utils import (
2727
add_doc,
2828
get_scale,
29+
match_variants,
2930
remove_node_from_tree,
3031
split_link_types,
3132
)
@@ -60,6 +61,7 @@ class NeedflowDirective(FilterBase):
6061
"config": directives.unchanged_required,
6162
"scale": directives.unchanged_required,
6263
"highlight": directives.unchanged_required,
64+
"border_color": directives.unchanged_required,
6365
"align": directives.unchanged_required,
6466
"debug": directives.flag,
6567
}
@@ -108,6 +110,7 @@ def run(self) -> Sequence[nodes.Node]:
108110
"config_names": config_names,
109111
"scale": get_scale(self.options, location),
110112
"highlight": self.options.get("highlight", ""),
113+
"border_color": self.options.get("border_color", None),
111114
"align": self.options.get("align"),
112115
"debug": "debug" in self.options,
113116
"caption": self.arguments[0] if self.arguments else None,
@@ -152,6 +155,16 @@ def get_need_node_rep_for_plantuml(
152155
):
153156
node_colors.append("line:FF0000")
154157

158+
elif current_needflow["border_color"]:
159+
color = match_variants(
160+
current_needflow["border_color"],
161+
{**need_info},
162+
needs_config.variants,
163+
location=(current_needflow["docname"], current_needflow["lineno"]),
164+
)
165+
if color:
166+
node_colors.append(f"line:{color}")
167+
155168
# need parts style use default "rectangle"
156169
if need_info["is_need"]:
157170
node_style = need_info["type_style"]

0 commit comments

Comments
 (0)