Git Product home page Git Product logo

nomnoml's Introduction

nomnoml npm version Known Vulnerabilities web site

Hello, this is nomnoml, a tool for drawing UML diagrams based on a simple syntax. It tries to keep its syntax visually as close as possible to the generated UML diagram without resorting to ASCII drawings.

Created by Daniel Kallin with help from a group of contributors.

Library

The nomnoml javascript library can render diagrams on your web page. The only dependency is graphre. Install nomnoml using either npm or good old script inclusion.

SVG output in NodeJS

npm install nomnoml
var nomnoml = require('nomnoml')
var src = '[nomnoml] is -> [awesome]'
console.log(nomnoml.renderSvg(src))

In the SVG output the node name is attached to SVG shapes and <g> containers with data-name attribute. You can use this to implement interactive diagrams.

document.querySelector('svg').onclick = function (e) {
  console.log(e.target.closest('g[data-name]')?.attributes['data-name'])
}

HTML Canvas rendering target

<script src="//unpkg.com/graphre/dist/graphre.js"></script>
<script src="//unpkg.com/nomnoml/dist/nomnoml.js"></script>

<canvas id="target-canvas"></canvas>
<script>
  var canvas = document.getElementById('target-canvas')
  var source = '[nomnoml] is -> [awesome]'
  nomnoml.draw(canvas, source)
</script>

Command Line Interface

npx nomnoml exposes the SVG renderer with a command-line interface. This mode also supports the #import: <filename> directive for dividing complex diagrams into multiple files.

npx nomnoml input-file.noml

Web application

The nomnoml web application is a simple editor with a live preview. It is purely client-side and uses your browser's localStorage, so your diagram should be here the next time you visit (but no guarantees).

Example

This is how the Decorator pattern can look in nomnoml syntax:

[<frame>Decorator pattern|
  [<abstract>Component||+ operation()]
  [Client] depends --> [Component]
  [Decorator|- next: Component]
  [Decorator] decorates -- [ConcreteComponent]
  [Component] <:- [Decorator]
  [Component] <:- [ConcreteComponent]
]

Association types

-    association
->   association
<->  association
-->  dependency
<--> dependency
-:>  generalization
<:-  generalization
--:> implementation
<:-- implementation
+-   composition
+->  composition
o-   aggregation
o->  aggregation
-o)  ball and socket
o<-) ball and socket
->o  ball and socket
--   note
-/-  hidden

Classifier types

[name]
[<abstract> name]
[<instance> name]
[<reference> name]
[<note> name]
[<package> name]
[<frame> name]
[<database> name]
[<pipe> name]
[<start> name]
[<end> name]
[<state> name]
[<choice> name]
[<sync> name]
[<input> name]
[<lollipop> lollipop]
[<sender> name]
[<socket> socket]
[<receiver> name]
[<transceiver> name]
[<actor> name]
[<usecase> name]
[<label> name]
[<hidden> name]
[<table> name| a | 5 || b | 7]

Comments

Comments are supported at the start of a line.

//[commented]
[not //commented]

Id attribute

Two distinct nodes can have the same display name with the id attribute.

[<actor id=a>User]
[<actor id=b>User]
[a] -- [b]

Directives

#import: my-common-styles.nomnoml
#arrowSize: 1
#bendSize: 0.3
#direction: down | right
#gutter: 5
#edgeMargin: 0
#gravity: 1
#edges: hard | rounded
#background: transparent
#fill: #eee8d5; #fdf6e3
#fillArrows: false
#font: Calibri
#fontSize: 12
#leading: 1.35
#lineWidth: 3
#padding: 8
#spacing: 40
#stroke: #33322E
#title: filename
#zoom: 1
#acyclicer: greedy
#ranker: network-simplex | tight-tree | longest-path

Custom classifier styles

A directive that starts with "." define a classifier style. The style is written as a space separated list of modifiers and key/value pairs.

#.box: fill=#8f8 dashed
#.blob: visual=ellipse title=bold
[<box> GreenBox]
[<blob> HideousBlob]

Modifiers

dashed
empty

Key/value pairs

fill=(any css color)

stroke=(any css color)

align=center
align=left

direction=right
direction=down

visual=actor
visual=class
visual=database
visual=ellipse
visual=end
visual=frame
visual=hidden
visual=input
visual=none
visual=note
visual=package
visual=pipe
visual=receiver
visual=rhomb
visual=roundrect
visual=sender
visual=start
visual=table
visual=transceiver

Style title and text body with a comma separated list of text modifiers

title=left,italic,bold
body=center,italic,bold

Text modifiers

bold
center
italic
left
underline

Contributing

If you want to contribute to the project, more info is available in CONTRIBUTING.md.

nomnoml's People

Contributors

0xflotus avatar a-bronx avatar andrew-sk avatar ashsearle avatar dcalsky avatar dependabot[bot] avatar deviantfero avatar korroz avatar petetnt avatar prantlf avatar rikharink avatar ronkok avatar skanaar avatar stefanpenner avatar stolksdorf avatar strobox avatar ttwno avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nomnoml's Issues

Use case stereotype support?

Hi,
Is it possible to put a label on relationships? for example, there are <<include>> and <<extend>> available in use case diagrams, for dependency relationship.
Stereotypes explained here.

Thanks for great your library. :)

Consider adding tags for the repo.

Hi~
Adding tags for repo could specify points in history and mark release points.
It's helpful for user to know the version and status of repository, and would enable wider distribution of the library, for example on CDNJS
Would you please consider on using tags?

Thanks for your great work!!
Piicksarn

How to arrow across scope

I want to make arrows across package, for example:

[<package> A|
    [Cat] -> [B.Dog]
]
[<package> B|
    [Dog]
]

Is there any way to do this?

Great project BTW!

Ho to use directives?

Hi!
In the language reference you talk about directives, but I can't figure out how to use them and there is no example. How do I put them in my code?

Thanks for a very practical tool!

Cannot escape characters

There is no way (that I know of) to escape special characters, it's not possible for instance to do something like [MyClass|ArrayOfNumbers:int[]]

Anyway great project! Keep going! ๐Ÿ‘

[enhancement] Add shortcut syntax from Turtle

Hi, and thanks again for this amazing tool

I've discovered a specific syntax to describe rdf files, it's called Turtle.

In turtle, there is three element who can be implemented in nomnoml to avoid redundancy

  1. Dot .
    Actually this is the same function as semicolon ; and backspace.
    It allow to write multiple different element on a single line.
  2. Semicolon ;
    In turtle, semicolon means "this is a new element with the same subject than before".
    In nomnoml it can replace sentences like:

[a]-[b]
[a]--[c]
[a]->[d]

by:

[a]-[b];--[c];->[d]

  1. Comma ,
    In turtle, comma means "this is a new element with the same subject and the same predicate (link) than before"
    In nomnoml it can replace sentences like:

[foo]-[bar]
[foo]-[baz]
[foo]-[fighter]
[foo]-[bang]

by:

[foo]-[bar],[baz],[fighter],[bang]

It lacks one element, if i want to link the last object with a new one:
in that case:

[a]-[b]
[b]-[c]
[c]-[d]

It can looks like:

[a]-[b]-[c]-[d]

I have only one question,
Is it parsable?

Regards,
Buridan

Layers ~= Virtual (?) packages

Hello

The tool as it is is really nice!

I'm using it to draw the internal of grails projets. I'm interested in showing the different layers, something like this :

http://www.nomnoml.com/#view/[Controler2]%20-%3E%20[HighLevelService1]%0A[Controler2]%20-%3E%20[HighLevelService2]%0A%0A%0A[Controler1]%20-%3E%20[HighLevelService2]%0A[Controler1]%20-%3E%20[HighLevelService3]%0A%0A[HighLevelService2]%20-%3E%20[DelegateService1]%0A[HighLevelService2]%20-%3E%20[DelegateService2]%0A[DelegateService1]%20-%3E%20[DelegateService2]%0A%0A[HighLevelService3]%20-%3E%20[DelegateService2]%0A%0A[HighLevelService3]%20-%3E%20[SubService1]%0A[HighLevelService2]%20-%3E%20[SubService1]%0A%0A[SubService1]--%3E[External%20WS]%0A

As you can see the layers would be controllers, high level services, delegate services, and subservices. Is there any way to group layers, for example by placing a dotted rectangle around them, with a label ?

Not a solution: use the syntaxe [vehicles|[Car]] . This is not possible because I want to be able to draw relations between items across packages (for example a specific controler to a specific high level service)

Cheers

Modelize Nomnoml with itself

Hi,

Thank you for this awesome program, i use it everytime i can.

I wonder if nomnoml couldn't be Modelized with itself?

This is not to challenge you (just a bit ;), but i wonder if that wouldn't make the codebase more maintainable, new features better expressed and Nomnoml more comprehensive?

Best Regards,
Buridan

SVG Rendering

Nomnoml looks like a very promising replacement for Blockdiag for many use cases, but the rendering of SVG appears faulty. A simple example:

#arrowSize: 0.5
#bendSize: 0.3
#direction: down
#gutter: 5
#edgeMargin: 0
#edges: hard
#fill: #fff; #ccc
#fillArrows: false
#fontSize: 16
#leading: 1.25
#lineWidth: 2
#padding: 10
#spacing: 40
#stroke: #33322E
#zoom: 1

[ABCDE]->[BCDEF]
[BCDEF]->[CDEFG]
[BCDEF]->[DEFGH]

It renders as the figure on the left with standalone.svg.usecase.html and as on the right with standalone.usecase.html:

image

The issue seemingly is with #fontSize: 16.

Allow the square brackets in texts

When writing explanations in notes:

[<note>...]

it would be useful to be able to use the control characters [ and ] too.

Would it be possible to introduce escaping by backslash, for example? Source like this:

[<note>An array \[1, 2\] example]

would render the following text:

An array [1, 2] example

[enhancement] Add dashed frame

hi,
All is in the title. That would be nice to descibe some optionnal groups.
No need, to rebuild some specific behavior, that's just a frame with dashed border.

thx & respect for what you've done

Directives with standalone library

Hi, thank you for this work.

How should I pass directives in the standalone library?

This worked but I don't think is the right way.
var source = '#fill: green \n #direction: right \n [nomnoml]is->[awesome]';

Multiple associations at once

Is there a way to write something like

[Animal]<:-[Cat],[Dog],[Pig]

instead of

[Animal]<:-[Cat]
[Animal]<:-[Dog]
[Animal]<:-[Pig]

It would be a very practical feature.

Confusion when using save button on edited shareable link diagram

Hi Skanaar,

thank you for starting this great project. I really like using it.
While using nomnoml in the team, one function lead to some confusion. It is related to the 'save' button functionality on a shareable link diagram (the one at the top middle).

The one interpretation is, that no changes are saved to local storage after clicking on ok.
And the other, in my team, more common interpretation, was that changes 'by default' are not saved automatically to local storage, but will be saved when clicking on the save button.
Part of the confusion is probably related to the confirm message dialog, which reads as
"Do you want to overwrite the diagram in localStorage with the currently viewed diagram?".
So, most of us thought that by clicking save the modified document would then be saved to local storage. Instead, the local storage was set to the content of the shareable link.

I just wanted to give you some feedback, from what we experienced by using nomnoml.

In my fork, I modified the save button to save the edited content to local storage. But if you want to keep functionality as is, perhaps you can modify the confirm message and make clear, that possible changes will be lost.

Thanks

Better sample

First of all, thank you for this awesome tool! I just found it but immediately fell in love with it.

I think it would be beneficial to create a better sample / welcome text. This tool is really powerful and highly customizable, but the current sample is a bit plain. It does not show the advanced classifier types, nor the custom styling capabilities. Creating a more eye-catching sample would definitely gain more users (for when people judge by a split second look at the sample. They usually think the sample contains everything the tool is capable of.)

What do you think? This would be a very easy to do but beneficial change to make (in the long run).

Manage abstract and class methods

I just discovered your tool, awesome work ! It helps me a lot ๐Ÿ‘
Something that is missing to me, that's just a very little point, but when I write

[Class||
  <abstract> + myMethod()
]

I'm actually expecting that the method is going to be written in italic, but that's not the case. In fact, the parser just does not take in account the type of the method. The same would be great for class methods and class attributes, but I don't know if a <class> classifier would be theright thing to do.

I'll be glad to help, but actually I'm a bit lost in those files, I'll probably take a deeper look at the code, so I can contribute to the project ๐Ÿ˜ƒ

Some way to include files

Thanks for the awesome work! This tool is by far the best!

I don't know how to formulate this issue properly, but let's try.

I feel that it would be extremely beneficial to be able to have the diagram code organized in multiple files and being able to include (or import) them, e.g. #include "some_class.noml"

I understand this is a long reaching issue, I guess it depends on #29 or #26

What do you think of it? To me that is the only thing that really would make creating big diagrams much easier.

UML Messages

Hi! Firstly, thank you for a really great project, it is already proving to be a lot more useful to me than many mature graphing packages out there. I really like the simple syntax that reminds me of markdown and gives the possibility to check differences from version to version. Keep up the good work!

A question about UML messaging charts - I saw from sequence.nomnoml something that reminds me of UML message flows, is this a work in progress and is that something I can expect to be added to nomnoml? :) It would be really great if message create/destroy async/sync flows could be beautifully mapped.

Don't stop here! ๐Ÿ‘

Standalone library version of nomnoml

It would be handy if nomnoml could come in a standalone javascript version for embedding on pages where you would want to render nomnoml diagrams.

