diagram(3tk)
๐ฆ diagram(3tk) โ Documentation toolbox ๐ฆ
okay so bestie, welcome to the diagram manual page, but make it cute. This is part 1, and there are more parts coming, so don't go anywhere. ๐
๐ NAME ๐
diagram โ Diagram drawing
โจ 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 ๐ธ
Welcome to diagram, bestie! It's a package for the easy construction of diagrams (sic), i.e. 2D vector graphics, sometimes also called pictures. ๐
Not me being a whole layer on top of Tk's canvas... but no cap, this package is not a replacement for Tk's canvas. It's 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. Iconic behavior, honestly. โจ
This is similar to Brian Kernighan's PIC language for troff, which is the spiritual ancestor of this package. ๐ง
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. ๐ซถ
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. periodt.
::diagram objectName canvas ?script?โ The command creates a new instance of adiagramcontroller and returns the fully qualified name of the object command as its result. The new instance is connected to the specifiedcanvasobject, 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 thekey/valuepairs coming after thename.
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, where0points east (to the right) and90points 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.namewill 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:
- The list of canvas items the drawn element consists of.
- The dictionary of named locations in the element, its corners.
- 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. - 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.namewill 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 likenew aliasexcept 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 thekey/valuepairs coming after thename.
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 (Seeget) 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
where value is the value to insert, and dict is the dictionary of attributes and values collected so far ๐ซถ
The result of the command is the new dictionary of attributes. Slay.
aggregateโ this key is a boolean flag, and it only does anything if and only if the keymergewas not specified. It's optional, and if you don't specify it, it defaults toFalseโจ
If the key is effective, then False means the attribute's value gets set into the dictionary using the value of key key (see above ๐) as its index โ overwriting anything that was specified before. Rip to the old value ๐
If the key is effective, then True means the attribute's value gets added to the dictionary using the value of key key (again, see above) as its index, extending any previously specified value. Which means the final value of the attribute, as seen after processing, will be a list of all the collected values. It's giving collector energy ๐
defaultโ the value of this key 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 (peep the argument attributes of methodnew element๐).
Note that the connection is made through the value of key key, not through the attribute name per se. Important distinction bestie, don't skip it.
Further note: this command prefix is invoked even if a user specified attribute value is present. That's on purpose โ it lets the command go beyond just setting defaults, it can calculate and store derived values too. Iconic, honestly ๐
This key is optional. If an element requires this attribute but default is not specified, then nothing will be done. Nothing. Nada. Moving on ๐
The signature of the command prefix is:
cmdprefix init
- This method is run 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 is run 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 is run 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 the keydefaultis not specified. In that case it supplies a default handling fordefault, linking the attribute to a variable in the language context. Mutual besties, basically ๐ซ
The value for this key is a 2-element list containing the name of the variable to link to, and its initial value โ in that order. Order matters, don't freestyle it.
๐ฆ diagramObject unknown attribute cmdprefix
This method registers the command prefix with the subsystem that processes the attributes for element commands, telling it to call it when it encounters an attribute it's unable to handle on its own. Like "hey bestie, I literally can't, you take this one" ๐ญ
You're allowed to register more than one callback. These will be called in order of registration (i.e. first to last), until one of the callbacks accepts the current input. The command prefix is expected to conform to the following 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 โ and the first entry is 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 that the new state of the wordqueue is where the general processing shall continue. No cap.
Given the signature, the command has basically two ways of handling (rewriting) the attributes it recognizes:
- Replace the attribute (and arguments) with a different attribute and arguments.
- 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 the 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. Yes this is a whole security thing, do not play with it ๐ฅ
โจ 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 you can use 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. Double corners, double the fun, I don't make the rules ๐
It handles the attributes:
anchornameljustrjustabovebelowโIMAGE: figure-22-text-anchoring-3Specifies 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 variableanchor, which itself defaults tocenter. The legal values are all those accepted byTk_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 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"
clockwisecwโ Specifies the direction of the arc element, here going clockwise. The complementary attribute iscounterclockwise. If not specified, the system falls back to the value taken from the language variableclockwise, which itself defaults tofalse, for counter-clockwise direction.colorspec โIMAGE: figure-21-style-colorsSpecifies the color used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variablelinecolor, which itself defaults toblack. ๐คcounterclockwiseccwโ Specifies the direction of the arc element, here counter-clockwise. The complementary attribute isclockwise. If not specified, the system falls back to the value taken from the language variableclockwise, which itself defaults tofalse, for counter-clockwise direction. Yes, that's the same fallback as the clockwise one. That's just how it is, bestie ๐fillcolorspec โIMAGE: figure-21-style-colorsSpecifies the color used to draw the inside of the element. If not specified, the system falls back to the value taken from the language variablefillcolor, which itself defaults to the empty string, signaling "no filling". Empty string = no vibe inside ๐ซ๏ธfromlocation โ Specifies the location where the arc element begins. Defaults to the current location as maintained by the layouting system. โจjustifyleft|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 variablejustify, which itself defaults toleft. The legal values areleft,right, andcenter. ๐radiuslength โ 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 variablearcradius, which itself defaults to the pixel equivalent of 1 cm. So specific, love that for it ๐strokewidth โIMAGE: figure-20-style-strokeSpecifies 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 variablelinewidth, which itself defaults to1.stylespec โIMAGE: figure-18-style-dashSpecifies the style used to draw the lines of the element. If not specified, the system falls back to the value taken from the language variablelinestyle, which itself defaults to solid lines. The legal values are all those accepted byTk_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,-โ 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.
bestie, quick note: the valuessolid,dot(ted),dash(ed),dash-dot, anddash-dot-dotare all accepted as shorthands for thestylecommand, using them as the argument. slay.
textstring โ the text you wanna stick on the element. defaults to nothing (crickets). when you specify it multiple times, what actually shows up is the concatenation of the individual strings, stacked vertically, and the first string you specified is the topmost element. top-to-bottom vibes, fr fr.textcolorspec โ the color used to draw the text of an element with. ignored if there's no text (like, why would it matter). if you don't specify it, the system falls back to the value from the language variabletextcolor, which itself defaults to black.textfontspec โ the font used to draw the text of an element with. ignored if there's no text. if not specified, the system falls back to the language variabletextfont, which itself defaults toHelvetica 12pt.tolocation โ where the arc element ends. defaults to a location such that a 90-degree arc is drawn in the chosen direction, starting atfrom.
arrow attr...
--> attr...
<--> attr...
<--> attr...
IMAGE: figure-02-arrow โ an alias for the line element (see below), with the attribute arrowhead preset to ->, <->, or <-. the arrow is equivalent to -->.
block script attr...
a closed element with the corresponding corners โ i.e. the eight directions of the compass rose โ plus center. the main effect here is the aggregation of all the elements created by the script into one single element. which also means that 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, and not the elements it's composed of. โจ
the script has access to the current state of all variables in the language context. any changes to the variables will be reverted after execution of the block. however โ also โ any variables set in the script will be exported as corners of the element, which lets users define their own named locations in the block. cute, right?
regarding 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, i.e. the eight directions of the compass rose, and center. it handles these attributes:
anchorname,ljust,rjust,above,belowโIMAGE: figure-22-text-anchoring-3specifies 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 variableanchor, which itself defaults tocenter. the legal values are all those accepted byTk_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 one is used. for combined directions you gotta use the main attribute command,anchor.ljustโ that'sanchor westrjustโ that'sanchor eastaboveโ that'sanchor southbelowโ that'sanchor north
atlocation โ specifies the location of the element's corner named by the attributewith. defaults to the current location as maintained by the layouting system.colorspec โIMAGE: figure-21-style-colorsspecifies the color used to draw the lines of the element. if not specified, the system falls back to the value taken from the language variablelinecolor, which itself defaults to black.fillcolorspec โIMAGE: figure-21-style-colorsspecifies the color used to draw the inside of the element. if not specified, the system falls back to the value taken from the language variablefillcolor, which itself defaults to the empty string, signaling "no filling". so like, hollow, mysterious, iconic.heightlengthhtlength โ specifies the height of the element. if not specified, the system falls back to the value taken from the language variableboxheight, which itself defaults to the pixel equivalent of 2 cm.justifyleft|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 variablejustify, which itself defaults toleft. the legal values areleft,right, andcenter.slantangle โ specifies 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 variableslant, which itself defaults to90, i.e. vertical, no slant.0degrees is slanting straight east, pointing to the right.90degrees is slanting to the north, pointing straight up.strokewidth โIMAGE: figure-20-style-strokespecifies 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 variablelinewidth, which itself defaults to1.stylespec โIMAGE: figure-18-style-dashspecifies the style used to draw the lines of the element. if not specified, the system falls back to the value taken from the language variablelinestyle, which itself defaults to solid lines. the legal values are all those accepted byTk_GetDash(http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm), and additionally all of these listed below: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.
also: the valuessolid,dot(ted),dash(ed),dash-dot, anddash-dot-dotare all accepted as shorthands for thestylecommand using them as argument. periodt.
textstring โ 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.textcolorspec โ 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 variabletextcolor, which itself defaults to black.textfontspec โ 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 variabletextfont, which itself defaults toHelvetica 12pt.widthlengthwidlength โ specifies the width of the element. if not specified, the system falls back to the value taken from the language variableboxwidth, which itself defaults to the pixel equivalent of 2 cm.withcorner โ specifies the corner of the element to place at the location given by the attributeat. defaults to the current corner as maintained by the layouting system, except if the value foratwas specified by the user. in that case it defaults tocenter.
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 these attributes:
anchorname,ljust,rjust,above,belowโIMAGE: figure-22-text-anchoring-3specifies 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 variableanchor, which itself defaults tocenter. the legal values are all those accepted byTk_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 one is used. for combined directions the main attribute command,anchor, has to be used.ljustโ that'sanchor westrjustโ that'sanchor east
aboveโ shorthand for"anchor south", that's it, that's the whole vibe ๐belowโ and this one is"anchor north", no cap โจ
atlocation โ says where to put the corner of the element that thewithattribute names. Don't specify it? It defaults to whatever the current location is, as the layouting system keeps track of it. ๐colorspec โ (IMAGE: figure-21-style-colors) the color used to draw the element's lines. If you don't specify it, the system falls back to the value from the language variablelinecolor, which itself defaults to black. ๐คdiameterlengthdiamlength โ the diameter of the circle element, which is a whole alternate way to specify its radius. Effective if and only if the radius was not specified. I.e. if bothdiameterandradiusare specified, then the radius info has precedence. This attribute has no default, because the defaults are taken from the radius. ๐fillcolorspec โ (IMAGE: figure-21-style-colors) the color used to draw the inside of the element. Not specified? Then the system falls back to the language variablefillcolor, which itself defaults to the empty string โ which signals "no filling". ๐ซjustifyleft|center|rightโ how multi-line text associated with the element is positioned within its box. This value is ignored if no text was specified for the element. If you don't specify it, the system falls back to the language variablejustify, which itself defaults toleft. Legal values areleft,right, andcenter. ๐radiuslengthradlength โ the radius of the circle element. If not specified, the system falls back to the language variablecircleradius, which itself defaults to the pixel equivalent of 1 cm. ๐ธstrokewidth โ (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 language variablelinewidth, which itself defaults to1. ๐๏ธstylespec โ (IMAGE: figure-18-style-dash) the style used to draw the element's lines. If not specified, the system falls back to the language variablelinestyle, which itself defaults to solid lines. The legal values are all of the ones accepted byTk_GetDash[http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], plus every one listed below, bestie: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 valuessolid,dot(ted),dash(ed),dash-dot, anddash-dot-dotare all accepted as shorthands for the style command using them as argument. ๐ซ
textstring โ the text to associate with the element. Defaults to nothing. When you specify it multiple times, the text actually shown is the concatenation of the individual strings, vertically stacked, with the first string specified being the topmost element. ๐textcolorspec โ 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 language variabletextcolor, which itself defaults to black. ๐คtextfontspec โ 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 language variabletextfont, which itself defaults toHelvetica 12pt. โ๏ธwithcorner โ the corner of the element to place at the location given by theatattribute. Defaults to the current corner as maintained by the layouting system โ except if the value foratwas specified by the user. In that case it defaults tocenter. ๐
diamondattr...<>attr... โ (IMAGE: figure-02-diamond) a closed element with the corresponding corners, i.e. the eight directions of the compass rose, plus"center". It handles these attributes, babes ๐anchornameljustrjustabovebelowโ (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 language variableanchor, which itself defaults tocenter. The legal values are all those accepted byTk_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 one is used. For combined directions, the main attribute commandanchorhas to be used. ๐งญljustโ"anchor west"rjustโ"anchor east"aboveโ"anchor south"belowโ"anchor north"
aspectnumber โ the aspect ratio, i.e. the ratio of width to height, of the diamond element. The manner in which a default is calculated when it's not specified also depends on the specifications of the attributeswidthandheight, if any. Here's the tea:- If both
widthandheightare specified, then any specification ofaspectis ignored, since it's implicitly defined in thewidthandheightas well, and that takes precedence. A missing specification is ignored in that case as well, i.e. no defaults are required. - If the
aspectis specified, and one of the attributeswidthorheight, 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
widthorheightis specified, then the system uses a fallback for the aspect โ the value taken from the language variablediamondaspect, which itself defaults to2. - If none of the attributes
widthorheightis specified, then the system uses a fallback for the width โ the value taken from the language variableboxwidth, 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. ๐
- If both
atlocation โ the location of the element's corner named by the attributewith. Defaults to the current location as maintained by the layouting system. ๐colorspec โ (IMAGE: figure-21-style-colors) the color used to draw the element's lines. If not specified, the system falls back to the value taken from the language variablelinecolor, which itself defaults to black. ๐คfillcolorspec โ (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 variablefillcolor, which itself defaults to the empty string, signaling "no filling". ๐ซheightlength โ the height of the diamond element. The manner in which a default is calculated when it's not specified also depends on the specifications of the attributesaspectandwidth, if any. Same energy asaspect, so let's run it back:- If both
widthandheightare specified, then any specification ofaspectis ignored, since it's implicitly defined in thewidthandheightas well, and that takes precedence. A missing specification is ignored in that case as well, i.e. no defaults are required. - If the
aspectis specified, and one of the attributeswidthorheight, 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
widthorheightis specified, then the system uses a fallback for the aspect โ the value taken from the language variablediamondaspect, which itself defaults to2. - If none of the attributes
widthorheightis specified, then the system uses a fallback for the width โ the value taken from the language variableboxwidth, 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. ๐
- If both
justifyleft|center|rightโ 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 variablejustify, which itself defaults toleft. The legal values areleft,right, andcenter. ๐
stroke widthโ how thick are the lines of this element, in pixels? โจ (pic:IMAGE: figure-20-style-stroke). Leave it out and the system falls back to the language variablelinewidth, which itself defaults to1.style specโ the style the element's lines get drawn in ๐ (pic:IMAGE: figure-18-style-dash). Leave it out and it falls back to the language variablelinestyle, which defaults to solid lines. Legal values = everythingTk_GetDashaccepts athttp://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm, plus 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 linedash-dot-dot,-..โ Draw a dash-dot-dotted line.
Also, heads up: 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 you want associated with the element. Defaults to nothing. Specify it multiple times and what actually shows is the concatenation of all the individual strings, stacked vertically, with the first string you specified sitting on top. ๐ซถtextcolor specโ the color the element's text gets drawn in. Ignored if there's no text. Leave it out and it falls back to the language variabletextcolor, which defaults to black.textfont specโ the font the element's text gets drawn in. Ignored if there's no text. Leave it out and it falls back to the language variabletextfont, which defaults toHelvetica 12pt.width lengthโ the width of the diamond element. How the default gets calculated when you don't specify it also depends on the attributesaspectandheight, if any. Here's the whole tea:- If both
widthandheightare specified, then anyaspectspecification is ignored, since it's implicitly defined bywidthandheightanyway, and those take precedence. A missing specification is ignored in that case too โ no defaults required, periodt. - If
aspectis specified along with one ofwidthorheight, the missing attribute is calculated from the two that are specified. No defaults required here either. - If only one of
widthorheightis specified, the system uses a fallback for the aspect: the value from the language variablediamondaspect, which defaults to2. - If none of
widthorheightis specified, the system uses a fallback for the width: the value from the language variableboxwidth, which defaults to the pixel equivalent of2 cm. For the aspect it uses either your value or the default described in the paragraph above.
- If both
with cornerโ which corner of the element gets placed at the location given by the attributeat. Defaults to the current corner as maintained by the layouting system, except if the value foratwas specified by the user โ in that case it defaults tocenter.
๐ฅ drum attr...
A closed element with the corresponding corners, aka the eight directions of the compass rose plus "center". ๐ (pic: IMAGE: figure-02-drum) It handles the attributes:
anchor nameljustrjustabovebelowโ 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. ๐ฏ (pic:IMAGE: figure-22-text-anchoring-3). 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 variableanchor, which itself defaults tocenter. The legal values are all those accepted byTk_GetAnchorathttp://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 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"
aspect numberโ the aspect ratio, i.e. ratio of width to height, of the ellipses 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 variabledrumaspect, which itself defaults to0.35. ๐ฅat locationโ the location of the element's corner named by the attributewith. Defaults to the current location as maintained by the layouting system.color specโ the color used to draw the lines of the element ๐จ (pic:IMAGE: figure-21-style-colors). If not specified the system falls back to the value taken from the language variablelinecolor, which itself defaults to black.fillcolor specโ the color used to draw the inside of the element ๐ (pic:IMAGE: figure-21-style-colors). If not specified the system falls back to the value taken from the language variablefillcolor, which itself defaults to the empty string, signaling"no filling".height lengthht lengthโ the height of the element. If not specified the system falls back to the value taken from the language variableboxheight, which itself defaults to the pixel equivalent of2 cm.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. If not specified the system falls back to the value taken from the language variablejustify, which itself defaults toleft. The legal values areleft,right, andcenter.stroke widthโ the width of the lines drawn for the element, in pixels โจ (pic:IMAGE: figure-20-style-stroke). If not specified the system falls back to the value taken from the language variablelinewidth, which itself defaults to1.style specโ the style used to draw the lines of the element ๐ (pic:IMAGE: figure-18-style-dash). If not specified the system falls back to the value taken from the language variablelinestyle, which itself defaults to solid lines. The legal values are all those accepted byTk_GetDashathttp://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm, plus 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 linedash-dot-dot,-..โ Draw a dash-dot-dotted line.
And 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. ๐
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 with. Ignored if there is no text. If not specified the system falls back to the value taken from the language variabletextcolor, which itself defaults to black.textfont specโ 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 variabletextfont, which itself defaults toHelvetica 12pt.width lengthwid lengthโ the width of the element. If not specified the system falls back to the value taken from the language variableboxwidth, which itself defaults to the pixel equivalent of2 cm.with cornerโ the corner of the element to place at the location given by the attributeat. Defaults to the current corner as maintained by the layouting system, except if the value foratwas specified by the user. In that case it defaults tocenter.
๐ฅ ellipse attr...
A closed element with the corresponding corners โ yep, the eight directions of the compass rose, and "center". ๐ธ (pic: IMAGE: figure-02-ellipse) It handles the attributes:
anchor nameljustrjustโ shorthand for"anchor east"๐aboveโ shorthand for"anchor south"โฌ๏ธbelowโ shorthand for"anchor north"โฌ๏ธ
(๐ธ IMAGE: figure-22-text-anchoring-3)
okay so let's talk about what anchor actually means, bestie. It sets the anchor of the text that's gonna sit at the element's center, and you do it by name. Which is a fancy way of saying: it decides where the text sits relative to that center point. If you didn't give the element any text, this value gets ignored โ like, nothing to anchor, girl. If you don't specify it, the system falls back to the value from the language variable anchor, and that itself defaults to center. The legal values are all the ones Tk_GetAnchor accepts: http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm
And the no-argument commands up there are all just shorthands with the anchor baked in. But read this part carefully: they do not combine โ only the last one you say counts. If you want a combined direction, you gotta use the main attribute command, anchor, directly. iykyk ๐
at location
Sets the location of the element's corner named by the with attribute. If you don't say anything, it defaults to whatever the current location is โ the layouting system keeps track of that for you. ๐
color spec
(๐ธ IMAGE: figure-21-style-colors)
The color used to draw the lines of the element. Not specified? 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. Not specified? Falls back to the language variable fillcolor, which itself defaults to the empty string โ and that's the signal for "no filling". So like, hollow. Iconic. ๐
height length
ht length
The height of the element. Not specified? Falls back to the language variable boxheight, which itself defaults to the pixel equivalent of 2 cm. ๐
justify left|center|right
How multi-line text that's attached to the element gets positioned inside its box. Ignored if the element has no text โ like, no text, nothing to justify, periodt. Not specified? Falls back to the language variable justify, which itself defaults to left. The legal values are left, right, and center. โจ
stroke width
(๐ธ IMAGE: figure-20-style-stroke)
The width of the lines drawn for the element, in pixels. Not specified? Falls back to 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. Not specified? Falls back to the language variable linestyle, which itself defaults to solid lines. The legal values are everything Tk_GetDash accepts: http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm โ plus all the extras listed right here:
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 the argument. Slay. ๐
text string
The text you wanna associate with the element. Defaults to nothing. And here's the fun part โ when you specify it multiple times, the text that actually shows up is the concatenation of all the individual strings, stacked vertically, with the first string you specified being the topmost element. Stack 'em up bestie. ๐ฅ
textcolor spec
The color used to draw the element's text. Ignored if there's no text. Not specified? Falls back to the language variable textcolor, which itself defaults to black. ๐ค
textfont spec
The font used to draw the element's text. Ignored if there's no text. Not specified? Falls back to the language variable textfont, which itself defaults to Helvetica 12pt. ๐ค
width length
wid length
The width of the element. Not specified? Falls back to the language variable boxwidth, which itself defaults to the pixel equivalent of 2 cm. ๐
with corner
Which corner of the element gets placed at the location given by the at attribute. Defaults to the current corner as maintained by the layouting system โ except if you specified a value for at yourself. In that case it defaults to center. ๐ฏ
line attr...
-- attr...
(๐ธ IMAGE: figure-02-line)
It's an open element with the matching corners, i.e. "start", "end", and "center". (And yeah, -- is just the other way to write it.) It handles these attributes:
anchor name
ljust
rjust
above
below
(๐ธ IMAGE: figure-22-text-anchoring-3)
Sets the anchor of the text that's to be placed at the element's center, by name. Translation: 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 you don't specify it, the system falls back to the value from the language variable anchor, which itself defaults to center. Legal values are all the ones Tk_GetAnchor accepts: 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 one 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
(๐ธ IMAGE: figure-19-style-arrowheads)
Where to draw arrowheads on the line element: at the beginning or end, at both ends, or none at all. Not specified? Falls back to the language variable arrowhead, which itself defaults to none. Legal values:
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. โ๏ธ
And note: the values "start", "end", "-", "->", "<-", and "<->" are all accepted as shorthands for the arrowhead command using them as the argument. ๐น
at location
Line elements are normally positioned absolutely, using the locations specified 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 the with attribute to the location given by this attribute. ๐
chop ?length?
The length of the line element to remove from the beginning and/or end. Defaults to nothing. 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 they get applied to the beginning and end of the line, in that order. Whenever the attribute is specified without an explicit length, the system falls back to the value from the language variable circleradius, which itself defaults to the pixel equivalent of 1 cm โ๏ธ
color spec
(๐ธ IMAGE: figure-21-style-colors)
The color used to draw the lines of the element. Not specified? 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. Not specified? Falls back to the language variable fillcolor, which itself defaults to the empty string, signaling "no filling". ๐
from location
Where the line element begins. Defaults to the current location as maintained by the layouting system. ๐ฉ
justify left|center|right
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. Not specified? Falls back to the language variable justify, which itself defaults to left. 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 it's not specified, the direction of the line becomes the new direction the layout. ๐ช๏ธ
smoothโ bestie this one turns ON bezier splines for the line element ๐ skip it and the lines get drawn exactly through the waypoints you specified, zero smooth curves, no cap.stroke widthโIMAGE: figure-20-style-strokeโ how wide (in pixels) the lines drawn for the element are. Don't specify it and the system falls back to whateverlinewidthsays, andlinewidthitself defaults to1.style specโIMAGE: figure-18-style-dashโ the style used to draw the element's lines. Not specified? Then it falls back to the language variablelinestyle, which itself defaults to solid lines. Legal values are everythingTk_GetDashaccepts (http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm), plus 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 linedash-dot-dot,-..โ draw a dash-dot-dotted line.
Heads up bestie:solid,dot(ted),dash(ed),dash-dot, anddash-dot-dotare all accepted as shorthands for the style command when you pass them as an argument. ๐
text stringโ the text to associate with the element. Defaults to nothing at all ๐. When 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 an element's text with. Ignored if there's no text. Not specified? Falls back to the language variabletextcolor, which itself defaults toblack.textfont specโ the font used to draw an element's text with. Ignored if there's no text. Not specified? Falls back to the language variabletextfont, which itself defaults toHelvetica 12pt.then locationthen (<direction> ?length?)...(<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 more location to the series the line will go through. These locations get traversed in the order you specified them, fr fr.
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 you don't give a distance 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 give 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 is not able to override this behaviour. ๐
And lastly, the names of the registered directions also serve as attribute commands, with an implicit attribute then in front of them. iykyk.
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 where the line element ends. This attribute has no default. The default is handled by the attributethen, which makes it look liketohas a default when you don't specify it.with cornerโ line elements are normally positioned absolutely, using the locations specified through the attributesfrom,then, andto. But ifatis specified, then those positions get translated one last time, moving the line's corner named by the attributewithto the location given by this attribute. Which meanswithis effective if and only if the attributeatwas specified for the line as well. ๐
๐ซฅ move attr
An open element with the corresponding corners, i.e. "start", "end", and "center". A move element is basically an invisible line. The main effect we care about is the change it makes to the layout system, but it's a real element โ same corners as an ordinary line, and it shows up in the history too, so future references can point at all the places it touched. It handles the same attributes as line elements.
๐ spline attr...
IMAGE: figure-02-spline โ an alias for the line element (see above), with the attribute smooth preset. Obsessed. โจ
๐ 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 these attributes:
anchor nameljustrjustabovebelowIMAGE: figure-22-text-anchoring-3โ specifies the anchor of the text which is to be placed at the element's center, by name. So like, 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. Not specified? Falls back to the language variableanchor, which itself defaults tocenter. The legal values are all thoseTk_GetAnchoraccepts (http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm). The commands with no 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 attributewith. Defaults to the current location as maintained by the layouting system.height lengthโ the height of the text element. Defaults to the natural height of its text.justify left|center|rightโ 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. Not specified? Falls back to the language variablejustify, which itself defaults toleft. Legal values:left,right, andcenter.text stringโ the text to associate with the element. Defaults to nothing. When specified multiple times, the text that actually shows up 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 an element's text with. Ignored if there is no text. Not specified? Falls back to the language variabletextcolor, which itself defaults toblack.textfont specโ the font used to draw an element's text with. Ignored if there is no text. Not specified? Falls back to the language variabletextfont, which itself defaults toHelvetica 12pt.width lengthโ the width of the text element. Defaults to the natural width of its text.with cornerโ the corner of the element to place at the location given by the attributeat. Defaults to the current corner as maintained by the layouting system, except if the value foratwas specified by the user. In that case it defaults tocenter.
๐ ATTRIBUTES โจ
The set of all attributes supported by all the element commands is shown below. And yeah, we call them commands and give you a syntax, but they're not truly available as actual commands โ they only exist as part of the arguments for an element command. ๐คซ
Note that some of the attribute names are overloaded, i.e. they have multiple, different definitions. When attributes are being processed for an element, the actual definition used is chosen based on the type of the element the processing is for.
And 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. ๐
anchor nameljustrjustabovebelowโ IMAGE: figure-22-text-anchoring-3 tells the system which anchor point of the text gets parked at the element's center โ like, by name. Basically: this is where the text sits relative to the center of the element. If the element has no text, this whole thing gets ignored, no cap. And if you don't set it? It falls back to the value of the language variableanchor, which itself defaults tocenter. The legal values are literally all the onesTk_GetAnchor[http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm] accepts. The argument-less commands below are all just shorthands with the anchor baked in โ and bestie, they do not stack. Only the last one you use counts. Want to combine directions? You gotta use the main attribute commandanchorfor that. Periodt.ljustโ same as"anchor west"rjustโ same as"anchor east"aboveโ same as"anchor south"belowโ same as"anchor north"
arrowhead specโ IMAGE: figure-19-style-arrowheads says where arrowheads go on the line element: at the start, the end, both ends, or nowhere at all. If you don't specify, it falls back to the language variablearrowhead, which itself defaults tonone. The legal values are:none,-โ draw no arrowheads, neither end. Nothing. Silence. ๐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. Main character energy at every edge. โจ
And note: the values "start", "end", "-", "->", "<-", and "<->" are all accepted as shorthands for the arrowhead command, just passed in as its argument.
aspect numberโ sets the aspect ratio (that's width-to-height, btw) of the diamond element. How a default gets worked out when you don't specify one also depends on whether you setwidthandheight. Here's the tea:- If both
widthandheightare specified, then anyaspectyou set is ignored โ it's already implied by width and height, and that takes precedence. A missing spec is also just ignored in that case, so no defaults needed at all. - If
aspectis specified and one ofwidthorheightis too, the missing one gets calculated from the two you did give. Again, no defaults required for this case. - If only one of
widthorheightis specified, the system uses a fallback foraspect: the value of the language variablediamondaspect, which itself defaults to2. - If neither
widthnorheightis specified, the system uses a fallback for the width โ the language variableboxwidth, which itself defaults to the pixel equivalent of2 cm. For the aspect it uses either your value or the default described in the previous paragraph.
- If both
aspect numberโ this one sets the aspect ratio (width to height again) 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 variabledrumaspect, which itself defaults to0.35.at locationโ sets the location of the element's corner named by thewithattribute. Defaults to the current location as maintained by the layouting system.at locationโ okay so line elements are normally positioned absolutely, using the locations given through thefrom,then, andtoattributes. But ifatis specified, those positions get translated one last time, moving the line's corner named bywithto the location given by this attribute. Sneaky little final nudge. ๐ฆchop ?length?โ sets how much length of the line element to remove from the beginning and/or end. Defaults to nothing. Specify it once and the chopping applies to both beginning and end. Specify it twice or more and the last two specifications are used โ applied to beginning and end, in that order. Whenever you use the attribute without an explicit length, the system falls back to the language variablecircleradius, which itself defaults to the pixel equivalent of1 cm.clockwise,cwโ sets the direction of the arc element, here going clockwise. The complementary attribute iscounterclockwise. If not specified, the system falls back to the language variableclockwise, which itself defaults tofalseโ meaning 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 variablelinecolor, which itself defaults toblack. Classic. Iconic. ๐คcounterclockwise,ccwโ sets the direction of the arc element, here going counter-clockwise. The complementary attribute isclockwise. If not specified, the system falls back to the language variableclockwise, which itself defaults tofalse, for counter-clockwise direction.diameter length,diam lengthโ sets the diameter of the circle element, as an alternate way to give its radius. It's effective if and only if the radius wasn't specified โ so if bothdiameterandradiusare set, the radius info wins, periodt. This attribute has no default, because the defaults are taken fromradius.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 variablefillcolor, which itself defaults to the empty string โ that's the signal for "no filling". Empty string = stay hollow, bestie. ๐ซถfrom locationโ sets the location where the line element begins. Defaults to the current location as maintained by the layouting system.from locationโ sets the location where the arc element begins. Defaults to the current location as maintained by the layouting system.height length,ht lengthโ sets the height of the element. If not specified, the system falls back to the language variableboxheight, which itself defaults to the pixel equivalent of2 cm.height lengthโ sets the height of the diamond element. How a default gets calculated when you skip it also depends on whether you setaspectandwidth. So, buckle up:- If both
widthandheightare specified, anyaspectyou set is ignored โ it's implicitly defined by width and height, and that takes precedence. A missing spec is ignored in that case too, so no defaults needed. - If
aspectis specified and one ofwidthorheightis, the missing attribute is calculated from the two that are specified. No defaults required here either. - If only one of
widthorheightis specified, the system uses a fallback foraspect: the language variablediamondaspect, which itself defaults to2. - If neither
widthnorheightis specified, the system uses a fallback for the width โ the language variableboxwidth, which itself defaults to the pixel equivalent of2 cm. For the aspect it uses either your value or the default from the previous paragraph.
- If both
height lengthโ sets the height of the text element. Defaults to the natural height of its text. It just knows its own size, okay? ๐justify left|center|rightโ sets how multi-line text attached to the element is positioned inside its box. Ignored entirely if there's no text on the element. If not specified, the system falls back to the language variablejustify, which itself defaults toleft. Legal values areleft,right, andcenter.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โ sets the radius of the circle element. If not specified, the system falls back to the language variablecircleradius, which itself defaults to the pixel equivalent of1 cm.radius lengthโ sets the radius of the arc element โ or rather, the radius of the circle that the shown arc is a piece of. If not specified, the system falls back to the language variablearcradius, which itself defaults to the pixel equivalent of1 cm.slant angleโ sets the angle by which the box element is slanted, in degrees. If not specified, the system falls back to the language variableslant, which itself defaults to90โ that's vertical, no slant.0degrees slants straight east, pointing right.90degrees slants north, pointing straight up. ๐smoothโ turns on bezier splines for the line element. If not specified, lines get drawn exactly through the specified waypoints, no smooth curves anywhere.stroke widthโ IMAGE: figure-20-style-stroke sets the width of the lines drawn for the element, in pixels. If not specified, the system falls back to the language variablelinewidth, which itself defaults to1.style specโ IMAGE: figure-18-style-dash sets the style used to draw the lines of the element. If not specified, the system falls back to the language variablelinestyle, which itself defaults to solid lines. The legal values are all the ones accepted byTk_GetDash[http://www.tcl.tk/man/tcl8.5/TkLib/GetDash.htm], plus everything listed below:solid, empty string โ Draws a solid line. Periodt. ๐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. โจ No cap.
textstring โ 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. ๐textcolorspec โ 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 variabletextcolor, which itself defaults to black. ๐คtextfontspec โ 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 variabletextfont, which itself defaults to Helvetica 12pt. ๐คthenlocationthen(<direction> ?length?)...(<direction> ?length?)...โ 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 will be 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 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 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. The use of noturn is not able to override this behaviour. ๐ซ
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. ๐
tolocation โ Specifies the location where the line element ends. This attribute has no default. The default is handled by the attributethen, which makes it appear as iftohas a default when not specified. ๐tolocation โ 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 atfrom. ๐ฏwidthlengthwidlength โ Specifies the width of the element. If not specified the system falls back to the value taken from the language variableboxwidth, which itself defaults to the pixel equivalent of 2 cm. ๐widthlength โ 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 attributesaspectandheight, 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 as well, 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. ๐
widthlength โ Specifies the width of the text element. Defaults to the natural width of its text. ๐withcorner โ Specifies the corner of the element to place at the location given by the attributeat. Defaults to the current corner as maintained by the layouting system, except if the value foratwas specified by the user. In that case it defaults tocenter. ๐withcorner โ Line elements are normally positioned absolutely, using the locations specified through the attributesfrom,then, andto. Ifatis specified however then these positions are translated a last time, moving the line's corner named by the attributewithto the location given by this attribute. This means thatwithis effective if and only if the attributeatwas specified as well for the line. ๐
โจ 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 attributesfromandtoof the element. ๐ฆ
IMAGE: figure-28-corners-open
- The center of line and move elements is the location halfway between
"start"and"end"corners, 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 in 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 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. See below for the full list. ๐
IMAGE: figure-27-corners-closed
This overlaps with the pre-defined corners for closed elements. This is used by the layout system, when are 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 does not exist the nearest actual corner by angle is used. ๐
westwleftlsouthsdownbottombotbeasterightrnorthnuptoptnorthwestnwup-leftupleftleftupnortheastneup-rightuprightrightupsouthwestswdown-leftdownleftleftdownsoutheastsedown-rightdownrightrightdown
โจ MISCELLANEOUS COMMANDS โจ
number cmnumber mmnumber inchnumber ptโ These commands allow the specification of 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. ๐
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. ๐
number number
IMAGE: figure-50-point-cons-absolute
This command takes the x and y coordinates of a location and returns the absolute point for it. ๐
by distance direction
IMAGE: figure-51-point-cons-relative
This command takes a distance and direction (angle in degrees, or registered direction name) and returns the relative point for it, i.e. the delta or translation it represents. โก๏ธ
Note also 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 ...
point1 + point2
IMAGE: figure-48-point-vectoradd
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. โ
point1 - point2
IMAGE: figure-49-point-vectorsub
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. โ
point by distance directionโ This command is a more convenient, or at least shorter, form of
[$point + [by $distance $direction]]
point1 | point2
IMAGE: figure-31-point-projection
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. ๐
n between poin1 point2
IMAGE: figure-29-point-interpolation-1
okay so this command computes the point that's n*100 percent of the way between point1 and point2, and hands it back to you as its result. Which means, for real:
n == 0โ the result ispoint1. That's it, that's the whole point. ๐n == 1โ the result ispoint2.n == 0.5โ the result is half way between the two points. dead center, main character position โจ- etc. โ and bestie, note that it's totally allowed to use values
< 0and> 1forn. no gatekeeping here.
intersect elem1 elem2โ this one takes two open elements, computes the lines going through their"start"- and"end"-corners, and returns the point where those two lines intersect. the command throws an error if the lines do not intersect, or are coincident โ so no parallel-line nonsense, it will absolutely call you out. ๐ญ
IMAGE: figure-32-point-intersection
element names ?pattern?โ returns a list with the names of all corners for the element. If apatternis specified then only the names matching it (viastring match) come back. Otherwise all names come back (which is the same as a default pattern of*). so basically: ask for everything or ask for your faves ๐element cornerโ returns the value for the corner of the element. And that value can be anything, including points and elements. it's giving chaotic range, love that for it ๐element corner1 corner2...โ a convenience shorthand for
[[[$elem $corner1] $corner2] ...]
assuming that the value for
[$elem $corner1]
is again an element.
element ?corner1... ?names ?pattern??]?โ a convenience shorthand for
[[[$elem $corner1] ...] names ?pattern?]
assuming that the value for
[$elem $corner1]
is again an element.
nth ?corner?โ this asks the diagram history for the *n*th element created, searching from the beginning of the history (counting from1) and returns it as its result. If thecorneris specified then the value for this corner is returned instead. counting from one, like a civilized little index ๐ฆnth last ?corner?โ same idea, but it asks the diagram history for the *n*th element created searching from the end of the history and returns it as its result. If thecorneris specified then the value for this corner is returned instead.nth shape ?corner?โ asks the diagram history for the *n*th element created, of the given shape, searching from the beginning of the history (counting from1) and returns it as its result. If thecorneris specified then the value for this corner is returned instead. filtering by shape, we love a specific queen ๐nth last shape ?corner?โ asks the diagram history for the *n*th element created, of the given shape, searching from the end of the history and returns it as its result. If thecorneris 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". because typing less is self care, fr fr ๐ธ1st2nd3rdโ aliases for1th,2th, and3th, for readability, usable wherevernthcan occur. iconic naming choices, no notes ๐
๐ 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 attributeanchor. Initialized tocenter. The legal values are all those accepted byTk_GetAnchor(http://www.tcl.tk/man/tcl8.5/TkLib/GetAnchor.htm).arcradiusโ the default value for the attributeradiusofarcelements. Initialized to the pixel equivalent of1 cm.arrowheadโ the default value for the attributearrowhead. Initialized tonone. 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 attributeheightofbox,diamondandellipseelements. Initialized to the pixel equivalent of2 cm.boxwidthโ the default value for the attributewidthofbox,diamondandellipseelements. Initialized to the pixel equivalent of2 cm.clockwiseโ the default value for the attributesclockwiseandcounterclockwiseofarcelements. Initialized toFalse, for counter-clockwise direction.circleradiusโ the default value for the attributeradiusofcircleelements, and also the default for the attributechop, when specified without an explicit length. Initialized to the pixel equivalent of1 cm.drumaspectโ the default value for the attributeaspectofdrumelements. Initialized to0.35.fillcolorโ the default value for the attributefillcolorof all elements which can be filled. Initialized to the empty string, signaling that the element is not filled.justifyโ the default value for the attributejustify. Initialized toleft. The legal values areleft,right, andcenter.linecolorโ the default value for the attributecolorof all elements having to draw lines (all buttext). Initialized toblack.linestyleโ the default value for the attributestyleof all elements having to draw some line. Initialized tosolid. The legal values are all those accepted byTk_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 attributestrokeof all elements having to draw some line. Initialized to1(pixels).movelengthโ the default value for the directional specification of intermediate locations by the attributethenoflineandmoveelements. Initialized to the pixel equivalent of2 cm.slantโ the default value for the attributeslantofboxelements. Initialized to90degrees, i.e. slant straight up.textcolorโ the default value for the attributetextcolorof all elements having to draw some text. Initialized toblack.textfontโ the default value for the attributetextfontof all elements having to draw some text. Initialized toHelvetica 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. (that's you, bestie โ you can scroll, no shame ๐ซถ)
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. the face of the operation ๐diagram::coreโ the core engine, itself distributed over four helper classes.diagram::basicโ the implementation of the standard shapes, likebox,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 ๐ฆ
this heading is just vibing here with absolutely nothing under it in the original. no references listed, no cap. moving on ๐
๐ BUGS, IDEAS, FEEDBACK ๐
This document, and the package it describes, will undoubtedly contain bugs and other problems. yes, they said it themselves, bestie โ the bugs are canon. 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. they want your ideas, they're literally asking ๐
โจ 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 whole page, bestie!! this one came from tklib version 0.3, and you were reading the diagram(3tk) page โ go draw something iconic with it ๐ธ๐โจ๐ฆ๐
๐ฆ where this page comes from
- debian trixie: tklib 0.9-1
- ubuntu questing: tklib 0.9-1
- ubuntu resolute: tklib 0.9-1build1
- ubuntu stonking: tklib 0.9-1build1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms