Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added version to package.json and circled actors #145

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.PHONY : all test dependencies clean veryclean lint
.PHONY : all test dependencies clean veryclean lint

NODE_MODULES := node_modules/.bin
BOWER_COMPONENTS := bower_components
Expand Down
5 changes: 3 additions & 2 deletions build/sequence-diagram-min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/sequence-diagram-min.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "js-sequence-diagrams",
"version": "1.0.6",
"repository": {
"type": "git",
"url": "https://github.com/bramp/js-sequence-diagrams.git"
Expand Down
6 changes: 4 additions & 2 deletions src/diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
this.index = index;
};

Diagram.Signal = function(actorA, signaltype, actorB, message) {
Diagram.Signal = function(actorA, signaltype, actorB, message, published, web) {
this.type = "Signal";
this.actorA = actorA;
this.actorA.published = !!published;
this.actorA.web = !!web;
this.actorB = actorB;
this.linetype = signaltype & 3;
this.arrowtype = (signaltype >> 2) & 3;
Expand Down Expand Up @@ -89,7 +91,7 @@

Diagram.unescape = function(s) {
// Turn "\\n" into "\n"
return s.trim().replace(/\\n/gm, "\n");
return s.trim().replace(/^"(.*)"$/m, "$1").replace(/\\n/gm, "\n");
};

Diagram.LINETYPE = {
Expand Down
6 changes: 3 additions & 3 deletions src/grammar.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* http://bramp.github.io/js-sequence-diagrams/
* (c) 2012-2013 Andrew Brampton (bramp.net)
* Simplified BSD license.
*
*
* EBNF version of the grammar for diagraming purposes only
* Paste this into http://www.bottlecaps.de/rr/ui to generate the diagram
* Paste this into http://www.bottlecaps.de/rr/ui to generate the diagram
*/
document ::= statement*

Expand All @@ -15,7 +15,7 @@ statement ::=
( 'left of' | 'right of') actor
| 'over' (actor | actor ',' actor)
) ':' message
| actor ( '-' | '--' ) ( '>' | '>>' )? actor ':' message
| ('o-')? actor ( '-' | '--' ) ( '>' | '>>' )? actor ':' message
)

/*
Expand Down
10 changes: 7 additions & 3 deletions src/grammar.jison
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
"note" return 'note';
"title" return 'title';
"," return ',';
[^\->:,\r\n]+ return 'ACTOR';
"<>" return 'PI';
"()" return 'PW';
[^\->\:()<,\r\n"]+ return 'ACTOR';
\"[^"]+\" return 'ACTOR';
"--" return 'DOTLINE';
"-" return 'LINE';
">>" return 'OPENARROW';
Expand Down Expand Up @@ -75,8 +78,9 @@ placement
;

signal
: actor signaltype actor message
{ $$ = new Diagram.Signal($1, $2, $3, $4); }
: PI actor signaltype actor message { $$ = new Diagram.Signal($2, $3, $4, $5, $1); }
| PW actor signaltype actor message { $$ = new Diagram.Signal($2, $3, $4, $5, null, $1); }
| actor signaltype actor message { $$ = new Diagram.Signal($1, $2, $3, $4); }
;

actor
Expand Down
75 changes: 74 additions & 1 deletion src/sequence-diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@
return bb;
};

Raphael.fn.handOval = function(x, y, w, h){
var r_x = w/2;
var r_y = h/2;
var start_x = x + r_x;
var start_y = y + r_y;
var ellipse = [["M", (start_x - r_x), (start_y)], ["a", r_x, r_y ,0, 1,1, 0,0.1 ],"z"];
return this.path(ellipse).attr(RECT);
};

/**
* Draws a wobbly (hand drawn) rect
*/
Raphael.fn.handRhombus = function (x, y, w, h) {
var w2 = w/2;
var h2 = h/2;
return this.path("M" + (x+w2) + "," + y +
this.wobble( x+w2, y, x + w, y+h2) +
this.wobble(x + w, y+h2, x+w2, y+h) +
this.wobble(x+h2, y+h, x, y+h2) +
this.wobble(x, y+h2, x+w2, y))
.attr(RECT);
};

/**
* Draws a wobbly (hand drawn) rect
*/
Expand Down Expand Up @@ -210,6 +233,13 @@
return this._paper.line(x1, y1, x2, y2);
},