For example something like this:

<script src="nomnoml.js"></script>
<script id="noml" type="text/plain">
    [nomnoml]is->[awesome]
</script>
<canvas id="target-canvas"></canvas>
<script>
    var canvas = document.getElementById('target-canvas');
    var noml = document.getElementById('noml').innerHTML;
    nomnoml.draw(canvas, noml);
</script>

On a sidenote, I've started this work and have a working build of a standalone nomnoml.js already.

Large Diagrams

For large diagrams, top/bottom left/right get's cut off.

If you add these two CSS styles, it should do the trick:

#wrap {
     overflow: auto;
}

#canvas {
    top: 0;
}

Alternatively, you could make the #canvas element draggable and resizable using jQuery (or any other preferred method) for better visibility and control over the output of the diagram.

Otherwise, great job on the tool!

test/requirejs.usecase.html error: Cannot read property 'Digraph' of undefined

Following the instructions in CONTRIBUTING.md, I cloned master, ran npm install, and began loading HTML files in "Chromium 58.0.3029.81 (Developer Build) Built on Ubuntu , running on Ubuntu 16.04 (64-bit)." The exact revision of nomnoml I tested is 9955b94.

When loading one of the HTML files described in CONTRIBUTING.md called test/requirejs.usecase.html I got the following error:

Uncaught TypeError: Cannot read property 'Digraph' of undefined
    at layoutCompartment (nomnoml.js:1282)
    at Kn (lodash.min.js:9)
    at Function.<anonymous> (lodash.min.js:29)
    at layoutClassifier (nomnoml.js:1321)
    at Kn (lodash.min.js:9)
    at Function.<anonymous> (lodash.min.js:29)
    at layoutCompartment (nomnoml.js:1280)
    at Object.nomnoml.layout (nomnoml.js:1328)
    at parseAndRender (nomnoml.js:1580)
    at Object.nomnoml.draw (nomnoml.js:1588)

NPM version

Any chance you could push the latest version to npm please?

The one that is currently there is 0.0.4.

Cheers

Allow usage outside of the browser - in NodeJS with node-canvas

Thanks a lot for publishing this project! I believe that it has more potential than powering the web page editor.

I'd like to use nomnoml for generating diagrams in developer documentation. Instead of checking in binary images together with nomnoml sources, just the nomnoml sources would be maintained and the images would be generated when the documentation output is generated. It would mean calling nomnoml from a command-line tool.

When not running in the browser, the tool would have to either start the browser in the background and communicate with it, or integrate a headless browser like PhantomJS, or use an alternative canvas implementation like node-canvas. The former two possibilities would be tricky to make for a quickly executable tool. The latter would need a reliable canvas implementation. Let's have a look at the latter:

// Writes a simple PNG diagram to the standard output
var Canvas = require('canvas'),
    nomnoml = require('nomnoml'),
    canvas = new Canvas(640, 480);
nomnoml.draw(canvas, '[nomnoml]is->[awesome]');
canvas.pngStream().pipe(process.stdout);

Luckily, nomnoml does not use other browser features than the canvas. What prevents nomnoml from being used like this?

  • Access to the global window object
  • Embedding the dagre module. which works only in the browser

I tried to make the necessary changes in my fork. Would you be interested in making nomnoml usable from NodeJS?

Save/load different nomnoml's

I find myself opening multiple browsers (= different localstorage) to work on multiple different, but related, nomnoml's. It would be great if I could open multiple nomnoml tabs and edit them in parallell, in the same browser.

Abillity to give different fill colors

Hi,

First of all, thanks for an awesome tool.

I noticed, that (sadly) when using the #fill directive, one can only color the whole diagram in the same color.

It would be great, if I could switch up those directives, to color code parts of the diagram. Maybe by putting them inside the declared object (like yuml does) or by simply being able to switch them out.

So:

#fill:red
[A]
[B]

#fill:blue
[C]

[A]->[C]

Would create a diagram, where 'A' and 'B' are filled red, but 'C' is filled blue.

Thanks.

is it using react

i want to learn this awesom tool..is it build in react..if its not .then in which laibrary,framework is it build.??

Command line renderer

Would it be possible to get a node command line interface for rendering nomnoml files?

It would be great to be able to:

npm install nomnoml
nomnoml myDiagram.nomnoml -o docs/myDiagram.png

...or similar.

My use case is that I'd like to be able to keep plain-text versions of diagrams under version control, and render these to image files as part of an npm build process to generate documentation. I'd love to use nomnoml for this purpose, as the rendering and syntax are quite nice compared to the few alternatives I've seen.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.