Connection.fromJson constructor

Connection.fromJson(
  1. Map<String, dynamic> json
)

Creates a Connection from a JSON map.

This factory constructor deserializes a connection from JSON, properly initializing all observable properties.

Implementation

factory Connection.fromJson(Map<String, dynamic> json) {
  final connection = _$ConnectionFromJson(json);
  // Initialize observable labels from JSON
  if (json['startLabel'] != null) {
    connection._startLabel.value = ConnectionLabel.fromJson(
      json['startLabel'] as Map<String, dynamic>,
    );
  }
  if (json['label'] != null) {
    connection._label.value = ConnectionLabel.fromJson(
      json['label'] as Map<String, dynamic>,
    );
  }
  if (json['endLabel'] != null) {
    connection._endLabel.value = ConnectionLabel.fromJson(
      json['endLabel'] as Map<String, dynamic>,
    );
  }
  // Initialize control points from JSON
  if (json['controlPoints'] != null) {
    final pointsList = json['controlPoints'] as List;
    connection._controlPoints.clear();
    connection._controlPoints.addAll(
      pointsList.map(
        (p) =>
            Offset((p['dx'] as num).toDouble(), (p['dy'] as num).toDouble()),
      ),
    );
  }
  return connection;
}