summaryrefslogtreecommitdiffstats
path: root/unit_trace/viz/canvas.py
diff options
context:
space:
mode:
authorMac Mollison <mollison@cs.unc.edu>2011-01-31 16:40:54 -0500
committerMac Mollison <mollison@cs.unc.edu>2011-01-31 16:40:54 -0500
commitd2240e7a9b15d18dfd0f3cbe75f3adf1c9e7fabf (patch)
treef7d164c21716b55f3d9195f055db73505bbf951d /unit_trace/viz/canvas.py
parent85a089c42749e1394ae12321564109f25fa8154f (diff)
Added support for visualizing arbitrary actions.
(By Jonathan, cherry-picked by Mac) Conflicts: unit_trace/trace_reader.py unit_trace/viz/canvas.py unit_trace/viz/graph.py unit_trace/viz/schedule.py
Diffstat (limited to 'unit_trace/viz/canvas.py')
-rw-r--r--unit_trace/viz/canvas.py80
1 files changed, 73 insertions, 7 deletions
diff --git a/unit_trace/viz/canvas.py b/unit_trace/viz/canvas.py
index ea73d98..c39c613 100644
--- a/unit_trace/viz/canvas.py
+++ b/unit_trace/viz/canvas.py
@@ -443,14 +443,44 @@ class Canvas(object):
443 self.add_sel_region(SelectableRegion(x - big_arrowhead_height / Canvas.SQRT3, 443 self.add_sel_region(SelectableRegion(x - big_arrowhead_height / Canvas.SQRT3,
444 y, 2.0 * big_arrowhead_height / Canvas.SQRT3, height, event)) 444 y, 2.0 * big_arrowhead_height / Canvas.SQRT3, height, event))
445 445
446 def draw_action_symbol(self, item, action, x, y, height, selected):
447 """Draws a release arrow: x, y should give the top (northernmost
448 point) of the arrow. The height includes the arrowhead."""
449
450 color = {False : GraphFormat.BORDER_COLOR,
451 True : GraphFormat.HIGHLIGHT_COLOR}[selected]
452
453 colors = [self.get_bar_pattern(item).get_color_list()[0], color]
454 draw_funcs = [self.__class__.fill_polyline, self.__class__.draw_polyline]
455
456 for i in range(0, 2):
457 color = colors[i]
458 draw_func = draw_funcs[i]
459
460 draw_func(self, [(x, y), (x - height / Canvas.SQRT3, \
461 y - height), \
462 (x + height / Canvas.SQRT3, \
463 y - height), \
464 (x, y)], color, GraphFormat.BORDER_THICKNESS)
465
466 self.draw_label(str(action), x, y - height / 2 - .1 * height,
467 GraphFormat.DEF_FOPTS_LABEL,
468 AlignMode.CENTER, AlignMode.CENTER, True)
469
470 def add_sel_action_symbol(self, x, y, height, event):
471 self.add_sel_region(SelectableRegion(x - height / Canvas.SQRT3,
472 y - height, 2.0 * height / Canvas.SQRT3, height, event))
473
446 def draw_release_arrow_small(self, x, y, height, selected): 474 def draw_release_arrow_small(self, x, y, height, selected):
447 """Draws a small release arrow (most likely coming off the x-axis, although 475 """Draws a small release arrow (most likely coming off the x-axis, although
448 this method doesn't enforce this): x, y should give the top of the arrow""" 476 this method doesn't enforce this): x, y should give the top of the arrow"""
449 small_arrowhead_height = GraphFormat.SMALL_ARROWHEAD_FACTOR * height 477 small_arrowhead_height = GraphFormat.SMALL_ARROWHEAD_FACTOR * height
450 478
451 color = {False : GraphFormat.BORDER_COLOR, True : GraphFormat.HIGHLIGHT_COLOR}[selected] 479 color = {False : GraphFormat.BORDER_COLOR,
480 True : GraphFormat.HIGHLIGHT_COLOR}[selected]
452 481
453 self.draw_line((x, y), (x - small_arrowhead_height, y + small_arrowhead_height), \ 482 self.draw_line((x, y),
483 (x - small_arrowhead_height, y + small_arrowhead_height),
454 color, GraphFormat.BORDER_THICKNESS) 484 color, GraphFormat.BORDER_THICKNESS)
455 self.draw_line((x, y), (x + small_arrowhead_height, y + small_arrowhead_height), \ 485 self.draw_line((x, y), (x + small_arrowhead_height, y + small_arrowhead_height), \
456 color, GraphFormat.BORDER_THICKNESS) 486 color, GraphFormat.BORDER_THICKNESS)
@@ -684,14 +714,35 @@ class CairoCanvas(Canvas):
684 self.surface.ctx.set_line_width(thickness * self.scale) 714 self.surface.ctx.set_line_width(thickness * self.scale)
685 self.surface.ctx.stroke() 715 self.surface.ctx.stroke()
686 716
717 def draw_circle(self, x, y, radius, fill_color, border_color,
718 thickness, do_snap=True):
719 p = self.surface.get_real_coor(x, y)
720 if do_snap:
721 p = (snap(p[0]), snap(p[1]))
722
723 self.surface.ctx.save()
724 self.surface.ctx.arc(p[0], p[1], radius, 0.0, 2 * math.pi)
725 self.surface.ctx.set_source_rgb(border_color[0],
726 border_color[1],
727 border_color[2])
728 self.surface.ctx.set_line_width(thickness * self.scale)
729 self.surface.ctx.stroke()
730 self.surface.ctx.arc(p[0], p[1], radius, 0.0, 2 * math.pi)
731 self.surface.ctx.set_source_rgb(fill_color[0],
732 fill_color[1],
733 fill_color[2])
734 self.surface.ctx.fill()
735 self.surface.ctx.restore()
736
687 def _polyline_common(self, coor_list, color, thickness, do_snap=True): 737 def _polyline_common(self, coor_list, color, thickness, do_snap=True):
688 scaled_coor_list = [self.scaled(coor[0], coor[1]) for coor in coor_list] 738 real_coor_list = [self.surface.get_real_coor(coor[0], coor[1]) \
689 real_coor_list = [self.surface.get_real_coor(coor[0], coor[1]) for coor in scaled_coor_list] 739 for coor in coor_list]
690 740
691 self.surface.ctx.move_to(real_coor_list[0][0], real_coor_list[0][1]) 741 self.surface.ctx.move_to(real_coor_list[0][0], real_coor_list[0][1])
692 if do_snap: 742 if do_snap:
693 for i in range(0, len(real_coor_list)): 743 for i in range(0, len(real_coor_list)):
694 real_coor_list[i] = (snap(real_coor_list[i][0]), snap(real_coor_list[i][1])) 744 real_coor_list[i] = (snap(real_coor_list[i][0]),
745 snap(real_coor_list[i][1]))
695 746
696 for coor in real_coor_list[1:]: 747 for coor in real_coor_list[1:]:
697 self.surface.ctx.line_to(coor[0], coor[1]) 748 self.surface.ctx.line_to(coor[0], coor[1])
@@ -753,8 +804,23 @@ class CairoCanvas(Canvas):
753 raise ValueError('Invalid alignment value') 804 raise ValueError('Invalid alignment value')
754 f_descent_factor, f_height_factor = valign_factors[valign] 805 f_descent_factor, f_height_factor = valign_factors[valign]
755 806
756 self._draw_label_common(text, x, y, fopts, x_bearing_factor, \ 807 return self._get_label_dim_common(text, x, y, fopts, x_bearing_factor,
757 f_descent_factor, width_factor, f_height_factor, do_snap) 808 f_descent_factor, width_factor, f_height_factor,
809 do_snap)
810
811 def draw_label(self, text, x, y, fopts=GraphFormat.DEF_FOPTS_LABEL,
812 halign=AlignMode.LEFT, valign=AlignMode.BOTTOM, do_snap=True):
813 """Draws a label with the given parameters, with the given horizontal and vertical justification."""
814
815 actual_x, actual_y, width, height, f_height = self.get_label_dim(text, x, y, fopts, halign, valign, do_snap)
816 actual_x, actual_y = self.surface.get_real_coor(actual_x, actual_y)
817
818 self.surface.ctx.select_font_face(fopts.name, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
819 self.surface.ctx.set_font_size(fopts.size * self.scale)
820 self.surface.ctx.set_source_rgb(fopts.color[0], fopts.color[1], fopts.color[2])
821 self.surface.ctx.move_to(actual_x, actual_y)
822
823 self.surface.ctx.show_text(text)
758 824
759 def draw_label_with_sscripts(self, text, supscript, subscript, x, y, \ 825 def draw_label_with_sscripts(self, text, supscript, subscript, x, y, \
760 textfopts=GraphFormat.DEF_FOPTS_LABEL, sscriptfopts=GraphFormat.DEF_FOPTS_LABEL_SSCRIPT, \ 826 textfopts=GraphFormat.DEF_FOPTS_LABEL, sscriptfopts=GraphFormat.DEF_FOPTS_LABEL_SSCRIPT, \