Nodus Draw: File format

This page is for people writing software (or scripts) that make Nodus Draw drawings and symbol libraries: what a Nodus file holds, and what Nodus reads from it. You don't need it to use Nodus Draw.

A Nodus drawing is an SVG file, so any SVG viewer shows it. Nodus adds attributes and elements of its own, in its own XML namespace, that other programs ignore. They hold what plain SVG cannot say: pages, connectors that stay attached, text that stays editable, anchor points, arrowheads by name.

Any SVG opens in Nodus, so the simplest generated file is plain SVG. The Nodus attributes are what make a generated file open as if it had been drawn in Nodus: connectors attached to their boxes, text in shapes, several pages, symbols with their terminals.

The rules

  • XML: an SVG 1.1 file in UTF-8, with the root element <svg> in the SVG namespace, http://www.w3.org/2000/svg.
  • Nodus's namespace is urn:nodus-draw:1, by convention with the prefix nodus: (xmlns:nodus="urn:nodus-draw:1"). Its attributes go on ordinary SVG elements; its few elements (nodus:document, nodus:guideline, nodus:anchor) are ignored by other programs.
  • Inkscape's namespaces are used for layers, names and locking, as Inkscape uses them: xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" and xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd".
  • Units: one SVG user unit is one millimetre. Coordinates are measured from the top-left corner of the page, with y downwards, as in SVG.
  • Numbers are plain decimals (12.5, -3), separated by spaces.
  • Colours are #rrggbb. On reading, Nodus also accepts #rgb, rgb(…), the CSS colour names, none and transparent; a colour with partial transparency is read as the colour itself.
  • IDs: every object, layer and page has an id, unique in the file. Nodus keeps the IDs of its own files, as connectors refer to the objects they are attached to by ID. If an ID appears twice, the second object gets a new one, and anything referring to it is lost.
  • What is missing takes its default, and attributes Nodus does not know are ignored.
  • Order: objects are drawn in the order of the file, the first at the back, as in SVG.

Nodus's own files, and other SVG files

Nodus reads a file as its own when the root <svg> has at least one child <g nodus:role="page">. Then the file's pages, layers, IDs and Nodus attributes are read exactly, as described below.

Any other SVG file is read as one page:

  • its size comes from the root's width, height and viewBox;
  • each Inkscape layer (<g inkscape:groupmode="layer">) becomes a layer, and anything outside one goes on a layer of its own;
  • shapes, paths, groups, text and embedded images are read;
  • Nodus attributes on its elements are still read, so a plain SVG drawing can have, say, a connector or a shape's anchor points.

Writing Nodus's own format is recommended for generated drawings: what you write is what opens.

An example drawing

Two boxes with text in them, joined by a connector with an arrowhead, and a title, on one A5 page:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:nodus="urn:nodus-draw:1"
     xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
     xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
     width="210mm" height="148mm" viewBox="0 0 210 148" version="1.1">
  <metadata>
    <nodus:document version="1">{"settings":{"grid":{"spacing":5}}}</nodus:document>
  </metadata>
  <g id="page-1" nodus:role="page" inkscape:groupmode="layer" inkscape:label="Page 1"
     nodus:auto-name="true" nodus:width="210" nodus:height="148">
    <g id="layer-1" inkscape:groupmode="layer" inkscape:label="Layer 1">
      <rect id="start" x="20" y="40" width="50" height="25" rx="3"
            fill="#e8f0ff" stroke="#000000" stroke-width="0.353"/>
      <text nodus:in-shape="start" nodus:shape="text" nodus:align="centre" nodus:valign="middle"
            font-family="Noto Sans" font-size="3.5" text-anchor="middle" fill="#000000"><tspan x="45" y="53.7">Start</tspan></text>
      <rect id="finish" x="100" y="40" width="50" height="25" rx="3"
            fill="#e8f0ff" stroke="#000000" stroke-width="0.353"/>
      <text nodus:in-shape="finish" nodus:shape="text" nodus:align="centre" nodus:valign="middle"
            font-family="Noto Sans" font-size="3.5" text-anchor="middle" fill="#000000"><tspan x="125" y="53.7">Finish</tspan></text>
      <path id="link" d="M 70 52.5 L 100 52.5" fill="none" stroke="#000000" stroke-width="0.353"
            nodus:shape="connector" nodus:routing="straight"
            nodus:start="70 52.5" nodus:start-object="start" nodus:start-anchor="right"
            nodus:end="100 52.5" nodus:end-object="finish" nodus:end-anchor="left"
            nodus:end-arrow="triangle"/>
      <text id="title" nodus:shape="text" nodus:x="20" nodus:y="25" nodus:align="left"
            font-family="Noto Sans" font-size="6" font-weight="bold" fill="#000000"><tspan x="20" y="25">A two-step process</tspan></text>
    </g>
  </g>
</svg>

Opened in Nodus, the boxes can be moved and the connector follows them, the text stays in its box, and the text tool edits all three texts.

The document

The root element

Attribute Value
width, height The first page's size, with units: 210mm, 148mm
viewBox 0 0 <width> <height> of the first page, in millimetres
xmlns, xmlns:nodus, xmlns:inkscape, xmlns:sodipodi The namespaces above (and xmlns:xlink if you use xlink:href)

Nodus takes the pages' sizes from the pages themselves; width, height and viewBox are for other programs, which show the first page.

Document settings (optional)

A <metadata> element may hold one <nodus:document version="1"> whose text is a JSON object. Everything in it is optional; leave it out for Nodus's defaults.

JSON Meaning Default
settings.grid.spacing The grid's spacing (mm) 5
settings.nudge How far the arrow keys move objects (mm) 0.1
settings.duplicateOffset How far Ctrl+D's copy is from the original (mm, {"x":5,"y":-5}: y down) {"x":5,"y":-5}
settings.connectorLabels Where new connector labels go: "start" or "middle" "start"
settings.view.showGrid Whether the grid is shown; with settings.view.snap, what snaps (both or neither; see below) as Tools › Options
settings.view.activeLayer The ID of the layer that is active when the drawing opens the first page's top layer
defaultStyle The outline and fill new objects get: Nodus's own JSON form, as Nodus writes it thin black outline, no fill
defaultText New text's font and layout (see below). All of it, or none Tools › Options' text defaults

For example, settings.view with what snaps:

{
  "showGrid": true,
  "snap": { "grid": true, "objects": true, "page": false, "guidelines": true }
}

and defaultText (the font's size in millimetres; align is for artistic text, frameAlign and verticalAlign for paragraph text):

{
  "font": { "family": "Noto Sans Condensed", "size": 3.528, "bold": false, "italic": false },
  "align": "left",
  "frameAlign": "left",
  "verticalAlign": "top",
  "lineSpacing": 1.2,
  "colour": "#000000"
}

Damaged JSON is ignored; the drawing itself is still read.

Pages

Each page is a <g> directly inside the root:

Attribute Value
nodus:role page (required: this is what makes the file Nodus's own)
id Unique
nodus:width, nodus:height The page's size (mm); 210 × 297 if left out
inkscape:label The page's name
nodus:auto-name true for a page without a name of its own, numbered by position ("Page 2"); false for a named one
inkscape:groupmode layer, so that Inkscape and other programs show the page as a layer
transform Other programs show the pages side by side if each is moved right by translate(x 0): Nodus places each page 20 mm to the right of the one before. Nodus itself ignores it
nodus:scale A page drawn to scale: drawing millimetres per page millimetre (4 for 1:4); 1 if left out
nodus:origin Where the rulers' zero is: rx ry dx dy, a reference point as fractions of the page (0 0 top-left, 0 1 bottom-left) and an offset from it (mm); the document's setting if left out

A page holds its layers (<g> elements) and its guidelines: <nodus:guideline id="…" orientation="horizontal|vertical" position="…"/>, the position being the y (horizontal) or x (vertical) in millimetres from the page's top-left corner.

Layers

Each layer is a <g> directly inside its page; the first is at the back.

Attribute Value
id Unique
inkscape:groupmode layer
inkscape:label The layer's name
style display:none for a hidden layer
sodipodi:insensitive true for a locked layer
nodus:printable false for a layer left out of printing and exports

Objects

What every object can have

Attribute Value
id Unique; needed if a connector is attached to the object
transform Any SVG transform (matrix(a b c d e f), translate, rotate, scale…), in millimetres
inkscape:label The object's name (shown in the Objects docker; a symbol's name)
style="display:none" Hidden
sodipodi:insensitive="true" Locked
nodus:anchors Added anchor points, for connectors: see Anchor points
nodus:avoid-connectors="false" Connectors may go through it (by default they go round shapes)
nodus:wrap-text="true" Paragraph text flows round it
nodus:note Its note (Markdown), not drawn

Outline and fill

Presentation attributes, as SVG (not CSS classes):

Attribute Value If left out
fill A colour, or none black (as SVG)
fill-rule evenodd or nonzero nonzero
stroke The outline's colour, or none none
stroke-width The outline's width (mm) 1
stroke-linejoin miter, round or bevel miter
stroke-linecap butt, round or square butt
stroke-miterlimit As SVG 4
stroke-dasharray Dash and gap lengths (mm) solid
paint-order="stroke" The outline is drawn behind the fill in front

SVG scales an outline with its object's transform; Nodus keeps the width as it is on the page. With a transform that scales, give the width on the page in nodus:outline-width, which Nodus reads in place of stroke-width. Other Nodus attributes for outlines: nodus:dash (dash pattern in multiples of the width), nodus:scale-with-object="true", nodus:outline-position (inside or outside) and nodus:mitre-angle (CorelDRAW's mitre limit, in degrees).

