render method

  1. @override
void render(
  1. Canvas canvas,
  2. Graph graph,
  3. Paint paint
)
override

Implementation

@override
void render(Canvas canvas, Graph graph, Paint paint) {
  var trianglePaint = Paint()
    ..color = paint.color
    ..style = PaintingStyle.fill;

  graph.edges.forEach((edge) {
    var source = edge.source;
    var destination = edge.destination;

    var sourceOffset = source.position;

    var x1 = sourceOffset.dx;
    var y1 = sourceOffset.dy;

    var destinationOffset = destination.position;

    var x2 = destinationOffset.dx;
    var y2 = destinationOffset.dy;

    var startX = x1 + source.width / 2;
    var startY = y1 + source.height / 2;
    var stopX = x2 + destination.width / 2;
    var stopY = y2 + destination.height / 2;

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

    Paint? edgeTrianglePaint;
    if (edge.paint != null) {
      edgeTrianglePaint = Paint()
        ..color = edge.paint?.color ?? paint.color
        ..style = PaintingStyle.fill;
    }

    var 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]),
        edge.paint ?? paint);
  });
}