Components
Svelvet

Description

Svelvet is the wrapping parent component that renders out nodes and edges. It is configurable via props, but no props are required. Many props can be set globally at this level and then overriden at the Node, Edge or Anchor level.

App.svelte
<script>
  import { Node, Svelvet, Minimap, Controls } from 'svelvet';
</script>

<Svelvet id="my-canvas" width="{500}" height="{500}" TD minimap locked>
  <Node />
  <Node id="alpha" bgColor="red" label="Default Node" />
  <Controls />
</Svelvet>

Props

widthDefault: "size of wrapping element"
number

Width of the canvas window on the DOM. If not passed, element will fill its wrapping container.

heightDefault: "size of wrapping element"
number

Height of the canvas window on the DOM. If not passed, element will fill its wrapping container.

idDefault: "incrementing integer"
number | string

Identification for the canvas. If not passed, defaults to an incrementing integer. Used as the HTML id value for the element taking the form G-id.

minimapDefault: "false"
boolean

Boolean used to render the default Minimap component. Just pass “minimap” rather than minimap= .

translationDefault: "{x: 0, y: 0}"
{x: number, y: number}

Initial translation of the graph. Does not currently feature two-way data binding.

controlsDefault: "false"
boolean

Boolean used to render the default Controls component. Just pass “controls” rather than controls= .

edge
Edge Component

A custom Edge component to be used as the global Edge style for the canvas. Can be overridden at the Node and Anchor level.

edgeStyleDefault: "bezier"
bezier | step | straight

Enum representing the global edge style for the canvas. Overriden when passing custom Edges.

snapToDefault: "1"
number

Pixel value at default scale that Nodes should snap to when being moved.

editableDefault: "false"
boolean

Allows the Node properties to be edited via CTRL+click.

fitViewDefault: "false"
boolean

Adjusts scale and translation to fit all Nodes in view on mount.

lockedDefault: "false"
boolean

Locks node movement, but still allows the canvas to be panned.

initialZoomDefault: "1"
number

Sets the initial zoom level for the canvas. Below 1 zooms out, above 1 zooms in.

themeDefault: "light"
string

A string associated with a custom theme created using a :root[svelvet-theme="theme-name"] CSS selector. Svelvet reserves light and dark.

mermaidDefault: ""
string

canvas representation using Mermaid-inspired string syntax. Great for quickly developing simple Nodes and Edges.

mermaidConfig
string

An object of key value pairs where the key is a Node ID and the value a Node configuration object. Used only when creating canvases via the Mermaid syntax.

TDDefault: "false"
boolean

Boolean controlling the directionality of the canvas. TD being set false by default means that the canvas direction is inherently left-to-right. Pass “TD” as a prop to change the direction to top-down.

disableSelectionDefault: "false"
boolean

Boolean controlling whether or not Shift + Click enables the selection of multiple components. This feature is enabled by default.

edgesAboveNodeDefault: "false"
boolean | 'all'

Sets whether Edges should, by default, be placed above or below connected Nodes. Can be set to all to force Edges above all nodes. Otherwise, true essentially turns on raiseEdgesOnSelect, but places the edges at higher z-Index than the Node.

raiseEdgesOnSelectDefault: "false"
boolean | 'source' | 'target'

When a Node is selected, this prop controls whether the z-index of a connected edge should be raised. Setting to true raises the edge regardless of if the source or target is selected.

modifierDefault: "meta"
'alt' | 'ctrl' | 'meta' | 'shift'

Sets global key modifier used to detect select all and duplicate events.

trackpadPanDefault: "false"
boolean

When using a trackpadPan, setting this prop to true enables two finger pan on the Graph and pinch to zoom. Will conflict with scroll behavior on mice. This mode of navigation can be enabled dynamically by hodling down the meta key.

Events

on:edgeDrop

Fires when an Edge connection is started and not completed. Does not fire on drops after a disconnection.