A point is 25.4 / 72 mm: a 1 pt outline is stroke-width="0.353", and 12 pt text is font-size="4.233".

Arrowheads

On paths and connectors, nodus:start-arrow and nodus:end-arrow name the arrowhead at each end. They grow with the outline's width; nodus:arrow-scale makes them bigger or smaller (1.5 for 150 %).

Name Arrowhead
triangle Filled triangle, its point on the end
roundTriangle Filled triangle with rounded corners
reverseTriangle Filled triangle turned round: its base across the end, pointing along the line
open Open arrow (two strokes)
hollowTriangle Outlined triangle (UML inheritance)
diamond Filled diamond
hollowDiamond Outlined diamond (UML aggregation)
dot Filled circle, centred on the end
square Filled square, centred on the end
bar Short bar across the line
cross Cross (×) over the end
endBar, triangleBar, roundTriangleBar, openBar Dimension line ends: a bar across the end, alone or with a triangle, rounded triangle or open arrow pointing into it

Other programs draw arrowheads only from SVG markers (marker-start, marker-end), which Nodus writes too. Nodus reads its own names in preference; an SVG marker without one is read as a triangle.

Shapes

Object Element Notes
Rectangle <rect x y width height> rx (or ry) rounds the corners
Ellipse <ellipse cx cy rx ry> or <circle cx cy r>
Line or curve <path d>, <line>, <polyline> or <polygon>
Group <g> Its children are its objects; groups nest
Picture <image x y width height href="data:image/png;base64,…"> PNG or JPEG, embedded (a linked file is not read); xlink:href is read too

Paths: d may use any SVG path commands. Nodus writes only absolute M, L, C and Z, which are the safest to generate. Its nodes are cusps unless sodipodi:nodetypes says otherwise: one letter a node, c cusp, s smooth or z symmetrical, as Inkscape writes it.

Nodus writes some shapes with more attributes, so that they stay editable as those shapes:

  • rectangles with corners of different sizes;
  • arcs and pies;
  • polygons and stars;
  • shaped corners.

These attributes are nodus:shape="rectangle|ellipse|polygon" with nodus:x/y/width/height/radii, nodus:cx/cy/rx/ry, nodus:start/end/closure, and nodus:sides/angle/star/corner. Generated files can draw such shapes as paths instead.

Text

Text is a <text> element with one <tspan> per line. For exact, editable text, mark it nodus:shape="text" and give its anchor point:

