diff --git a/python/views/activity_diagram.py b/python/views/activity_diagram.py index 4d2c07112363c6cda97fd49d570728ef20658435..ec58ee1ee94a7d0b4201588817c2293650e475f5 100644 --- a/python/views/activity_diagram.py +++ b/python/views/activity_diagram.py @@ -12,6 +12,8 @@ ACTIVITY_W = 127 ACTIVITY_H = 17 DECISION_W = 14 DECISION_H = 14 +BRANCH_W = 350 +BRANCH_H = 17 START_D = 10 END_D = 10 END_D2 = 3 @@ -39,6 +41,8 @@ def _xy_in(json_node): raise RuntimeError("bad") elif json_node[0] == "e": return x, y - END_D/2 + elif json_node[0] == "b": + return x, y - BRANCH_H/2 else: raise RuntimeError("bad") @@ -50,6 +54,8 @@ def _xy_out(json_node): return x, y + DECISION_H/2 elif json_node[0] == "s": return x, y + START_D/2 + elif json_node[0] == "b": + return x, y + BRANCH_H/2 elif json_node[0] == "e": raise RuntimeError("bad") else: @@ -77,8 +83,13 @@ def _add_node_path(json_node, path): d2 = END_D2 path.addEllipse(x - d/2, y - d/2, d, d) path.addEllipse(x - d2/2, y - d2/2, d2, d2) + elif json_node[0] == "b": + w = BRANCH_W + h = BRANCH_H + left = ACTIVITY_W/2 + path.addRect(x - left, y - h/2, w, h) else: - raise RuntimeError("bad") + raise RuntimeError("bad node type: '%s'"%json_node[0]) def _add_edge_path(from_json_node, to_json_node, path): from_x, from_y = _xy_out(from_json_node) @@ -161,12 +172,10 @@ class ActivityDiagram(QGraphicsItem): def paint(self, painter, _option, _widget): - w = ACTIVITY_W - h = ACTIVITY_H title_w = self.bounding_rect.width() # title - painter.drawText(QRectF(0, TITLE_Y, title_w, h), Qt.AlignCenter, + painter.drawText(QRectF(0, TITLE_Y, title_w, 20), Qt.AlignCenter, self.title) # painter_path of nodes and edges @@ -174,8 +183,18 @@ class ActivityDiagram(QGraphicsItem): # any text for node in self.nodes: - if node[0] == "a": # activity has text + if node[0] == "a": # activity + w = ACTIVITY_W + h = ACTIVITY_H x, y = _xy(node) painter.drawText(QRectF(x - w/2, y - h/2, w, h), Qt.AlignCenter, node[4]) + elif node[0] == "b": # branch + w = BRANCH_W + h = BRANCH_H + x, y = _xy(node) + painter.drawText(QRectF(x - ACTIVITY_W/2, y - h/2, w, h), + Qt.AlignCenter, node[5]) + else: + pass # some nodes don't have text diff --git a/python/views/gantt_chart.py b/python/views/gantt_chart.py index 12d517cb1992927551385974dac2b498eccbffc5..7475a14ac6c31c141fed0b70b61832e69e70f589 100644 --- a/python/views/gantt_chart.py +++ b/python/views/gantt_chart.py @@ -6,7 +6,8 @@ from PyQt5.QtWidgets import QGraphicsItem from next_graphics_index import next_graphics_index MAX_BAR_W = 200 -BAR_H = 20 +ROW_H = 20 +ROW_SPACING = 4 CHART_Y = 20 + 20 + 20 # 2 titles and spacing def _text_width(text): @@ -67,7 +68,7 @@ class GanttChart(QGraphicsItem): self.gantt_chart_w = max([_text_width(self.title), _text_width(self.legend), self.max_bar_name_w + MAX_BAR_W]) - self.gantt_chart_h = CHART_Y + BAR_H * self.num_bars + self.gantt_chart_h = CHART_Y + ROW_H * self.num_bars # rectangle for mouse sense self.bounding_path = QPainterPath() @@ -101,13 +102,14 @@ class GanttChart(QGraphicsItem): self.legend) # bars + s = ROW_SPACING / 2 for i in range(len(self.bar_names)): # bar names painter.drawText(QRectF(2, - CHART_Y + BAR_H * i, + CHART_Y + ROW_H * i, self.max_bar_name_w, - BAR_H), + ROW_H), Qt.AlignCenter, self.bar_names[i]) # non-zero start time bar value labels @@ -116,23 +118,23 @@ class GanttChart(QGraphicsItem): if start > 0: painter.drawText(QRectF(self.max_bar_name_w, - CHART_Y + BAR_H * i, + CHART_Y + ROW_H * i, start_x, - BAR_H), + ROW_H), Qt.AlignCenter, "%s"%self.bar_starts[i]) # stop time bar value labels stop = self.bar_stops[i] stop_x = stop * self.bar_scale painter.drawText(QRectF(self.max_bar_name_w + start_x, - CHART_Y + BAR_H * i, + CHART_Y + ROW_H * i, stop_x, - BAR_H), + ROW_H), Qt.AlignCenter, "%s"%self.bar_stops[i]) # stop time bar painter.drawRect(self.max_bar_name_w + start_x, - CHART_Y + BAR_H * i, + CHART_Y + ROW_H * i + ROW_SPACING / 2, stop_x, - BAR_H) + ROW_H - ROW_SPACING)