Skip to content

Commit

Permalink
✨ Add border_color option for needflow (#1194)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisjsewell authored Jun 12, 2024
1 parent 14fffc5 commit ac2d3e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/directives/needflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,26 @@ sets the border for each need of the needflow to **red** if the need also passes
:link_types: tests, blocks
:highlight: id in ['spec_flow_002', 'subspec_2'] or type == 'req'

.. _needflow_border_color:

border_color
~~~~~~~~~~~~

.. versionadded:: 3.0.0

The ``:border_color:`` allows for setting per need border colors, based on the need data.
The value should be written with the :ref:`variant syntax <needs_variant_support>`, and each return value should be a hex (RGB) color.

.. need-example::

.. needflow:: Engineering plan to develop a car
:tags: flow_example
:link_types: tests, blocks
:border_color:
[type == 'req']:FF0000,
[type == 'spec']:0000FF,
[type == 'test']:00FF00

.. _needflow_align:

align
Expand Down
3 changes: 3 additions & 0 deletions sphinx_needs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ class NeedsFlowType(NeedsFilteredDiagramBaseType):
root_depth: int | None
"""How many levels to include from the root node (if set)."""

border_color: str | None
"""Color of the outline of the needs, specified using the variant syntax."""


class NeedsGanttType(NeedsFilteredDiagramBaseType):
"""Data for a single (filtered) gantt chart."""
Expand Down
13 changes: 13 additions & 0 deletions sphinx_needs/directives/needflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from sphinx_needs.utils import (
add_doc,
get_scale,
match_variants,
remove_node_from_tree,
split_link_types,
)
Expand Down Expand Up @@ -60,6 +61,7 @@ class NeedflowDirective(FilterBase):
"config": directives.unchanged_required,
"scale": directives.unchanged_required,
"highlight": directives.unchanged_required,
"border_color": directives.unchanged_required,
"align": directives.unchanged_required,
"debug": directives.flag,
}
Expand Down Expand Up @@ -108,6 +110,7 @@ def run(self) -> Sequence[nodes.Node]:
"config_names": config_names,
"scale": get_scale(self.options, location),
"highlight": self.options.get("highlight", ""),
"border_color": self.options.get("border_color", None),
"align": self.options.get("align"),
"debug": "debug" in self.options,
"caption": self.arguments[0] if self.arguments else None,
Expand Down Expand Up @@ -152,6 +155,16 @@ def get_need_node_rep_for_plantuml(
):
node_colors.append("line:FF0000")

elif current_needflow["border_color"]:
color = match_variants(
current_needflow["border_color"],
{**need_info},
needs_config.variants,
location=(current_needflow["docname"], current_needflow["lineno"]),
)
if color:
node_colors.append(f"line:{color}")

# need parts style use default "rectangle"
if need_info["is_need"]:
node_style = need_info["type_style"]
Expand Down

1 comment on commit ac2d3e6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: ac2d3e6 Previous: 14fffc5 Ratio
Small, basic Sphinx-Needs project 0.351153920999991 s 0.18976810099999852 s 1.85

This comment was automatically generated by workflow using github-action-benchmark.

CC: @danwos

Please sign in to comment.