Attribute Value
nodus:shape text
nodus:x, nodus:y Artistic text: where its first line's baseline starts (left aligned), is centred or ends (right aligned). Paragraph text: the frame's top-left corner
nodus:frame Paragraph text only: the frame's width height (mm); its lines wrap to the width
nodus:align left, centre or right (else from text-anchor: start, middle, end)
nodus:valign Paragraph text: top, middle or bottom in its frame
nodus:line-spacing Line spacing as a multiple of the font size; 1.2 if left out
font-family The font. The first name of a list is used; without one, Noto Sans
font-size In millimetres; 16 if left out
font-weight bold (or 600 and over) for bold
font-style italic for italic
fill The text's colour

The text is the <tspan>s' text, each <tspan> a line (a line break between them). A <tspan> with nodus:wrapped="true" continues the line before it, as when paragraph text wraps. Give each <tspan> an x and y where the line is drawn, so that other programs show the lines in place; Nodus lays the text out again itself.

Text not marked nodus:shape="text" is read as artistic text from the <text>'s or first <tspan>'s x and y, with a line for each <tspan> that has a y of its own: plain SVG text works too.

Nodus bundles these fonts, which look the same on every computer: Noto Sans, Noto Sans Condensed, Liberation Sans Narrow, Nunito, Noto Serif, Roboto, Roboto Condensed and Noto Sans Mono. Any other font is used if the computer has it.

Text in a shape

Text in a rectangle, ellipse, polygon or closed path is a <text> straight after the shape's element, with nodus:in-shape holding the shape's id, as in the example. Nodus lays it out in the shape, so its nodus:x, nodus:y and nodus:frame are not needed. Give it nodus:align and nodus:valign (middle to centre it), and nodus:fit="shape" to wrap its lines to the shape's outline, rather than to the box inside it. A connector's label is written the same way after the connector, with nodus:label-at="t dx dy": how far along the connector (0 to 1, by length) and the offset from there (mm).

Connectors

A connector is a <path> with nodus:shape="connector":

Attribute Value
nodus:routing straight, rightAngle or curved
nodus:start, nodus:end Each end's point on the page: x y (mm)
nodus:start-object, nodus:end-object The id of the object the end is attached to (leave out for a loose end)
nodus:start-anchor, nodus:end-anchor Which of that object's anchor points: top, right, bottom, left, centre, an added anchor's ID, or auto for the side facing the other end
nodus:start-direction, nodus:end-direction Which way a right-angle or curved connector leaves that end: up, down, left or right
nodus:radius A right-angle connector's corner radius (mm)
d The line as other programs show it; Nodus works it out from the ends

Nodus draws a connector from its two end points. Each time the drawing is changed, it moves every attached end to its anchor and routes the connector again; it does not when the file is opened. So write each attached end's point where its anchor is. The top, right, bottom and left anchors are the middles of the sides of the object's box (in its own coordinates, before its transform); centre is its middle.

A right-angle connector with only nodus:start-direction and nodus:end-direction is drawn with the simple route between its ends (an L or a Z) until the drawing is first changed, when Nodus routes it round other shapes.

Anchor points

Every object (but a connector) has the anchors top, right, bottom, left and centre. Added anchors, a symbol's terminals for instance, are listed in nodus:anchors:

nodus:anchors="in 0 0.5 main; out 1 0.5"

Each anchor, separated by ;, is its ID, then its position as fractions of the object's box: 0 0 is the top-left corner, 1 1 the bottom-right. The box is the object's geometry, without its outline, in its own coordinates: for a group, the box round its children. main marks a symbol's main anchor, the point it is held by when it is placed. A connector's nodus:start-anchor or nodus:end-anchor can name an added anchor by its ID.

What Nodus writes for itself

Some objects keep descriptions that only Nodus uses:

  • dimensions (nodus:dimension);
  • centre marks and centrelines (nodus:centreline);
  • timing diagrams (nodus:timing);
  • graphs (nodus:graph);
  • text fitted to a path (nodus:text-on-path);
  • fountain fills (nodus:fountain);
  • hatched fills (nodus:hatch, on the fill's pattern);
  • cropped pictures (nodus:crop);
  • formatted parts of text (nodus:spans);
  • Markdown text (nodus:markdown);
  • equations (nodus:maths-of).

Each is also drawn with ordinary SVG, so other programs show it. These are not described here; to make such things, draw them in Nodus. A file can leave them out.

Symbol libraries

A symbol library is an SVG drawing that the Symbols docker reads in a particular way. It can be opened with Open library… in the Symbols docker and dragged from there, or opened with File › Open and edited as a drawing (see Symbols).

  • Categories are layers: each layer's name (inkscape:label) is a category. A group's nodus:category puts it in another category.
  • Symbols are the named groups directly on a layer (or at the top level, or in an unnamed group that only holds symbols). A single named object (a path, a rectangle…) is a symbol too.
  • A symbol's name is its nodus:symbol, else its <title> child, else its inkscape:label. A group's id is used as well, unless it looks made up (g123, _2513814411552). Unnamed groups and objects are not symbols; in a file with no names at all, every top-level group is a symbol, numbered.
  • Order: the Symbols docker lists the last layer in the file first, and the last symbol in a layer first, as the Objects docker does (SVG draws the first thing at the back).
  • Terminals: a symbol's anchor points, where connectors attach, are its added anchors: nodus:anchors on the symbol's group (fractions of its box, as above), or <nodus:anchor id="…" x="…" y="…"/> elements in the group, in the group's own coordinates (millimetres), with main="true" on the main anchor. The main anchor is the point the symbol is held by when it is dragged in. Without one, the leftmost anchor (then the uppermost) is used.
  • Size: symbols keep the size they are drawn at, in millimetres.

An example with one category and two symbols, a resistor and a capacitor, each with a terminal at either end on the 5 mm grid:

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:nodus="urn:nodus-draw:1"
     xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
     width="80mm" height="30mm" viewBox="0 0 80 30" version="1.1">
  <g id="page-1" nodus:role="page" inkscape:groupmode="layer" inkscape:label="Page 1"
     nodus:auto-name="true" nodus:width="80" nodus:height="30">
    <g id="passive" inkscape:groupmode="layer" inkscape:label="Passive components">
      <g id="resistor" nodus:symbol="Resistor">
        <path d="M 10 15 L 15 15 M 25 15 L 30 15" fill="none" stroke="#000000" stroke-width="0.353"/>
        <rect x="15" y="12.5" width="10" height="5" fill="none" stroke="#000000" stroke-width="0.353"/>
        <nodus:anchor id="a" x="10" y="15" main="true"/>
        <nodus:anchor id="b" x="30" y="15"/>
      </g>
      <g id="capacitor" nodus:symbol="Capacitor">
        <path d="M 45 15 L 53.5 15 M 56.5 15 L 65 15 M 53.5 10 L 53.5 20 M 56.5 10 L 56.5 20"
              fill="none" stroke="#000000" stroke-width="0.353"/>
        <nodus:anchor id="a" x="45" y="15" main="true"/>
        <nodus:anchor id="b" x="65" y="15"/>
      </g>
    </g>
  </g>
</svg>

<nodus:anchor> elements are read only in libraries. A drawing (and a library saved again by Nodus) has the anchors in nodus:anchors.

Nodus's own libraries keep to a few more conventions, which make symbols line up when they are placed on the default grid:

  • every symbol's main anchor, and its other anchors, on a point of the 5 mm grid;
  • symbols laid out in rows on the page;
  • nothing drawn that is not part of a symbol.

Checking a file

  • File › Open shows what Nodus made of a drawing. A message at the bottom of the window lists anything it left out (unsupported elements, linked pictures, clipping).
  • Open library… in the Symbols docker shows a library's categories, symbols and names. The connector tool's Edit anchor points shows a symbol's anchors.
  • File › Save writes the drawing back in Nodus's own form: compare it with what you generated to see the attributes Nodus adds.

Next: Command line


This website is free and ad-free, but costs me money to run. If you'd like to support this site, please consider making a small donation or sending me a message to let me know what you liked or found useful.