Install nomnoml
masterYou can install nomnoml via npm for use in NodeJS environments or include it via script tags for web applications.
npm install nomnomlrepository·master·Indexed 25 days ago
https://github.com/skanaar/nomnomlA UML renderer that generates diagrams from text. It provides a JavaScript library for web rendering (Canvas/SVG), a NodeJS API for SVG generation via nomnoml.renderSvg(src), and a CLI for automated workflows. The tool supports a wide range of association types, classifier types, and global diagram directives for styling and layout configuration.
You can install nomnoml via npm for use in NodeJS environments or include it via script tags for web applications.
npm install nomnomlTo render a diagram directly onto an HTML <canvas> element, ensure graphre and nomnoml are loaded, then use nomnoml.draw(canvas, source).
<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>Use nomnoml.renderSvg(src) to convert a nomnoml syntax string into an SVG string. The resulting SVG includes data-name attributes on <g> containers, allowing you to identify nodes during interaction.
var nomnoml = require('nomnoml')
var src = '[nomnoml] is -> [awesome]'
console.log(nomnoml.renderSvg(src))The Config interface defines the global styling and layout parameters for a nomnoml diagram. Key properties include:
padding: Number for diagram padding.stroke: Default stroke color.font: Default font family.fontSize: Default font size.lineWidth: Default line width.styles: A dictionary of Style objects keyed by name.fill: An array of colors for node fills.background: Background color.edges: Edge color.direction: Layout direction, either 'TB' (Top-to-Bottom) or 'LR' (Left-to-Right).gravity: Layout gravity.spacing: Node spacing.acyclicer: Set to 'greedy' to enable the acyclic layout algorithm.ranker: A Ranker type for layout ranking.Define custom styles for specific classifiers using a directive starting with .. A style consists of a space-separated list of modifiers and key/value pairs.
dashedemptyfill=(css color)stroke=(css color)align=(center|left)direction=(right|down)visual=(actor|class|database|ellipse|end|frame|hidden|input|none|note|package|pipe|receiver|rhomb|roundrect|sender|start|table|transceiver)Use a comma-separated list for title and body modifiers:
title=left,italic,boldbody=center,italic,boldText modifiers: bold, center, italic, left, underline
Example:
#.box: fill=#8f8 dashed
[<box> GreenBox]#.box: fill=#8f8 dashed
#.blob: visual=ellipse title=bold
[<box> GreenBox]
[<blob> HideousBlob]Specify node types using the [<type> name] syntax. Common types include:
[name] (standard)[<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> name][<sender> name][<socket> name][<receiver> name][<transceiver> name][<actor> name][<usecase> name][<label> name][<hidden> name][<table> name| a | 5 || b | 7] (table with columns/rows)[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> name]
[<receiver> name]
[<transceiver> name]
[<actor> name]
[<usecase> name]
[<label> name]
[<hidden> name]
[<table> name| a | 5 || b | 7]Use // at the start of a line to add comments.
Use the id attribute to distinguish between nodes that share the same display name.
Example:
[<actor id=a>User]
[<actor id=b>User]
[a] -- [b]//[commented]
[not //commented]
[<actor id=a>User]
[<actor id=b>User]
[a] -- [b]Directives starting with # control global diagram properties. Available directives include:
#import: <filename>: Import external files#arrowSize: <number>#bendSize: <number>#direction: down | right#gutter: <number>#edgeMargin: <number>#gravity: <number>#edges: hard | rounded#background: <css color>#fill: <css color>#fillArrows: <boolean>#font: <font name>#fontSize: <number>#leading: <number>#lineWidth: <number>#padding: <number>#spacing: <number>#stroke: <css color>#title: <string>#zoom: <number>#acyclicer: greedy#ranker: network-simplex | tight-tree | longest-path#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-pathDefine relationships between nodes using the following association types:
association: -, ->, <->dependency: -->, <-->generalization: -:>, <:-implementation: --:>, <:--composition: +-, +->aggregation: o-, o->ball and socket: -o), o<-), ->onote: --hidden: -/-- 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
-/- hiddenThe npx nomnoml command provides a CLI to render SVG files from .noml input files. This mode supports the #import: <filename> directive for modularizing diagrams.
npx nomnoml input-file.nomlThe GraphicsSvg instance provides several methods for drawing standard geometric shapes:
circle(p: Vector, r: number): Draws a circle at position p with radius r.ellipse(center: Vector, w: number, h: number, [start: number], [stop: number]): Draws an ellipse. If start or stop are provided, it draws an arc.arc(cx: number, cy: number, r: number): Draws a circular arc.roundRect(x: number, y: number, width: number, height: number, r: number): Draws a rectangle with rounded corners.rect(x: number, y: number, width: number, height: number): Draws a standard rectangle.line(p1: Vector, p2: Vector): (Note: While not explicitly listed in the return object's visible methods in this snippet, standard graphics implementations usually include this; however, based strictly on this file, use beginPath and lineTo for lines).vector.ts module provides utility functions for common 2D vector operations including addition, subtraction, scaling, and distance calculation.