0.3.2 • Published 1 year ago

perfect-wires v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Functions

getWire - for wires between points getBoxToBoxWire - for wires between boxes

Installation

npm i perfect-wires

or

yarn add perfect-wires

Usage

The functions in this library return path data for an SVG path that you can use to draw a wire. It only provides the data for the path.

Open in StackBlitz

getWire()

Returns path data for use in and SVG <path> object

Syntax

getWire(sx, sy, ex, ey)

Parameters

ArgumentTypeDescription
sxnumberX-coordinate of the starting point.
synumberY-coordinate of the starting point.
exnumberX-coordinate of the end point.
eynumberY-coordinate of the end point.

Returns

SVG Path data

//Example
const pathData = getWire(400, 400, 500, 500);
console.log(pathData);

///Returns
'M400,400 L400,450 a 50,50 90 0 0 50,50 L500,500'

getBoxToBoxWire()

Returns path data for use in and SVG <path> object

Syntax

getBoxToBoxWire(sBox, eBox, options )

Parameters

ArgumentTypeDescription
sBoxnumberX-coordinate of the starting point.
eBoxnumberY-coordinate of the starting point.
optionsWireOptionsOptional configuration for wiring

WireOptions

OptionTypeDefaultDescription
deadZonenumber0Amount of space (padding) to use before creating a straight line between boxes. Useful when using boxes with rounded corners.

Returns

SVG Path data

//Example
const box1: Box = {
    x: 300,
    y: 350,
    h: 100,
    w: 200
  };
  const box2: Box = {
    x: 550,
    y: 500,
    h: 100,
    w: 150
  };

const pathData = getBoxToBoxWire(box1, box2, {deadZone: 5});
console.log(pathData);

///Returns
'M500,400 L575,400 a 50,50 90 0 1 50,50 L625,500'

Contributing

This library is still a work in progress. Currently not accepting contributions, but feel free to create an issue.

Author

@nateClicks