GraphViewport class final

Represents the viewport transformation for a node flow graph.

The viewport defines how the infinite graph coordinate space is mapped to the finite screen space. It consists of:

  • Pan offset (x, y): Translation of the graph on screen
  • Zoom level (zoom): Scale factor for the graph

Graph coordinates are independent of screen size and allow nodes to be positioned anywhere. The viewport transforms these coordinates to screen pixels for rendering.

All coordinate transformations use typed extension types (GraphPosition, ScreenPosition, GraphOffset, ScreenOffset) to prevent accidentally mixing coordinate spaces.

Example:

// Create a viewport centered at origin with 100% zoom
final viewport = GraphViewport(x: 0, y: 0, zoom: 1.0);

// Convert screen position to graph coordinates (type-safe!)
final screenPos = ScreenPosition.fromXY(100, 100);
final graphPos = viewport.toGraph(screenPos);

// Convert graph position to screen coordinates
final nodePos = GraphPosition.fromXY(50, 50);
final screenNodePos = viewport.toScreen(nodePos);

// Check if a rectangle is visible
final bounds = GraphRect.fromLTWH(0, 0, 100, 100);
final isVisible = viewport.isRectVisible(bounds, Size(800, 600));

Constructors

GraphViewport({double x = 0.0, double y = 0.0, double zoom = 1.0})
Creates a viewport with the specified pan and zoom.
const
GraphViewport.fromJson(Map<String, dynamic> json)
Creates a viewport from JSON data.
factory

Properties

hashCode int
The hash code for this object.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
x double
Horizontal pan offset in screen pixels.
final
y double
Vertical pan offset in screen pixels.
final
zoom double
Zoom scale factor.
final

Methods

copyWith({double? x, double? y, double? zoom}) GraphViewport
Creates a new viewport with updated values.
getVisibleArea(Size screenSize) GraphRect
Gets the visible area in graph coordinates.
isPointVisible(GraphPosition point, Size screenSize) bool
Checks if a point is visible in the current viewport.
isRectVisible(GraphRect rect, Size screenSize) bool
Checks if a rectangle is visible in the current viewport.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toGraph(ScreenPosition screenPoint) GraphPosition
Transforms a ScreenPosition to a GraphPosition.
toGraphOffset(ScreenOffset screenOffset) GraphOffset
Transforms a ScreenOffset to a GraphOffset.
toGraphRect(ScreenRect screenRect) GraphRect
Transforms a ScreenRect to a GraphRect.
toJson() Map<String, dynamic>
Serializes this viewport to JSON.
toScreen(GraphPosition graphPoint) ScreenPosition
Transforms a GraphPosition to a ScreenPosition.
toScreenOffset(GraphOffset graphOffset) ScreenOffset
Transforms a GraphOffset to a ScreenOffset.
toScreenRect(GraphRect graphRect) ScreenRect
Transforms a GraphRect to a ScreenRect.
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override