Here is my beautiful code:
def addArrow(self, arrow):
cql = """
MATCH (s),(t)
WHERE id(s)=$srcid AND id(t)=$tarid
CREATE (s)-[r:Morphism {labels:$labels, labelposx:$labelposx, labelposy:$labelposy,
tailstyle:$tailstyle, headcount:$headcount, pendash:$pendash, penwidth:$penwidth, pencol:$pencol,
pos0:$pos0, pos1:$pos1, pos2:$pos2, pos3:$pos3, pos:$pos}]->(t)
RETURN id(r)
"""
points = arrow.controlPoints()
try:
with self._driver.session() as session:
id = session.run(cql, parameters={
'labels': [label.text() for label in arrow.labels()],
'labelposx': [label.pos().x() for label in arrow.labels()],
'labelposy': [label.pos().y() for label in arrow.labels()],
'srcid': arrow.sourceNode().databaseID(),
'tarid': arrow.targetNode().databaseID(),
'tailstyle': arrow.tailStyle(),
'headcount': arrow.numberOfHeads(),
'pendash': arrow.pen().style(),
'penwidth': arrow.pen().widthF(),
'pencol': colorToList(arrow.pen().color()),
'pos0': pointToList(points[0].pos()),
'pos1': pointToList(points[1].pos()),
'pos2': pointToList(points[2].pos()),
'pos3': pointToList(points[3].pos()),
'pos': pointToList(arrow.pos()),
}).single().value()
arrow.setDatabaseID(id)
except Exception as e:
Error(str(e)).exec_()
if __debug__:
raise e
'labels': [label.text() for label in arrow.labels()], 'labelposx': [label.pos().x() for label in arrow.labels()], 'labelposy': [label.pos().y() for label in arrow.labels()],
The problem is: each arrow has a list of labels, but each label has a position which is a list of floats. So as you can see I've broken it up into labelposx
/ labelposy
so that these label lists can be dynamically updated. Is there a better way to do this such that the positions are contained with a "Label" structure? The problem now becomes worse if I want an independent color per label. Then I need labelcolorred
... labelcoloralpha
, which is four more lists.
Just wondering, I'm happy with the above if that's what we're limited to.
Thank you!