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

fix centering in graph pane

parent 6629463f
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,6 @@ class Box(QGraphicsItem):
self.setVisible(gry_data["visible"])
self.show_box = gry_data["show_box"]
self.setPos(QPoint(gry_data["x"], gry_data["y"]))
self.painter_path = QPainterPath() # box can be accessed early
self.is_initialized = False
def itemChange(self, change, value):
......@@ -26,13 +25,13 @@ class Box(QGraphicsItem):
return super(Box, self).itemChange(change, value)
def initialize_box(self):
print("box initialize_box")
# graphicsItem mode
if self.parentItem():
self.setFlag(QGraphicsItem.ItemIsMovable)
self.setFlag(QGraphicsItem.ItemIsSelectable)
self.setFlag(QGraphicsItem.ItemSendsGeometryChanges)
self.setAcceptHoverEvents(True)
self.reset_appearance()
self.is_initialized = True
def type(self):
......
......@@ -28,7 +28,8 @@ def export_trace(trace_filename, graph_item, graph_index):
# maybe make bounds wider if this is the global view to fit its title
if graph_index == 0:
bounding_rect = bounding_rect.united(QRectF(0, 0, 90, 0))
bounding_rect = bounding_rect.united(QRectF(
bounding_rect.x(), bounding_rect.y(), 90, 0))
# add border padding
bounding_rect.adjust(-banner_height, -banner_height,
......
......@@ -31,17 +31,15 @@ class GraphItem(QObject):
gry_trace = gry_graph["trace"]
self.mark = gry_trace["graph_mark"]
self.probability = gry_trace["probability"]
self.layout = gry_trace["layout"]
self.node_lookup = dict()
# top parent
print("graph_item init")
self.graph_box = Box(None,
{"visible":True,
"show_box":gry_graph["show_box"],
"x":0, "y":0})
self.graph_box = Box(None, gry_graph["box"])
# trace
self.trace_box = Box(self.graph_box, gry_trace)
if "box" in gry_trace:
self.trace_box = Box(self.graph_box, gry_trace["box"])
# trace nodes
self.nodes = list()
......@@ -65,21 +63,29 @@ class GraphItem(QObject):
for gry_table in gry_graph["tables"]:
self.view_tables.append(ViewTable(self.graph_box, gry_table))
# other views
self.view_says = list()
self.view_graphs = list()
self.view_bar_charts = list()
self.view_gantt_charts = list()
self.view_activity_diagrams = list()
self.view_user_annotations = list()
self.items_initialized = False
self._highlighted_edge = None
def get_gry_graph(self):
gry_graph = empty_graph()
gry_graph.update({"probability":self.probability,
"layout":"default",
"visible":self.trace_box.isVisible(),
"show_box":self.trace_box.show_box,
"x":self.trace_box.x(),
"y":self.trace_box.y(),
})
gry_graph["box"] = self.graph_box.get_gry()
# trace
gry_graph["trace"]["graph_mark"] = self.mark
gry_trace = gry_graph["trace"]
gry_trace["graph_mark"] = self.mark
gry_trace["layout"] = self.layout
gry_trace["probability"] = self.probability
if self.nodes:
gry_trace["box"] = self.trace_box.get_gry()
for node in self.nodes:
gry_graph["trace"]["nodes"].append(node.get_gry_node())
for edge in self.edges:
......@@ -87,12 +93,10 @@ class GraphItem(QObject):
# view | report
for report in self.view_reports:
print("get_gry_graph report", report)
gry_graph["reports"].append(report.get_gry())
# view | table
for table in self.view_tables:
print("get_gry_graph table", table)
gry_graph["tables"].append(table.get_gry())
......@@ -100,8 +104,11 @@ class GraphItem(QObject):
def non_empty_global_view(self):
# any non-trace view present
# zzzz
return True
is_non_empty_global_view = self.view_says or self.view_reports \
or self.view_graphs or self.view_tables \
or self.view_bar_charts or self.view_gantt_charts \
or self.view_activity_diagrams or self.view_user_annotations
return is_non_empty_global_view
# maybe box coordinates are not set
def _maybe_set_x(self, graphics_item):
......@@ -113,12 +120,13 @@ class GraphItem(QObject):
# perform orderly just-in-time initialization of graph item components
def initialize_items(self):
if not self.items_initialized:
# trace
for node in self.nodes:
node.initialize_node(self)
for edge in self.edges:
edge.initialize_edge(self.node_lookup)
self.trace_box.initialize_box()
if self.nodes:
# trace
for node in self.nodes:
node.initialize_node(self)
for edge in self.edges:
edge.initialize_edge(self.node_lookup)
self.trace_box.initialize_box()
# views
for view_report in self.view_reports:
......@@ -128,19 +136,19 @@ class GraphItem(QObject):
view_table.initialize_view_table()
self._maybe_set_x(view_table)
# initialize QGraphicsItem graph object top parent
print("graph_item.initialize_items")
self.graph_box.initialize_box()
self.items_initialized = True
# reset appearance when graph color or shape changes
def reset_appearance(self):
self.graph_box.reset_appearance()
for node in self.nodes:
node.reset_appearance()
for edge in self.edges:
edge.reset_appearance()
self.trace_box.reset_appearance()
def change_item_spacing(self, ratios):
ratio_0 = ratios[0]
......@@ -164,7 +172,7 @@ class GraphItem(QObject):
# perform any just-in-time initialization
self.initialize_items()
return self.graph_box.childrenBoundingRect()
return self.graph_box.boundingRect()
def highlight_edge(self, edge):
if self._highlighted_edge:
......
......@@ -64,23 +64,29 @@ def paint_graph_item(painter, graph_item, graph_index, scale, option,
# find the corners of this graph item
graph_bounds = graph_item.bounding_rect()
# paint graph
# transform painter below banner and fit nodes and edges
# transform painter below banner and fit bound items
painter.save()
painter.translate(0, banner_height)
painter.scale(scale, scale)
painter.translate(-graph_bounds.x(), -graph_bounds.y())
# paint nodes and edges and possible box
for edge in graph_item.edges:
edge.paint(painter, option, None)
for node in graph_item.nodes:
# translate for this node
painter.save()
painter.translate(node.pos())
node.paint(painter, option, None)
painter.restore()
graph_item.graph_box.paint(painter, option, None) # always at (0, 0)
# paint graph items
painter.save()
painter.translate(graph_item.graph_box.pos())
graph_item.graph_box.paint(painter, option, None)
if graph_item.nodes:
painter.translate(graph_item.trace_box.pos())
graph_item.trace_box.paint(painter, option, None)
for edge in graph_item.edges:
edge.paint(painter, option, None)
for node in graph_item.nodes:
# translate for this node
painter.save()
painter.translate(node.pos())
node.paint(painter, option, None)
painter.restore()
painter.restore()
# paint any views
for report in graph_item.view_reports:
......
......@@ -11,18 +11,20 @@ The graphs data structure can be represented directly in JSON.
from edge_bezier_placer import EdgeBezierPlacer
from settings_manager import settings
# dict for new box
def _box(should_show):
return {"visible":True, "show_box":should_show, "x":0, "y":0}
# starting template for a graph
def empty_graph():
graph = dict()
# background
graph["show_box"] = settings["background_use_box"]
graph["box"] = _box(settings["background_use_box"])
# one trace, empty if global view at [0]
graph["trace"] = {"graph_mark":"", "probability":0, "nodes":[], "edges":[],
"layout":"default",
"show_box":settings["trace_use_box"],
"x":0, "y":0, "visible":True}
graph["trace"] = {"graph_mark":"", "probability":0, "layout":"default",
"nodes":[], "edges":[]}
# zero or more of these views
graph["says"] = list()
......@@ -40,8 +42,8 @@ def empty_graph():
def _view_report(view_object):
return {"title":view_object[0],
"lines":view_object[1:],
"visible":True, "show_box":settings["report_use_box"],
"x":0, "y":0}
"box":_box(settings["report_use_box"]),
}
# (22)
......@@ -51,8 +53,7 @@ def _view_graph(view_object):
edges = list()
index = 0
graph = {"title":view_object[0], "nodes":nodes, "edges":edges,
"visible":True, "show_box":settings["background_use_box"],
"x":0, "y":0}
"box":_box(settings["background_use_box"])}
for tg_node in view_object[1]: # (23)
x= index * settings["graph_node_h_spacing"]
y= index * settings["graph_node_v_spacing"]
......@@ -74,24 +75,24 @@ def _view_table(view_object):
return {"title":view_object["title"],
"headers":view_object["tabs"],
"rows":view_object["rows"],
"visible":True, "show_box":settings["table_use_box"],
"x":0, "y":0}
"box":_box(settings["table_use_box"]),
}
# (33)
def _view_bar_chart(view_object):
return {"title":view_object["title"],
"headers":view_object["tabs"], # unused X_AXIS same as tabs[0]
"rows":view_object["rows"],
"visible":True, "show_box":settings["bar_chart_use_box"],
"x":0, "y":0}
"box":_box(settings["bar_chart_use_box"]),
}
# (34)
def _view_gantt_chart(view_object):
return {"title":view_object["title"],
"headers":view_object["tabs"], # unused X_AXIS same as tabs[0]
"rows":view_object["rows"],
"visible":True, "show_box":settings["gantt_chart_use_box"],
"x":0, "y":0}
"box":_box(settings["gantt_chart_use_box"]),
}
# (35)
def _view_activity_diagram(view_object):
......@@ -99,8 +100,9 @@ def _view_activity_diagram(view_object):
edges = list()
index = 0
graph = {"title":view_object[0], "nodes":nodes, "edges":edges,
"visible":True, "show_box":settings["activity_diagram_use_box"],
"x":0, "y":0}
"box":_box(settings["activity_diagram_use_box"]),
}
# for tg_node in view_object[1]: # (23)
# x= index * recommended_h_spacing + recommended_node_width/2
# y= index * recommended_v_spacing + recommended_node_height/2
......@@ -173,15 +175,15 @@ def tg_to_gry_graphs(tg_data):
gry_graphs = list()
# global views for global graph[0]
graph = empty_graph()
gry_graphs.append(graph)
gry_graph = empty_graph()
gry_graphs.append(gry_graph)
if "GLOBAL" in tg_data:
g = tg_data["GLOBAL"]
graph["trace"]["graph_mark"] = g[0]
graph["say"] = g[1] # list
gry_graph["global_mark"] = g[0]
gry_graph["say"] = g[1] # list
for view_object in g[2:]:
_add_view_object(view_object, graph)
_add_view_object(view_object, gry_graph)
# traces and trace views for graphs [1:]
if "traces" in tg_data:
......@@ -191,24 +193,25 @@ def tg_to_gry_graphs(tg_data):
for tg_trace in tg_traces:
# start with empty graph template
graph = empty_graph()
gry_graphs.append(graph)
gry_graph = empty_graph()
gry_graphs.append(gry_graph)
# trace
trace = graph["trace"]
gry_trace = gry_graph["trace"]
gry_trace["box"] = _box(settings["trace_use_box"])
# item 0: graph mark, "U" or "M"
trace["graph_mark"] = tg_trace[0]
gry_trace["graph_mark"] = tg_trace[0]
# item 1: trace probability
trace["probability"] = tg_trace[1]
gry_trace["probability"] = tg_trace[1]
# item 2: event list of nodes
tg_nodes = tg_trace[2] # event list
y_extra_say = 0
nodes = list()
_nodes = dict() # for placing edges
trace["nodes"] = nodes
gry_trace["nodes"] = nodes
for tg_node in tg_nodes: # event in event list
# prepare event name without underscores
......@@ -241,7 +244,7 @@ def tg_to_gry_graphs(tg_data):
# item 3: IN relation edges
tg_in_edges = tg_trace[3]
trace["edges"] = edges
gry_trace["edges"] = edges
for tg_edge in tg_in_edges:
edges.append(_trace_edge(tg_edge, "IN", "", _nodes, placer))
......@@ -264,7 +267,7 @@ def tg_to_gry_graphs(tg_data):
and "VIEWS" in type_specific_element:
# view
for view_object in type_specific_element["VIEWS"]: # 17
_add_view_object(view_object, graph)
_add_view_object(view_object, gry_graph)
else:
print("Unexpected input:", type_specific_element)
......
......@@ -15,9 +15,10 @@ class ViewReport(QGraphicsItem):
# values for get_gry
self._gry_data = gry_data
self.setVisible(self._gry_data["visible"])
self.show_box = self._gry_data["show_box"]
self.setPos(QPoint(self._gry_data["x"], self._gry_data["y"]))
gry_box = gry_data["box"]
self.setVisible(gry_box["visible"])
self.show_box = gry_box["show_box"]
self.setPos(QPoint(gry_box["x"], gry_box["y"]))
def _make_painter_paths(self):
p = BOX_PADDING
......@@ -70,10 +71,10 @@ class ViewReport(QGraphicsItem):
def get_gry(self):
gry_data = self._gry_data
gry_data["x"] = self.x()
gry_data["y"] = self.y()
gry_data["visible"] = self.isVisible()
gry_data["show_box"] = self.show_box
gry_data["box"] = {"visible":self.isVisible(),
"show_box":self.show_box,
"x":self.x(), "y":self.y()
}
return gry_data
def type(self):
......
......@@ -16,9 +16,10 @@ class ViewTable(QGraphicsItem):
# values for get_gry
self._gry_data = gry_data
self.setVisible(self._gry_data["visible"])
self.show_box = self._gry_data["show_box"]
self.setPos(QPoint(self._gry_data["x"], self._gry_data["y"]))
gry_box = gry_data["box"]
self.setVisible(gry_box["visible"])
self.show_box = gry_box["show_box"]
self.setPos(QPoint(gry_box["x"], gry_box["y"]))
def _make_painter_paths(self):
p = BOX_PADDING
......@@ -86,10 +87,10 @@ class ViewTable(QGraphicsItem):
def get_gry(self):
gry_data = self._gry_data
gry_data["x"] = self.x()
gry_data["y"] = self.y()
gry_data["visible"] = self.isVisible()
gry_data["show_box"] = self.show_box
gry_data["box"] = {"visible":self.isVisible(),
"show_box":self.show_box,
"x":self.x(), "y":self.y()
}
return gry_data
def type(self):
......
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