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.

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
final graphPos = viewport.screenToGraph(Offset(100, 100));

// Convert graph position to screen coordinates
final screenPos = viewport.graphToScreen(Offset(50, 50));

// Check if a rectangle is visible
final isVisible = viewport.isRectVisible(
  Rect.fromLTWH(0, 0, 100, 100),
  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) Rect
Gets the visible area in graph coordinates.
graphToScreen(Offset graphPoint) Offset
Transforms a graph point to screen coordinates.
isRectVisible(Rect 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
screenToGraph(Offset screenPoint) Offset
Transforms a screen point to graph coordinates.
screenToGraphDelta(Offset screenDelta) Offset
Transforms a screen delta to graph delta (without translation).
toJson() Map<String, dynamic>
Serializes this viewport to JSON.
toString() String
A string representation of this object.
override

Operators

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