• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    CSS
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔀 A JavaScript library for connecting SVG things.

svg.connectable.js

A JavaScript library for connecting SVG things.

svg.connectable.js

CDN

The library is available on CDNJS as well. To use it, just do:

<script src="https://cdnjs.cloudflare.com/ajax/libs/svg.connectable.js/2.0.1/svg.connectable.min.js"></script>

Usage

This library depends on:

<script src="path/to/svg.js"></script>
<script src="path/to/svg.draggy.js"></script>
<script src="path/to/svg.connectable.js"></script>
<!-- Or from CDN
<script src="https://cdnjs.cloudflare.com/ajax/libs/svg.connectable.js/2.0.1/svg.connectable.min.js"></script>
-->
<div class="graph"></div>
<script>
    var svg = new SVG(document.querySelector(".graph")).size("100%", 500);
    var links = svg.group();
    var markers = svg.group();
    var nodes = svg.group();

    var g1 = nodes.group().translate(300, 200).draggy();
    g1.circle(80).fill("#C2185B");

    var g2 = nodes.group().translate(100, 200).draggy();
    g2.circle(50).fill("#E91E63");

    var g3 = nodes.group().translate(200, 400).draggy();
    g3.circle(100).fill("#FF5252");

    g1.connectable({
        container: links,
        markers: markers
    }, g2).setLineColor("#5D4037");

    g2.connectable({
        padEllipse: true
    }, g3).setLineColor("#5D4037")
</script>

This Demo in jsfiddle: https://jsfiddle.net/u8qck0h3/

Documentation

connectable(options, elmTarget)

Connects two elements. If called multiple times, the lines will be curved.

Params

  • Object options: An object containing the following fields:
  • container (SVGElement): The line elements container.
  • markers (SVGElement): The marker elements container.
  • padEllipse (Boolean): If true, the line coordinates will be placed with a padding.
  • SVGElement elmTarget: The target SVG element.

Return

computeLineCoordinates(con)

The function that computes the new coordinates. It can be overriden with a custom function.

Params

  • Connectable con: The connectable instance.

Return

  • Object An object containing the x1, x2, y1 and y2 coordinates.

update()

Updates the line coordinates.

setLineColor(color, c)

Sets the line color.

Params

  • String color: The new color.
  • Connectable c: The connectable instance.

How to contribute

Have an idea? Found a bug? See how to contribute.

License

See the LICENSE file.

More Repositories

1

url.js

📃 A lightweight JavaScript library to manipulate the page url.
CSS
245
star
2

jQuery-sidebar

🍫 A stupid simple sidebar jQuery plugin.
JavaScript
216
star
3

svg.pan-zoom.js

🐭 A JavaScript library for panning and zooming SVG things.
CSS
75
star
4

medium-editor-custom-html

❎ An extension that inserts custom HTML using a new button in the Medium Editor toolbar
HTML
74
star
5

svg.draggy.js

🐭 A JavaScript library for dragging SVG things.
CSS
65
star
6

piklor.js

🎨 A tiny JavaScript color picker library.
CSS
62
star
7

jQuery-json-editor

🇮🇹 A jQuery plugin for editing JSON data.
HTML
29
star
8

jQuery-form-serializer

🅰️ Serialize forms to JSON objects in a friendly way.
CSS
18
star
9

jQuery-prompt21

🅰️ A minimalist jQuery prompt plugin for the 21st Century.
CSS
14
star
10

csv-to-array

✌️ A small NPM library for converting CSV files to JSON arrays.
JavaScript
11
star
11

a-csv

🎃 A lightweight CSV parser.
JavaScript
6
star
12

worky

👷 An EventEmitter like interface for web workers.
CSS
5
star
13

jQuery-image-upload

👴 A jQuery plugin that adds controls to the selected jQuery elements with a simple call.
JavaScript
4
star
14

kubernetes-mysql-prestashop-pd

Shell
3
star
15

engine-terminal

🚒 The web term version for Engine.
JavaScript
2
star
16

schema

JSON-LD Schemas for structured data
JavaScript
2
star
17

materializecss-theme

🎨 A jillix theme based on the materializecss framework.
CSS
2
star
18

cayley-jsonld-io

JSON-LD based cayley driver
JavaScript
2
star
19

svg.cytoscape.js

♻️ Build cytoscape environments in SVG.
JavaScript
2
star
20

flow-browser

Flow for client side environments
JavaScript
2
star
21

modm

💼 Mongodb Object Document Mapper
JavaScript
2
star
22

ruut.js

🐏 A tiny and fast route parsing library, supporting parameters and more.
JavaScript
2
star
23

flow-api

🔆 Flow API
JavaScript
2
star
24

wrabbit

💃 Wrap scripts by providing the wrapping function.
JavaScript
1
star
25

captcha

🎓 Mono module for captcha
JavaScript
1
star
26

starter

⭐ A basic starter project
HTML
1
star
27

jQuery-image-resize

🎃 Lightweight jQuery plugin that adds resize controls to selected images.
JavaScript
1
star
28

libobject

Object utility library
JavaScript
1
star
29

engine-builder

👷 Composition parser for engine
JavaScript
1
star
30

enny

📎 Generate Engine compositions from human-readable inputs.
JavaScript
1
star