33import os
44from functools import reduce
55from sys import modules as sysmodules
6- from cmtrace .graphics .svgcanvas import SVGCanvas , MMPERPT
6+ from cmtrace .graphics .svgcanvas import SVGCanvas , MM_PER_PT
77from cmtrace .graphics .tracesettings import TraceSettings
88if 'cairosvg' in sysmodules :
99 import cairosvg
@@ -25,7 +25,7 @@ def alternate_color(self, col):
2525 """ modify the color to be used for alternating colors """
2626 return (col [0 ] * 0.9 , col [1 ] * 0.9 , col [2 ] * 0.9 )
2727
28- def draw_firings (self , firing_intervals , lb , ub ):
28+ def draw_firings (self , firing_intervals , lb , _ub ):
2929 """ draw firings in figure; firings are tuple (start, end, actor name, scenario name)"""
3030 # sort the firings on start time
3131 firing_intervals .sort ()
@@ -55,7 +55,7 @@ def draw_firings(self, firing_intervals, lb, ub):
5555 if coloring_mode == "by-actor" :
5656 f_color = color_map [firing [2 ]]
5757 elif coloring_mode == "by-iteration" :
58- f_color = color_palette [firing [4 ] % len (color_palette )]
58+ f_color = color_palette [firing [5 ] % len (color_palette )]
5959 elif coloring_mode == "by-scenario" :
6060 f_color = color_map [firing [3 ]]
6161 if self .settings .alternate_color ():
@@ -84,10 +84,20 @@ def draw_firings(self, firing_intervals, lb, ub):
8484 self .settings .scale_mm_per_unit_x (), self .settings .origin_y () \
8585 + (lb + self .settings .overlap_offset ()* active_offset )* \
8686 self .settings .scale_mm_per_unit_y ()
87- bottom_right = self .settings .scale_mm_per_unit_x ()* (f_duration ), \
87+ width_height = self .settings .scale_mm_per_unit_x ()* (f_duration ), \
8888 self .settings .scale_mm_per_unit_y ()
89- self .canvas .draw_rect (top_left , bottom_right , f_color ,
89+ self .canvas .draw_rect (top_left , width_height , f_color ,
9090 stroke_width = self .settings .firing_stroke_width ())
91+ if firing [4 ] is not None :
92+ self .canvas .draw_text (
93+ firing [4 ],
94+ (top_left [0 ]+ width_height [0 ]/ 2 , top_left [1 ]+ width_height [1 ]/ 2 ),
95+ font = self .settings .font (),
96+ font_size = 0.5 * self .settings .font_size (),
97+ text_anchor = "middle" ,
98+ alignment_baseline = "central"
99+ )
100+
91101 f_count += 1
92102 last_end = f_start + f_duration
93103
@@ -117,21 +127,21 @@ def draw_traces(self, actors, num_arrivals, trace_heights):
117127 mix = num_arrivals
118128 for (label , actor_list ) in actors :
119129 self .draw_label (label , 0.5 * (lb [mix ]+ ub [mix ]))
120- scaled_firings = list ()
130+ scaled_firings = []
121131 for actor in actor_list :
122132 if not actor is None :
123133 fix = 0
124134 for firing in actor .firing_intervals ():
125135 scaled_firings .append ([firing [0 ]/ unit , firing [1 ]/ unit ,
126- actor .name , actor .scenario , actor . text , fix ])
136+ actor .name , actor .scenario , firing [ 3 ] , fix ])
127137 fix += 1
128138 self .draw_firings (scaled_firings , lb [mix ], ub [mix ])
129139 mix += 1
130140
131141 def draw_arrivals (self , arrivals , offset ):
132142 """ draw the arrival event sequences """
133- coloring_mode = self .settings .vector_color_mode ()
134- color_index = self .settings .color_map ()
143+ # coloring_mode = self.settings.vector_color_mode()
144+ # color_index = self.settings.color_map()
135145 nix = offset
136146 for label in arrivals .keys ():
137147 # draw the label
@@ -196,7 +206,7 @@ def draw_sequences(self, sequences):
196206 # draw the label
197207 lx = self .settings .origin_x () - self .settings .label_separation ()
198208 ly = self .settings .origin_y ()+ (nix + 0.5 )* self .settings .scale_mm_per_unit_y () + \
199- 3.0 * MMPERPT
209+ 3.0 * MM_PER_PT
200210 self .canvas .draw_text (
201211 label ,
202212 (lx , ly ),
@@ -414,8 +424,8 @@ def save_gantt(self, actors, arrivals, outputs, filename='trace.svg'):
414424 canvas = self .make_gantt_svg (actors , arrivals , outputs , filename )
415425 canvas .save ()
416426
417- def __make_vector_svg (self , event_seqs , filename = 'trace.svg' , height_in_mm = 200 ,
418- width_in_mm = 300 ):
427+ def __make_vector_svg (self , event_seqs , filename = 'trace.svg' , _height_in_mm = 200 ,
428+ _width_in_mm = 300 ):
419429 """ make a graph in svg of the event sequences and save to file """
420430
421431 # determine settings
0 commit comments