blt::graph(3tcl)
β¨ blt::graph β the 2D graph glow-up β¨
okay bestie, listen. This is a page from the BLT Built-In Commands manual, and it's literally the blueprint for making a graph widget that plots X-Y coordinate data. It's giving very main-character data-visualization energy. Sit down, hydrate, let's go. π«Ά
πΈ NAME πΈ
graph β a 2D graph for plotting X-Y coordinate data. That's it. That's the whole vibe.
π SYNOPSIS π
graph pathName ?option value?...
π DESCRIPTION π
The graph command creates a graph for plotting two-dimensional data (X-Y coordinates). No cap.
It has so many configurable components β coordinate axes, elements, legend, grid lines, cross hairs, etc. β and they all exist so you can customize the look and feel of the graph. It's fully customizable. Iconic behaviour, honestly.
π¦ INTRODUCTION π¦
The graph command creates a new window for plotting two-dimensional data (X-Y coordinates). Your data points get plotted in a rectangular area displayed in the center of that new window β that's called the plotting area. β¨
The coordinate axes get drawn in the margins around the plotting area. By default, the legend is displayed in the right margin, and the title is displayed in the top margin. Cute, right?
The graph widget is composed of several components: coordinate axes, data elements, legend, grid, cross hairs, pens, postscript, and annotation markers. Let's meet the whole squad. π
- axis β The graph has four standard axes (
x,x2,y, andy2), but you can create and display any number of axes, bestie. Axes control what region of data is displayed and how the data is scaled. Each axis consists of the axis line, title, major and minor ticks, and tick labels. Tick labels display the value at each major tick. - crosshairs β Cross hairs are used to position the mouse pointer relative to the X and Y coordinate axes. Two perpendicular lines, intersecting at the current location of the mouse, extend across the plotting area to the coordinate axes. It's giving targeting reticle, but make it β¨dataβ¨.
- element β An element represents a set of data points. Elements can be plotted with a symbol at each data point and lines connecting the points. The appearance of the element β its symbol, line width, color β is all configurable. Glow-up potential: unlimited.
- grid β Extends the major and minor ticks of the X-axis and/or Y-axis across the plotting area. Little lines, big impact.
- legend β The legend displays the name and symbol of each data element. It can be drawn in any margin or in the plotting area. Flexible queen.
- marker β Markers are used to annotate or highlight areas of the graph. For example, you could use a polygon marker to fill an area under a curve, or a text marker to label a particular data point. Markers come in various forms: text strings, bitmaps, connected line segments, images, polygons, or embedded widgets.
- pen β Pens define attributes (both symbol and line style) for elements. Data elements use pens to specify how they should be drawn, and a data element may use many pens at once. Here's the tea: the particular pen used for a data point is determined from each element's weight vector (see the element's
-weightand-styleoptions). π - postscript β The widget can generate encapsulated PostScript output. This component has several options to configure how the PostScript is generated. Fancy.
β SYNTAX β
graph pathName ?option value?...
The graph command creates a new window pathName and makes it into a graph widget. Heads up though: at the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. Rules are rules. π
Additional options may be specified on the command line or in the option database to configure aspects of the graph such as its colors and font. See the configure operation below for the exact details about what option and value pairs are valid.
If successful, graph returns the path name of the widget. It also creates a new Tcl command by the same name β yes, the widget and the command share a name, it's a whole twin situation. You can use this command to invoke various operations that query or modify the graph. The general form is:
pathName operation ?arg?...
Both operation and its arguments determine the exact behavior of the command. The operations available for the graph are described in the GRAPH OPERATIONS section. π₯
The command can also be used to access components of the graph:
pathName component operation ?arg?...
The operation, now located after the name of the component, is the function to be performed on that component. Each component has its own set of operations that manipulate that component. They will be described below in their own sections. π
πΈ EXAMPLE πΈ
Okay bestie, gather round, because this is the part where it all clicks. The graph command creates a new graph. That's it. That's the whole job. π
# Create a new graph. Plotting area is black.
graph .g -plotbackground black
And boom β a new Tcl command .g is also created. Not me getting a whole new command as a little treat. π This command is how you query and modify the graph. Wanna change the title to "My Plot"? You use the new command plus the graph's configure operation. Simple.
# Change the title.
.g configure -title "My Plot"
A graph has several components, and to get at a particular one you use the component's name. So say you wanna add data elements β you use the new command and the element component. Yes queen, components are the whole personality here. π¦
# Create a new element named "line1"
.g element create line1 \
-xdata { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 } \
-ydata { 26.18 50.46 72.85 93.31 111.86 128.47 143.14
155.85 166.60 175.38 }
The element's X-Y coordinates get specified using lists of numbers. But alternately, bestie, BLT vectors could hold those X-Y coordinates instead. Choose your fighter. β¨
# Create two vectors and add them to the graph.
vector xVec yVec
xVec set { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 }
yVec set { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 155.85
166.60 175.38 }
.g element create line1 -xdata xVec -ydata yVec
The advantage of vectors is literally that when you modify one, the graph is automatically redrawn to reflect the new values. Autoupdate? We love to see it. π
# Change the y coordinate of the first point.
set yVector(0) 25.18
So an element named e1 is now created in .b. It's automatically added to the display list of elements, and you can use that list to control in what order elements are displayed. To query or reset the element display list, you use the element's show operation.
# Get the current display list
set elemList [.b element show]
# Remove the first element so it won't be displayed.
.b element show [lrange $elemList 0 end]
The element will be displayed by as many bars as there are data points β in this case there are ten. The bars are drawn centered at the x-coordinate of the data point, and all of them share the same attributes (colors, stipple, etc). The width of each bar is by default one unit, and you can change that using the -barwidth option.
# Change the X-Y coordinates of the first point.
set xVec(0) 0.18
set yVec(0) 25.18
An element named line1 is now created in .g. By default, the element's label in the legend will also be line1. You can change that label, or specify no legend entry at all, again using the element's configure operation. Iconic behavior, honestly. π
# Don't display "line1" in the legend.
.g element configure line1 -label ""
And you can configure more than just the element's label, bestie. An element has many attributes β symbol type and size, dashed or solid lines, colors, line width, etc. So many vibes to choose from. π
.g element configure line1 -symbol square -color red \
-dashes { 2 4 2 } -linewidth 2 -pixels 2c
Four coordinate axes are automatically created: x, x2, y, and y2. And by default, elements are mapped onto the axes x and y. You can change that with the -mapx and -mapy options. β¨
# Map "line1" on the alternate Y-axis "y2".
.g element configure line1 -mapy y2
Axes can be configured in many ways too. For example, you change the scale of the Y-axis from linear to log using the axis component. Math girlies rise up. π
# Y-axis is log scale.
.g axis configure y -logscale yes
One important way axes are used is to zoom in on a particular data region. Zooming is done by simply specifying new axis limits using the -min and -max configuration options. No cap.
.g axis configure x -min 1.0 -max 1.5
.g axis configure y -min 12.0 -max 55.15
To zoom interactively, you link the axis configure operations with some user interaction (such as pressing the mouse button), using the bind command. And to convert between screen and graph coordinates, you use the invtransform operation. That's the secret sauce right there. π₯
# Click the button to set a new minimum
bind .g <ButtonPress-1> {
%W axis configure x -min [%W axis invtransform x %x]
%W axis configure x -min [%W axis invtransform x %y]
}
By default, the limits of the axis are determined from data values. To reset back to the default limits, you set the -min and -max options to the empty value. Clean slate, bestie. π«Ά
# Reset the axes to autoscale again.
.g axis configure x -min {} -max {}
.g axis configure y -min {} -max {}
By default, the legend is drawn in the right margin. You can change this, or any legend configuration options, using the legend component.
# Configure the legend font, color, and relief
.g legend configure -position left -relief raised \
-font fixed -fg blue
And to prevent the legend from being displayed, you turn on the -hide option. Gone. Poof. π
# Don't display the legend.
.g legend configure -hide yes
The graph widget has simple drawing procedures called markers. They can be used to highlight or annotate data in the graph. The types of markers available are bitmaps, images, polygons, lines, or windows. Markers can be used, for example, to mark or brush points. In this example, it's a text marker that labels the data's first point. Markers are created using the marker component. π
# Create a label for the first data point of "line1".
.g marker create text -name first_marker -coords { 0.2 26.18 } \
-text "start" -anchor se -xoffset -10 -yoffset -10
This creates a text marker named first_marker. It will display the text "start" near the coordinates of the first data point. The -anchor, -xoffset, and -yoffset options are used to display the marker above and to the left of the data point, so that the data point isn't covered by the marker. By default, markers are drawn last, on top of data. You can change that with the -under option. π
# Draw the label before elements are drawn.
.g marker configure first_marker -under yes
You can add cross hairs or grid lines using the crosshairs and grid components. Because why have data if it's not cute and organized? β
# Display both cross hairs and grid lines.
.g crosshairs configure -hide no -color red
.g grid configure -hide no -dashes { 2 2 }
# Set up a binding to reposition the crosshairs.
bind .g <Motion> {
.g crosshairs configure -position @%x,%y
}
The crosshairs are repositioned as the mouse pointer is moved in the graph. The pointer X-Y coordinates define the center of the crosshairs. Following your cursor around like the most loyal bestie. π¦
Finally β to get hardcopy of the graph, you use the postscript component. Screenshot era is over, we're going physical. πβ¨
# Print the graph into file "file.ps"
.g postscript output file.ps -maxpect yes -decorations no
This generates a file file.ps containing the encapsulated PostScript of the graph. The option -maxpect says to scale the plot to the size of the page. And turning off the -decorations option denotes that no borders or color backgrounds should be drawn (i.e. the background of the margins, legend, and plotting area will be white). Minimalist era. π€
β¨ GRAPH OPERATIONS β¨
okay bestie, this is the big one β all the things you can actually do to a graph widget. buckle up, we're going through every single one π
pathName axis operation ?arg?...β head over to the AXIS COMPONENTS section, it's all there π¦pathName bar elemName ?option value?...β spins up a brand new barchart element called elemName. it is an error if an element elemName already exists, so like, don't do that π. the barchart manual has all the tea on which option/value pairs are valid πpathName cget optionβ hands you back the current value of the config option option. and option can be literally any option described below for theconfigureoperation πpathName configure ?option value?...β query or change the graph's config options. no option? you get a list describing the current options forpathName. option but no value? you get a list describing just that option. one or more option value pairs? each option gets set to its value, one by one β¨. and here's every option that's valid π-aspect width/heightβ forces a fixed aspect ratio of width/height, which is a floating point number π-background colorβ sets the background color. this covers the margins and the legend, but not the plotting area π¨-borderwidth pixelsβ sets how wide the 3-D border around the outside edge of the widget is. the-reliefoption decides whether that border even gets drawn. default is2πΌοΈ-bottommargin pixelsβ if it's non-zero, it overrides the computed size of the margin below the X-coordinate axis. if pixels is0, the automatically computed size is used. default is0β¬οΈ-bufferelements booleanβ says whether an internal pixmap should buffer the display of data elements. if boolean is true, data elements get drawn to an internal pixmap. this one is especially useful when the graph redraws a lot while the data stays the same (think: dragging a marker across the plot, no cap). check the SPEED TIPS section. default is1β‘-cursor cursorβ specifies the widget's cursor. default cursor iscrosshairπ―-font fontNameβ specifies the font of the graph title. default is*-Helvetica-Bold-R-Normal-*-18-180-*π€-halo pixelsβ the max distance to consider when hunting for the closest data point (see the element'sclosestoperation below). data points further than pixels away get ignored. default is0.5iπ-height pixelsβ the requested height of the widget. default is4iπ-invertxy booleanβ whether the placement of the X-axis and Y-axis should be flipped. if boolean is true, X and Y axes get swapped. default is0π-justify justifyβ how the title should be justified. only matters when the title has more than one line of text. justify must beleft,right, orcenter. default iscenterβοΈ-leftmargin pixelsβ if non-zero, overrides the computed size of the margin from the left edge of the window to the Y-coordinate axis. if pixels is0, the automatically computed size is used. default is0β¬ οΈ-plotbackground colorβ the background color of the plotting area. default iswhiteπ€-plotborderwidth pixelsβ width of the 3-D border around the plotting area. the-plotreliefoption decides if a border is drawn. default is2πΌοΈ-plotpadx padβ how much padding to add to the left and right sides of the plotting area. pad can be a list of one or two screen distances. two elements? the left side of the plotting area entry gets padded by the first distance and the right side by the second. just one distance? both left and right get padded evenly. default is8βοΈ-plotpady padβ how much padding to add to the top and bottom of the plotting area. pad can be a list of one or two screen distances. two elements? the top gets padded by the first distance and the bottom by the second. just one distance? both top and bottom get padded evenly. default is8βοΈ-plotrelief reliefβ the 3-D effect for the plotting area. relief says how the interior of the plotting area should look relative to the rest of the graph β for example,raisedmeans the plot should appear to protrude from the graph, relative to the surface of the graph. default issunkenπ³οΈ-relief reliefβ the 3-D effect for the graph widget itself. relief says how the graph should look relative to the widget it's packed into β for example,raisedmeans the graph should appear to protrude. default isflatπ«§-rightmargin pixelsβ if non-zero, overrides the computed size of the margin from the plotting area to the right edge of the window. by default, the legend gets drawn in this margin. if pixels is0, the automatically computed size is used. default is0β‘οΈ-takefocus focusβ info used when moving focus window-to-window via keyboard traversal (think Tab and Shift-Tab). if focus is0, this window gets skipped entirely during keyboard traversal.1means this window should always receive the input focus. an empty value means the traversal scripts decide whether to focus on the window. default is""β¨οΈ-tile imageβ a tiled background for the widget. if image isn't"", the background gets tiled using image. otherwise the normal background color gets drawn (see the-backgroundoption). image must be an image made with the Tkimagecommand. default is""π§©-title textβ sets the title to text. if text is"", no title gets displayed π-topmargin pixelsβ if non-zero, overrides the computed size of the margin above the x2 axis. if pixels is0, the automatically computed size is used. default is0β¬οΈ-width pixelsβ the requested width of the widget. default is5iπ
pathName crosshairs operation ?arg?β go see the CROSSHAIRS COMPONENT section π―pathName element operation ?arg?...β go see the ELEMENT COMPONENTS section π§±pathName extents itemβ returns the size of a particular item in the graph. item must be one ofleftmargin,rightmargin,topmargin,bottommargin,plotwidth, orplotheightπ¦pathName grid operation ?arg?...β go see the GRID COMPONENT section πΈοΈpathName invtransform winX winYβ does an inverse coordinate transformation, mapping window coordinates back to graph coordinates, using the standard X-axis and Y-axis. returns a list containing the X-Y graph coordinates πpathName inside x yβ returns1if the designated screen coordinate (x and y) is inside the plotting area, and0otherwise πpathName legend operation ?arg?...β go see the LEGEND COMPONENT section π·οΈpathName line operation arg...β the operation is the same aselementπpathName marker operation ?arg?...β go see the MARKER COMPONENTS section πpathName postscript operation ?arg?...β go see the POSTSCRIPT COMPONENT section π¨οΈpathName snap ?switches? outputNameβ takes a snapshot of the graph and saves the output in outputName. here are the switches you can use π-format formatβ specifies how the snapshot gets output. format can be one of these, listed below. default isphoto.photoβ saves a Tk photo image. outputName represents the name of a Tk photo image that must already have been created πΈwmfβ saves an Aldus Placeable Metafile. outputName represents the filename where the metafile is written. if outputName isCLIPBOARD, then output is written directly to the Windows clipboard. this format is available only under Microsoft Windows πͺemfβ saves an Enhanced Metafile. outputName represents the filename where the metafile is written. if outputName isCLIPBOARD, then output is written directly to the Windows clipboard. this format is available only under Microsoft Windows πͺ
-height sizeβ specifies the height of the graph. size is a screen distance. the graph will be redrawn using this dimension, rather than its current window height π-width sizeβ specifies the width of the graph. size is a screen distance. the graph will be redrawn using this dimension, rather than its current window width π
pathName transform x yβ does a coordinate transformation, mapping graph coordinates to window coordinates, using the standard X-axis and Y-axis. returns a list containing the X-Y screen coordinates πpathName xaxis operation ?arg?...β β¨pathName x2axis operation ?arg?...β β¨pathName yaxis operation ?arg?...β β¨pathName y2axis operation ?arg?...β and all four of these? go see the AXIS COMPONENTS section π¦
π GRAPH COMPONENTS π
okay bestie, a graph is literally made of several components: coordinate axes, data elements, legend, grid, cross hairs, postscript, and annotation markers. Instead of one big giant set of configuration options and operations, the graph is partitioned, where each component has its own configuration options and operations that specifically control that aspect or part of the graph. π
π¦ AXIS COMPONENTS π¦
Four coordinate axes are automatically created: two X-coordinate axes (x and x2) and two Y-coordinate axes (y, and y2). By default, the axis x is located in the bottom margin, y in the left margin, x2 in the top margin, and y2 in the right margin. β¨
An axis consists of the axis line, title, major and minor ticks, and tick labels. Major ticks are drawn at uniform intervals along the axis. Each tick is labeled with its coordinate value. Minor ticks are drawn at uniform intervals within major ticks. π
The range of the axis controls what region of data is plotted. Data points outside the minimum and maximum limits of the axis are not plotted. By default, the minimum and maximum limits are determined from the data, but you can reset either limit. π
You can have several axes. To create an axis, invoke the axis component and its create operation.
# Create a new axis called "tempAxis"
.g axis create tempAxis
You map data elements to an axis using the element's -mapy and -mapx configuration options. They specify the coordinate axes an element is mapped onto. πΊοΈ
# Now map the tempAxis data to this axis.
.g element create "e1" -xdata $x -ydata $y -mapy tempAxis
Any number of axes can be displayed simultaneously. They are drawn in the margins surrounding the plotting area. The default axes x and y are drawn in the bottom and left margins. The axes x2 and y2 are drawn in top and right margins. By default, only x and y are shown. Note that the axes can have different scales. π
To display a different axis or more than one axis, you invoke one of the following components: xaxis, yaxis, x2axis, and y2axis. Each component has a use operation that designates the axis (or axes) to be drawn in that corresponding margin: xaxis in the bottom, yaxis in the left, x2axis in the top, and y2axis in the right. π
# Display the axis tempAxis in the left margin.
.g yaxis use tempAxis
The use operation takes a list of axis names as its last argument. This is the list of axes to be drawn in this margin. π
You can configure axes in many ways. The axis scale can be linear or logarithmic. The values along the axis can either monotonically increase or decrease. If you need custom tick labels, you can specify a Tcl procedure to format the label any way you wish. You can control how ticks are drawn, by changing the major tick interval or the number of minor ticks. You can define non-uniform tick intervals, such as for time-series plots. π
π pathName axis bind π
pathName axis bind tagName ?sequence? ?command?
Associates command with tagName such that whenever the event sequence given by sequence occurs for an axis with this tag, command will be invoked. The syntax is similar to the bind command except that it operates on graph axes, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it. π«Ά
If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence is returned (and if there's no such binding, it's an error, bestie π). If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName. π
π
pathName axis cget π
pathName axis cget axisName option
Returns the current value of the option given by option for axisName. option may be any option described below for the axis configure operation. β¨
πΈ pathName axis configure πΈ
pathName axis configure axisName ?axisName?... ?option value?...
Queries or modifies the configuration options of axisName. Several axes can be changed. If option isn't specified, a list describing all the current options for axisName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the axis option option is set to value. The following options are valid for axes. π₯
-bindtags tagListβ Specifies the binding tags for the axis.TagListis a list of binding tag names. The tags and their order will determine how events for axes are handled. Each tag in the list matching the current event sequence will have its Tcl command executed. Implicitly the name of the element is always the first tag in the list. The default value isall.-color colorβ Sets the color of the axis and tick labels. The default isblack.-command prefixβ Specifies a Tcl command to be invoked when formatting the axis tick labels.Prefixis a string containing the name of a Tcl proc and any extra arguments for the procedure. This command is invoked for each major tick on the axis. Two additional arguments are passed to the procedure: the pathname of the widget and the current numeric value of the tick. The procedure returns the formatted tick label. If""is returned, no label will appear next to the tick. You can get the standard tick labels again by settingprefixto"". The default is"".
Please note that this procedure is invoked while the graph is redrawn. You may query configuration options. But do not set them, because this can have unexpected results. π
-descending booleanβ Indicates whether the values along the axis are monotonically increasing or decreasing. Ifbooleanis true, the axis values will be decreasing. The default is0.-hide booleanβ Indicates if the axis is displayed. Ifbooleanis false the axis will be displayed. Any element mapped to the axis is displayed regardless. The default value is0.-justify justifyβ Specifies how the axis title should be justified. This matters only when the axis title contains more than one line of text.Justifymust beleft,right, orcenter. The default iscenter.-limits formatStrβ Specifies a printf-like description to format the minimum and maximum limits of the axis. The limits are displayed at the top/bottom or left/right sides of the plotting area.FormatStris a list of one or two format descriptions. If one description is supplied, both the minimum and maximum limits are formatted in the same way. If two, the first designates the format for the minimum limit, the second for the maximum. If""is given as either description, then that limit will not be displayed. The default is"".-linewidth pixelsβ Sets the width of the axis and tick lines. The default is1pixel.-logscale booleanβ Indicates whether the scale of the axis is logarithmic or linear. Ifbooleanis true, the axis is logarithmic. The default scale is linear.-loose booleanβ Indicates whether the limits of the axis should fit the data points tightly, at the outermost data points, or loosely, at the outer tick intervals. If the axis limit is set with the-minor-maxoption, the axes are displayed tightly. Ifbooleanis true, the axis range is "loose". The default is0.-majorticks majorListβ Specifies where to display major axis ticks. You can use this option to display ticks at non-uniform intervals.MajorListis a list of axis coordinates designating the location of major ticks. No minor ticks are drawn. IfmajorListis"", major ticks will be automatically computed. The default is"".-max valueβ Sets the maximum limit ofaxisName. Any data point greater thanvalueis not displayed. Ifvalueis"", the maximum limit is calculated using the largest data value. The default is"".-min valueβ Sets the minimum limit ofaxisName. Any data point less thanvalueis not displayed. Ifvalueis"", the minimum limit is calculated using the smallest data value. The default is"".-minorticks minorListβ Specifies where to display minor axis ticks. You can use this option to display minor ticks at non-uniform intervals.MinorListis a list of real values, ranging from0.0to1.0, designating the placement of a minor tick. No minor ticks are drawn if the-majortickoption is also set. IfminorListis"", minor ticks will be automatically computed. The default is"".-rotate thetaβ Specifies how many degrees to rotate the axis tick labels.Thetais a real value representing the number of degrees to rotate the tick labels. The default is0.0degrees.-scrollcommand commandβ Specify the prefix for a command used to communicate with scrollbars for this axis, such as.sbar set.-scrollmax valueβ Sets the maximum limit of the axis scroll region. Ifvalueis"", the maximum limit is calculated using the largest data value. The default is"".-scrollmin valueβ Sets the minimum limit of axis scroll region. Ifvalueis"", the minimum limit is calculated using the smallest data value. The default is"".-showticksboolean β do we want little ticks on the axis, or just the bare line? If boolean is true, ticks get drawn. If false, it's just the axis line, no lil marks. Default is1. π-stepsizevalue β sets the gap between the major axis ticks. But bestie, listen: if value isn't a valid interval (and heads up, it has to be less than the axis range), the request just gets ignored and the step size gets calculated automatically. The math said no. π-subdivisionsnumber β how many minor axis ticks get drawn. So like, if number is two, only one minor tick shows up. If number is one, no minor ticks at all, zero, gone. Default is2.-tickfontfontName β the font for the axis tick labels. Default is*-Courier-Bold-R-Normal-*-100-*.-ticklengthpixels β sets the length of both major and minor ticks (and minor ticks are literally half the length of major ones, iconic). If pixels is less than zero, the axis gets inverted and the ticks get drawn pointing towards the plot. Default is0.1i.-titletext β sets the axis title. If text is"", no axis title gets displayed at all. Silent. β¨-titlealternateboolean β shows the axis title in its alternate location. Normally the title is centered along the axis, but this option puts the axis either to the right (for horizontal axes) or above (for vertical axes). Default is0.-titlecolorcolor β sets the color of the axis title. Default is black.-titlefontfontName β the font for the axis title. Default is*-Helvetica-Bold-R-Normal-*-14-140-*.
Axis config options can also be set through the option command, no cap. The resource class is Axis, and the resource names are the names of the axes themselves (so like x or x2). π
option add *Graph.Axis.Color blue
option add *Graph.x.LogScale true
option add *Graph.x2.LogScale false
pathName axis create axisName ?option value?...
Makes a brand new axis called axisName. And no, you can't reuse a name β no axis with the same name can already exist, that's the rule. option and value are the same ones described up above in the axis configure operation.
pathName axis delete ?axisName?...
Deletes the named axes. But here's the tea: an axis isn't really deleted until it's no longer in use, so it's totally safe to delete axes that are mapped to elements. It'll hang around until nobody needs it. π«Ά
pathName axis invtransform axisName value
Does the inverse transformation β flips the screen coordinate value into a graph coordinate, mapping it to axisName. Returns the graph coordinate.
pathName axis limits axisName
Returns a list of the minimum and maximum limits for axisName. The order is min max. Simple as that.
pathName axis names ?pattern?...
Returns a list of axes matching zero or more patterns. If you don't give it any pattern argument, it hands you the names of all the axes. All of them. π
pathName axis transform axisName value
Transforms the coordinate value into a screen coordinate by mapping it to axisName. Returns the transformed screen coordinate.
pathName axis view axisName
Changes the viewable area of this axis. Use it as an argument to a scrollbar's -command, iykyk.
The default axes are x, y, x2, and y2. But bestie, you can display more than four axes at once. You can also swap in a different axis with the use operation of the special axis components: xaxis, x2axis, yaxis, and y2axis.
.g create axis temp
.g create axis time
...
.g xaxis use temp
.g yaxis use time
Only the axes that are actually specified for use get displayed on the screen. If you don't use it, it's not showing up. Periodt.
The xaxis, x2axis, yaxis, and y2axis components work on an axis location rather than a specific axis, unlike the more general axis component. They implicitly control whichever axis is currently being used at that location. By default, xaxis uses the x axis, yaxis uses y, x2axis uses x2, and y2axis uses y2. And when more than one axis is displayed in a margin, it represents the first axis displayed.
The following operations are available for axes, and they mirror exactly the operations of the axis component. The axis argument has to be xaxis, x2axis, yaxis, or y2axis.
β οΈ Okay so real talk β this feature is deprecated, because more than one axis can now be used in a margin. You should only use thexaxis,x2axis,yaxis, andy2axiscomponents with theuseoperation. For literally all other operations, use the generalaxiscomponent instead. π
pathName axis cget option
pathName axis configure ?option value?...
pathName axis invtransform value
pathName axis limits
pathName axis transform value
pathName axis use ?axisName?
Designates that the axis axisName is to be displayed at this location. And axisName can't already be in use at another location β one location per axis, we don't share. This command returns the name of the axis currently using this location.
π CROSSHAIRS COMPONENT π
Cross hairs are two intersecting lines β one vertical, one horizontal β drawn alllll the way across the plotting area. They're how you position the mouse in relation to the coordinate axes. πΈ
Cross hairs differ from line markers in that they're implemented using XOR drawing primitives. Which means they can be quickly drawn and erased without redrawing the entire graph. Iconic, efficient, slay.
π Note that crosshairs are enabled by callingBlt_Crosshairsand turned off by callingBlt_ResetCrosshairs. Similarly, callBlt_ZoomStackfor zooming.
The following operations are available for cross hairs:
pathName crosshairs cget option
Returns the current value of the cross hairs configuration option given by option. option can be any of the options described below for the crosshairs configure operation.
pathName crosshairs configure ?option value?...
Queries or modifies the configuration options of the cross hairs.
- If option isn't specified, you get back a list describing all the current options for the cross hairs.
- If option is specified but not value, you get a list describing just that option.
- If one or more option and value pairs are specified, then for each pair, the cross hairs option option gets set to value.
The following options are available for cross hairs:
-colorcolor β sets the color of the cross hairs. Default is black.-dashesdashList β sets the dash style of the cross hairs. dashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and the gaps on the cross hair lines. Each number must be between 1 and 255. And if dashList is"", the cross hairs become solid lines. β¨-hideboolean β indicates whether cross hairs are drawn. Careful here bestie, it's the reverse of what you'd expect: if boolean is true, cross hairs are not drawn. The default isyes.-linewidthpixels β sets the width of the cross hair lines. The default is1.-positionpos β specifies the screen position where the cross hairs intersect. pos must be in the form"@x,y", where x and y are the window coordinates of the intersection.
Cross hairs configuration options may also be set by the option command. The resource name and class are crosshairs and Crosshairs respectively.
option add *Graph.Crosshairs.LineWidth 2
option add *Graph.Crosshairs.Color red
pathName crosshairs off
Turns off the cross hairs.
pathName crosshairs on
Turns on the display of the cross hairs.
pathName crosshairs toggle
Toggles the current state of the cross hairs β alternately mapping and unmapping them. It's giving light switch. π¦
π ELEMENT COMPONENTS π
A data element represents a set of data. It holds x and y vectors containing the coordinates of the data points. Elements can be displayed with a symbol at each data point and lines connecting those points. Elements also control how the data looks β the symbol type, line width, color, all of it. Main character energy fr fr.
When new data elements are created, they get automatically added to a list of displayed elements. That display list controls what elements get drawn and in what order. π
The following operations are available for elements.
pathName element activate elemName ?index?...
Specifies the data points of element elemName to be drawn using active foreground and background colors. elemName is the name of the element, and index is a number representing the index of the data point. If no indices are given, then all the data points become active.
pathName element bind tagName ?sequence? ?command?
Associates command with tagName so that whenever the event sequence given by sequence occurs for an element with this tag, command gets invoked. The syntax is similar to the bind command, except it operates on graph elements rather than widgets. See the bind manual entry for the complete details on sequence and the substitutions performed on command before it's invoked.
Here's how it breaks down:
- If all arguments are specified, a new binding is created, replacing any existing binding for the same sequence and tagName.
- If the first character of command is
+, then command augments an existing binding instead of replacing it. - If no command argument is provided, then the command currently associated with tagName and sequence gets returned (and it's an error if there's no such binding).
- If both command and sequence are missing, then you get a list of all the event sequences for which bindings have been defined for tagName.
pathName element cget elemName option
Returns the current value of the element configuration option given by option. option can be any of the options described below for the element configure operation.
pathName element closest x y varName ?option value?... ?elemName?...
okay so this one is lowkey the best and you're gonna use it constantly. It searches for the data point closest to the window coordinates x and y. π
By default, every single element gets searched, no cap. Hidden elements are ignored (peep the -hide option π). And you can narrow the whole thing down by naming only the elements you actually want considered. ElemName has to be the name of an element that isn't hidden β so no sneaking ghost elements in there, bestie, that's not the vibe.
VarName is the name of a Tcl array variable and it comes back stuffed with the search results: the name of the closest element, the index of the closest data point, and the graph coordinates of that point. β¨
Returns 0 if no data point within the threshold distance can be found, otherwise 1 is returned. So like⦠vibe check the return value, fr fr.
The following option-value pairs are available:
-alongdirection β search for the closest element using these criteria:xβ find the closest element vertically from the given X-coordinate.yβ find the closest element horizontally from the given Y-coordinate.bothβ find the closest element for the given point (using both the X and Y coordinates).
-halopixels β specifies a threshold distance where selected data points get ignored. Pixels is a valid screen distance, like2or1.2i. If you don't specify this option, it defaults to the value of the graph's-halooption.-interpolatestring β says whether to consider projections that lie along the line segments connecting data points while hunting for the closest point. The default value is0. The values for string are described below.noβ search only for the closest data point.yesβ search includes projections that lie along the line segments connecting the data points.
Now for the glow-up part: π
pathName element configure elemName ?elemName... ?option value?...
Queries or modifies the configuration options for elements. And yes, you can modify several elements at the same time β multitasking queen behavior. If option isn't specified, a list describing all the current options for elemName is returned. If option is specified but not value, then a list describing the option option is returned. And if one or more option and value pairs are specified, then for each pair, the element option option gets set to value. Slay.
The following options are valid for elements:
-activepenpenName β specifies the pen to use to draw the active element. If penName is"", no active elements will be drawn. The default isactiveLine.-bindtagstagList β specifies the binding tags for the element. TagList is a list of binding tag names. The tags and their order determine how events are handled for elements. Each tag in the list matching the current event sequence will have its Tcl command executed. Implicitly the name of the element is always the first tag in the list. The default value isall.-colorcolor β sets the color of the traces connecting the data points.-dashesdashList β sets the dash style of the element line. DashList is a list of up to11numbers that alternately represent the lengths of the dashes and gaps on the element line. Each number must be between1and255. If dashList is"", the lines will be solid.-datacoordList β specifies the X-Y coordinates of the data. CoordList is a list of numeric expressions representing the X-Y coordinate pairs of each data point.-fillcolor β sets the interior color of symbols. If color is"", then the interior of the symbol is transparent. If color isdefcolor, then the color will be the same as the-coloroption. The default isdefcolor.-hideboolean β indicates whether the element is displayed. The default isno.-labeltext β sets the element's label in the legend. If text is"", the element will have no entry in the legend. The default label is the element's name.-linewidthpixels β sets the width of the connecting lines between data points. If pixels is0, no connecting lines will be drawn between symbols. The default is0.-mapxxAxis β selects the X-axis to map the element's X-coordinates onto. XAxis must be the name of an axis. The default isx.-mapyyAxis β selects the Y-axis to map the element's Y-coordinates onto. YAxis must be the name of an axis. The default isy.-offdashcolor β sets the color of the stripes when traces are dashed (see the-dashesoption). If color is"", then the "off" pixels will represent gaps instead of stripes. If color isdefcolor, then the color will be the same as the-coloroption. The default isdefcolor.-outlinecolor β sets the color or the outline around each symbol. If color is"", then no outline is drawn. If color isdefcolor, then the color will be the same as the-coloroption. The default isdefcolor.-penpenname β set the pen to use for this element.-outlinewidthpixels β sets the width of the outline bordering each symbol. If pixels is0, no outline will be drawn. The default is1.-pixelspixels β sets the size of symbols. If pixels is0, no symbols will be drawn. The default is0.125i.-scalesymbolsboolean β if boolean is true, the size of the symbols drawn for elemName will change with the scale of the X-axis and Y-axis. At the time this option is set, the current ranges of the axes are saved as the normalized scales (i.e. scale factor is1.0) and the element is drawn at its designated size (see the-pixelsoption). As the scale of the axes change, the symbol will be scaled according to the smaller of the X-axis and Y-axis scales. If boolean is false, the element's symbols are drawn at the designated size, regardless of axis scales. The default is0.-smoothsmooth β specifies how connecting line segments are drawn between data points. Smooth can be eitherlinear,step,natural, orquadratic. If smooth islinear, a single line segment is drawn, connecting both data points. When smooth isstep, two line segments are drawn. The first is a horizontal line segment that steps the next X-coordinate. The second is a vertical line, moving to the next Y-coordinate. Bothnaturalandquadraticgenerate multiple segments between data points. Ifnatural, the segments are generated using a cubic spline. Ifquadratic, a quadratic spline is used. The default islinear.-stylesstyleList β specifies what pen to use based on the range of weights given. StyleList is a list of style specifications. Each style specification, in turn, is a list consisting of a pen name, and optionally a minimum and maximum range. Data points whose weight (see the-weightoption) falls in this range are drawn with this pen. If no range is specified it defaults to the index of the pen in the list. Note that this affects only symbol attributes. Line attributes, such as line width, dashes, etc. are ignored.-symbolsymbol β specifies the symbol for data points. Symbol can be eithersquare,circle,diamond,plus,cross,splus,scross,triangle,""(where no symbol is drawn), or a bitmap. Bitmaps are specified as"source ?mask?", where source is the name of the bitmap, and mask is the bitmap's optional mask. The default iscircle.-tracedirection β indicates whether connecting lines between data points (whose X-coordinate values are either increasing or decreasing) are drawn. Direction must beincreasing,decreasing, orboth. For example, if direction isincreasing, connecting lines will be drawn only between those data points where X-coordinate values are monotonically increasing. If direction isboth, connecting lines will be drawn between all data points. The default isboth.-weightswVec β specifies the weights of the individual data points. This, with the list pen styles (see the-stylesoption), controls how data points are drawn. WVec is the name of a BLT vector or a list of numeric expressions representing the weights for each data point.-xdataxVec β specifies the X-coordinates of the data. XVec is the name of a BLT vector or a list of numeric expressions.-ydatayVec β specifies the Y-coordinates of the data. YVec is the name of a BLT vector or a list of numeric expressions.
Element configuration options may also be set by the option command. The resource class is Element. The resource name is the name of the element.
option add *Graph.Element.symbol line
option add *Graph.e1.symbol line
pathName element create elemName ?option value?...
Creates a new element elemName. It's an error if an element elemName already exists β like, duplicate names are not it. π If additional arguments are present, they specify options valid for the element configure operation.
pathName element deactivate elemName ?elemName?...
Deactivates all the elements matching pattern. Elements whose names match any of the patterns given are redrawn using their normal colors. back to their regular fit, basically. π
pathName element delete ?elemName?...β yeets every element you name π and the graph gets redrawn all by itself, no extra steps.pathName element exists elemNameβ hands back1if an element called elemName is out here existing right now, and0if she's simply not.pathName element names ?pattern?...β returns the elements matching one or more pattern. Give it no pattern and you get the names of literally every single element. πpathName element show ?nameList?β queries or changes the element display list, which is the iconic little roster that says which elements get drawn and in what order. nameList is a list of elements to display in the order they're named. Skip the nameList argument and you just get the current display list back. π«ΆpathName element type elemNameβ returns the type of elemName. If the element is a bar element, the command returns the string"bar"; otherwise it returns"line". That's it, that's the whole vibe check. β¨
π GRID COMPONENT π
Grid lines stretch from the major and minor ticks of each axis, horizontally or vertically, all the way across the plotting area. Here's everything you can do with them.
pathName grid cget optionβ returns the current value of the grid line configuration option given by option. option can be any of the options described below for thegrid configureoperation. πpathName grid configure ?option value?...β queries or modifies the configuration options for grid lines. If option isn't specified, you get back a list describing all the current grid options forpathName. If option is specified but value isn't, you get a list describing option. And if one or more option and value pairs are specified, then for each pair the grid line option option gets set to value. These are the valid options, bestie:-colorcolor β sets the color of the grid lines. Default isblack.-dashesdashList β sets the dash style of the grid lines. dashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and the gaps on the grid lines. Each number has to be between 1 and 255. If dashList is"", the grid will be solid lines.-hideboolean β says whether the grid should be drawn. If boolean is true, grid lines are not shown. The default isyes.-linewidthpixels β sets the width of grid lines. The default width is1.-mapxxAxis β specifies the X-axis to display grid lines. xAxis must be the name of an axis, or""for no grid lines. The default is"".-mapyyAxis β specifies the Y-axis to display grid lines. yAxis must be the name of an axis, or""for no grid lines. The default isy.-minorboolean β says whether the grid lines should be drawn for minor ticks. If boolean is true, the lines appear at minor tick intervals. The default is1.
Grid configuration options can also be set through the option command. The resource name and class are grid and Grid respectively. Like so, babes:
option add *Graph.grid.LineWidth 2
option add *Graph.Grid.Color black
-raisedboolean β Grid is to be raised or drawn over elements. π₯
pathName grid offβ turns off the display of the grid lines.pathName grid onβ turns on the display of the grid lines.pathName grid toggleβ toggles the display of the grid. A lil flip of the switch, as a treat. πΈ
π¦ LEGEND COMPONENT π¦
The legend displays a list of the data elements. Every entry is made up of the element's symbol and its label. The legend can show up in any margin (the default location is the right margin), and it can also be positioned anywhere inside the plotting area. Main character energy, honestly. π
The following operations are valid for the legend.
pathName legend activate pattern...β selects legend entries to be drawn using the active legend colors and relief. Every entry whose element name matches pattern gets selected. To be selected, the element name must match only one pattern.pathName legend bind tagName ?sequence? ?command?β associates command with tagName so that whenever the event sequence given by sequence occurs for a legend entry with this tag, command gets invoked. Implicitly, the element names in the entry are tags. The syntax is similar to thebindcommand, except that it operates on legend entries rather than widgets. Go read thebindmanual entry for the complete details on sequence and the substitutions performed on command before it's invoked. π
If all arguments are specified, then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is +, then command augments an existing binding instead of replacing it. If no command argument is provided, then the command currently associated with tagName and sequence is returned (and it's an error if there's no such binding). If both command and sequence are missing, then you get a list of all the event sequences for which bindings have been defined for tagName.
pathName legend cget optionβ returns the current value of a legend configuration option. option can be any option described below in thelegend configureoperation.pathName legend configure ?option value?...β queries or modifies the configuration options for the legend. If option isn't specified, a list describing the current legend options forpathNameis returned. If option is specified but value isn't, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair the legend option option is set to value. These are the valid options for the legend:-activebackgroundcolor β sets the background color for active legend entries. Every legend entry marked active (see thelegend activateoperation) gets drawn with this background color.-activeborderwidthpixels β sets the width of the 3-D border around the outside edge of the active legend entries. The default is2.-activeforegroundcolor β sets the foreground color for active legend entries. All legend entries marked as active (see thelegend activateoperation) get drawn with this foreground color.-activereliefrelief β specifies the 3-D effect you want for active legend entries. relief denotes how the interior of the entry should appear relative to the legend; for example,raisedmeans the entry should appear to protrude from the legend, relative to the surface of the legend. The default isflat.-anchoranchor β tells how to position the legend relative to the positioning point for the legend. This depends on the value of the-positionoption. The default iscenter.- left or right β The anchor describes how to position the legend vertically.
- top or bottom β The anchor describes how to position the legend horizontally.
- @x,y β The anchor specifies how to position the legend relative to the positioning point. For example, if anchor is
centerthen the legend is centered on the point; if anchor isnthen the legend will be drawn such that the top center point of the rectangular region occupied by the legend will be at the positioning point. - plotarea β The anchor specifies how to position the legend relative to the plotting area. For example, if anchor is
centerthen the legend is centered in the plotting area; if anchor isnethen the legend will be drawn such that it occupies the upper right corner of the plotting area.
-backgroundcolor β sets the background color of the legend. If color is"", the legend background will be transparent. β¨-bindtagstagList β specifies the binding tags for legend entries. tagList is a list of binding tag names. The tags and their order determine how events are handled for legend entries. Each tag in the list matching the current event sequence will have its Tcl command executed. The default value isall.-borderwidthpixels β sets the width of the 3-D border around the outside edge of the legend (if such a border is being drawn; thereliefoption decides that). The default is2pixels.-fontfontName β fontName specifies a font to use when drawing the labels of each element into the legend. The default is*-Helvetica-Bold-R-Normal-*-12-120-*.-foregroundcolor β sets the foreground color of the text drawn for the element's label. The default isblack.-hideboolean β says whether the legend should be displayed. If boolean is true, the legend will not be drawn. The default isno.-ipadxpad β sets the amount of internal padding to be added to the width of each legend entry. pad can be a list of one or two screen distances. If pad has two elements, the left side of the legend entry is padded by the first distance and the right side by the second. If pad is just one distance, both the left and right sides are padded evenly. The default is2. π
-ipadypad β sets how much internal padding gets added to the height of each legend entry π pad can be a list of one or two screen distances. Two elements? Then the top of the entry gets padded by the first distance and the bottom by the second. Just one distance? Both top and bottom get padded evenly, no favorites. Default is2.-padxpad β the padding for the left and right exteriors of the legend β¨ pad can be a list of one or two screen distances. Two elements means the left side is padded by the first distance and the right side by the second. One distance means both sides get padded evenly. Default is4.-padypad β sets the padding above and below the legend π pad can be a list of one or two screen distances. With two elements, the area above the legend is padded by the first distance and the area below by the second. With just one distance, top and bottom areas get padded evenly. Default is0.-positionpos β where the legend actually gets drawn π the-anchoroption also affects where the legend is positioned, so they're besties, lowkey. If pos isleft,left,top, orbottom, the legend is drawn in the specified margin. If pos isplotarea, then the legend is drawn inside the plotting area at a particular anchor. And if pos is in the form"@x,y", where x and y are the window coordinates, the legend is drawn in the plotting area at the specified coordinates. Default isright.-raisedboolean β says whether the legend is above or below the data elements π this only matters if the legend is in the plotting area, so if it's not, this option is literally just vibing. If boolean is true, the legend will be drawn on top of any elements that may overlap it. Default isno.-reliefrelief β the 3-D effect for the border around the legend π¦ relief specifies how the interior of the legend should appear relative to the graph; for example,raisedmeans the legend should appear to protrude from the graph, relative to the surface of the graph. Default issunken.
Legend configuration options may also be set by the option command π
The resource name and class are legend and Legend respectively, so:
option add *Graph.legend.Foreground blue
option add *Graph.Legend.Relief raised
β¨ pathName legend deactivate pattern... β¨
Selects legend entries to be drawn using the normal legend colors and relief π All entries whose element names match pattern are selected. To be selected, the element name must match only one pattern β no double-dipping.
β¨ pathName legend get pos β¨
Returns the name of the element whose entry is at the screen position pos in the legend π pos must be in the form "@x,y", where x and y are window coordinates. If the given coordinates do not lie over a legend entry, "" is returned. Sad, but accurate π
ποΈ PEN COMPONENTS ποΈ
Pens define attributes (both symbol and line style) for elements β¨ Pens mirror the configuration options of data elements that pertain to how symbols and lines are drawn. Data elements use pens to determine how they are drawn. And a data element may use several pens at once β main character behavior, honestly. In this case, the pen used for a particular data point is determined from each element's weight vector (see the element's -weight and -style options).
One pen, called activeLine, is automatically created π It's used as the default active pen for elements. So you can change the active attributes for all elements by simply reconfiguring this pen:
.g pen configure "activeLine" -color green
You can create and use several pens. To create a pen, invoke the pen component and its create operation:
.g pen create myPen
You map pens to a data element using either the element's -pen or -activepen options:
.g element create "line1" -xdata $x -ydata $tempData \
-pen myPen
An element can use several pens at once πΈ This is done by specifying the name of the pen in the element's style list (see the -styles option):
.g element configure "line1" -styles { myPen 2.0 3.0 }
This says that any data point with a weight between 2.0 and 3.0 is to be drawn using the pen myPen π All other points are drawn with the element's default attributes.
The following operations are available for pen components.
β¨ pathName pen cget penName option β¨
Returns the current value of the option given by option for penName π option may be any option described below for the pen configure operation.
β¨ pathName pen configure penName ?penName... ?option value?... β¨
Queries or modifies the configuration options of penName π§ Several pens can be modified at once. If option isn't specified, a list describing the current options for penName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the pen option option is set to value. The following options are valid for pens.
-colorcolor β sets the color of the traces connecting the data points π¨-dashesdashList β sets the dash style of element line βοΈ dashList is a list of up to11numbers that alternately represent the lengths of the dashes and gaps on the element line. Each number must be between1and255. If dashList is"", the lines will be solid.-fillcolor β sets the interior color of symbols π If color is"", then the interior of the symbol is transparent. If color isdefcolor, then the color will be the same as the-coloroption. Default isdefcolor.-linewidthpixels β sets the width of the connecting lines between data points π If pixels is0, no connecting lines will be drawn between symbols. Default is0.-offdashcolor β sets the color of the stripes when traces are dashed (see the-dashesoption) π If color is"", then the "off" pixels will represent gaps instead of stripes. If color isdefcolor, then the color will be the same as the-coloroption. Default isdefcolor.-outlinecolor β sets the color or the outline around each symbol βοΈ If color is"", then no outline is drawn. If color isdefcolor, then the color will be the same as the-coloroption. Default isdefcolor.-outlinewidthpixels β sets the width of the outline bordering each symbol ποΈ If pixels is0, no outline will be drawn. Default is1.-pixelspixels β sets the size of symbols β If pixels is0, no symbols will be drawn. Default is0.125i.-symbolsymbol β specifies the symbol for data points π· symbol can be eithersquare,circle,diamond,plus,cross,splus,scross,triangle,""(where no symbol is drawn), or a bitmap. Bitmaps are specified as"source ?mask?", where source is the name of the bitmap, and mask is the bitmap's optional mask. Default iscircle.-typeelemType β specifies the type of element the pen is to be used with π§ This option should only be employed when creating the pen. This is for those that wish to mix different types of elements (bars and lines) on the same graph. The default type is"line".
Pen configuration options may be also be set by the option command π
The resource class is Pen. The resource names are the names of the pens.
option add *Graph.Pen.Color blue
option add *Graph.activeLine.color green
β¨ pathName pen create penName ?option value?... β¨
Creates a new pen by the name penName π No pen by the same name can already exist. option and value are described in above in the pen configure operation.
β¨ pathName pen delete ?penName?... β¨
Deletes the named pens ποΈ A pen is not really deleted until it is not longer in use, so it's safe to delete pens mapped to elements. Iconic, honestly β it waits for you to be done.
β¨ pathName pen names ?pattern?... β¨
Returns a list of pens matching zero or more patterns π If no pattern argument is give, the names of all pens are returned.
π¨οΈ POSTSCRIPT COMPONENT π¨οΈ
The graph can generate encapsulated PostScript output β¨ There are several configuration options you can specify to control how the plot will be generated. You can change the page dimensions and borders. The plot itself can be scaled, centered, or rotated to landscape. The PostScript output can be written directly to a file or returned through the interpreter. Versatile fr fr.
The following postscript operations are available.
β¨ pathName postscript cget option β¨
Returns the current value of the postscript option given by option π option may be any option described below for the postscript configure operation.
β¨ pathName postscript configure ?option value?... β¨
Queries or modifies the configuration options for PostScript generation π§ If option isn't specified, a list describing the current postscript options for pathName is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the postscript option option is set to value. The following postscript options are available.
-centerboolean β indicates whether the plot should be centered on the PostScript page π― If boolean is false, the plot will be placed in the upper left corner of the page. Default is1.-colormapvarName β bestie, varName has to be the name of a global array variable that maps X color names β PostScript. Every element of varName has to be PostScript code that sets a color value, like`1.0 1.0 0.0 setrgbcolor`π . When the graph is cooking up color info for PostScript, it checks varName to see if there's an element named after that color. If yes? It uses that value as the PostScript command to set the color, periodt. If you never set this option, or there's just no entry in varName for that color, it falls back to the red, green, and blue intensities from the X color. π-colormodemode β tells it how to spit out color info. mode has to be one of:colorβ full color output, the moment β¨grayβ converts all colors to their gray-scale equivalentsmonoβ converts foreground colors to black and background colors to white
The default mode is color. π
-fontmapvarName β varName must be the name of a global array variable that maps X font names β PostScript. Each element of varName has to be a Tcl list with one or two elements: the name and point size of a PostScript font. When it's outputting PostScript commands for a particular font, it checks varName for an element by that font. If there is one, the font info in that element goes into the PostScript output. (If the point size is omitted from the list, the point size of the X font is used instead.) Otherwise it examines the X font and tries to guess what PostScript font to use β and ngl this only works for fonts whose foundry property is Adobe (like Times, Helvetica, Courier, etc.). If all of that fails, the font defaults toHelvetica-Bold. π-decorationsboolean β says whether PostScript commands to generate color backgrounds and 3-D borders get output. If boolean is false, the background is white and no 3-D borders are generated at all. Default is1. π-heightpixels β sets the height of the plot. This is the glow-up that lets you print the graph at a height different from what's drawn on screen. If pixels is0, the height matches the widget's height. Default is0. π-landscapeboolean β if boolean is true, the printed area gets rotated 90 degrees, iconic. In non-rotated output the X-axis of the printed area runs along the short dimension of the page (that'sportrait '' orientation); in rotated output the X-axis runs along the **long** dimension of the page (landscape '' orientation). Defaults to0. π¦-maxpectboolean β scales the plot so it fills the PostScript page. The aspect ratio of the graph is still retained, no cap. Default is0. β¨-padxpad β sets the horizontal padding for the left and right page borders. These borders are exterior to the plot. pad can be a list of one or two screen distances. Two elements? The left border gets padded by the first distance, the right border by the second. Just one distance? Both left and right get padded evenly. Default is1i. π-padypad β sets the vertical padding for the top and bottom page borders. Borders are exterior to the plot. pad can be a list of one or two screen distances. Two elements? Top border padded by the first distance, bottom by the second. One distance? Both top and bottom padded evenly. Default is1i. π«Ά-paperheightpixels β sets the height of the postscript page. Use this to pick between page sizes (letter, A4, etc). Default height is11.0i. π-paperwidthpixels β sets the width of the postscript page. Again, this picks between page sizes (letter, A4, etc). Default width is8.5i. π-widthpixels β sets the width of the plot, letting you generate a plot at a width different from the widget's. If pixels is0, the width matches the widget's width. Default is0. π
Postscript configuration options may also be set by the option command. The resource name and class are postscript and Postscript respectively. Like, for real:
option add *Graph.postscript.Decorations false
option add *Graph.Postscript.Landscape true
πΈ THE postscript OPERATION πΈ
pathName postscript output ?fileName? ?option value?...
Outputs a file of encapsulated PostScript, slay. If a fileName argument isn't present, the command returns the PostScript right to you instead. If any option-value pairs are present, they set configuration options controlling how the PostScript is generated. Option and value can be anything accepted by the postscript configure operation above. π
π MARKER COMPONENTS π
Markers are simple drawing procedures used to annotate or highlight areas of the graph. They come in various types: text strings, bitmaps, images, connected lines, windows, or polygons β a whole squad. They can be associated with a particular element, so that when the element is hidden or un-hidden, so is the marker (besties that vanish together π). By default, markers are the last items drawn, so data elements will appear in behind them. You can change this by configuring the -under option. π
Markers, in contrast to elements, don't affect the scaling of the coordinate axes. They can also have elastic coordinates (specified by -Inf and Inf respectively) that translate into the minimum or maximum limit of the axis. For example, you can place a marker so it always remains in the lower left corner of the plotting area, by using the coordinates -Inf,-Inf. Lowkey iconic. β¨
The following operations are available for markers. π
pathName marker after markerId ?afterId?
Changes the order of the markers, drawing the first marker after the second. If no second afterId argument is specified, the marker is placed at the end of the display list. This command can be used to control how markers are displayed, since markers are drawn in the order of this display list. π
pathName marker before markerId ?beforeId?
Changes the order of the markers, drawing the first marker before the second. If no second beforeId argument is specified, the marker is placed at the beginning of the display list. Same deal β this controls how markers are displayed, since markers are drawn in the order of this display list. π¦
pathName marker bind tagName ?sequence? ?command?
Associates command with tagName such that whenever the event sequence given by sequence occurs for a marker with this tag, command will be invoked. The syntax is similar to the bind command except that it operates on graph markers, rather than widgets. See the bind manual entry for complete details on sequence and the substitutions performed on command before invoking it. π
If all arguments are specified then a new binding is created, replacing any existing binding for the same sequence and tagName. If the first character of command is + then command augments an existing binding rather than replacing it. If no command argument is provided then the command currently associated with tagName and sequence is returned (it's an error if there's no such binding). If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName comes back to you. π
pathName marker cget option
Returns the current value of the marker configuration option given by option. Option may be any option described below in the configure operation. π
pathName marker configure markerId ?option value?...
Queries or modifies the configuration options for markers. If option isn't specified, a list describing the current options for markerId is returned. If option is specified, but not value, then a list describing option is returned. If one or more option and value pairs are specified, then for each pair, the marker option option is set to value. π
The following options are valid for all markers. Each type of marker also has its own type-specific options β they're described in the sections below. πΈ
-bindtagstagList β specifies the binding tags for the marker. TagList is a list of binding tag names. The tags and their order determine how events for markers are handled. Each tag in the list matching the current event sequence will have its Tcl command executed. Implicitly, the name of the marker is always the first tag in the list. The default value isall. β¨-coordscoordList β specifies the coordinates of the marker. CoordList is a list of graph coordinates. The number of coordinates required depends on the type of marker, iykyk:- Text, image, and window markers need only two coordinates (an X-Y coordinate).
- Bitmap markers can take either two or four coordinates (if four, they represent the corners of the bitmap).
- Line markers need at least four coordinates, polygons at least six.
If coordList is "", the marker will not be displayed. The default is "". π―
-elementelemName β links the marker with the element elemName. The marker is drawn only if the element is also currently displayed (see the element'sshowoperation). If elemName is"", the marker is always drawn. The default is"". π-hideboolean β is the marker even being drawn rn? If boolean is true, nope, it's hidden. Default isno. π-mapxxAxis β which X-axis the marker's X-coordinates get mapped onto. xAxis has to be the name of an axis. Default isx.-mapyyAxis β same deal but for Y: which Y-axis the marker's Y-coordinates get mapped onto. yAxis must be an axis name. Default isy.-namemarkerId β renames the marker, changing its identifier. Heads up bestie: markerId can not already be used by another marker. If you don't pass this option, the marker's name is uniquely generated for you. β¨-underboolean β does the marker chill below or above the data elements? If boolean is true, the marker is drawn underneath the data element symbols and lines. Otherwise it's drawn on top of the element. Default is0.-xoffsetpixels β a screen distance to nudge the marker horizontally. pixels is a valid screen distance, like2or1.2i. Default is0.-yoffsetpixels β same energy, vertical. pixels is a valid screen distance, such as2or1.2i. Default is0.
Marker configuration options may also be set with the option command, iykyk. The resource class is either BitmapMarker, ImageMarker, LineMarker, PolygonMarker, TextMarker, or WindowMarker, depending on what kind of marker it is. The resource name is the name of the marker. π
option add *Graph.TextMarker.Foreground white
option add *Graph.BitmapMarker.Foreground white
option add *Graph.m1.Background blue
pathName marker createtype ?option value?... β makes a marker of the chosen type. type can be eithertext,line,bitmap,image,polygon, orwindow. This command hands you back the marker identifier, which you then use as the markerId argument in all the other marker-related commands. If the-nameoption is used, it overrides the normal marker identifier. And if that name is already used by another marker, the new marker replaces the old one. πpathName marker delete?name?... β yeets one or more markers. The graph automatically redraws itself without the marker. poof, gone π¦pathName marker existsmarkerId β returns1if the marker markerId exists and0otherwise.pathName marker names?pattern? β returns the names of every marker that currently exists. If pattern is supplied, only the markers whose names match it come back.pathName marker typemarkerId β returns the type of the marker given by markerId, likelineortext. If markerId isn't a valid marker identifier, you get""back. π
πΌοΈ BITMAP MARKERS πΌοΈ
A bitmap marker displays a bitmap. The size of the bitmap is controlled by how many coordinates you specify. Give it two coordinates and they specify the position of the top-left corner of the bitmap β the bitmap keeps its normal width and height, no notes. Give it four coordinates and the first and second pairs of coordinates represent the corners of the bitmap. The bitmap gets stretched or reduced as necessary to fit into that bounding rectangle. β¨
Bitmap markers are created with the marker's create operation like this:
pathName marker create bitmap ?option value?...
There may be many option-value pairs, each one setting a configuration option for the marker. Those same option-value pairs may also be used with the marker's configure operation.
The following options are specific to bitmap markers:
-backgroundcolor β same as the-filloption.-bitmapbitmap β specifies the bitmap to be displayed. If bitmap is"", the marker will not be displayed. Default is"".-fillcolor β sets the background color of the bitmap. If color is the empty string, no background will be transparent. The default background color is"".-foregroundcolor β same as the-outlineoption.-maskmask β specifies a mask for the bitmap to be displayed. This mask is a bitmap itself, denoting the pixels that are transparent. If mask is"", all pixels of the bitmap will be drawn. Default is"".-outlinecolor β sets the foreground color of the bitmap. Default value isblack.-rotatetheta β sets the rotation of the bitmap. theta is a real number representing the angle of rotation in degrees. The marker is first rotated and then placed according to its anchor position. Default rotation is0.0. π
πΈ IMAGE MARKERS πΈ
An image marker displays an image. Image markers are created with the marker's create operation like this:
pathName marker create image ?option value?...
There may be many option-value pairs, each setting a configuration option for the marker. Those same option-value pairs may be used with the marker's configure operation too.
The following options are specific to image markers:
-anchoranchor β anchor tells how to position the image relative to the positioning point for the image. For example, if anchor iscenterthen the image is centered on the point; if anchor isnthen the image will be drawn such that the top center point of the rectangular region occupied by the image will be at the positioning point. This option defaults tocenter.-imageimage β specifies the image to be drawn. If image is"", the marker will not be drawn. Default is"".
π LINE MARKERS π
A line marker displays one or more connected line segments. Line markers are created with the marker's create operation in the form:
pathName marker create line ?option value?...
There may be many option-value pairs, each setting a configuration option for the marker. Those same option-value pairs may be used with the marker's configure operation.
The following options are specific to line markers:
-dashesdashList β sets the dash style of the line. dashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the line. Each number must be between1and255. If dashList is"", the marker line will be solid.-fillcolor β sets the background color of the line. This color is used with striped lines (see the-fdashesoption). If color is the empty string, no background color is drawn (the line will be dashed, not striped). The default background color is"".-linewidthpixels β sets the width of the lines. Default width is0.-outlinecolor β sets the foreground color of the line. Default value isblack.-stipplebitmap β specifies a stipple pattern used to draw the line, rather than a solid line. bitmap specifies a bitmap to use as the stipple pattern. If bitmap is"", then the line is drawn in a solid fashion. Default is"".
πΊ POLYGON MARKERS πΊ
A polygon marker displays a closed region described as two or more connected line segments. It's assumed the first and last points are connected, obviously. Polygon markers are created using the marker create operation in the form:
pathName marker create polygon ?option value?...
There may be many option-value pairs, each setting a configuration option for the marker. Those same option-value pairs may be used with the marker configure command to change the marker's configuration. The following options are supported for polygon markers:
-dashesdashList β sets the dash style of the outline of the polygon. dashList is a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the outline. Each number must be between1and255. If dashList is"", the outline will be a solid line.-fillcolor β sets the fill color of the polygon. If color is"", then the interior of the polygon is transparent. Default iswhite.-linewidthpixels β sets the width of the outline of the polygon. If pixels is zero, no outline is drawn. Default is0.-outlinecolor β sets the color of the outline of the polygon. If the polygon is stippled (see the-stippleoption), then this represents the foreground color of the stipple. Default isblack.-stipplebitmap β specifies that the polygon should be drawn with a stippled pattern rather than a solid color. bitmap specifies a bitmap to use as the stipple pattern. If bitmap is"", then the polygon is filled with a solid color (if the-filloption is set). Default is"".
π¬ TEXT MARKERS π¬
A text marker displays a string of characters on one or more lines of text. Embedded newlines cause line breaks. They may be used to annotate regions of the graph. Text markers are created with the create operation in the form:
pathName marker create text ?option value?...
There may be many option-value pairs, each setting a configuration option for the text marker. Those same option-value pairs may be used with the marker's configure operation.
The following options are specific to text markers:
-anchoranchor β anchor tells how to position the text relative to the positioning point for the text. For example, if anchor iscenterthen the text is centered on the point; if anchor isnthen the text will be drawn such that the top center point of the rectangular region occupied by the text will be at the positioning point. This default iscenter.-backgroundcolor β same as the-filloption.-fontfontName β specifies the font of the text. Default is*-Helvetica-Bold-R-Normal-*-120-*.-fillcolor β sets the background color of the text. If color is the empty string, no background will be transparent. The default background color is"".-foregroundcolor β same as the-outlineoption.-justifyjustify β specifies how the text should be justified. This only matters when the marker contains more than one line of text. justify must beleft,right, orcenter. Default iscenter.-outlinecolor β sets the color of the text. Default value isblack.-padxpad β the personal space bubble for the left and right sides of the text, bestie. pad can be a list of one or two screen distances. Two elements? Left side gets padded by the first distance, right side by the second. Just one distance? Both sides get padded evenly, symmetric queen. Default is4.-padypad β same energy but vertical π . Sets the padding above and below the text. pad can be a list of one or two screen distances. Two elements β the area above gets the first distance, the area below gets the second. One distance β top and bottom both padded evenly. Default is4.-rotatetheta β spins the text, no cap. theta is a real number for the angle of rotation in degrees. The marker gets rotated around its center first, then drawn according to its anchor position. Default is0.0.-texttext β literally just the text of the marker, that's it. Heads up though: how it actually shows up can be affected by other options like-anchoror-rotate. So don't come for me if it looks weird, check your other settings first π«Ά.
πͺ WINDOW MARKERS πͺ
A window marker is giving widget, but make it a landmark β it displays a widget at a given position. You create them with the marker's create operation, like this:
pathName marker create window ?option value?...
There can be a whole bunch of option-value pairs, and each one sets a configuration option for the marker. Same option-value pairs work with the marker's configure command too, iykyk.
These are the options that are specifically for window markers:
-anchoranchor β tells you how to position the widget relative to the positioning point. So if anchor iscenter, the widget is centered on the point. If anchor isn, the widget shows up so that the top center point of the rectangular region it occupies sits at the positioning point. Defaults tocenter.-heightpixels β the height you're assigning to the marker's window. If you don't specify it, or you specify it as"", the window just gets whatever height the widget requests internally. Let the widget choose, main character behavior β¨.-widthpixels β the width you're assigning to the marker's window. If it's not specified, or it's specified as"", the window gets whatever width the widget requests internally.-windowpathName β the widget that the graph is going to manage. pathName must be a child of the graph widget, no exceptions, that's the rule π.
π GRAPH COMPONENT BINDINGS π
Specific graph components β elements, markers, legend entries β can have a command trigger when an event happens in them, basically exactly like canvas items in Tk's canvas widget. But not every event sequence is valid, bestie. The only binding events you can specify are the ones related to the mouse and keyboard, like Enter, Leave, ButtonPress, Motion, and KeyPress.
Only one element or marker can be picked during an event. Which means if your mouse is sitting directly over both an element and a marker, only the uppermost component gets selected. That's just how it is. This is not true for legend entries though β for those, both a legend entry binding command and an element (or marker) binding command will be invoked if both items are picked. Two for one, slay.
It's possible for multiple bindings to match a particular event. This could happen if, say, one binding is associated with the element name and another is associated with one of the element's tags (peep the -bindtags option). When that happens, all the matching bindings get invoked. The binding associated with the element name goes first, then one binding for each of the element's bindtags. And if there are multiple matching bindings for a single tag, then only the most specific binding is invoked. A continue command in a binding script terminates that script, and a break command terminates that script and skips any remaining scripts for the event β exactly like the bind command does.
The -bindtags option for these components controls additional tag names that can be matched. Implicitly, elements and markers always have tags matching their names, and setting the value of the -bindtags option doesn't change that. Periodt.
π§ C LANGUAGE API π§
Okay so you can manipulate data elements straight from the C language. Sometimes it's just too expensive to translate data values from ASCII strings π, or maybe you wanna read data in some special file format. Valid.
Data can be manipulated from C using BLT vectors. You specify the X-Y data coordinates of an element as vectors and then manipulate the vector from C. The graph will redraw itself automatically after the vectors are updated. No manual refresh needed, iconic.
From Tcl, create the vectors and configure the element to use them:
vector X Y
.g element configure line1 -xdata X -ydata Y
To set data points from C, you pass the values as arrays of doubles using the Blt_ResetVector call. The vector gets reset with the new data, and at the next idle point (when Tk re-enters its event loop), the graph redraws automatically β¨.
#include <tcl.h>
#include <blt.h>
register int i;
Blt_Vector *xVec, *yVec;
double x[50], y[50];
/* Get the BLT vectors "X" and "Y" (created above from Tcl) */
if ((Blt_GetVector(interp, "X", &xVec) != TCL_OK) ||
(Blt_GetVector(interp, "Y", &yVec) != TCL_OK)) {
return TCL_ERROR;
}
for (i = 0; i < 50; i++) {
x[i] = i * 0.02;
y[i] = sin(x[i]);
}
/* Put the data into BLT vectors */
if ((Blt_ResetVector(xVec, x, 50, 50, TCL_VOLATILE) != TCL_OK) ||
(Blt_ResetVector(yVec, y, 50, 50, TCL_VOLATILE) != TCL_OK)) {
return TCL_ERROR;
}
See the vector manual page for more details, bestie π«Ά.
β‘ SPEED TIPS β‘
There are cases where the graph needs to be drawn and updated as fast as humanly possible. If drawing speed becomes a big problem, here are a few tips to speed up displays:
- Try to minimize the number of data points. The more data points that get looked at, the more work the graph has to do. Simple math, no cap.
- If your data is generated as floating point values, the time needed to convert data values to and from ASCII strings can be significant, especially when there are many data points. You can dodge the redundant string-to-decimal conversions using the C API to BLT vectors.
- Data elements without symbols are drawn faster than with symbols. Set the data element's
-symboloption tonone. If you really need symbols, try the simple ones likesplusandscross. - Don't stipple or dash the element. Solid lines are much faster. Solid is the moment π .
- If you update data elements frequently, try turning off the widget's
-bufferelementsoption. When the graph is first displayed, it draws data elements into an internal pixmap. That pixmap acts as a cache, so when the graph needs to be redrawn and the data elements or coordinate axes haven't changed, the pixmap is just copied to the screen. This is especially useful when you're using markers to highlight points and regions on the graph. But if the graph is updated frequently β changing either the element data or coordinate axes β the buffering becomes redundant.
π LIMITATIONS π
Auto-scale routines do not use requested min/max limits as boundaries when the axis is logarithmically scaled. Just so you know, don't come for me.
The PostScript output generated for polygons with more than 1500 points may exceed the limits of some printers (See PostScript Language Reference Manual, page 568). The work-around is to break the polygon into separate pieces.
π KEYWORDS π
graph, widget
And that's the whole page, bestie, you made it to the end ππ This was from the BLT 2.5 era, the blt::graph(3tcl) manual page β go forth and graph gorgeously, you absolute legend ππβ
π¦ where this page comes from
- debian bookworm: blt-dev 2.5.3+dfsg-4.1
- debian trixie: blt-dev 2.5.3+dfsg-8
- ubuntu jammy: blt-dev 2.5.3+dfsg-4.1build2
- ubuntu noble: blt-dev 2.5.3+dfsg-7build1
- ubuntu questing: blt-dev 2.5.3+dfsg-8
- ubuntu resolute: blt-dev 2.5.3+dfsg-8build1
- ubuntu stonking: blt-dev 2.5.3+dfsg-9
- Copyright 1991-1998 by Bell Labs Innovations for Lucent Technologies
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms