Skip to content

Commit

Permalink
Merge pull request #108 from devolo/feature/allow-triangleless-sugiya…
Browse files Browse the repository at this point in the history
…ma-graph

Add option to draw edges in Sugiyama-style graphs without arrowheads
  • Loading branch information
nabil6391 authored Dec 21, 2023
2 parents 5d3f6e8 + 9e30905 commit 76ddad3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/layered/SugiyamaAlgorithm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SugiyamaAlgorithm extends Algorithm {
var nodeCount = 1;

SugiyamaAlgorithm(this.configuration) {
renderer = SugiyamaEdgeRenderer(nodeData, edgeData, configuration.bendPointShape);
renderer = SugiyamaEdgeRenderer(nodeData, edgeData, configuration.bendPointShape, configuration.addTriangleToEdge);
}

int get dummyId => 'Dummy ${nodeCount++}'.hashCode;
Expand Down
2 changes: 2 additions & 0 deletions lib/layered/SugiyamaConfiguration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SugiyamaConfiguration {
BendPointShape bendPointShape = SharpBendPointShape();
CoordinateAssignment coordinateAssignment = CoordinateAssignment.Average;

bool addTriangleToEdge = true;

int getLevelSeparation() {
return levelSeparation;
}
Expand Down
31 changes: 22 additions & 9 deletions lib/layered/SugiyamaEdgeRenderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ class SugiyamaEdgeRenderer extends ArrowEdgeRenderer {
Map<Node, SugiyamaNodeData> nodeData;
Map<Edge, SugiyamaEdgeData> edgeData;
BendPointShape bendPointShape;
bool addTriangleToEdge;

SugiyamaEdgeRenderer(this.nodeData, this.edgeData, this.bendPointShape);
SugiyamaEdgeRenderer(this.nodeData, this.edgeData, this.bendPointShape, this.addTriangleToEdge);

var path = Path();

Expand Down Expand Up @@ -51,9 +52,6 @@ class SugiyamaEdgeRenderer extends ArrowEdgeRenderer {
bendPoints[size - 4], bendPoints[size - 3], bendPoints[size - 2], bendPoints[size - 1], destination);
}

final triangleCentroid = drawTriangle(
canvas, edgeTrianglePaint ?? trianglePaint, clippedLine[0], clippedLine[1], clippedLine[2], clippedLine[3]);

path.reset();
path.moveTo(bendPoints[0], bendPoints[1]);

Expand Down Expand Up @@ -83,7 +81,16 @@ class SugiyamaEdgeRenderer extends ArrowEdgeRenderer {
_drawSharpBendPointsEdge(bendPointsWithoutDuplication);
}

path.lineTo(triangleCentroid[0], triangleCentroid[1]);
if (addTriangleToEdge) {
final triangleCentroid = drawTriangle(
canvas, edgeTrianglePaint ?? trianglePaint, clippedLine[0], clippedLine[1], clippedLine[2], clippedLine[3]);

path.lineTo(triangleCentroid[0], triangleCentroid[1]);
} else {
final stopX = x1 + destination.width / 2;
final stopY = y1 + destination.height / 2;
path.lineTo(stopX, stopY);
}
canvas.drawPath(path, currentPaint);
} else {
final startX = x + source.width / 2;
Expand All @@ -93,11 +100,17 @@ class SugiyamaEdgeRenderer extends ArrowEdgeRenderer {

clippedLine = clipLine(startX, startY, stopX, stopY, destination);

final triangleCentroid = drawTriangle(
canvas, edgeTrianglePaint ?? trianglePaint, clippedLine[0], clippedLine[1], clippedLine[2], clippedLine[3]);
if (addTriangleToEdge) {
final triangleCentroid = drawTriangle(
canvas, edgeTrianglePaint ?? trianglePaint, clippedLine[0],
clippedLine[1], clippedLine[2], clippedLine[3]);

canvas.drawLine(
Offset(clippedLine[0], clippedLine[1]), Offset(triangleCentroid[0], triangleCentroid[1]), currentPaint);
canvas.drawLine(
Offset(clippedLine[0], clippedLine[1]), Offset(triangleCentroid[0], triangleCentroid[1]), currentPaint);
} else {
canvas.drawLine(
Offset(clippedLine[0], clippedLine[1]), Offset(stopX, stopY), currentPaint);
}
}
});
}
Expand Down

0 comments on commit 76ddad3

Please sign in to comment.