Predefined Values

There are a number of predefined values that control the default behavior of the functions you use to draw byte field diagrams. They are set up as variables before your code starts running, and as described in the introduction, you can change their values using Clojure’s def mechanism.

Unless you append a specific unit type to them, distances and coordinates in SVG are interpreted as “user units”, which default in these diagrams to pixels (as if you had added px after the number).
Variable Default Value Purpose

left-margin

40

How far from the left edge of the diagram the first box begins. This default is large enough to accommodate the row address labels for all but extremely long byte fields. If you are drawing a single row (which won’t have a row label), it’s nice to set this to 1 so the diagram is centered.

right-margin

1

How far from the right edge of the diagram the last box ends. This default is just large enough to make sure the box boundary doesn’t get clipped. You can make it bigger if you want to draw custom content there.

bottom-margin

1

How far from the bottom edge of the diagram the last row of boxes ends. This default is just large enough to make sure the box boundaries don’t get clipped. You can make it bigger if you want to draw custom content there.

box-width

40

How much horizontal space each box takes up.

boxes-per-row

16

How many boxes are drawn on a row before moving to the next row. The default is 16, so that the hexadecimal row labels increment by 10 and the diagram is a nice width. If you are drawing smaller structures you can reduce this.

column-labels

["0" "1" …​ "f"]

A sequence whose elements are used as the actual text of each column header in order. Although you can change this globally by redefining this value, it is more common to simply pass a different sequence (often by transforming this one) as the :labels attribute when calling draw-column-headers.

row-height

30

How much vertical space a row of boxes takes up.

named-attributes

See the next section.

row-header-fn

default-row-header-fn

The function that is called to draw the row header when necessary. See the source for more details (near the end of the file).

You can def any other variables that might be useful to your diagrams, perhaps in a shared include file, but they won’t affect the existing drawing functions the way these values do.