Skip to content

Commit

Permalink
Sort targets and nested targets by natural sorting order
Browse files Browse the repository at this point in the history
  • Loading branch information
JasperCraeghs committed Mar 19, 2024
1 parent 1faac17 commit a08643e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mlx/traceability/directives/item_pie_chart_directive.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for the item-piechart directive"""
import operator
import re
from hashlib import sha256
from os import environ, mkdir, path
Expand All @@ -9,6 +10,7 @@
if not environ.get('DISPLAY'):
mpl.use('Agg')
import matplotlib.pyplot as plt # pylint: disable=wrong-import-order
from natsort import natsorted
from sphinx.builders.latex import LaTeXBuilder

from ..traceability_exception import report_warning
Expand All @@ -34,6 +36,11 @@ def __init__(self, label):
self.label = label
self.targets = {}

@property
def targets_iter(self):
for target in natsorted(self.targets, key=operator.attrgetter('identifier')):
yield target, natsorted(self.targets[target], key=operator.attrgetter('identifier'))

def add_target(self, target):
if target not in self.targets:
self.targets[target] = []
Expand Down Expand Up @@ -410,7 +417,7 @@ def build_table(self, app):
source_row += self._create_cell_for_items([source], app, morerows=max(0, len(match.targets)-1))
if match.targets:
row_without_targets = source_row
for target, nested_targets in match.targets.items():
for target, nested_targets in match.targets_iter:
row_without_targets += self._create_cell_for_items([target], app)
if self.nested_target_regex.pattern:
row_without_targets += self._create_cell_for_items(nested_targets, app)
Expand Down

0 comments on commit a08643e

Please sign in to comment.