bramp / js-sequence-diagrams

Draws simple SVG sequence diagrams from textual representation of the diagram
https://bramp.github.io/js-sequence-diagrams/
BSD 2-Clause "Simplified" License
7.81k stars 1.08k forks source link

Add support for execution specifications #156

Open Andrew-Dunn opened 8 years ago

Andrew-Dunn commented 8 years ago

It would be great if support would be added for execution specifications, which are the thin grey rectangles which identify the beginning and end of an action being executed. Ideally we could support overlapping execution specifications too.

In websequencediagrams.com, the syntax used to denote execution specifications is by prepending the target actor with a + or -, so the following sequence:

Bob->+Alice: Say Hello
note right of Alice: Process salutation.
Alice->-Bob: Say Goodbye.

Would be rendered like this:

Image

I personally don't think this is a great syntax as when ending an execution you are using the - character on the other actor, which doesn't make a whole lot of sense. This also makes it impossible to do things like ending an execution on one lifeline and immediately beginning a new execution specification on the target actor, which is common with asynchronous communications.

So I'm proposing we instead prepend the + or - modifier to the lifeline/actor which is actually being modified, always, so the above example would actually be written as:

Bob->+Alice: Say Hello
note right of Alice: Process salutation.
-Alice->Bob: Say Goodbye.

Cheers!

Andrew-Dunn commented 8 years ago

I'm currently working on an implementation of this using my proposed syntax. I may do a simpler enhancement to learn the codebase before attempting it though. (probably won't)

bramp commented 8 years ago

Sounds good to me. Changing the syntax should be easy as it is covered in unit tests (which you should add to).

Andrew-Dunn commented 8 years ago

Progress so far, the following code generates the given sequence diagram:

Bob->+Alice: Say "Hello".
+Alice->-Alice: Process salutation.
-Alice->+Bob: Say "Goodbye".
note right of Bob: Reflect on life

TODO

@bramp Do you have any preferences when it comes to code style, esp with regard to line length?

Andrew-Dunn commented 8 years ago

Unit/regression tests written. All that's left is to fix this rendering bug related to self signals that both end and begin an ExecutionSpecification, as well as bringing the code up to scratch for a PR.

screen shot 2016-07-20 at 8 09 55 am
bramp commented 8 years ago

"@bramp Do you have any preferences when it comes to code style, esp with regard to line length?" no real preference, but keep it reasonable <80-120 ish.

However, please run make lint as that should catch most of the things I care about.