Skip to content

Options ​

The full reference, with every type, is in the API.

new Arclace(options?) ​

OptionTypeDefaultDescription
containerElement | stringdocument.bodyThe element the overlay is added to.
autoUpdateboolean | 'frame'truetrue redraws on window resize, scroll, element resize and DOM/style changes in the container. 'frame' redraws every animation frame. false only redraws when you call update().
defaultsConnection options{}Defaults for every connection made by this instance.
classNamestringExtra classes for the overlay.
MemberDescription
connect(start, end, options?)Connects two elements (or selectors) and draws the line. Returns a Connection.
connectAll(definitions)Connects many { startElement, endElement, ...options } pairs in one go: all of them or, if one fails, none.
get(id)The connection with that id.
find(element)Every connection that starts or ends at an element. [] when a selector matches nothing.
disconnect(target)Removes a connection, a connection by id, or every connection of an element.
clear()Removes every connection.
update()Remeasures and redraws everything.
destroy()Removes everything and stops listening for changes.
connectionsAll connections, in the order they were made.
container, svgThe container and the overlay.

Connection ​

MemberDescription
setOptions(options)Changes options and redraws.
remove()Removes the connection.
update()Redraws (all connections of the instance, since spreading depends on the others).
optionsThe options in effect, with defaults filled in.
geometry{ start, end, startSide, endSide, labelPoint, d } from the last draw, or null when hidden.
id, startElement, endElement
element, pathThe connection's <g> and <path>, for styling or event listeners.

A connection is hidden while one of its elements is detached or display: none, and shown again when it comes back.

Connection options ​

OptionTypeDefaultDescription
idstringgeneratedUnique id, for get() and disconnect().
type'bezier' | 'straight' | 'orthogonal''bezier'How the line is drawn.
startSide'auto' | 'top' | 'right' | 'bottom' | 'left''auto'Side of the start element. auto picks the side facing the other element.
endSidesame as startSide'auto'Side of the end element.
arrow'none' | 'start' | 'end' | 'both''none'Arrow heads.
labelstringText in the middle of the line.
colorstringLine color. Without it, lines use --arc-color or the container's text color.
strokeWidthnumber2Line width in pixels, 0 or more. Arrows and anchors scale with it.
dashedbooleanfalseDashed line.
animatedbooleanfalseDashes flowing from start to end. Needs style.css.
anchorsbooleanfalseDots where the line meets the elements.
classNamestringExtra classes for the connection's <g>.
gapnumber0Space between the element edge and the line end. Negative moves the end into the element.
spreadbooleantrueSpread lines that share a side of an element.
spacingnumber16Distance between spread lines, 0 or more. Shrinks to fit the side.
curvaturenumber1bezier: how far the curve bulges out. Negative bulges the other way.
radiusnumber8orthogonal: corner radius, 0 or more. 0 for sharp corners.
offsetnumber20orthogonal: how far the line goes straight out of an element before turning, 0 or more.

The path builders bezierPath, straightPath and orthogonalPath are also exported if you want to draw lines between points yourself.

Errors ​

Options are checked when they are given, so a mistake fails at once with a message that names the option:

  • TypeError: a value of the wrong type, for example strokeWidth: '3', label: 0, or a target that is neither an element nor a selector.
  • RangeError: a value out of range, for example type: 'wavy', startSide: 'middle' or radius: -5.
  • ArclaceError: Arclace can't do what was asked: a selector matches nothing or is invalid (with the browser's error as cause), an id is taken, or the connection or the instance has been removed. It is exported, for instanceof checks.

Every message starts with arclace:. When a call throws, nothing is added, so the lines already drawn keep working. An option set to undefined uses the default, and option names Arclace doesn't know are ignored.

Released under the MIT License.