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

adjust graph bounds

parent be3fd68e
No related branches found
No related tags found
No related merge requests found
Pipeline #4997 failed
......@@ -6,8 +6,8 @@ from PyQt5.QtWidgets import QGraphicsItem
from next_graphics_index import next_graphics_index
# see also typical settings_manager values
TITLE_Y = 15
TITLE_SPACING = 25
TITLE_Y = 5
TITLE_Y_SPACING = 30
ACTIVITY_W = 127
ACTIVITY_H = 17
DECISION_W = 14
......@@ -18,10 +18,15 @@ END_D2 = 3
H_SPACING = 165
V_SPACING = 55
def _text_width(text):
fm = QFontMetrics(QFont()) # use default font since we do not set it
width = fm.horizontalAdvance(text)
return width
def _xy(json_node):
# node center point
x = json_node[2] * H_SPACING
y = json_node[3] * V_SPACING + TITLE_SPACING
x = json_node[2] * H_SPACING + ACTIVITY_W/2
y = json_node[3] * V_SPACING + TITLE_Y_SPACING
return x, y
def _xy_in(json_node):
......@@ -109,6 +114,9 @@ class ActivityDiagram(QGraphicsItem):
self.nodes = data[1]
edges = data[2]
# title width
self.title_width = _text_width(self.title)
# indexed nodes for edges
indexed_nodes = dict()
......@@ -126,11 +134,14 @@ class ActivityDiagram(QGraphicsItem):
indexed_nodes[json_edge[1]],
self.painter_path)
# rectangle for mouse sense
# rectangle, adjusted for title
self.bounding_path = QPainterPath()
bounding_rect = self.painter_path.boundingRect()
bounding_rect.setTop(0)
self.bounding_path.addRect(bounding_rect)
self.bounding_rect = self.painter_path.boundingRect()
self.bounding_rect.adjust(0, -TITLE_Y_SPACING, 0, 0)
w = _text_width(self.title)
if w > self.bounding_rect.width():
self.bounding_rect.adjust(0, 0, w - self.bounding_rect.width(), 0)
self.bounding_path.addRect(self.bounding_rect)
def json_data(self):
self._json_data["x"] = self.x()
......@@ -152,9 +163,10 @@ class ActivityDiagram(QGraphicsItem):
w = ACTIVITY_W
h = ACTIVITY_H
title_w = self.bounding_rect.width()
# title
painter.drawText(QRectF(0, TITLE_Y, w, h), Qt.AlignCenter,
painter.drawText(QRectF(0, TITLE_Y, title_w, h), Qt.AlignCenter,
self.title)
# painter_path of nodes and edges
......
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