LiveFlow.Paths.Path behaviour (LiveFlow v0.4.0)

Copy Markdown View Source

Behaviour for edge path calculations.

Path modules calculate SVG path strings for rendering edges between nodes. Each path type (bezier, straight, step, smoothstep) implements this behaviour.

Path Result

The calculate/2 function returns a map with:

  • :path - SVG path string (e.g., "M0,0 C50,0 50,100 100,100")
  • :label_x - X coordinate for edge label
  • :label_y - Y coordinate for edge label

Implementing a Custom Path

defmodule MyApp.CustomPath do
  @behaviour LiveFlow.Paths.Path

  @impl true
  def calculate(source, target, opts) do
    # Custom path calculation
    %{
      path: "M ...",
      label_x: ...,
      label_y: ...
    }
  end
end

Summary

Types

Source/target point with position information.

Path calculation result.

Callbacks

Calculates the SVG path between source and target points.

Functions

Calculates a path using the specified path module.

Gets the path module for an edge type.

Types

point()

@type point() :: %{
  x: number(),
  y: number(),
  position: :top | :bottom | :left | :right
}

Source/target point with position information.

  • :x - X coordinate
  • :y - Y coordinate
  • :position - Handle position (:top, :bottom, :left, :right)

result()

@type result() :: %{path: String.t(), label_x: number(), label_y: number()}

Path calculation result.

Callbacks

calculate(source, target, opts)

@callback calculate(source :: point(), target :: point(), opts :: keyword()) :: result()

Calculates the SVG path between source and target points.

Options

Options are path-type specific. Common options include:

  • :curvature - Curve intensity (0.0 to 1.0)
  • :offset - Distance from node before turning
  • :border_radius - Corner rounding for step paths

Functions

calculate(module, source, target, opts \\ [])

@spec calculate(module(), point(), point(), keyword()) :: result()

Calculates a path using the specified path module.

module_for_type(arg1)

@spec module_for_type(atom()) :: module()

Gets the path module for an edge type.