Skip to content
Snippets Groups Projects
Commit f8f696f3 authored by Allen, Bruce (CIV)'s avatar Allen, Bruce (CIV)
Browse files

add branch node

parent 113bdf9a
No related branches found
No related tags found
No related merge requests found
Pipeline #5005 failed
...@@ -12,6 +12,8 @@ ACTIVITY_W = 127 ...@@ -12,6 +12,8 @@ ACTIVITY_W = 127
ACTIVITY_H = 17 ACTIVITY_H = 17
DECISION_W = 14 DECISION_W = 14
DECISION_H = 14 DECISION_H = 14
BRANCH_W = 350
BRANCH_H = 17
START_D = 10 START_D = 10
END_D = 10 END_D = 10
END_D2 = 3 END_D2 = 3
...@@ -39,6 +41,8 @@ def _xy_in(json_node): ...@@ -39,6 +41,8 @@ def _xy_in(json_node):
raise RuntimeError("bad") raise RuntimeError("bad")
elif json_node[0] == "e": elif json_node[0] == "e":
return x, y - END_D/2 return x, y - END_D/2
elif json_node[0] == "b":
return x, y - BRANCH_H/2
else: else:
raise RuntimeError("bad") raise RuntimeError("bad")
...@@ -50,6 +54,8 @@ def _xy_out(json_node): ...@@ -50,6 +54,8 @@ def _xy_out(json_node):
return x, y + DECISION_H/2 return x, y + DECISION_H/2
elif json_node[0] == "s": elif json_node[0] == "s":
return x, y + START_D/2 return x, y + START_D/2
elif json_node[0] == "b":
return x, y + BRANCH_H/2
elif json_node[0] == "e": elif json_node[0] == "e":
raise RuntimeError("bad") raise RuntimeError("bad")
else: else:
...@@ -77,8 +83,13 @@ def _add_node_path(json_node, path): ...@@ -77,8 +83,13 @@ def _add_node_path(json_node, path):
d2 = END_D2 d2 = END_D2
path.addEllipse(x - d/2, y - d/2, d, d) path.addEllipse(x - d/2, y - d/2, d, d)
path.addEllipse(x - d2/2, y - d2/2, d2, d2) 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: else:
raise RuntimeError("bad") raise RuntimeError("bad node type: '%s'"%json_node[0])
def _add_edge_path(from_json_node, to_json_node, path): def _add_edge_path(from_json_node, to_json_node, path):
from_x, from_y = _xy_out(from_json_node) from_x, from_y = _xy_out(from_json_node)
...@@ -161,12 +172,10 @@ class ActivityDiagram(QGraphicsItem): ...@@ -161,12 +172,10 @@ class ActivityDiagram(QGraphicsItem):
def paint(self, painter, _option, _widget): def paint(self, painter, _option, _widget):
w = ACTIVITY_W
h = ACTIVITY_H
title_w = self.bounding_rect.width() title_w = self.bounding_rect.width()
# title # 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) self.title)
# painter_path of nodes and edges # painter_path of nodes and edges
...@@ -174,8 +183,18 @@ class ActivityDiagram(QGraphicsItem): ...@@ -174,8 +183,18 @@ class ActivityDiagram(QGraphicsItem):
# any text # any text
for node in self.nodes: 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) x, y = _xy(node)
painter.drawText(QRectF(x - w/2, y - h/2, w, h), painter.drawText(QRectF(x - w/2, y - h/2, w, h),
Qt.AlignCenter, node[4]) 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
...@@ -6,7 +6,8 @@ from PyQt5.QtWidgets import QGraphicsItem ...@@ -6,7 +6,8 @@ from PyQt5.QtWidgets import QGraphicsItem
from next_graphics_index import next_graphics_index from next_graphics_index import next_graphics_index
MAX_BAR_W = 200 MAX_BAR_W = 200
BAR_H = 20 ROW_H = 20
ROW_SPACING = 4
CHART_Y = 20 + 20 + 20 # 2 titles and spacing CHART_Y = 20 + 20 + 20 # 2 titles and spacing
def _text_width(text): def _text_width(text):
...@@ -67,7 +68,7 @@ class GanttChart(QGraphicsItem): ...@@ -67,7 +68,7 @@ class GanttChart(QGraphicsItem):
self.gantt_chart_w = max([_text_width(self.title), self.gantt_chart_w = max([_text_width(self.title),
_text_width(self.legend), _text_width(self.legend),
self.max_bar_name_w + MAX_BAR_W]) 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 # rectangle for mouse sense
self.bounding_path = QPainterPath() self.bounding_path = QPainterPath()
...@@ -101,13 +102,14 @@ class GanttChart(QGraphicsItem): ...@@ -101,13 +102,14 @@ class GanttChart(QGraphicsItem):
self.legend) self.legend)
# bars # bars
s = ROW_SPACING / 2
for i in range(len(self.bar_names)): for i in range(len(self.bar_names)):
# bar names # bar names
painter.drawText(QRectF(2, painter.drawText(QRectF(2,
CHART_Y + BAR_H * i, CHART_Y + ROW_H * i,
self.max_bar_name_w, self.max_bar_name_w,
BAR_H), ROW_H),
Qt.AlignCenter, self.bar_names[i]) Qt.AlignCenter, self.bar_names[i])
# non-zero start time bar value labels # non-zero start time bar value labels
...@@ -116,23 +118,23 @@ class GanttChart(QGraphicsItem): ...@@ -116,23 +118,23 @@ class GanttChart(QGraphicsItem):
if start > 0: if start > 0:
painter.drawText(QRectF(self.max_bar_name_w, painter.drawText(QRectF(self.max_bar_name_w,
CHART_Y + BAR_H * i, CHART_Y + ROW_H * i,
start_x, start_x,
BAR_H), ROW_H),
Qt.AlignCenter, "%s"%self.bar_starts[i]) Qt.AlignCenter, "%s"%self.bar_starts[i])
# stop time bar value labels # stop time bar value labels
stop = self.bar_stops[i] stop = self.bar_stops[i]
stop_x = stop * self.bar_scale stop_x = stop * self.bar_scale
painter.drawText(QRectF(self.max_bar_name_w + start_x, painter.drawText(QRectF(self.max_bar_name_w + start_x,
CHART_Y + BAR_H * i, CHART_Y + ROW_H * i,
stop_x, stop_x,
BAR_H), ROW_H),
Qt.AlignCenter, "%s"%self.bar_stops[i]) Qt.AlignCenter, "%s"%self.bar_stops[i])
# stop time bar # stop time bar
painter.drawRect(self.max_bar_name_w + start_x, painter.drawRect(self.max_bar_name_w + start_x,
CHART_Y + BAR_H * i, CHART_Y + ROW_H * i + ROW_SPACING / 2,
stop_x, stop_x,
BAR_H) ROW_H - ROW_SPACING)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment