• Stars
    star
    7,764
  • Rank 4,824 (Top 0.1 %)
  • Language
    JavaScript
  • License
    BSD 2-Clause "Sim...
  • Created almost 12 years ago
  • Updated almost 2 years ago

Reviews

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

Repository Details

Draws simple SVG sequence diagrams from textual representation of the diagram

JS Sequence Diagrams Bower Build Status Code Climate Libraries.io License

Generates UML sequence diagrams from simple text
https://bramp.github.io/js-sequence-diagrams/

by Andrew Brampton 2012-2017

Example

We turn

Alice->Bob: Hello Bob, how are you?
Note right of Bob: Bob thinks
Bob-->Alice: I am good thanks!

into

Sample generated UML diagram

Requirements

You will need Snap.svg, Web Font Loader (if you wish to use custom fonts), underscore.js (or lodash), and optionally jQuery.

Installation

bower

Run bower install bramp/js-sequence-diagrams and include the scripts below:

<script src="{{ bower directory }}/bower-webfontloader/webfont.js" />
<script src="{{ bower directory }}/snap.svg/dist/snap.svg-min.js" />
<script src="{{ bower directory }}/underscore/underscore-min.js" />
<script src="{{ bower directory }}/js-sequence-diagrams/dist/sequence-diagram-min.js" />

also import the CSS if you plan to use the hand drawn theme:

<link href="{{ bower directory }}/js-sequence-diagrams/dist/sequence-diagram-min.css" rel="stylesheet" />

Not using bower? No problem. Just download the dependencies, and include them yourself. If you plan to use the hand draw theme, don't forget to put the two fontfiles in your css folder: /fonts/daniel/danielbd.woff and /fonts/daniel/danielbd.woff2

Usage

You can use the Diagram class like:

<div id="diagram">Diagram will be placed here</div>
<script> 
  var d = Diagram.parse("A->B: Does something");
  var options = {theme: 'simple'};
  d.drawSVG('diagram', options);
</script>

or use jQuery to do all the work:

<script src="{{ bower directory }}/jquery/dist/jquery.min.js" />
<div class="diagram">A->B: Message</div>
<script>
  var options = {theme: 'hand'};
  $(".diagram").sequenceDiagram(options);
</script>

For full examples check out the demo site.

Options

var options = {
    // Change the styling of the diagram, typically one of 'simple', 'hand'. New themes can be registered with registerTheme(...).
    theme: string,

    // CSS style to apply to the diagram's svg tag. (Only supported if using snap.svg)
    css_class: string,
};

Styling

The following CSS classes are applied to the SVG diagram when using snap.svg:

  • sequence: Applies to main SVG tag.
  • title: Applied to the title of the diagram.
  • actor: Applied to the actors.
  • signal: Applied to the signals.
  • note: Applied to all notes.

The diagram can then be customised, for example:

.signal text {
    fill: #000000;
}
.signal text:hover {
    fill: #aaaaaa
}
.note rect, .note path {
    fill: #ffff00;
}
.title rect, .title path,
.actor rect, .actor path {
    fill: #ffffff
}

Raphaël Deprecation

Version 1.x of this library used Raphaël for drawing the diagrams, however, Raphaël had some limitations, and since disappeared from the Internet. We've decided to move to Snap.svg, which is a pure SVG implementation, instead of Raphaël which in addition to SVG, also supported VML (on Internet Explorer). This support of VML made it impossible to use some newer SVG capabilities. Native SVG allows us to use CSS styling, better font support, animations and more.

To aid in the transition Version 2.x will support both Raphaël and Snap.svg (preferring Snap.svg). If you include Raphaël instead of snap.svg, it will default to using Raphaël as the rendering library. For example

<script src="{{ bower directory }}/raphael/raphael-min.js"></script>

There are also four transitional themes, 'snapSimple', 'snapHand', 'raphaelSimple', 'raphaelHand', which force the use of either Snap.svg, or Raphaël.

