diagram(n)
β¨ 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 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 thescriptargument is specified then methoddrawwill 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 namesangleandopposite. They are special to thediagrampackage 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.namewill become a new command in the language, and the specified command prefix (cmdprefix) will be called to perform the actual drawing.attributesspecifies the set of attributes for which data has to be available. I.e. the system will run the...-callbacks for these attributes. See the methodnew attributefor 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 andbody.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 ofsnitvalidation types. See the documentation of thesnitpackage.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 forkeyaggregate, 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 keymergewas not specified. It's optional; if you don't specify it, it defaults toFalse.
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 methodnew 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 byvarname. 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 keydefaultis not specified. In that case it supplies a default handling fordefault, 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:
- 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 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: π
anchorname β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 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 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. π€counterclockwise,ccwβ 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. π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". π¨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 of1 cm. β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,-β 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 thestylecommand, using them as the argument. iykyk π«Ά
textstring β 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 πΈ.textcolorspec β 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 variabletextcolor, which itself defaults toblackπ€.textfontspec β 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 variabletextfont, which itself defaults toHelvetica 12ptβ¨.tolocation β 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.
π the arrow girlies
arrowattr...-->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:
anchornameljustrjustabovebelow
(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"
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-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 variablelinecolor, which itself defaults toblackπ€.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"π³οΈ.heightlengthhtlength
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.
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. legal values areleft,right, andcenter.slantangle β 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-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 variablelinewidth, which itself defaults to1ποΈ.stylespec β (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 variablelinestyle, which itself defaults to solid lines. legal values are all those accepted byTk_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 thestylecommand using them as argument π«Ά.
textstring β 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 β 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 variabletextcolor, which itself defaults toblackπ€.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 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 variable boxwidth, 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 the attributes:
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 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".
atlocation β where the element's corner (the one named bywith) actually sits π―. If you don't say, it defaults to the current location that the layouting system is keeping track of.colorspec β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 variablelinecolor, which itself defaults to black. π€diameterlengthdiamlength β 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 bothdiameterandradius, the radius info wins, periodt. No default here, because the defaults come from the radius side of things.fillcolorspec βIMAGE: figure-21-style-colors. The color for the inside of the element π¨. Skip it and the system falls back to the language variablefillcolor, which defaults to the empty string β that's the signal for "no filling".justifyleft|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 variablejustify, which defaults toleft. The legal values areleft,right, andcenterβ¨.radiuslengthradlength β the circle's radius. Skip it and the system falls back to the language variablecircleradius, which itself defaults to the pixel equivalent of1 cmπ«.strokewidth β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 variablelinewidth, which defaults to1.stylespec βIMAGE: figure-18-style-dash. The style used to draw the element's lines. Skip it and the system falls back to the language variablelinestyle, which defaults to solid lines. The legal values are everythingTk_GetDashaccepts [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 linedash-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 π
textstring β 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 πΈ.textcolorspec β 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 variabletextcolor, which defaults to black.textfontspec β 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 variabletextfont, which defaults toHelvetica 12ptβ¨.withcorner β which corner of the element goes at the location given byat. Defaults to the current corner the layouting system is trackingβ¦ except when you specifiedatyourself. In that case it defaults tocenterπ―.
π 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:
anchornameljustrjustabovebelowβ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 variableanchor, which defaults tocenter. The legal values are all the onesTk_GetAnchoraccepts [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"
aspectnumber β 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 whetherwidthandheightwere given. Buckle up π’:- If both
widthandheightare specified then anyaspectyou gave is ignored, because it's implicitly defined bywidthandheightanyway and that takes precedence. A missing specification is ignored in that case too β no defaults needed, we're chillin'. - If
aspectis specified, plus one ofwidthorheight, then the missing attribute gets calculated from the two that are specified. No defaults required for these cases either β¨. - If only one of
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
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 of2 cm. For the aspect it uses either your value or the default taken as described in the paragraph above π
- If both
atlocation β where the element's corner (the one named bywith) sits. 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. Skip it and the system falls back to the language variablelinecolor, which itself defaults to black π€.fillcolorspec β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 variablefillcolor, which defaults to the empty string, signaling "no filling" π«§.heightlength β the height of the diamond element. How a default gets calculated when you don't specify it also depends on whetheraspectandwidthwere given. Same drill as before:- If both
widthandheightare specified then anyaspectyou gave is ignored, because it's implicitly defined inwidthandheightand that takes precedence. A missing specification is ignored in that case too β no defaults required. - If
aspectis specified, plus one ofwidthorheight, the missing attribute is calculated from the two that are specified. No defaults needed here either β¨. - If only one of
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
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 of2 cm. For the aspect it uses either your value or the default described in the paragraph above π.
- If both
justifyleft|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 variablejustify, which defaults toleft. Legal values:left,right, andcenterπΈ.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 variablelinewidth, which itself defaults to1. β¨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 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: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.
Note: the values"solid","dot(ted)","dash(ed)","dash-dot", and"dash-dot-dot"are all accepted as shorthands for thestylecommand 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 variabletextcolor, 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 variabletextfont, which itself defaults toHelvetica 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 attributesaspectandheight, if any. π- If both
widthandheightare specified, then any specification ofaspectis ignored, as it is implicitly defined in thewidthandheightas well, and this takes precedence. A missing specification is ignored in that case too, 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 of2 cm. For the aspect it uses either the user-specified value or the default taken as described in the previous paragraph.
- If both
with cornerβ 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 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 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.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 variabledrumaspect, which itself defaults to0.35. π₯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.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 variablelinecolor, 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 variablefillcolor, 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 variableboxheight, which itself defaults to the pixel equivalent of2 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 variablejustify, which itself defaults toleft. The legal values areleft,right, andcenter.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 variablelinewidth, which itself defaults to1.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 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: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.
Note: the values"solid","dot(ted)","dash(ed)","dash-dot", and"dash-dot-dot"are all accepted as shorthands for thestylecommand 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 variabletextcolor, 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 variabletextfont, which itself defaults toHelvetica 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 variableboxwidth, which itself defaults to the pixel equivalent of2 cm.with cornerβ 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 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 nameljustrjustβ shorthand foranchor eastπ (yes bestie, these are the no-argument versions and the anchor is just implied)aboveβ shorthand foranchor southβ¬οΈbelowβ shorthand foranchor 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 thewithattribute. 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. (seefigure-21-style-colors, she's iconic) If not specified, the system falls back to the value taken from the language variablelinecolor, which itself defaults toblack. π€fillcolor specβ specifies the color used to draw the inside of the element. (figure-21-style-colorsagain, same vibe) If not specified, the system falls back to the value taken from the language variablefillcolorβ and that one defaults to the empty string, which literally signals "no filling". Empty string = no vibes inside, just outline. β¨height lengthht lengthβ 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 of2 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 variablejustify, which itself defaults toleft. The legal values areleft,right, andcenter. β¬ οΈβοΈβ‘οΈ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 variablelinewidth, which itself defaults to1. ποΈ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 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 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 variabletextcolor, which itself defaults toblack. π€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 variabletextfont, which itself defaults toHelvetica 12pt. π€width lengthwid lengthβ 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 of2 cm. πwith cornerβ specifies which 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 which case it defaults tocenter. 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 nameljustrjustabovebelowβ (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 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 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 variablearrowhead, which itself defaults 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.
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 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. π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 variablecircleradius, which itself defaults to the pixel equivalent of1 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 variablelinecolor, which itself defaults toblack. π€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 variablefillcolor, 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 variablejustify, which itself defaults toleft. The legal values areleft,right, andcenter. π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-strokethis 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 variablelinewidth, which itself defaults to1. slay.style specβIMAGE: figure-18-style-dashthis 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 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], 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 variabletextcolor, which itself defaults toblack.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 variabletextfont, which itself defaults toHelvetica 12pt.then locationthen (<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 attributethen, which makes it appear as iftohas a default when not specified.with cornerβ 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. 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 nameljustrjustabovebelowβ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 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 is used. for combined directions, the main attribute commandanchorhas 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 attributewith. 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 variablejustify, which itself defaults toleft. the legal values areleft,right, andcenter.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 variabletextcolor, which itself defaults toblack.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 variabletextfont, which itself defaults toHelvetica 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 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. 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 nameljustrjustabovebelowβ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 variableanchorsays, and that one defaults tocenter. The legal values are all the onesTk_GetAnchoraccepts [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 variablearrowhead, which itself defaults tonone. 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 thewidthandheightattributes, if anything:- If both
widthandheightare specified then anyaspectyou 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
aspectis specified and you also gave one ofwidthorheight, then the missing attribute is calculated from the two you did specify. No defaults needed here either π«Ά - If only one of
widthorheightis specified, the system uses a fallback for the aspect: the value from the language variablediamondaspect, which itself defaults to2. - If none of
widthorheightis specified, the system falls back for the width to the language variableboxwidth, which itself defaults to the pixel equivalent of2 cm. For the aspect it uses either your user-specified value or the default taken as described in the previous paragraph β
- If both
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 variabledrumaspect, which itself defaults to0.35.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 πat locationβ for line elements, okay so lines are normally positioned absolutely, using the locations given through the attributesfrom,then, andto. But ifatis specified, then those positions get translated one last time, moving the line's corner named bywithto 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 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, 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 variablelinecolor, which itself defaults toblack.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 a little alternative way to specify its radius β Effective if and only if the radius was not specified. I.e. if you specify bothdiameterandradius, 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 variablefillcolor, 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 variableboxheight, which itself defaults to the pixel equivalent of2 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 theaspectandwidthattributes, if any:- If both
widthandheightare specified then anyaspectspec 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
aspectis specified and you gave one ofwidthorheight, then the missing attribute is calculated from the two which are specified. No defaults required in these cases either π«Ά - If only one of
widthorheightis specified, the system uses a fallback for the aspect: the value from the language variablediamondaspect, which itself defaults to2. - If none of
widthorheightis specified, the system falls back for the width to the language variableboxwidth, which itself defaults to the pixel equivalent of2 cm. For the aspect it uses either your user-specified value or the default taken as described in the previous paragraph β
- If both
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 variablejustify, which itself defaults toleft. The 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β specifies 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β 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 variablearcradius, which itself defaults to the pixel equivalent of1 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 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 π§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 variablelinewidth, which itself defaults to1.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 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 β draws a solid line π (yes, the empty string counts, she's valid, we love her)dash,dashed,-β draws a dashed linedot,dotted,.β draws a dotted linedash-dot,-.β draws a dash-dotted linedash-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 thestylecommand when you use them as its argument. iykyk π«Ά
textstring β 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 β¨textcolorspec β 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 variabletextcolor, which itself defaults to black π€textfontspec β 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 variabletextfont, which itself defaults toHelvetica 12ptπthenlocation β 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 β¨
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 it's 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πwidthlength /widlength β 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 of2 cmπwidthlength β 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 attributesaspectandheight, if any. Let's break that down, because it's giving β¨decision treeβ¨:- If both
widthandheightare specified, then any specification ofaspectis 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
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 of2 cm. For the aspect it uses either the user-specified value or the default taken as described in the previous paragraph π
- If both
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 one last time, moving the line's corner named by the attributewithto the location given by this attribute. This meanswithis effective if and only if the attributeatwas 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 attributesfromandtoof 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,lsouth,s,down,bottom,bot,beast,e,right,rnorth,n,up,top,tnorthwest,nw,up-left,upleft,leftupnortheast,ne,up-right,upright,rightupsouthwest,sw,down-left,downleft,leftdownsoutheast,se,down-right,downright,rightdown
π MISCELLANEOUS COMMANDS π
number cmnumber mmnumber inchnumber 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 oftk scalingand are computed once, at the time the package is sourced. Future changes of thetk scalingfactor 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 ofpoint1and the y-coordinate ofpoint2π―
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 ispoint1.n == 1β The result ispoint2.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 (viastring 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 thenthelement created, searching from the beginning of the history (counting from1) 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 thenthelement 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 thenthelement created, of the given shape, searching from the beginning of the history (counting from1) 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 thenthelement 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 for1th,2th, and3th, for readability, usable whereevernthcan 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 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 attributeradiusof arc elements. 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 attributeheightof box, diamond and ellipse elements. Initialized to the pixel equivalent of2 cm. π¦boxwidthβ The default value for the attributewidthof box, diamond and ellipse elements. Initialized to the pixel equivalent of2 cm. πclockwiseβ The default value for the attributesclockwiseandcounterclockwiseof arc elements. Initialized toFalse, for counter-clockwise direction. πcircleradiusβ The default value for the attributeradiusof circle elements, 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 attributeaspectof drum elements. 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 but text). 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 linedash-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 attributethenof line and move elements. Initialized to the pixel equivalent of2 cm. πΆββοΈslantβ The default value for the attributeslantof box elements. Initialized to90 degrees, 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. π«Ά
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, 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 π
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
- alpine 3.24: tk-lib-doc 0.7-r0 Β· TCL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms