diagram(n)

πŸ“¦ version 0.7, in alpine 3.24

✨ NAME ✨

diagram β€” Diagram drawing πŸ’…

(also known as diagram(n), from the Documentation toolbox β€” iykyk πŸŽ€)


🌸 SYNOPSIS 🌸

package require Tcl  8.5

package require Tk  8.5

package require diagram  1

::diagram objectName canvas ?script?

diagramObject new direction name ?key value...?

diagramObject new element name attributes cmdprefix

diagramObject new alias name cmdprefix

diagramObject new command name arguments body

diagramObject new attribute name ?key value...?

diagramObject unknown attribute cmdprefix

diagramObject draw script

arc attr...

arrow attr...

--> attr...

<--> attr...

<--> attr...

block script attr...

box attr...

circle attr...

O attr...

diamond attr...

<> attr...

drum attr...

ellipse attr...

line attr...

-- attr...

move attr

spline attr...

text attr...

west

w

left

l

south

s

down

bottom

bot

b

east

e

right

r

north

n

up

top

t

northwest

nw

up-left

upleft

leftup

northeast

ne

up-right

upright

rightup

southwest

sw

down-left

downleft

leftdown

southeast

se

down-right

downright

rightdown

number cm

number mm

number inch

number pt

number number

by distance direction

point1 + point2

point1 - point2

point by distance direction

point1 | point2

n between poin1 point2

intersect elem1 elem2

element names ?pattern?

element corner

element corner1 corner2...

element ?corner1... ?names ?pattern??]?

nth ?corner?

nth last ?corner?

nth shape ?corner?

nth last shape ?corner?

last ?corner?

last shape ?corner?

1st

2nd

3rd

πŸ’– DESCRIPTION πŸ’–

okay so welcome to diagram, a package for the easy construction of diagrams (sic), i.e. 2D vector graphics, sometimes also called pictures. 🎨✨ Note that this package is not a replacement for Tk's canvas β€” it's more like a layer sitting on top of it to make it easier to use. In other words, using the canvas as the core graphics engine, diagram abstracts away from the minutiae of handling coordinates to position and size the drawn elements, allowing the user to concentrate on the content of the diagram instead. Literally the glow-up your canvas workflow needed πŸ’…

This is similar to Brian Kernighan's PIC language for troff, which is the spiritual ancestor of this package. No cap, we're carrying on a whole legacy here πŸ‘‘

This document contains the reference to the API and drawing (language) commands. Its intended audience are users of the package wishing to refresh their memory. Newcomers should read the Diagram Language Tutorial first. Developers wishing to work on the internals of the package and its supporting packages should look at section Diagram Classes first, and then the comments in the sources of the packages itself. fr fr, read the tutorial first bestie 🫢

In the remainder of the document we first describe the APIs of the diagram class and its instances, followed by the language reference for the drawing language itself.


πŸ¦‹ API πŸ¦‹

πŸŽ€ CLASS API πŸŽ€

The package exports the API described here.

  • ::diagram objectName canvas ?script? β€” The command creates a new instance of a diagram controller and returns the fully qualified name of the object command as its result. The new instance is connected to the specified canvas object, which is used as the diagram's graphics engine. This is usually an instance of Tk's canvas, however any object which is API compatible to Tk's canvas can be used here. The API of this object command is described in the following section, Object API. It may be used to invoke various operations on the object. If the script argument is specified then method draw will be invoked on it. ✨

πŸ’… OBJECT API πŸ’…

Instances of the diagram class support the following methods:

  • diagramObject new direction name ?key value...? β€” This method defines a new named direction and its attributes. The latter is given through the key/value pairs coming after the name. Users are mostly free to specify arbitrary attributes with whatever meaning they desire. The exception are the names angle and opposite. They are special to the diagram package and have a fixed meaning.
    • angle β€” This attribute specifies the angle of the direction in degrees, where 0 points east (to the right) and 90 points north (up). πŸ“
    • opposite β€” This attribute specifies the name of the direction which should be considered as complementary to the named one.
  • diagramObject new element name attributes cmdprefix β€” This method defines a new graphics element for the drawing language. I.e. name will become a new command in the language, and the specified command prefix (cmdprefix) will be called to perform the actual drawing. attributes specifies the set of attributes for which data has to be available. I.e. the system will run the ...-callbacks for these attributes. See the method new attribute for more information on attribute definitions. The command prefix is expected to conform to the following signature:
cmdprefix canvas attributes

Where canvas is the handle of the canvas widget to draw to, and attributes is a dictionary holding the attributes for the element, be they user-specified, or defaults. The results of the command has to be a list containing at least two and at most four items. These are, in order:

  1. The list of canvas items the drawn element consists of.
  2. The dictionary of named locations in the element, its corners.
  3. An optional mode, either "relative" or "absolute". When not returned "relative" is assumed. In the case of a relative element position the attributes "with" and "at" are used to determine the final position of the new element.
  4. An optional name of a direction. If not the empty string this is handed to the automatic layouter as the new direction to follow.
  • diagramObject new alias name cmdprefix β€” This method defines a new command for the drawing language. I.e. name will become a new command in the language, and the specified command prefix (cmdprefix) will be called on use of this new command. Any arguments given to the command are simply passed to the prefix. There is no fixed signature. Note that the prefix is run in the context of the drawing language, allowing the direct use of any existing commands. πŸͺ„
  • diagramObject new command name arguments body β€” This is like new alias except that the new command is defined as a procedure in the language's context, with regular argument list and body.
  • diagramObject new attribute name ?key value...? β€” This method defines a new named attribute which can be used by graphical elements. The handling of the attribute by the processor is declared through the key/value pairs coming after the name. The accepted keys and their meanings are:
    • key β€” The value of this key is the name of the key under which the attribute's value shall be stored in the attribute dictionary given to the drawing command after attribute processing is complete. This key is optional. If it is not specified it defaults to the name of the attribute.
    • get β€” The value of this key is a command prefix which will be invoked to retrieve the attribute's argument(s) from the command line. This key is optional. If it is not specified a default is used which takes the single word after the attribute name as the attribute's value. The signature of the command prefix is:
cmdprefix wordqueue

Where wordqueue is the handle of a queue object conforming to the API of the queues provided by package struct::queue. This queue contains the not-yet-processed part of the attribute definitions, with one entry per word, with the first entry the word after name of the attribute. In other words, the attribute's name has already been removed from the queue. The result of the command is the value of the attribute, which may have been taken from the queue, or not.

  • transform β€” The value of this key is a command prefix which will be invoked to transform the retrieved value (See get) into their final form. This key is optional. If it is not specified no transformation is done. The signature of the command prefix is:
cmdprefix value

Where value is the value to transform. The result of the command is the final value of the attribute.

  • type β€” The value of this key is a command prefix which will be invoked to validate the attribute's argument(s). This key is optional. If it is not specified no validation is done. The signature of the command prefix is that of snit validation types. See the documentation of the snit package.
  • merge β€” The value of this key is a command prefix which will be invoked to insert the transformed and validated attribute value into the dictionary of collected attributes. This key is optional. If it is not specified a default merge is chosen, based on the data for key aggregate, see below. The signature of the command prefix is

cmdprefix value dict β€” okay bestie, this signature is doing the most πŸ’… value is the value to insert, and dict is the dictionary of attributes and values collected so far. The command returns the new dictionary of attributes. ✨

  • aggregate β€” this key is a boolean flag, and it has an effect if and only if the key merge was not specified. It's optional; if you don't specify it, it defaults to False.

If it's effective, False means the attribute's value gets set into the dictionary using the value of key key (see above) as the index, overwriting any previously specified value.

If it's effective, True means the attribute's value gets added to the dictionary using the value of key key (see above) as the index, extending any previously specified value. This means the final value of the attribute as seen after processing will be a list of the collected values. 🫢

  • default β€” this key's value is a command prefix that gets invoked after collection of attributes has been completed, and this attribute is in the list of required attributes for the drawing element (see argument attributes of method new element). πŸ‘‘

Note that the connection is made through the value of key key, not through the attribute name per se.

Further note that this command prefix is invoked even if a user-specified attribute value is present. This lets the command go beyond simply setting defaults β€” it can calculate and store derived values as well. πŸ”₯

This key is optional. If an element requires this attribute, but default is not specified, then nothing will be done.

The signature of the command prefix is:

  • cmdprefix init β€” this method runs when the attribute is defined. Its responsibility is to initialize anything in the language namespace for the attribute and default processing. The result of this method is ignored.
  • cmdprefix fill varname β€” this method runs to put defaults, or derived values, into the attribute dictionary named by varname. This variable will be found in the calling context. The result of this method is ignored.
  • cmdprefix set name value β€” this method runs to push the current attribute value into the language namespace, to make it the new default. The result of this method is ignored. πŸ’–
  • linked β€” this key is effective if and only if key default is not specified. In that case it supplies a default handling for default, linking the attribute to a variable in the language context.

The value for this key is a 2-element list containing the name of the variable to link to, and its initial value, in this order. πŸŽ€

diagramObject unknown attribute cmdprefix

This method registers the command prefix with the subsystem processing the attributes for element commands, telling it to call it when it encounters an attribute it is unable to handle on its own.

It is allowed to register more than one callback β€” these will be called in order of registration (first to last), until one of the callbacks accepts the current input. The command prefix is expected to conform to this signature:

cmdprefix wordqueue

Where wordqueue is the handle of a queue object conforming to the API of the queues provided by package struct::queue. This queue contains the not-yet-processed part of the attribute definitions, with one entry per word, with the first entry being the name of the attribute which could not be processed.

The result of the command has to be a boolean value where True signals that this callback has accepted the attribute, processed it, and the new state of the wordqueue is where the general processing shall continue. 🌸

Given the signature, the command has basically two ways of handling (rewriting) the attributes it recognizes:

  1. Replace the attribute (and arguments) with a different attribute and arguments.
  2. Push additional words in front to get the general processing unstuck. πŸ¦‹

diagramObject draw script

This method runs the given script in the context of the drawing language definitions. See section Language Reference for details on the available commands.

Note that script is trusted. It is executed in the current interpreter with access to its full abilities. For the execution of untrusted diagram scripts, this interpreter should be a safe one. ⚠️

🌈 LANGUAGE REFERENCE 🌈

✨ ELEMENTS ✨

This section lists the commands for the predefined drawing elements, aka shapes. These commands are all defined in the language's context. All commands of this section return the handle of the newly created element as their result. This handle also exists as a command which can be used to query the element for its corners (names, values). See section Miscellaneous Commands. IMAGE: figure-02-basic-shapes πŸ‘‘

arc attr...

IMAGE: figure-02-arc β€” an open element with the corresponding corners, i.e. "start", "end", and "center". Note however that it also has the compass rose of closed elements as its corners, with the center of the arc's circle as the center of the compass and the other points on the circle the arc is part of. It handles the attributes: 🌈

  • anchor name β€” IMAGE: figure-22-text-anchoring-3 specifies the anchor of the text which is to be placed at the element's center, by name. I.e. this attribute defines the text's position relative to the element's center. The value is ignored if no text was specified for the element. If not specified, the system falls back to the value taken from the language variable anchor, which itself defaults to center. The legal values are all those accepted by Tk_GetAnchor [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm]. The commands without arguments are all shorthands with the anchor implied. Note that they do not combine β€” only the last is used. For combined directions, the main attribute command, anchor, has to be used. πŸ’…
    • ljust β€” shorthand for "anchor west"
    • rjust β€” shorthand for "anchor east"
    • above β€” shorthand for "anchor south"
    • below β€” shorthand for "anchor north"
  • clockwise, cw β€” specifies the direction of the arc element, here going clockwise. The complementary attribute is counterclockwise. If not specified, the system falls back to the value taken from the language variable clockwise, which itself defaults to false, for counter-clockwise direction. πŸ”„
  • color spec β€” IMAGE: figure-21-style-colors specifies the color used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variable linecolor, which itself defaults to black. πŸ–€
  • counterclockwise, ccw β€” specifies the direction of the arc element, here counter-clockwise. The complementary attribute is clockwise. If not specified, the system falls back to the value taken from the language variable clockwise, which itself defaults to false, for counter-clockwise direction. πŸ”
  • fillcolor spec β€” IMAGE: figure-21-style-colors specifies the color used to draw the inside of the element. If not specified, the system falls back to the value taken from the language variable fillcolor, which itself defaults to the empty string, signaling "no filling". 🎨
  • from location β€” specifies the location where the arc element begins. Defaults to the current location as maintained by the layouting system. πŸ“
  • justify left|center|right β€” specifies how multi-line text associated with the element is positioned within its box. The value is ignored if no text was specified for the element. If not specified, the system falls back to the value taken from the language variable justify, which itself defaults to left. The legal values are left, right, and center. πŸ“
  • radius length β€” specifies the radius of the arc element, or rather, the radius of the circle the shown arc is a part of. If not specified, the system falls back to the value taken from the language variable arcradius, which itself defaults to the pixel equivalent of 1 cm. β­•
  • stroke width β€” IMAGE: figure-20-style-stroke specifies the width of the lines drawn for the element, in pixels. If not specified, the system falls back to the value taken from the language variable linewidth, which itself defaults to 1. πŸ–ŠοΈ
  • style spec β€” IMAGE: figure-18-style-dash specifies the style used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variable linestyle, which itself defaults to solid lines. The legal values are all those accepted by Tk_GetDash [http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], and additionally all which are listed below: ✨
    • solid, empty string β€” draw solid line. πŸŽ€
  • dash, dashed, - β€” draw a dashed line ✨ like, three whole ways to say the same thing, we love an accessible queen.
    • dot, dotted, . β€” draw a dotted line πŸŽ€ so dainty.
    • dash-dot, -. β€” draw a dash-dotted line.
    • dash-dot-dot, -.. β€” draw a dash-dot-dotted line, the fanciest of the bunch πŸ’….
ngl this bit matters: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command, using them as the argument. iykyk 🫢
  • text string β€” the text you wanna associate with the element. defaults to nothing (so, empty, no text, tragic). and here's the cute part: if you specify it multiple times, the text that actually shows up is the concatenation of the individual strings, vertically stacked, with the first string you specified being the topmost element 🌸.
  • textcolor spec β€” the color used to draw the text of an element. ignored if there's no text (obvi, can't color nothing). if you don't specify it, the system falls back to the value taken from the language variable textcolor, which itself defaults to black πŸ–€.
  • textfont spec β€” the font used to draw the text of an element. also ignored if there's no text. if not specified, the system falls back to the value from the language variable textfont, which itself defaults to Helvetica 12pt ✨.
  • to location β€” the location where the arc element ends πŸ¦‹. defaults to a location such that a 90-degree arc is drawn in the chosen direction, starting at from.

🌈 the arrow girlies

  • arrow attr...
  • --> attr...
  • <--> attr...
  • <- attr...

(IMAGE: figure-02-arrow) so these are all an alias for the line element (peep it below πŸ‘‡), with the attribute arrowhead preset to ->, <->, or <-. and arrow is literally equivalent to -->. same girl, different wig πŸ’–.


🧚 block script attr...

a closed element with the corresponding corners β€” and by "corresponding corners" we mean the eight directions of the compass rose plus "center" πŸ‘‘. the main character effect here is the aggregation of all elements created by the script into one single element. which also means: while the elements created by the script are visible in the element history while the script is executing, afterward the history contains only the block itself β€” not the elements it's composed of. poof, aggregated, gone πŸ™ˆ.

the script has access to the current state of all variables in the language context. any changes to the variables get reverted after execution of the block. however β€” and this is the slay part β€” any variables set in the script will be exported as corners of the element, letting users define their own named locations in the block πŸŽ€.

about the layout mechanism: any changes made by the script are reverted after the element is done. in other words, a block is an implicit group 🫢.

blocks handle all attributes, propagating their settings into the script as the default values active during script execution ✨.


🎁 box attr...

(IMAGE: figure-02-box) a closed element with the corresponding corners β€” again, the eight directions of the compass rose plus "center" β€” and it handles these attributes:

  • anchor name
  • ljust
  • rjust
  • above
  • below

(IMAGE: figure-22-text-anchoring-3) specifies the anchor of the text that's gonna be placed at the element's center, by name β€” i.e. this attribute defines the text's position relative to the element's center πŸ“. the value is ignored if no text was specified for the element. if not specified, the system falls back to the value taken from the language variable anchor, which itself defaults to center. legal values are all those accepted by Tk_GetAnchor [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm] β€” yes bestie, we're linking the Tcl docs, it's giving thorough πŸ’…. the commands without arguments are all shorthands with the anchor implied. note that they do not combine β€” only the last one is used 🫠. for combined directions you have to use the main attribute command, anchor.

  • ljust β†’ "anchor west"
  • rjust β†’ "anchor east"
  • above β†’ "anchor south"
  • below β†’ "anchor north"
  • at location β€” specifies the location of the element's corner named by the attribute with πŸ—ΊοΈ. defaults to the current location as maintained by the layouting system.
  • color spec β€” (IMAGE: figure-21-style-colors) the color used to draw the lines of the element. if not specified, the system falls back to the value taken from the language variable linecolor, which itself defaults to black πŸ–€.
  • fillcolor spec β€” (IMAGE: figure-21-style-colors) the color used to draw the inside of the element. if not specified, the system falls back to the value taken from the language variable fillcolor, which itself defaults to the empty string, signaling "no filling" πŸ•³οΈ.
  • height length
  • ht length

specifies the height of the element πŸ“. if not specified, the system falls back to the value taken from the language variable boxheight, which itself defaults to the pixel equivalent of 2 cm.

  • justify left|center|right β€” specifies how multi-line text associated with the element is positioned within its box πŸ“. the value is ignored if no text was specified for the element. if not specified, the system falls back to the value taken from the language variable justify, which itself defaults to left. legal values are left, right, and center.
  • slant angle β€” the angle by which the box element is slanted, in degrees πŸŒͺ️. if not specified, the system falls back to the value taken from the language variable slant, which itself defaults to 90, i.e. vertical, no slant. 0 degrees is slanting straight east, pointing to the right. 90 degrees is slanting to the north, pointing straight up ⬆️.
  • stroke width β€” (IMAGE: figure-20-style-stroke) the width of the lines drawn for the element, in pixels. if not specified, the system falls back to the value taken from the language variable linewidth, which itself defaults to 1 πŸ–ŠοΈ.
  • style spec β€” (IMAGE: figure-18-style-dash) the style used to draw the lines of the element. if not specified, the system falls back to the value taken from the language variable linestyle, which itself defaults to solid lines. legal values are all those accepted by Tk_GetDash [http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], and additionally all of these:
    • solid, empty string β€” draw solid line.
    • dash, dashed, - β€” draw a dashed line.
    • dot, dotted, . β€” draw a dotted line.
    • dash-dot, -. β€” draw a dash-dotted line.
    • dash-dot-dot, -.. β€” draw a dash-dot-dotted line.
reminder bestie: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command using them as argument 🫢.
  • text string β€” the text to associate with the element. defaults to nothing. when specified multiple times, the actually shown text is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element 🌸.
  • textcolor spec β€” the color used to draw the text of an element. ignored if there is no text. if not specified, the system falls back to the value taken from the language variable textcolor, which itself defaults to black πŸ–€.
  • textfont spec β€” the font used to draw the text of an element. ignored if there is no text. if not specified, the system falls back to the value taken from the language variable textfont, which itself defaults to Helvetica 12pt ✨.
  • width length
  • wid length

specifies the width of the element πŸ“. if not specified, the system falls back to the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm.

  • with corner β€” specifies the corner of the element to place at the location given by the attribute at πŸ“Œ. defaults to the current corner as maintained by the layouting system, except if the value for at was specified by the user β€” in that case it defaults to center.

β­• circle attr...

πŸ”΅ O attr...

(IMAGE: figure-02-circle) a closed element with the corresponding corners, i.e. the eight directions of the compass rose, and "center" πŸ‘‘. it handles the attributes:

  • anchor name
  • ljust
  • rjust
  • above
  • below

(IMAGE: figure-22-text-anchoring-3) specifies the anchor of the text which is to be placed at the element's center, by name. i.e. this attribute defines the text's position relative to the element's center πŸ“. the value is ignored if no text was specified for the element. if not specified, the system falls back to the value taken from the language variable anchor, which itself defaults to center. the legal values are all those accepted by Tk_GetAnchor [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm]. the commands without arguments are all shorthands with the anchor implied. note that they do not combine β€” only the last is used 🫠. for combined directions the main attribute command, anchor, has to be used.

  • ljust β†’ "anchor west"
  • rjust β†’ "anchor east"
  • above β€” shorthand for "anchor south".
    • below β€” shorthand for "anchor north".
  • at location β€” where the element's corner (the one named by with) actually sits 🎯. If you don't say, it defaults to the current location that the layouting system is keeping track of.
  • color spec β€” IMAGE: figure-21-style-colors. Sets the color used to draw the element's outlines. Leave it out and the system falls back to the language variable linecolor, which itself defaults to black. πŸ–€
  • diameter length
  • diam length β€” the circle's diameter, as another way to say its radius. This one is effective if and only if the radius wasn't specified β€” so if you give both diameter and radius, the radius info wins, periodt. No default here, because the defaults come from the radius side of things.
  • fillcolor spec β€” IMAGE: figure-21-style-colors. The color for the inside of the element 🎨. Skip it and the system falls back to the language variable fillcolor, which defaults to the empty string β€” that's the signal for "no filling".
  • justify left|center|right β€” how multi-line text attached to the element lines up inside its box. Ignored if the element has no text. Skip it and the system falls back to the language variable justify, which defaults to left. The legal values are left, right, and center ✨.
  • radius length
  • rad length β€” the circle's radius. Skip it and the system falls back to the language variable circleradius, which itself defaults to the pixel equivalent of 1 cm πŸ’«.
  • stroke width β€” IMAGE: figure-20-style-stroke. How wide the lines drawn for the element are, in pixels. Skip it and the system falls back to the language variable linewidth, which defaults to 1.
  • style spec β€” IMAGE: figure-18-style-dash. The style used to draw the element's lines. Skip it and the system falls back to the language variable linestyle, which defaults to solid lines. The legal values are everything Tk_GetDash accepts [http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], plus all of these icons:
    • solid, empty string β€” Draw solid line.
    • dash, dashed, - β€” Draw a dashed line.
    • dot, dotted, . β€” Draw a dotted line.
    • dash-dot, -. β€” Draw a dash-dotted line
    • dash-dot-dot, -.. β€” Draw a dash-dot-dotted line.
Heads up bestie: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command when you pass them as its argument πŸ’…
  • text string β€” the text to attach to the element. Defaults to nothing. Specify it more than once and the text actually shown is the concatenation of the individual strings, stacked vertically, with the first string you gave sitting at the top 🌸.
  • textcolor spec β€” the color the element's text gets drawn in. Ignored if there's no text. Skip it and the system falls back to the language variable textcolor, which defaults to black.
  • textfont spec β€” the font the element's text gets drawn in. Ignored if there's no text. Skip it and the system falls back to the language variable textfont, which defaults to Helvetica 12pt ✨.
  • with corner β€” which corner of the element goes at the location given by at. Defaults to the current corner the layouting system is tracking… except when you specified at yourself. In that case it defaults to center 🎯.

πŸ’Ž diamond attr...

πŸ’Ž <> attr...

IMAGE: figure-02-diamond β€” a closed element rocking the corresponding corners, i.e. the eight directions of the compass rose, plus "center" 🧭. It handles these attributes:

  • anchor name
  • ljust
  • rjust
  • above
  • below β€” IMAGE: figure-22-text-anchoring-3. Sets the anchor of the text that's placed at the element's center, by name. So like, this attribute defines the text's position relative to the element's center 😌. Ignored if no text was specified for the element. Skip it and the system falls back to the language variable anchor, which defaults to center. The legal values are all the ones Tk_GetAnchor accepts [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm].

The commands with no arguments are all shorthands with the anchor baked in. Note that they do not combine β€” only the last one counts. For combined directions you gotta use the main anchor command, fr fr.

  • ljust β†’ "anchor west"
  • rjust β†’ "anchor east"
  • above β†’ "anchor south"
  • below β†’ "anchor north"
  • aspect number β€” the aspect ratio, i.e. ratio of width to height, of the diamond element. How a default gets calculated when you don't specify it also depends on whether width and height were given. Buckle up 🎒:
    • If both width and height are specified then any aspect you gave is ignored, because it's implicitly defined by width and height anyway and that takes precedence. A missing specification is ignored in that case too β€” no defaults needed, we're chillin'.
    • If aspect is specified, plus one of width or height, then the missing attribute gets calculated from the two that are specified. No defaults required for these cases either ✨.
    • If only one of width or height is specified then the system uses a fallback for the aspect: the value taken from the language variable diamondaspect, which itself defaults to 2.
    • If none of width or height is specified then the system uses a fallback for the width: the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. For the aspect it uses either your value or the default taken as described in the paragraph above πŸ‘‘
  • at location β€” where the element's corner (the one named by with) sits. Defaults to the current location as maintained by the layouting system 🎯.
  • color spec β€” IMAGE: figure-21-style-colors. The color used to draw the element's lines. Skip it and the system falls back to the language variable linecolor, which itself defaults to black πŸ–€.
  • fillcolor spec β€” IMAGE: figure-21-style-colors. The color used to draw the inside of the element. Skip it and the system falls back to the language variable fillcolor, which defaults to the empty string, signaling "no filling" 🫧.
  • height length β€” the height of the diamond element. How a default gets calculated when you don't specify it also depends on whether aspect and width were given. Same drill as before:
    • If both width and height are specified then any aspect you gave is ignored, because it's implicitly defined in width and height and that takes precedence. A missing specification is ignored in that case too β€” no defaults required.
    • If aspect is specified, plus one of width or height, the missing attribute is calculated from the two that are specified. No defaults needed here either ✨.
    • If only one of width or height is specified then the system uses a fallback for the aspect: the value taken from the language variable diamondaspect, which itself defaults to 2.
    • If none of width or height is specified then the system uses a fallback for the width: the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. For the aspect it uses either your value or the default described in the paragraph above πŸ’œ.
  • justify left|center|right β€” how multi-line text associated with the element is positioned within its box. Ignored if no text was specified for the element. Skip it and the system falls back to the language variable justify, which defaults to left. Legal values: left, right, and center 🌸.
  • stroke width β€” IMAGE: figure-20-style-stroke. This sets the width, in pixels, of the lines drawn for the element. If you don’t specify it, the system falls back to the value taken from the language variable linewidth, which itself defaults to 1. ✨
  • style spec β€” IMAGE: figure-18-style-dash. This sets the style used to draw the lines of the element. If you don’t specify it, the system falls back to the value taken from the language variable linestyle, which itself defaults to solid lines. The legal values are all those accepted by Tk_GetDash (http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm), and additionally all of these:
    • solid, empty string β€” draw a solid line.
    • dash, dashed, - β€” draw a dashed line.
    • dot, dotted, . β€” draw a dotted line.
    • dash-dot, -. β€” draw a dash-dotted line
    • dash-dot-dot, -.. β€” draw a dash-dot-dotted line.
Note: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command using them as argument. 🫢
  • text string β€” Specifies the text to associate with the element. Defaults to nothing. When specified multiple times, the actually shown text is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element. πŸ’¬
  • textcolor spec β€” Specifies the color used to draw the text of an element with. Ignored if there is no text. If not specified, the system falls back to the value taken from the language variable textcolor, which itself defaults to black.
  • textfont spec β€” Specifies the font used to draw the text of an element with. Ignored if there is no text. If not specified, the system falls back to the value taken from the language variable textfont, which itself defaults to Helvetica 12pt. πŸŽ€
  • width length β€” Specifies the width of the diamond element. The manner in which a default is calculated when not specified also depends on the specifications of the attributes aspect and height, if any. 😭
    • If both width and height are specified, then any specification of aspect is ignored, as it is implicitly defined in the width and height as well, and this takes precedence. A missing specification is ignored in that case too, i.e. no defaults are required.
    • If the aspect is specified, and one of the attributes width or height, then the missing attribute is calculated from the two which are specified. No defaults are required for these cases either.
    • If only one of the attributes width or height is specified, then the system uses a fallback for the aspect: the value taken from the language variable diamondaspect, which itself defaults to 2.
    • If none of the attributes width or height is specified, then the system uses a fallback for the width: the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. For the aspect it uses either the user-specified value or the default taken as described in the previous paragraph.
  • with corner β€” Specifies the corner of the element to place at the location given by the attribute at. Defaults to the current corner as maintained by the layouting system, except if the value for at was specified by the user. In that case it defaults to center. πŸ“

πŸ₯ drum attr...

IMAGE: figure-02-drum. A closed element with the corresponding corners, i.e. the eight directions of the compass rose, and "center". It handles the attributes anchor name, ljust, rjust, above, below. πŸ’–

  • anchor name β€” IMAGE: figure-22-text-anchoring-3. Specifies the anchor of the text which is to be placed at the element’s center, by name. I.e. this attribute defines the text’s position relative to the element’s center. The value is ignored if no text was specified for the element. If not specified, the system falls back to the value taken from the language variable anchor, which itself defaults to center. The legal values are all those accepted by Tk_GetAnchor (http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm). The commands without arguments are all shorthands with the anchor implied.
    • ljust β†’ "anchor west"
    • rjust β†’ "anchor east"
    • above β†’ "anchor south"
    • below β†’ "anchor north"
Note: they do not combine, only the last is used. For combined directions the main attribute command, anchor, has to be used. πŸ’€
  • aspect number β€” Specifies the aspect ratio, i.e. ratio of width to height, of the ellipses which are used to draw the top and bottom of the drum element. If not specified, the system falls back to the value taken from the language variable drumaspect, which itself defaults to 0.35. πŸ₯
  • at location β€” Specifies the location of the element’s corner named by the attribute with. Defaults to the current location as maintained by the layouting system.
  • color spec β€” IMAGE: figure-21-style-colors. Specifies the color used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variable linecolor, which itself defaults to black.
  • fillcolor spec β€” IMAGE: figure-21-style-colors. Specifies the color used to draw the inside of the element. If not specified, the system falls back to the value taken from the language variable fillcolor, which itself defaults to the empty string, signaling "no filling". 🎨
  • height length, ht length β€” Specifies the height of the element. If not specified, the system falls back to the value taken from the language variable boxheight, which itself defaults to the pixel equivalent of 2 cm.
  • justify left|center|right β€” Specifies how multi-line text associated with the element is positioned within its box. The value is ignored if no text was specified for the element. If not specified, the system falls back to the value taken from the language variable justify, which itself defaults to left. The legal values are left, right, and center.
  • stroke width β€” IMAGE: figure-20-style-stroke. Specifies the width of the lines drawn for the element, in pixels. If not specified, the system falls back to the value taken from the language variable linewidth, which itself defaults to 1.
  • style spec β€” IMAGE: figure-18-style-dash. Specifies the style used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variable linestyle, which itself defaults to solid lines. The legal values are all those accepted by Tk_GetDash (http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm), and additionally all of these:
    • solid, empty string β€” draw a solid line.
    • dash, dashed, - β€” draw a dashed line.
    • dot, dotted, . β€” draw a dotted line.
    • dash-dot, -. β€” draw a dash-dotted line
    • dash-dot-dot, -.. β€” draw a dash-dot-dotted line.
Note: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command using them as argument. 🌈
  • text string β€” Specifies the text to associate with the element. Defaults to nothing. When specified multiple times, the actually shown text is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element.
  • textcolor spec β€” Specifies the color used to draw the text of an element with. Ignored if there is no text. If not specified, the system falls back to the value taken from the language variable textcolor, which itself defaults to black.
  • textfont spec β€” Specifies the font used to draw the text of an element with. Ignored if there is no text. If not specified, the system falls back to the value taken from the language variable textfont, which itself defaults to Helvetica 12pt. ✨
  • width length, wid length β€” Specifies the width of the element. If not specified, the system falls back to the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm.
  • with corner β€” Specifies the corner of the element to place at the location given by the attribute at. Defaults to the current corner as maintained by the layouting system, except if the value for at was specified by the user. In that case it defaults to center. 🫢

πŸ₯š ellipse attr...

IMAGE: figure-02-ellipse. A closed element with the corresponding corners, i.e. the eight directions of the compass rose, and "center". It handles the attributes:

  • anchor name
  • ljust
  • rjust β€” shorthand for anchor east πŸ’… (yes bestie, these are the no-argument versions and the anchor is just implied)
  • above β€” shorthand for anchor south ⬆️
  • below β€” shorthand for anchor north ⬇️ (I know, south is above and north is below, just go with it, it's giving math class 😭)
Heads up babe β€” these shorthands do not combine. Only the last one you type is used. If you want a combined direction you gotta use the main attribute command, anchor, with the full name. No shortcuts for combo moves, sorry. 🫢
  • at location β€” tells the system where to put the element's corner β€” specifically the corner named by the with attribute. If you don't say anything, it defaults to the current location as maintained by the layouting system. πŸ“
  • color spec β€” specifies the color used to draw the lines of the element. (see figure-21-style-colors, she's iconic) If not specified, the system falls back to the value taken from the language variable linecolor, which itself defaults to black. πŸ–€
  • fillcolor spec β€” specifies the color used to draw the inside of the element. (figure-21-style-colors again, same vibe) If not specified, the system falls back to the value taken from the language variable fillcolor β€” and that one defaults to the empty string, which literally signals "no filling". Empty string = no vibes inside, just outline. ✨
  • height length
  • ht length β€” specifies the height of the element. If not specified, the system falls back to the value taken from the language variable boxheight, which itself defaults to the pixel equivalent of 2 cm. πŸ“
  • justify left|center|right β€” specifies how multi-line text associated with the element is positioned within its box. Ignored if no text was specified for the element (no text, no justification, we love an honest king πŸ’€). If not specified, the system falls back to the value taken from the language variable justify, which itself defaults to left. The legal values are left, right, and center. β¬…οΈβ†”οΈβž‘οΈ
  • stroke width β€” (figure-20-style-stroke, she's serving) specifies the width of the lines drawn for the element, in pixels. If not specified, the system falls back to the value taken from the language variable linewidth, which itself defaults to 1. πŸ–ŠοΈ
  • style spec β€” (figure-18-style-dash, dash queen) specifies the style used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variable linestyle, which itself defaults to solid lines. The legal values are all those accepted by Tk_GetDash [http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], and additionally all of these cuties listed below: 🌈
    • solid, empty string β€” draws a solid line.
    • dash, dashed, - β€” draws a dashed line.
    • dot, dotted, . β€” draws a dotted line.
    • dash-dot, -. β€” draws a dash-dotted line.
    • dash-dot-dot, -.. β€” draws a dash-dot-dotted line.

Also note: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command using them as an argument. So like, you can just say dot and she knows. πŸŽ€

  • text string β€” specifies the text to associate with the element. Defaults to nothing. When specified multiple times, the actually shown text is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element. So multiple text calls = a lil stacked sandwich of words, first one on top πŸ₯ͺ
  • textcolor spec β€” specifies the color used to draw the text of an element with. Ignored if there is no text. If not specified, the system falls back to the value taken from the language variable textcolor, which itself defaults to black. πŸ–€
  • textfont spec β€” specifies the font used to draw the text of an element with. Ignored if there is no text. If not specified, the system falls back to the value taken from the language variable textfont, which itself defaults to Helvetica 12pt. πŸ”€
  • width length
  • wid length β€” specifies the width of the element. If not specified, the system falls back to the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. πŸ“
  • with corner β€” specifies which corner of the element to place at the location given by the at attribute. Defaults to the current corner as maintained by the layouting system β€” except if the value for at was specified by the user, in which case it defaults to center. Rude little plot twist but okay 😌

🧡 line attr... and -- attr...

line attr...
-- attr...

(figure-02-line, the moment) This is an open element with the corresponding corners, i.e. "start", "end", and "center". It handles these attributes:

  • anchor name
  • ljust
  • rjust
  • above
  • below β€” (figure-22-text-anchoring-3, anchoring icon) specifies the anchor of the text which is to be placed at the element's center, by name. I.e. this attribute defines the text's position relative to the element's center. The value is ignored if no text was specified for the element. If not specified, the system falls back to the value taken from the language variable anchor, which itself defaults to center. The legal values are all those accepted by Tk_GetAnchor [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm]. The commands without arguments are all shorthands with the anchor implied. Note that they do not combine β€” only the last is used. For combined directions, the main attribute command, anchor, has to be used. πŸ’…
    • ljust β€” "anchor west"
    • rjust β€” "anchor east"
    • above β€” "anchor south"
    • below β€” "anchor north"
  • arrowhead spec β€” (figure-19-style-arrowheads, arrow slay) specifies where to draw arrowheads on the line element: at the beginning or end, at both ends, or none. If not specified, the system falls back to the value taken from the language variable arrowhead, which itself defaults to none. The legal values are:
    • none, - β€” draw no arrowheads, at neither end of the line.
    • start, first, <- β€” draw an arrowhead at the beginning of the line, but not at its end.
    • end, last, -> β€” draw an arrowhead at the end of the line, but not at its beginning.
    • both, <-> β€” draw arrowheads at both ends of the line.

Note that the values "start", "end", "-", "->", "<-", and "<->" are all accepted as shorthands for the arrowhead command using them as argument. 🏹

  • at location β€” line elements are normally positioned absolutely, using the locations specified through the attributes from, then, and to. If at is specified however, then these positions are translated a last time, moving the line's corner named by the attribute with to the location given by this attribute. 🚚
  • chop ?length? β€” specifies the length of the line element to remove from the beginning and/or end. Defaults to nothing. If specified once, the chopping applies to both beginning and end of the line. If specified twice or more, the last two specifications are used, and applied to beginning and end of the line, in this order. Whenever the attribute is specified without an explicit length, the system falls back to the value taken from the language variable circleradius, which itself defaults to the pixel equivalent of 1 cm. βœ‚οΈ (chop chop bestie)
  • color spec β€” (figure-21-style-colors) specifies the color used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variable linecolor, which itself defaults to black. πŸ–€
  • fillcolor spec β€” (figure-21-style-colors) specifies the color used to draw the inside of the element. If not specified, the system falls back to the value taken from the language variable fillcolor, which itself defaults to the empty string, signaling "no filling". πŸ•³οΈ
  • from location β€” specifies the location where the line element begins. Defaults to the current location as maintained by the layouting system. 🏁
  • justify left|center|right β€” specifies how multi-line text associated with the element is positioned within its box. The value is ignored if no text was specified for the element. If not specified, the system falls back to the value taken from the language variable justify, which itself defaults to left. The legal values are left, right, and center. πŸ“
  • noturn β€” specifies that the direction of the line element at its end is not propagated to the layout management. If not specified, the direction of the line becomes the new direction of the layout. πŸ”„
  • smooth β€” okay so this one makes the line element use bezier splines ✨ if you don’t specify it, the lines get drawn exactly through the specified waypoints, with zero smooth curves. no cap.
  • stroke width β€” IMAGE: figure-20-style-stroke this sets how wide the lines drawn for the element are, in pixels. if it’s not specified, the system falls back to the value from the language variable linewidth, which itself defaults to 1. slay.
  • style spec β€” IMAGE: figure-18-style-dash this sets the style used to draw the element’s lines. if it’s not specified, the system falls back to the value from the language variable linestyle, which itself defaults to solid lines. the legal values are all those accepted by Tk_GetDash [http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], plus all the ones listed below πŸ‘‡
    • solid, empty string β€” draws a solid line.
    • dash, dashed, - β€” draws a dashed line.
    • dot, dotted, . β€” draws a dotted line.
    • dash-dot, -. β€” draws a dash-dotted line.
    • dash-dot-dot, -.. β€” draws a dash-dot-dotted line.

note that the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command using them as argument. iykyk πŸ’…

  • text string β€” this specifies the text to associate with the element. defaults to nothing. when specified multiple times, the actually shown text is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element. cute.
  • textcolor spec β€” this specifies the color used to draw the text of an element with. ignored if there is no text. if not specified, the system falls back to the value from the language variable textcolor, which itself defaults to black.
  • textfont spec β€” this specifies the font used to draw the text of an element with. ignored if there is no text. if not specified, the system falls back to the value from the language variable textfont, which itself defaults to Helvetica 12pt.
  • then location
  • then (<direction> ?length?)...
  • (<direction> ?length?)...

okay so those three are the intermediate-location crew 🫢 this attribute specifies an intermediate location the line element has to go through. it can be specified multiple times, with each use adding one additional location to the series which the line will go through. these locations are traversed in the order they were specified.

the location can be given explicitly, or as a series of directions with distances. in the latter case, the names of all known directions are accepted for the direction part. if no distance is specified for a direction, the system falls back to the value from the language variable movelength, which itself defaults to the pixel equivalent of 2 cm. the whole set of direction,distance pairs is treated as a series of translations which are added up to provide the final translation specifying the intermediate point (relative to the preceding point).

the last named direction is propagated to the layout system as the direction to follow. using noturn cannot override this behavior.

and finally, the names of the registered directions also serve as attribute commands, with an implicit attribute then in front of them.

if no intermediate or last location is specified for the line, the system falls back to a point movelength pixels away from the starting location, in the current direction as maintained by the layouting system.

  • to location β€” specifies the location where the line element ends. this attribute has no default. the default is handled by the attribute then, which makes it appear as if to has a default when not specified.
  • with corner β€” line elements are normally positioned absolutely, using the locations specified through the attributes from, then, and to. if at is specified, however, then these positions are translated a last time, moving the line’s corner named by the attribute with to the location given by this attribute. this means that with is effective if and only if the attribute at was specified as well for the line. periodt.

πŸ’« move attr πŸ’«

an open element with the corresponding corners, i.e. "start", "end", and "center". a move element is in essence an invisible line. while the main effect we’re interested in is the change it makes to the layout system, it is an actual element, i.e. it has the same corners as an ordinary line, and shows up in the history as well, allowing future references to all the places it touched. it handles the same attributes as line elements. lowkey iconic.

🧚 spline attr... 🧚

IMAGE: figure-02-spline an alias for the line element (see above), with the attribute smooth preset.

πŸ¦‹ text attr... πŸ¦‹

IMAGE: figure-02-text a closed element with the corresponding corners, i.e. the eight directions of the compass rose, and "center". it handles the attributes:

  • anchor name
  • ljust
  • rjust
  • above
  • below β€” IMAGE: figure-22-text-anchoring-3 specifies the anchor of the text which is to be placed at the element’s center, by name. i.e. this attribute defines the text’s position relative to the element’s center. the value is ignored if no text was specified for the element. if not specified, the system falls back to the value from the language variable anchor, which itself defaults to center. the legal values are all those accepted by Tk_GetAnchor [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm]. the commands without arguments are all shorthands with the anchor implied. note that they do not combine, only the last is used. for combined directions, the main attribute command anchor has to be used.
    • ljust β€” "anchor west"
    • rjust β€” "anchor east"
    • above β€” "anchor south"
    • below β€” "anchor north"
  • at location β€” specifies the location of the element’s corner named by the attribute with. defaults to the current location as maintained by the layouting system.
  • height length β€” specifies the height of the text element. defaults to the natural height of its text.
  • justify left|center|right β€” specifies how multi-line text associated with the element is positioned within its box. the value is ignored if no text was specified for the element. if not specified, the system falls back to the value from the language variable justify, which itself defaults to left. the legal values are left, right, and center.
  • text string β€” specifies the text to associate with the element. defaults to nothing. when specified multiple times, the actually shown text is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element.
  • textcolor spec β€” specifies the color used to draw the text of an element with. ignored if there is no text. if not specified, the system falls back to the value from the language variable textcolor, which itself defaults to black.
  • textfont spec β€” specifies the font used to draw the text of an element with. ignored if there is no text. if not specified, the system falls back to the value from the language variable textfont, which itself defaults to Helvetica 12pt.
  • width length β€” specifies the width of the text element. defaults to the natural width of its text.
  • with corner β€” specifies the corner of the element to place at the location given by the attribute at. defaults to the current corner as maintained by the layouting system, except if the value for at was specified by the user. in that case it defaults to center.

πŸŽ€ ATTRIBUTES πŸŽ€

the set of all attributes supported by all the element commands is shown below. while we speak of them as commands, and provide a syntax, they are not truly available as actual commands, but only as part of the arguments for an element command.

note that some of the attribute names are overloaded, i.e. have multiple, different, definitions. during processing of attributes for an element, the actual definition used is chosen based on the type of the element the processing is for.

further, as a catch-all clause, any attribute which could not be processed according to the definitions below will be treated as the argument of an implicit text attribute. bestie, that’s the safety net ✨

  • anchor name
  • ljust
  • rjust
  • above
  • below β€” IMAGE: figure-22-text-anchoring-3. This one sets the anchor of the text that's gonna sit at the element's center, by name πŸ’… like, it literally defines where the text lands relative to the center of the element. If you didn't give the element any text, this value just gets ignored, no drama. And if you don't specify it at all? The system falls back to whatever the language variable anchor says, and that one defaults to center. The legal values are all the ones Tk_GetAnchor accepts [http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm].

So the versions with no arguments are all shorthands with the anchor baked in. But bestie, listen β€” they do not combine, only the last one you write is used 😭 so if you want a combined direction you gotta use the main attribute command, anchor.

  • ljust β€” "anchor west"
  • rjust β€” "anchor east"
  • above β€” "anchor south"
  • below β€” "anchor north"
  • arrowhead spec β€” IMAGE: figure-19-style-arrowheads. Tells you where to draw arrowheads on the line element: at the beginning, at the end, at both ends, or none at all 🏹 If you don't specify it, the system falls back to the language variable arrowhead, which itself defaults to none. Legal values:
    • none, - β€” draw no arrowheads, like, at neither end of the line. Naked line, iconic.
    • start, first, <- β€” arrowhead at the beginning of the line only, not the end.
    • end, last, -> β€” arrowhead at the end of the line only, not the beginning.
    • both, <-> β€” arrowheads at both ends. Double the slay.

Also note that the values "start", "end", "-", "->", "<-", and "<->" are all accepted as shorthands for the arrowhead command using them as argument ✨

  • aspect number β€” sets the aspect ratio (that's ratio of width to height, iykyk) of the diamond element πŸ”· And the way a default gets calculated when you don't specify it also depends on what you did with the width and height attributes, if anything:
    • If both width and height are specified then any aspect you threw in is ignored, because it's implicitly defined by the width and height anyway and they take precedence πŸ‘‘ A missing spec is ignored in that case too β€” no defaults required, we're good.
    • If aspect is specified and you also gave one of width or height, then the missing attribute is calculated from the two you did specify. No defaults needed here either 🫢
    • If only one of width or height is specified, the system uses a fallback for the aspect: the value from the language variable diamondaspect, which itself defaults to 2.
    • If none of width or height is specified, the system falls back for the width to the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. For the aspect it uses either your user-specified value or the default taken as described in the previous paragraph ⭐
  • aspect number β€” this one sets the aspect ratio (again, ratio of width to height) of the ellipses used to draw the top and bottom of the drum element πŸ₯ If you don't specify it, the system falls back to the language variable drumaspect, which itself defaults to 0.35.
  • at location β€” specifies the location of the element's corner named by the attribute with. Defaults to the current location as maintained by the layouting system πŸ’–
  • at location β€” for line elements, okay so lines are normally positioned absolutely, using the locations given through the attributes from, then, and to. But if at is specified, then those positions get translated one last time, moving the line's corner named by with to the location given by this attribute πŸ¦‹
  • chop ?length? β€” sets the length of the line element to remove from the beginning and/or end. Defaults to nothing, ngl. If you specify it once, the chopping applies to both beginning and end of the line. If you specify it twice or more, the last two specifications are used, and applied to beginning and end of the line, in this order βœ‚οΈ And whenever you write the attribute without an explicit length, the system falls back to the language variable circleradius, which itself defaults to the pixel equivalent of 1 cm.
  • clockwise, cw β€” sets the direction of the arc element, here going clockwise πŸ”„ The complementary attribute is counterclockwise. If not specified, the system falls back to the language variable clockwise, which itself defaults to false, for counter-clockwise direction.
  • color spec β€” IMAGE: figure-21-style-colors. Sets the color used to draw the lines of the element 🎨 If not specified, the system falls back to the language variable linecolor, which itself defaults to black.
  • counterclockwise, ccw β€” sets the direction of the arc element, here going counter-clockwise πŸŒ€ The complementary attribute is clockwise. If not specified, the system falls back to the language variable clockwise, which itself defaults to false, for counter-clockwise direction.
  • diameter length, diam length β€” sets the diameter of the circle element, as a little alternative way to specify its radius β­• Effective if and only if the radius was not specified. I.e. if you specify both diameter and radius, then the radius info has precedence πŸ‘‘ This attribute has no default, because the defaults are taken from the radius.
  • fillcolor spec β€” IMAGE: figure-21-style-colors. Sets the color used to draw the inside of the element πŸ–οΈ If not specified, the system falls back to the language variable fillcolor, which itself defaults to the empty string, signaling "no filling".
  • from location β€” specifies the location where the line element begins. Defaults to the current location as maintained by the layouting system πŸ’«
  • from location β€” specifies the location where the arc element begins. Defaults to the current location as maintained by the layouting system πŸ’«
  • height length, ht length β€” specifies the height of the element. If not specified, the system falls back to the language variable boxheight, which itself defaults to the pixel equivalent of 2 cm πŸ“
  • height length β€” specifies the height of the diamond element πŸ”· And again, how a default gets calculated when you don't specify it depends on the aspect and width attributes, if any:
    • If both width and height are specified then any aspect spec is ignored, because it's implicitly defined in the width and height as well, and that takes precedence πŸ‘‘ A missing spec is ignored in that case too β€” no defaults required.
    • If aspect is specified and you gave one of width or height, then the missing attribute is calculated from the two which are specified. No defaults required in these cases either 🫢
    • If only one of width or height is specified, the system uses a fallback for the aspect: the value from the language variable diamondaspect, which itself defaults to 2.
    • If none of width or height is specified, the system falls back for the width to the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. For the aspect it uses either your user-specified value or the default taken as described in the previous paragraph ⭐
  • height length β€” specifies the height of the text element. Defaults to the natural height of its text, cute right? πŸ’œ
  • justify left|center|right β€” specifies how multi-line text associated with the element is positioned within its box πŸ“ The value is ignored if no text was specified for the element. If not specified, the system falls back to the language variable justify, which itself defaults to left. The legal values are left, right, and center.
  • noturn β€” says that the direction of the line element at its end is not propagated to the layout management πŸ™…β€β™€οΈ If not specified, the direction of the line becomes the new direction of the layout.
  • radius length, rad length β€” specifies the radius of the circle element β­• If not specified, the system falls back to the language variable circleradius, which itself defaults to the pixel equivalent of 1 cm.
  • radius length β€” specifies the radius of the arc element, or rather, the radius of the circle that the shown arc is a part of 🌈 If not specified, the system falls back to the language variable arcradius, which itself defaults to the pixel equivalent of 1 cm.
  • slant angle β€” specifies the angle by which the box element is slanted, in degrees πŸ“ If not specified, the system falls back to the language variable slant, which itself defaults to 90, i.e. vertical, no slant. 0 degrees is slanting straight east, pointing to the right. 90 degrees is slanting to the north, pointing straight up 🧭
  • smooth β€” specifies the use of bezier splines for the line element 〰️ If not specified, lines are drawn exactly through the specified waypoints, without any smooth curves.
  • stroke width β€” IMAGE: figure-20-style-stroke. Specifies the width of the lines drawn for the element, in pixels πŸ–ŒοΈ If not specified, the system falls back to the language variable linewidth, which itself defaults to 1.
  • style spec β€” IMAGE: figure-18-style-dash. Specifies the style used to draw the lines of the element ✨ If not specified, the system falls back to the language variable linestyle, which itself defaults to solid lines. The legal values are all those accepted by Tk_GetDash [http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], and additionally all which are listed below:
  • solid, empty string β€” draws a solid line πŸ’… (yes, the empty string counts, she's valid, we love her)
  • dash, dashed, - β€” draws a dashed line
  • dot, dotted, . β€” draws a dotted line
  • dash-dot, -. β€” draws a dash-dotted line
  • dash-dot-dot, -.. β€” draws a dash-dot-dotted line
okay so real talk: the values "solid", "dot(ted)", "dash(ed)", "dash-dot", and "dash-dot-dot" are all accepted as shorthands for the style command when you use them as its argument. iykyk 🫢
  • text string β€” specifies the text to associate with the element. Defaults to nothing. And here's the cute part: when you specify it multiple times, the text that actually shows up is the concatenation of the individual strings, stacked vertically, with the first string you specified being the topmost element ✨
  • textcolor spec β€” specifies the color used to draw the text of an element with. Ignored if there's no text. If you don't specify it, the system falls back to the value taken from the language variable textcolor, which itself defaults to black πŸ–€
  • textfont spec β€” specifies the font used to draw the text of an element with. Ignored if there's no text. If you don't specify it, the system falls back to the value taken from the language variable textfont, which itself defaults to Helvetica 12pt πŸŽ€
  • then location β€” see the next one, bestie, they're a matched set πŸ’–
  • then (<direction> ?length?)... β€” see below ⬇️
  • (<direction> ?length?)... β€” this attribute specifies an intermediate location the line element has to go through πŸ¦‹. You can specify it multiple times, and each use adds one additional location to the series the line will go through. These locations get traversed in the order they were specified.

The location can be given explicitly, or as a series of directions with distances. In that second case, the names of all known directions are accepted for the direction part. If no distance is specified for a direction, the system falls back to the value taken from the language variable movelength, which itself defaults to the pixel equivalent of 2 cm. The whole set of direction,distance pairs is treated as a series of translations which get added up to provide the final translation specifying the intermediate point (relative to the preceding point) πŸ”₯

heads up: the last named direction is propagated to the layout system as the direction to follow. The use of noturn is not able to override this behaviour. no cap, it just can't πŸ™ˆ

And at last, the names of the registered directions also serve as attribute commands, with an implicit attribute then in front of them πŸ‘‘

If no intermediate or last location is specified for the line, the system falls back to a point movelength pixels away from the starting location, in the current direction as maintained by the layouting system ✨

  • to location β€” specifies the location where the line element ends. This attribute has no default. The default is handled by the attribute then, which makes it appear as if to has a default when it's not specified πŸŽ€
  • to location β€” specifies the location where the arc element ends. Defaults to a location such that a 90-degree arc is drawn in the chosen direction, starting at from 🌈
  • width length / wid length β€” specifies the width of the element. If not specified the system falls back to the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm πŸ’…
  • width length β€” specifies the width of the diamond element. The manner in which a default is calculated when it's not specified also depends on the specifications of the attributes aspect and height, if any. Let's break that down, because it's giving ✨decision tree✨:
    • If both width and height are specified, then any specification of aspect is ignored, as it's implicitly defined in the width and height as well, and this takes precedence. A missing specification is ignored in that case as well β€” i.e. no defaults are required 🫢
    • If aspect is specified, and one of the attributes width or height, then the missing attribute is calculated from the two which are specified. No defaults are required for these cases either ⭐
    • If only one of the attributes width or height is specified, then the system uses a fallback for the aspect β€” the value taken from the language variable diamondaspect, which itself defaults to 2 πŸŽ€
    • If none of the attributes width or height is specified, then the system uses a fallback for the width β€” the value taken from the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. For the aspect it uses either the user-specified value or the default taken as described in the previous paragraph πŸ’œ
  • width length β€” specifies the width of the text element. Defaults to the natural width of its text 🌸
  • with corner β€” specifies the corner of the element to place at the location given by the attribute at. Defaults to the current corner as maintained by the layouting system, except if the value for at was specified by the user. In that case it defaults to center 🎯
  • with corner β€” line elements are normally positioned absolutely, using the locations specified through the attributes from, then, and to. If at is specified, however, then these positions are translated one last time, moving the line's corner named by the attribute with to the location given by this attribute. This means with is effective if and only if the attribute at was specified as well for the line πŸ’€ (conditional queen behaviour)

πŸ¦‹ CORNERS πŸ¦‹

Corners are named values for in elements, usually locations πŸ’–

  • The closed elements define corners for the compass rose, including the "center", and their "width" and "height" 🧭

IMAGE: figure-27-corners-closed

  • block elements additionally export all variables which were set during their definition as corners πŸ‘‘
  • The open elements, on the other hand, define "start", "end", and "center". The first two map to the locations originally provided through the attributes from and to of the element πŸŽ€

IMAGE: figure-28-corners-open

  • The center of line and move elements is the location halfway between the "start" and "end" corners β€” and this is regardless of any intermediate locations the element may have 😀
  • The line and move elements additionally name all their locations as corners using numbers as names, starting from 1 (equivalent to "start"), in order of traversal 🌈

IMAGE: figure-15-spline-1

  • The center of arc elements is the center of the circle the arc is part of β­•
  • The arc elements additionally define the compass rose of closed elements as well πŸ’«

🌸 NAMED DIRECTIONS 🌸

The named directions are commands which tell the layout system which direction to go when placing the next element without an explicit position specification 🧭. They can also be used as arguments to the attribute then, and to the command by for relative points β€” see there for the relevant syntax πŸ‘€

The diagram core defines the directions of the compass rose, plus a number of aliases. Full list is right below, bestie ⬇️

IMAGE: figure-27-corners-closed

This overlaps with the pre-defined corners for closed elements. This is used by the layout system: when we're going in direction X, the name of the opposite direction is the name of the corner at which the new element will be attached to the current position β€” and if this corner doesn't exist, the nearest actual corner by angle is used 🎯

  • west, w, left, l
  • south, s, down, bottom, bot, b
  • east, e, right, r
  • north, n, up, top, t
  • northwest, nw, up-left, upleft, leftup
  • northeast, ne, up-right, upright, rightup
  • southwest, sw, down-left, downleft, leftdown
  • southeast, se, down-right, downright, rightdown

πŸ’œ MISCELLANEOUS COMMANDS πŸ’œ

  • number cm
  • number mm
  • number inch
  • number pt

These commands let you specify distances and coordinates in metric and imperial units, returning the equivalent distance or coordinate in pixels, which is the unit used internally for all calculations πŸ“

important: the conversion factors are based on the result of tk scaling and are computed once, at the time the package is sourced. Future changes of the tk scaling factor have no effect. periodt πŸ’…
  • number number β€” this command takes the x and y coordinates of a location and returns the absolute point for it ✨

IMAGE: figure-50-point-cons-absolute

  • by distance direction β€” this command takes a distance and a direction (an angle in degrees, or a registered direction name) and returns the relative point for it, i.e. the delta or translation it represents πŸ¦‹

IMAGE: figure-51-point-cons-relative

also note the (dis)similarities to the directional specifications for the attribute then of line and move elements. Where we say here:
by 50 east
for the attribute we say:
... then east 50 ...
or just:
... then east ...

like, same energy, different outfit πŸŽ€

  • point1 + point2 β€” this command interprets two points as vectors and adds them together. If at least one of the points is absolute, the result is absolute as well. The result is a relative point if and only if both points are relative πŸ”₯

IMAGE: figure-48-point-vectoradd

  • point1 - point2 β€” this command interprets two points as vectors and subtracts the second from the first. If at least one of the points is absolute, the result is absolute as well. The result is a relative point if and only if both points are relative πŸ’€

IMAGE: figure-49-point-vectorsub

  • point by distance direction β€” this command is a more convenient, or at least shorter, form of:
[$point + [by $distance $direction]]

obsessed, honestly 🫢

  • point1 | point2 β€” this command calculates the projection of two points, i.e. the result is the point having the x-coordinate of point1 and the y-coordinate of point2 🎯

IMAGE: figure-31-point-projection

  • n between poin1 point2 β€” (yes, poin1, that's literally how it's written, don't come for me πŸ™ˆ)

IMAGE: figure-29-point-interpolation-1

okay so this command computes the point which is n*100 percent of the way between point1 and point2, and returns it as its result. This means that for

  • n == 0 β€” The result is point1.
  • n == 1 β€” The result is point2.
  • n == 0.5 β€” The result is half way between the two points.
  • etc.

Note that it is allowed to use values < 0 and > 1 for n πŸ’…


  • intersect elem1 elem2 β€” this one is giving geometry main character energy. It takes two open elements, computes the lines going through their "start"- and "end"-corners, and returns the point where these two lines intersect. It throws an error if the lines do not intersect, or are coincident. Also: IMAGE: figure-32-point-intersection πŸ¦‹
  • element names ?pattern? β€” Returns a list containing the names of all corners for the element. If a pattern is specified then only the names matching it (via string match) are returned. Otherwise all names are returned (equivalent to a default pattern of *). ✨
  • element corner β€” Returns the value for the corner of the element. This can be anything, including points and elements. versatile icon behavior πŸŽ€
  • element corner1 corner2... β€” This is a convenience shorthand for
[[[$elem $corner1] $corner2] ...]

assuming that the value for

[$elem $corner1]

is again an element. 🫢

  • element ?corner1... ?names ?pattern??]? β€” This is a convenience shorthand for
[[[$elem $corner1] ...] names ?pattern?]

assuming that the value for

[$elem $corner1]

is again an element. yes bestie, the brackets are doing a lot, we respect them πŸ’›

  • nth ?corner? β€” Asks the diagram history for the nth element created, searching from the beginning of the history (counting from 1) and returns it as its result. If the corner is specified then the value for this corner is returned instead. πŸ”₯
  • nth last ?corner? β€” Asks the diagram history for the nth element created, searching from the end of the history and returns it as its result. If the corner is specified then the value for this corner is returned instead. 🌈
  • nth shape ?corner? β€” Asks the diagram history for the nth element created, of the given shape, searching from the beginning of the history (counting from 1) and returns it as its result. If the corner is specified then the value for this corner is returned instead. ⭐
  • nth last shape ?corner? β€” Asks the diagram history for the nth element created, of the given shape, searching from the end of the history and returns it as its result. If the corner is specified then the value for this corner is returned instead. πŸ’«
  • last ?corner?
  • last shape ?corner? β€” Convenience commands mapping to "1st last" and "1st last shape". 🎯
  • 1st, 2nd, 3rd β€” Aliases for 1th, 2th, and 3th, for readability, usable whereever nth can ocur. (yes, that spelling is literally in the source β€” we love a typo moment) 😭

🌸 VARIABLES 🌸

The language context contains a number of predefined variables which hold the default values for various attributes. These variables, their uses, and values are:

  • anchor β€” The default value for the attribute anchor. Initialized to center. The legal values are all those accepted by Tk_GetAnchor (http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm). πŸŽ€
  • arcradius β€” The default value for the attribute radius of arc elements. Initialized to the pixel equivalent of 1 cm. πŸŒ€
  • arrowhead β€” The default value for the attribute arrowhead. Initialized to none. The legal values are:
    • none, - β€” Draw no arrowheads, at neither end of the line.
    • start, first, <- β€” Draw an arrowhead at the beginning of the line, but not at its end.
    • end, last, -> β€” Draw an arrowhead at the end of the line, but not at its beginning.
    • both, <-> β€” Draw arrowheads at both ends of the line. 🏹
  • boxheight β€” The default value for the attribute height of box, diamond and ellipse elements. Initialized to the pixel equivalent of 2 cm. πŸ“¦
  • boxwidth β€” The default value for the attribute width of box, diamond and ellipse elements. Initialized to the pixel equivalent of 2 cm. 🎁
  • clockwise β€” The default value for the attributes clockwise and counterclockwise of arc elements. Initialized to False, for counter-clockwise direction. πŸ”„
  • circleradius β€” The default value for the attribute radius of circle elements, and also the default for the attribute chop, when specified without an explicit length. Initialized to the pixel equivalent of 1 cm. β­•
  • drumaspect β€” The default value for the attribute aspect of drum elements. Initialized to 0.35. πŸ₯
  • fillcolor β€” The default value for the attribute fillcolor of all elements which can be filled. Initialized to the empty string, signaling that the element is not filled. 🎨
  • justify β€” The default value for the attribute justify. Initialized to left. The legal values are left, right, and center. πŸ“
  • linecolor β€” The default value for the attribute color of all elements having to draw lines (all but text). Initialized to black. πŸ–€
  • linestyle β€” The default value for the attribute style of all elements having to draw some line. Initialized to solid. The legal values are all those accepted by Tk_GetDash (http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm), and additionally all which are listed below:
    • solid, empty string β€” Draw solid line.
    • dash, dashed, - β€” Draw a dashed line.
    • dot, dotted, . β€” Draw a dotted line.
    • dash-dot, -. β€” Draw a dash-dotted line
    • dash-dot-dot, -.. β€” Draw a dash-dot-dotted line. ✏️
  • linewidth β€” The default value for the attribute stroke of all elements having to draw some line. Initialized to 1 (pixels). πŸ“
  • movelength β€” The default value for the directional specification of intermediate locations by the attribute then of line and move elements. Initialized to the pixel equivalent of 2 cm. πŸšΆβ€β™€οΈ
  • slant β€” The default value for the attribute slant of box elements. Initialized to 90 degrees, i.e. slant straight up. πŸ“
  • textcolor β€” The default value for the attribute textcolor of all elements having to draw some text. Initialized to black. πŸ–€
  • textfont β€” The default value for the attribute textfont of all elements having to draw some text. Initialized to Helvetica 12pt. πŸ”€

πŸ’œ DIAGRAM CLASSES πŸ’œ

The intended audience of this section are developers wishing to work on the internals of the diagram package. Regular users of diagram can skip this section without missing anything. 🫢

The main information seen here is the figure below, showing the hierarchy of the classes implementing diagram.

IMAGE: figure-00-dependencies πŸ¦‹

At the bottom, all at the same level are the supporting packages like snit, etc. These can all be found in Tcllib. 🌈

Above them is the set of diagram classes implementing the various aspects of the system, i.e.:

  • diagram β€” The main class, that which is seen by the user. πŸ‘‘
  • diagram::core β€” The core engine, itself distributed over four helper classes. βš™οΈ
  • diagram::basic β€” The implementation of the standard shapes, like box, circle, etc., based on the extension features of the core. πŸ”·
  • diagram::element β€” Core support class, the database of created elements. It also keeps the history, i.e. the order in which elements were created. πŸ—‚οΈ
  • diagram::attribute β€” Core support class, the generic handling of definition and processing of attributes. 🏷️
  • diagram::direction β€” Core support class, the database of named directions. 🧭
  • diagram::navigation β€” Core support class, the state of layout engine, i.e. current position and direction, and operations on it. πŸ—ΊοΈ
  • diagram::point β€” General support class handling various vector operations. πŸ“

πŸŽ€ REFERENCES πŸŽ€

bestie, the heading is here, but the page doesn’t list anything under it β€” minimalist icon behavior, honestly. ✨

πŸ’€ BUGS, IDEAS, FEEDBACK πŸ’€

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category diagram of the Tklib Trackers (http://core.tcl.tk/tklib/reportlist). Please also report any ideas for enhancements you may have for either package and/or documentation. πŸ™ˆ

⭐ KEYWORDS ⭐

2D geometry, arc, arrow, box, canvas, circle, diagram, diamond, drawing, drum, ellipse, image, interpolation, intersection, line, move, picture, plane geometry, plotting, point, raster image, spline, text, vector 🧚

🌈 CATEGORY 🌈

Documentation tools πŸ‘‘


and that’s the page, bestie. Footer cuteness: source tklib, version 0.3, page diagram(n), plus the date line in its footer spot. mwah πŸ’‹

πŸ“¦ where this page comes from