Viewport data structure for LiveFlow.
The viewport represents the current pan/zoom state of the flow canvas. It tracks the translation (x, y) and zoom level to transform flow coordinates to screen coordinates.
Fields
:x- Horizontal pan offset:y- Vertical pan offset:zoom- Zoom level (1.0 = 100%)
Coordinate Transformation
To convert from flow space to screen space:
screen_x = flow_x * zoom + viewport.x
screen_y = flow_y * zoom + viewport.yTo convert from screen space to flow space:
flow_x = (screen_x - viewport.x) / zoom
flow_y = (screen_y - viewport.y) / zoomExamples
iex> vp = LiveFlow.Viewport.new()
%LiveFlow.Viewport{x: 0.0, y: 0.0, zoom: 1.0}
iex> LiveFlow.Viewport.pan(vp, 100, 50)
%LiveFlow.Viewport{x: 100.0, y: 50.0, zoom: 1.0}
Summary
Functions
Calculates viewport to fit given bounds with optional padding.
Converts flow coordinates to screen coordinates.
Creates a new viewport with optional initial values.
Pans the viewport by the given delta.
Sets the viewport pan position.
Converts screen coordinates to flow coordinates.
Sets the viewport position and zoom.
Gets the CSS transform string for the viewport.
Zooms the viewport by a factor.
Sets the zoom level directly.
Types
Functions
Calculates viewport to fit given bounds with optional padding.
Options
:padding- Padding ratio (default:0.1= 10%):min_zoom- Minimum zoom level (default:0.1):max_zoom- Maximum zoom level (default:4.0)
Examples
iex> bounds = %{x: 0, y: 0, width: 400, height: 300}
iex> LiveFlow.Viewport.fit_bounds(%{width: 800, height: 600}, bounds)
%LiveFlow.Viewport{x: 80.0, y: 60.0, zoom: 1.6}
Converts flow coordinates to screen coordinates.
Examples
iex> vp = LiveFlow.Viewport.new(x: 100, y: 50, zoom: 2.0)
iex> LiveFlow.Viewport.flow_to_screen(vp, 50, 50)
{200.0, 150.0}
Creates a new viewport with optional initial values.
Options
:x- Initial x pan (default:0.0):y- Initial y pan (default:0.0):zoom- Initial zoom level (default:1.0)
Examples
iex> LiveFlow.Viewport.new()
%LiveFlow.Viewport{x: 0.0, y: 0.0, zoom: 1.0}
iex> LiveFlow.Viewport.new(x: 100, y: 50, zoom: 1.5)
%LiveFlow.Viewport{x: 100.0, y: 50.0, zoom: 1.5}
Pans the viewport by the given delta.
Sets the viewport pan position.
Converts screen coordinates to flow coordinates.
Examples
iex> vp = LiveFlow.Viewport.new(x: 100, y: 50, zoom: 2.0)
iex> LiveFlow.Viewport.screen_to_flow(vp, 200, 150)
{50.0, 50.0}
Sets the viewport position and zoom.
Gets the CSS transform string for the viewport.
Examples
iex> vp = LiveFlow.Viewport.new(x: 100, y: 50, zoom: 1.5)
iex> LiveFlow.Viewport.transform_style(vp)
"translate(100.0px, 50.0px) scale(1.5)"
Zooms the viewport by a factor.
Options
:center- Point to zoom towards{x, y}in screen coordinates:min_zoom- Minimum zoom level (default:0.1):max_zoom- Maximum zoom level (default:4.0)
Examples
iex> vp = LiveFlow.Viewport.new()
iex> LiveFlow.Viewport.zoom_by(vp, 1.5)
%LiveFlow.Viewport{x: 0.0, y: 0.0, zoom: 1.5}
Sets the zoom level directly.
Options
:center- Point to zoom towards{x, y}in screen coordinates:min_zoom- Minimum zoom level (default:0.1):max_zoom- Maximum zoom level (default:4.0)