The plan is to drop support for Raphaël in a future release, simplifying the library, and reducing the file size.

Adding a Font

Raphael requires Cufon style fonts. Find the font you want in ttf or otf format, visit Cufon's site and process it into a javascript file. Then ensure the font is included via the HTML, or recompile after altering main.js. So far only the hand drawn font, Daniel Bold, has been included.

Build requirements

The build is managed by a Makefile, and uses various tools available from npm. Thus both make and npm are required, and can easily be installed on any Linux or Mac machine.

make

The Makefile will use npm to install all the dev dependencies, build, and test.

Testing

We use qunit for testing. It can be ran from the command line, or via a browser. The command line actually tests multiple permutations of lodash, Underscore, and with and without minification.

make test
...
Global summary:
┌───────┬───────┬────────────┬────────┬────────┬─────────┐
│ Files │ Tests │ Assertions │ Failed │ Passed │ Runtime │
├───────┼───────┼────────────┼────────┼────────┼─────────┤
│ 1     │ 13    │ 231        │ 0      │ 231    │ 250     │
└───────┴───────┴────────────┴────────┴────────┴─────────┘

or make and then open test/qunit.html in a browser. Finally a simple playground is available at test/test.html.

How to release

  • Make sure all changes checked in
  • Bump version in src/main.js and bower.json
  • make clean
  • make
  • git add -f src/main.js bower.json dist/*
  • git commit -m "Released version 2.x.x"
  • git push origin master
  • git tag -a v2.x.x -m v2.x.x
  • git push origin v2.x.x

TODO

  • Other themes

  • Automate the release process

  • Testing that checks the generated SVG is correct

  • Improve the hand drawn theme

    • "Note left of Bob: " generates a small empty box.
    • The font seems to have extra margin at the bottom.
    • The wiggly lines don't always touch.
  • Dozens of other issues on https://github.com/bramp/js-sequence-diagrams/issues

Contributors

via GitHub

Thanks

This project makes use of Jison, snap.svg, underscore.js, and the awesome Daniel font (which is free to use for any purpose).

Many thanks to Web Sequence Diagrams which greatly inspired this project, and forms the basis for the syntax.

Related

Licence (Simplified BSD License)

Copyright (c) 2012-2017, Andrew Brampton All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

More Repositories

1

ffmpeg-cli-wrapper

Java wrapper around the FFmpeg command line tool
Java
1,663
star
2

prob.js

Generate random numbers from different probability distributions.
JavaScript
112
star
3

unsafe

Assorted java classes that make use of sun.misc.Unsafe
Java
97
star
4

antlr4-grammars

Precompiled Go versions of most of the grammars on https://github.com/antlr/grammars-v4.
Go
97
star
5

libcec-daemon

A Linux daemon for connecting libcec to uinput. That is, using your TV to control your PC!
C++
64
star
6

myip

(A better) What's My IP Address web application
Go
54
star
7

archivemount

FUSE filesystem using libarchive (this is out of date copy of:
C
43
star
8

protoc-gen-php

*DEPRECATED* A PHP Protocol Buffer Generator Plugin for protoc - Please use the now official compiler https://github.com/google/protobuf/tree/master/php
C++
42
star
9

Connected-component-labelling

A javascript library for connected-component labelling (aka blob extraction)
JavaScript
21
star
10

rustdns

DNS Client in Rust
Rust
19
star
11

goredirects

A tool to help host go packages with vanity domains on GitHub
Go
17
star
12

goadvent-antlr

Examples from my goadvent blog post
Go
17
star
13

dsector

API for parsing binary files using a predefined grammar
Go
14
star
14

smart-health-card-scanner

Scan Smart Health Cards
JavaScript
14
star
15

dataflow-art

Go
12
star
16

morebeam

Additional functions useful for building Apache Beam pipelines in Go.
Go
11
star
17

node-ioctl

Simple nodejs addon to add ioctl
C++
10
star
18

objectgraph

Simple library to traverse Java object graph
Java
10
star
19

ndsfs

A FUSE application to mount Nintendo DS roms
C
9
star
20

hessian.js

Node.js support for the Hessian binary web service protocol
JavaScript
8
star
21

mysqldump2csv

Convert mysqldump files to CSVs
Go
7
star
22

funcs

Google Cloud Functions
JavaScript
7
star
23

pmtiles-dart

pmtiles decoder for dart
Dart
7
star
24

curriculum-vitae

Andrew Brampton's Curriculum Vitae
Makefile
5
star
25

p2psim

A peer-to-peer DHT simulator
Java
5
star
26

js-scan

Attempt to scan the Internet and determine what libraries everyone is using
JavaScript
4
star
27

jambox

Tool to interact with the Jawbone Jambox
C++
4
star
28

libarchive

C library and command-line tools for reading and writing tar, cpio, zip, ISO, and other archive formats
C
4
star
29

flvtool-plus-plus

flvtool++
C++
4
star
30

libphonenumber-php

PHP Bindings for libphonenumber
C++
3
star
31

snow.js

A simple snow demo (using device orientation)
JavaScript
3
star
32

jackson-datatype-commons-lang3

Simple Jackson library for some datatypes in Apache Commons Lang3
Java
3
star
33

db-patterns

Some simple DB patterns implemented onto of MySQL
Java
3
star
34

dissector

Dissects various file formats
Java
3
star
35

nodewii-talk

A talk I gave on nodewii at NodeDC Nov 2012 and later at NationJS 2012
JavaScript
2
star
36

ssltester

Tests how well a SSL service is set up, and alerts if it's below required threshold
Go
2
star
37

php5-spotify

This is a simple PHP extension that wraps some of the functionality of libspotify.
C
2
star
38

ByteTorrent

Some old code I wrote to speak BitTorrent
C++
2
star
39

us-census-tools

A collection of scripts I've written to handle census data.
PHP
2
star
40

jPsyScript

PsyScript (written in Java)
Java
2
star
41

sms-rpc

Simple Android app to explose a RESTful API to control your device, such as for sending SMS.
Java
2
star
42

threadnetperf

Threadnetperf is a highly customisable high performance multi-threaded network benchmarking tool
C
2
star
43

libmintchip

Unofficial C library for interfacing with MintChips - Unfinished, and mostly an exercise in reverse engineering a protocol
C
2
star
44

bithacks

A collection of bit twiddling hacks in dart
Dart
2
star
45

php-sdk

PHP SDK for the Facebook API
PHP
1
star
46

blog

My blog (work in progress)
HTML
1
star
47

khan-index

Index of Khan Academy
Go
1
star
48

ultimate-tic-tac-toe

Rust
1
star
49

bounce

Bouncing Ball Game (unfinished)
1
star
50

aoc

Advent Of Code
Rust
1
star
51

godot-test

Test Repo for Godot
HTML
1
star
52

nine_patch

Dart
1
star
53

solvers

Solvers for sudoku and more
Go
1
star
54

par-rs

Rust PAR File implementation
Rust
1
star
55

lusernet

LUSerNet - a peer-to-peer network that runs over a LAN.
Visual Basic
1
star
56

handy-tools

A collection of helpful cli tools written in python
Python
1
star
57

is_x86_feature_detected

Rust
1
star
58

publication

A selection of my publications (with source tex/resources/etc)
TeX
1
star
59

yii-bootstrap

A clone of the mercurial yii-bootstrap - https://bitbucket.org/Crisu83/yii-bootstrap
PHP
1
star
60

js-sudoku

Sudoku solver written in javascript which uses computer vision to extract the sudoku from a image
CSS
1
star
61

phd-thesis

Andrew Brampton's PhD Thesis
TeX
1
star
62

categories

Randomly generates categories
JavaScript
1
star
63

sms-count

Simple app to count the length of a SMS message using different encodings
CSS
1
star