Skip to content

Commit df73857

Browse files
committed
add option for row-ordering
1 parent 9b982fa commit df73857

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

package/cmtrace/cmtrace/graphics/tracesettings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
'graphics:alternate-color': True,
3333
'graphics:show-text-labels': True,
3434
'graphics:background-color': (255, 255, 255),
35-
'graphics:row-background-color': (240, 240, 240)
35+
'graphics:row-background-color': (240, 240, 240),
36+
'structure:row-order': "by-first-firing"
3637
}
3738

3839
# TODO: raise exception on invalid settings
@@ -424,6 +425,11 @@ def __get_subtree(self, node_label):
424425
result[key[len(node_label)+1:]] = val
425426
return result
426427

428+
def row_order(self):
429+
""" returns the row ordering """
430+
return self.__get_value('structure:row-order')
431+
432+
427433
def groups(self):
428434
""" returns the groups of actors that are drawn on a single row """
429435
if self.__includes_label('structure:groups'):

package/cmtrace/cmtrace/libtracetosvg.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,20 +229,32 @@ def create_gantt_fig(trace_filename, svg_filename, settings=None):
229229
print(f"Warning: actor {act} not found (missing scenario specification s@A?).")
230230
acts_list.append(None)
231231
else:
232-
acts_list = [actors[row]]
232+
if not row in actors:
233+
print(f"Warning: actor {row} not found.")
234+
acts_list = [None]
235+
else:
236+
acts_list = [actors[row]]
233237
gantt_actors.append((row, acts_list))
234238
else:
235239
# make a default structure
236240
# gantt_actors: list of tuples with name, list of Actors
237-
#TODO: group same actor in different scenarios together
238241
c_idx = 0
239242
sorted_actors = sorted(actors.items(), key=lambda a: a[1].min_firing_time())
243+
grouped_actors = {}
240244
for act_name, act in sorted_actors:
241245
parts = act_name.split(SCENARIO_SEPARATOR)
242246
act_name = parts[len(parts)-1]
243-
gantt_actors.append((act_name, [act]))
247+
if act_name in grouped_actors:
248+
g_idx = grouped_actors[act_name]
249+
gantt_actors[g_idx][1].append(act)
250+
else:
251+
grouped_actors[act_name] = len(gantt_actors)
252+
gantt_actors.append((act_name, [act]))
253+
if settings.row_order() == "by-actor-name":
254+
gantt_actors = sorted(gantt_actors, key=lambda a: a[0])
244255
c_idx = (c_idx + 1) % len(COLOR_PALETTE_FILLS)
245256

257+
# gantt_actors: list of tuples with name, list of Actors
246258
save_gantt_svg(gantt_actors, arrivals, outputs, svg_filename, settings=settings)
247259
convert_svg_to_pdf(svg_filename)
248260

package/cmtrace/example/settings.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ layout:
4848
overlap-horizontal-offset: 10.0
4949

5050
structure:
51+
# order is one of the following: by-actor-name, by-first-firing
52+
# it is ignored if rows are defined
53+
row-order: by-first-firing
5154
# rows define the rows shown in the Gantt chart, referring to actors or actor groups defined in structure:groups
5255
rows: [A, B, C]
5356
# define groups of actors that can be referred on the row layout and in the color map

0 commit comments

Comments
 (0)