draw_oval : function(x, y, w, h){
return this._paper.ellipse(x, y, w, h);
},
draw_rhombus: function(x, y, w, h){
var xStep = w/2, yStep=h/2;
return this._paper.path("M "+x+" "+(y+yStep)+" l"+xStep+" -"+yStep+" l"+xStep+" "+yStep+" l-"+xStep+" "+yStep+" l-"+xStep+" -"+yStep);
},
draw_rect : function(x, y, w, h) {
return this._paper.rect(x, y, w, h);
},
Expand Down Expand Up @@ -413,7 +443,12 @@
draw_actor : function (actor, offsetY, height) {
actor.y = offsetY;
actor.height = height;
this.draw_text_box(actor, actor.name, ACTOR_MARGIN, ACTOR_PADDING, this._font);
if( actor.published )
this.draw_text_rhombus(actor, actor.name, ACTOR_MARGIN, ACTOR_PADDING, this._font);
else if( actor.web )
this.draw_text_oval(actor, actor.name, ACTOR_MARGIN, ACTOR_PADDING, this._font);
else
this.draw_text_box(actor, actor.name, ACTOR_MARGIN, ACTOR_PADDING, this._font);
},

draw_signals : function (offsetY) {
Expand Down Expand Up @@ -541,6 +576,38 @@
t.toFront();
},

draw_text_oval: function (box, text, margin, padding, font) {
var x = box.x + margin;
var y = box.y + margin;
var w = box.width - 2 * margin;
var h = box.height - 2 * margin;

// Draw inner box
var rect = this.draw_oval(x, y, w, h);
rect.attr(LINE);

// Draw text (in the center)
x = getCenterX(box);
y = getCenterY(box);

this.draw_text(x, y, text, font);
},
draw_text_rhombus: function (box, text, margin, padding, font) {
var x = box.x;
var y = box.y;
var w = box.width;
var h = box.height;

// Draw inner box
var rect = this.draw_rhombus(x, y, w, h);
rect.attr(LINE);

// Draw text (in the center)
x = getCenterX(box);
y = getCenterY(box);

this.draw_text(x, y, text, font);
},
draw_text_box : function (box, text, margin, padding, font) {
var x = box.x + margin;
var y = box.y + margin;
Expand Down Expand Up @@ -613,6 +680,12 @@
return this._paper.handLine(x1, y1, x2, y2);
},

draw_oval : function(x, y, w, h) {
return this._paper.handOval(x, y, w, h);
},
draw_rhombus : function(x, y, w, h) {
return this._paper.handRhombus(x, y, w, h);
},
draw_rect : function(x, y, w, h) {
return this._paper.handRect(x, y, w, h);
}
Expand Down
24 changes: 24 additions & 0 deletions test/grammar-tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
function assertInterfaceActor(d, hasInterface){
equal(d.actors.length, 2, "Correct actors count");
var a = d.actors[0];
equal(a.published, hasInterface, "Actors property");
}
function assertWebActor(d, hasWeb){
equal(d.actors.length, 2, "Correct actors count");
var a = d.actors[0];
equal(a.web, hasWeb, "Actors property");
}
function assertSingleActor(d, alias, name) {

name = name || alias;
Expand Down Expand Up @@ -91,6 +101,14 @@ test("Regex Tests", function() {
});
*/

test( "Actors with rhombus", function() {
assertWebActor(Diagram.parse("()A->B: Message"), true);
});

test( "Actors with circle", function() {
assertInterfaceActor(Diagram.parse("<>A->B: Message"), true);
});

test( "Solid Arrow", function() {
var d = Diagram.parse("A->B: Message");
assertSingleArrow(d, ARROWTYPE.FILLED, LINETYPE.SOLID);
Expand Down Expand Up @@ -181,6 +199,12 @@ test( "Newlines", function() {
assertSingleActor(Diagram.parse("Participant A\r\nNote left of A: Hello"), "A");
});

test( "Quoted names", function() {
assertSingleArrow(Diagram.parse("\"->:\"->B: M"), ARROWTYPE.FILLED, LINETYPE.SOLID, "->:", "B", "M");
assertSingleArrow(Diagram.parse("A->\"->:\": M"), ARROWTYPE.FILLED, LINETYPE.SOLID, "A", "->:", "M");
assertSingleActor(Diagram.parse("Participant \"->:\""), "->:");
});

test( "API", function() {
// Public API
ok(typeof Diagram.parse == "function");
Expand Down