blt::barchart(3tcl)
π blt::barchart β the vibe-coded guide to bar charts π
okay bestie, sit down, grab a strawberry π, because we're talking about blt::barchart from the BLT Built-In Commands β and no, it is not a snack, it's the thing that draws your X-Y data as bars and it's lowkey iconic.
β¨ NAME β¨
barchart β Bar chart for plotting X-Y coordinate data. that's it, that's the whole job description, and she does it flawlessly π
πΈ SYNOPSIS πΈ
barchart pathName ?option value?...
π DESCRIPTION π
so the barchart command makes you a bar chart for plotting two-dimensional data (X-Y coordinates). a bar chart is basically a graphic way of comparing numbers by showing bars whose lengths are proportional to the y-coordinates of the points they represent. math but make it fashion β¨
and the bar chart has so many configurable components it's giving main character energy: coordinate axes, elements, legend, grid lines, cross hairs, etc. they let you customize the look and feel of the graph β like, full glow-up, no cap.
π¦ INTRODUCTION π¦
the barchart command creates a new window for plotting two-dimensional data (X-Y coordinates), using bars of various lengths to represent the data points. the bars are drawn in a rectangular area displayed in the center of the new window. this is the plotting area. π«Ά
the coordinate axes are drawn in the margins surrounding the plotting area. by default, the legend is drawn in the right margin. the title is displayed in the top margin. cute, organized, we love a layout queen π
a barchart widget has several configurable components: coordinate axes, data elements, legend, grid, cross hairs, pens, postscript, and annotation markers. each component can be queried or modified. here's the whole squad:
- axis β up to four coordinate axes (two X-coordinate and two Y-coordinate axes) can be displayed, but you can create and use any number of axes. 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.
- element β an element represents a set of data to be plotted. it contains an x and y vector of values representing the data points. each data point is displayed as a bar where the length of the bar is proportional to the ordinate (Y-coordinate) of the data point. the appearance of the bar, such as its color, stipple, or relief, is configurable.
π¨ special case alert π¨ when two or more data points have the same abscissa (X-coordinate). by default, the bars are overlayed, one on top of the other. the bars are drawn in the order of the element display list. but you can also configure the bars to be displayed in two other ways: they may be displayed as a stack, where each bar (with the same abscissa) is stacked on the previous. or they can be drawn side-by-side as thin bars. the width of each bar is a function of the number of data points with the same abscissa. literally three whole aesthetics, pick your fighter π
- grid β extends the major and minor ticks of the X-axis and/or Y-axis across the plotting area.
- legend β the legend displays the name and symbol of each data element. the legend can be drawn in any margin or in the plotting area. flexible fr fr.
- marker β markers are used to annotate or highlight areas of the graph. for example, you could use 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. the range?? unmatched π
- pen β pens define attributes for elements. data elements use pens to specify how they should be drawn. a data element may use many pens at once. here 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.
π SYNTAX π
barchart pathName ?option value?...
the barchart command creates a new window pathName and makes it into a barchart widget. at the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist. (yes, both of those are hard requirements, do not fight them π)
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, barchart returns the path name of the widget. it also creates a new Tcl command by the same name. 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 BARCHART 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. stay tuned bestie, there's more π
π EXAMPLE π
okay bestie, sit down, hydrate, because this is the full glow-up tutorial π the barchart command is literally how you summon a brand-new bar chart out of the void, no cap.
# Create a new bar chart. Plotting area is black.
barchart .b -plotbackground black
and boom π₯ a brand-new Tcl command called .b now exists. that command is your new bestie β you use it to query the bar chart and to modify it. like, say you wanna change the title of the graph to "My Plot"? you grab that fresh new command and hit it with the configure operation. slay.
# Change the title.
.b configure -title "My Plot"
to actually put data in there, you use the command plus the element component.
# Create a new element named "e1"
.b element create e1 \
-xdata { 1 2 3 4 5 6 7 8 9 10 } \
-ydata { 26.18 50.46 72.85 93.31 111.86 128.47 143.14
155.85 166.60 175.38 }
your element's X-Y coordinates go in as lists of numbers π alternatively, BLT vectors can hold those X-Y coordinates instead.
# Create two vectors and add them to the barchart.
vector xVector yVector
xVector set { 1 2 3 4 5 6 7 8 9 10 }
yVector set { 26.18 50.46 72.85 93.31 111.86 128.47 143.14 155.85
166.60 175.38 }
n.b element create e1 -xdata xVector -ydata yVector
the advantage of using vectors is genuinely iconic: when you modify one, the graph is automatically redrawn to reflect the new values. it just knows. main character energy fr fr β¨
# Change the y coordinate of the first point.
set yVector(0) 25.18
so an element named e1 is now living inside .b, and it's automatically added to the display list of elements. you can use that list to control the order things get displayed in π to query it or reset it, 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 get displayed as as many bars as there are data points (in this case, ten of them). the bars get drawn centered at the x-coordinate of the data point, and they all share the same attributes β colors, stipple, all of it. each bar is by default one unit wide, and you can change that with the -barwidth option.
# Change the scale of the x-coordinate data
xVector set { 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0 }
# Make sure we change the bar width too.
.b configure -barwidth 0.2
and the height of each bar? proportional to the ordinate (that's the Y-coordinate) of the data point. math is mathing π
the same-x-coordinate situation π«Ά
so if two or more data points share the same abscissa (the X-coordinate value, bestie), the bars for those points can be drawn a few different ways. the default is to overlay the bars β one right on top of the other. the ordering comes from the element display list. but if you pick stacked mode (via the -barmode configuration option), the bars stack up, each one above the previous.
# Display the elements as stacked.
.b configure -barmode stacked
and if you pick aligned mode, the bars with the same x-coordinates get displayed side by side instead. each bar's width becomes a fraction of its normal width, based on how many bars share that same x-coordinate. cute, right?
# Display the elements side-by-side.
.b configure -barmode aligned
legend, labels, and looks π
by default, the element's label in the legend is also just e1. you can change that label, or say "no legend entry for you," again using the element's configure operation.
# Don't display "e1" in the legend.
.b element configure e1 -label ""
but bestie, you can configure so much more than just the label. an element has a whole wardrobe of attributes β stipple, foreground and background colors, relief, etc. π
.b element configure e1 -fg red -bg pink \
-stipple gray50
axes, but make it β¨customizedβ¨
four coordinate axes get created automatically: x, x2, y, and y2 π and by default, elements are mapped onto the x and y axes. you can switch that up with the -mapx and -mapy options.
# Map "e1" on the alternate y axis "y2".
.b element configure e1 -mapy y2
axes can be configured a million ways too. for example, you can change the scale of the Y-axis from linear to log using the axis component.
# Y-axis is log scale.
.b axis configure y -logscale yes
one big way axes get used is to zoom in on a particular data region. zooming is literally just you specifying new axis limits with the -min and -max configuration options. periodt.
.b axis configure x -min 1.0 -max 1.5
.b axis configure y -min 12.0 -max 55.15
to zoom interactively, you link the axis configure operations up with some user interaction (like pressing the mouse button π±οΈ) using the bind command. and to convert between screen and graph coordinates, you use the invtransform operation.
# Click the button to set a new minimum
bind .b <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 figured out from the data values. to reset back to those default limits, you set the -min and -max options to the empty value.
# Reset the axes to autoscale again.
.b axis configure x -min {} -max {}
.b axis configure y -min {} -max {}
legend component π
by default, the legend gets drawn in the right margin</c>. you can change that, or any other legend configuration option, using the legend component.
# Configure the legend font, color, and relief
.b legend configure -position left -relief raised \
-font fixed -fg blue
and if you want the legend to just. not. show up? turn on the -hide option.
# Don't display the legend.
.b legend configure -hide yes
markers, crosshairs, and grid πΈ
the barchart has simple drawing procedures called markers. they're for highlighting or annotating data in the graph. the types of markers available are bitmaps, polygons, lines, or windows. markers can be used, for example, to mark or brush points β like, say there's a line marker that indicates some low-water value. markers are created with the marker operation.
# Create a line represent the low water mark at 10.0
.b marker create line -name "low_water" \
-coords { -Inf 10.0 Inf 10.0 } \
-dashes { 2 4 2 } -fg red -bg blue
this creates a line marker named low_water. it'll display a horizontal line stretching all the way across the plotting area at the y-coordinate 10.0. the coordinates -Inf and Inf mean the relative minimum and maximum of the axis (in this case, the x-axis). and by default, markers are drawn last, on top of the bars β you can flip that with the -under option.
# Draw the marker before elements are drawn.
.b marker configure low_water -under yes
you can also add cross hairs or grid lines using the crosshairs and grid components π¦
# Display both cross hairs and grid lines.
.b crosshairs configure -hide no -color red
.b grid configure -hide no -dashes { 2 2 }
hardcopy time π
finally, to get an actual hardcopy of the graph, you use the postscript component.
# Print the bar chart into file "file.ps"
.b postscript output file.ps -maxpect yes -decorations no
this generates a file file.ps containing the encapsulated PostScript of the graph. the -maxpect option says "scale the plot to the size of the page." and turning off the -decorations option means no borders or color backgrounds get drawn β i.e. the background of the margins, the legend, and the plotting area will be white. clean, minimal, iconic.
π¦ SYNTAX π¦
barchart pathName ?option value?...
the barchart command creates a new window called pathName and turns it into a barchart widget</p>. at the moment you invoke this command, there must not already be a window named pathName β but pathName's parent window must exist. got it? new name, existing parent, no exceptions π«Ά
extra options can be specified on the command line or in the option database to configure aspects of the bar chart like its colors and font. see the configure operation below for the exact deets on which option and value pairs are valid.
if it all goes well, barchart returns pathName β¨ it also creates a new Tcl command, pathName. you use that command to invoke all kinds of operations to query or modify the bar chart. its general form is:
pathName operation ?arg?...
both the operation and its arguments decide exactly what the command does. all the operations available for the bar chart are described in the section that follows π
π BARCHART OPERATIONS π
okay so THIS is the part where you actually do stuff. every one of these is you yelling at your barchart widget pathName to make a thing happen, and honestly? they all ate. let's get into it bestie π«Ά
pathName bar elemName ?option value?...β makes a brand new barchart element called elemName. and like, if an element with that elemName is already there? that's an error, no cap. π for the tea on whichoptionandvaluepairs are even legal here, go read the manual for barchart.pathName cget optionβ hands you back the current value of whatever configurationoptionyou asked about. andoptioncan be literally any of the options listed down below for theconfigureoperation. every single one. πpathName configure ?option value?...β this is the glow-up station: it queries or modifies the graph's config options. the rules are:- no
optionat all? you get a list describing all the current options forpathName. β¨ optionbut novalue? you get a list describing just that oneoption.- one or more
optionvaluepairs? then for each pair, thatoptiongets set to thatvalue. periodt.
- no
here's the valid option roster, bestie, all 25 of them, no skipping:
-backgroundcolor β sets the background color. this covers the margins and the legend, but not the plotting area. π¨-barmodemode β tells the graph how related bar elements get drawn. "related" = elements whose data points share the same abscissas (that's X-coordinates, iykyk). mode decides how those segments are rendered. mode can beinfront,aligned,overlap, orstacked. the default mode isinfront.infrontβ each successive segment is drawn in front of the previous one.stackedβ each successive segment is stacked vertically on top of the previous one.alignedβ segments get displayed aligned from right-to-left.overlapβ likealigned, but the segments slightly overlap each other.
-barwidthvalue β the width of the bars. individual elements can override this with their own-barwidthconfiguration option. value is measured in graph coordinates. default width is1.0.-borderwidthpixels β width of the 3-D border around the outside edge of the widget. whether that border actually gets drawn is up to the-reliefoption. default is2.-bottommarginpixels β size of the margin below the X-coordinate axis. if pixels is0, the margin size gets picked automatically. default is0.-bufferelementsboolean β whether to use an internal pixmap to buffer how data elements are displayed. if boolean is true, data elements get drawn to an internal pixmap. this one is especially useful when the graph gets redrawn a lot while the data stays the same (like, moving a marker across the plot, for example). see the SPEED TIPS section. default is1. π₯-cursorcursor β the widget's cursor. default cursor iscrosshair.-fontfontName β the font of the graph title. default is*-Helvetica-Bold-R-Normal-*-18-180-*.-halopixels β the maximum distance to consider when hunting for the closest data point (check the element'sclosestoperation below). data points further than pixels away just get ignored. default is0.5i.-heightpixels β the requested height of the widget. default is4i.-invertxyboolean β whether the placement of the X-axis and Y-axis should be inverted. if boolean is true, X and Y get swapped. default is0.-justifyjustify β how the title should be justified. this only matters when the title has more than one line of text, fr. justify must beleft,right, orcenter. default iscenter.-leftmarginpixels β size of the margin from the left edge of the window to the Y-coordinate axis. if pixels is0, the size gets calculated automatically. default is0.-plotbackgroundcolor β background color of the plotting area. default iswhite.-plotborderwidthpixels β width of the 3-D border around the plotting area. whether a border gets drawn is up to the-plotreliefoption. default is2.-plotpadxpad β how much padding gets added 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.-plotpadypad β how much padding gets added 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.-plotreliefrelief β the 3-D effect for the plotting area. relief says how the interior of the plotting area should appear relative to the rest of the graph β for example,raisedmeans the plot should look like it's protruding from the graph, relative to the graph's surface. default issunken.-reliefrelief β the 3-D effect for the barchart widget itself. relief says how the graph should appear relative to the widget it's packed into β for example,raisedmeans the graph should look like it's protruding. default isflat.-rightmarginpixels β 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 is than 1, the margin size is selected automatically.-takefocusfocus β info used when moving focus from window to window via keyboard traversal (think Tab and Shift-Tab). if focus is0, that means this window should be skipped entirely during keyboard traversal.1means this window should always receive the input focus. an empty value means the traversal scripts get to decide whether to focus on the window. default is"".-tileimage β a tiled background for the widget. if image isn't"", the background gets tiled using image. otherwise, the normal background color gets drawn (peep the-backgroundoption). image must be an image created with the Tkimagecommand. default is"".-titletext β sets the title to text. if text is"", no title gets displayed.-topmarginpixels β size of the margin above the x2 axis. if pixels is0, the margin size gets calculated automatically.-widthpixels β the requested width of the widget. default is5i.
pathName crosshairs operation ?arg?β head to the CROSSHAIRS COMPONENT section, bestie. π―pathName element operation ?arg?...β head to the ELEMENT COMPONENTS section.pathName extents itemβ gives you the size of a particular item in the graph. item has to be one ofleftmargin,rightmargin,topmargin,bottommargin,plotwidth, orplotheight.pathName grid operation ?arg?...β head to the GRID COMPONENT section. πΈοΈpathName invtransform winX winYβ does an inverse coordinate transformation: it maps 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. (yes, the original says "Returns 1 is the designated screen coordinate" β typos happen, the meaning is clear π)pathName legend operation ?arg?...β head to the LEGEND COMPONENT section. πpathName line operation arg...β the operation is the same aselement.pathName marker operation ?arg?...β head to the MARKER COMPONENTS section. πpathName metafile ?fileName?β β οΈ Window platforms ONLY, bestie. it creates a Windows enhanced metafile of the barchart. if fileName is present, that's the file name of the new metafile. otherwise, the metafile gets automatically added to the clipboard. π₯οΈpathName postscript operation ?arg?...β head to the POSTSCRIPT COMPONENT section.pathName snap photoNameβ takes a snapshot of the graph and stores the contents in the photo image photoName. photoName is the name of a Tk photo image that must already exist β like, it's not gonna make one for you. πΈpathName transform x yβ does a coordinate transformation: maps 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?...
^ all four of those go check the AXIS COMPONENTS section. π
π¦ BARCHART COMPONENTS π¦
a graph is composed of several components, bestie, and here's the whole friend group: coordinate axes, data elements, legend, grid, cross hairs, postscript, and annotation markers. π
and instead of one giant overwhelming pile of configuration options and operations (we love a chaotic queen but no), the graph is partitioned β each component gets its own configuration options and its own operations that specifically control that aspect or part of the graph. so you only gotta look at the corner of the graph you're actually messing with. iconic, honestly. β¨
πΈ AXIS COMPONENTS πΈ
Okay so plot twist (literally) π
β the second your chart exists, it auto-creates four coordinate axes: two X-coordinate axes (x and x2) and two Y-coordinate axes (y and y2). By default x chills in the bottom margin, y in the left margin, x2 in the top margin, and y2 in the right margin. Four sides, four vibes, no cap β¨
An axis is a whole little ensemble: the axis line, the title, major and minor ticks, and tick labels. Major ticks get drawn at uniform intervals along the axis, and each one is labeled with its coordinate value. Minor ticks are drawn at uniform intervals within the major ticks β nesting-doll energy, obsessed π
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, sorry not sorry π. By default the minimum and maximum limits get determined from the data itself, but bestie you can reset either limit whenever you want.
You can create and use several axes. To create an axis, invoke the axis component and its create operation.
# Create a new axis called "temperature"
.b axis create temperature
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 temperature data to this axis.
.b element create "temp" -xdata $x -ydata $tempData \
-mapy temperature
Now here's the tea π« β you can have many axes, but only four can be displayed simultaneously. They're drawn in each of the margins surrounding the plotting area. The axes x and y are drawn in the bottom and left margins. The axes x2 and y2 are drawn in the top and right margins. Only x and y are shown by default. And heads up, the axes can have different scales β yes, really. Slay.
To display a different axis, you invoke one of the following components: xaxis, yaxis, x2axis, and y2axis. The use operation designates the axis to be drawn in the corresponding margin: xaxis in the bottom, yaxis in the left, x2axis in the top, and y2axis in the right.
# Display the axis temperature in the left margin.
.b yaxis use temperature
You can configure axes in a million little ways, and I love that for them. 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 β full main character behavior π . You can control how ticks are drawn by changing the major tick interval or the number of minor ticks. And you can define non-uniform tick intervals, like for time-series plots. Iconic π
π¦ Axis Commands π¦
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 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.
-autorangerange β Sets the range of values for the axis to range. The axis limits are automatically reset to display the most recent data points in this range. If range is0.0, the range is determined from the limits of the data. If-minor-maxare specified, they override this option. The default is0.0.-colorcolor β Sets the color of the axis and tick labels. The default isblack.-commandprefix β Specifies a Tcl command to be invoked when formatting the axis tick labels. Prefix is 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 setting prefix to"". The default is"".
Please note that this procedure is invoked while the bar chart is redrawn. You may query the widget's configuration options. But do not reset options, because this can have unexpected results. π
-descendingboolean β Indicates whether the values along the axis are monotonically increasing or decreasing. If boolean is true, the axis values will be decreasing. The default is0.-hideboolean β Indicates whether the axis is displayed.-justifyjustify β Specifies how the axis title should be justified. This matters only when the axis title contains more than one line of text. Justify must beleft,right, orcenter. The default iscenter.-limitsformatStr β 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. FormatStr is 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"".-linewidthpixels β Sets the width of the axis and tick lines. The default is1pixel.-logscaleboolean β Indicates whether the scale of the axis is logarithmic or linear. If boolean is true, the axis is logarithmic. The default scale is linear.-looseboolean β 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. This is relevant only when the axis limit is automatically calculated. If boolean is true, the axis range is "loose". The default is0.-majorticksmajorList β Specifies where to display major axis ticks. You can use this option to display ticks at non-uniform intervals. MajorList is a list of axis coordinates designating the location of major ticks. No minor ticks are drawn. If majorList is"", major ticks will be automatically computed. The default is"".-maxvalue β Sets the maximum limit of axisName. Any data point greater than value is not displayed. If value is"", the maximum limit is calculated using the largest data value. The default is"".-minvalue β Sets the minimum limit of axisName. Any data point less than value is not displayed. If value is"", the minimum limit is calculated using the smallest data value. The default is"".-minorticksminorList β Specifies where to display minor axis ticks. You can use this option to display minor ticks at non-uniform intervals. MinorList is 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. If minorList is"", minor ticks will be automatically computed. The default is"".-rotatetheta β Specifies the how many degrees to rotate the axis tick labels. Theta is a real value representing the number of degrees to rotate the tick labels. The default is0.0degrees.-shiftbyvalue β Specifies how much to automatically shift the range of the axis. When the new data exceeds the current axis maximum, the maximum is increased in increments of value. You can use this option to prevent the axis limits from being recomputed at each new time point. If value is0.0, then no automatic shifting is done. The default is0.0.-showticksboolean β Indicates whether axis ticks should be drawn. If boolean is true, ticks are drawn. If false, only the axis line is drawn. The default is1.-stepsizevalue β Specifies the interval between major axis ticks. If value isn't a valid interval (must be less than the axis range), the request is ignored and the step size is automatically calculated.-subdivisionsnumber β Indicates how many minor axis ticks are to be drawn. For example, if number is two, only one minor tick is drawn. If number is one, no minor ticks are displayed. The default is2.-tickfontfontName β Specifies the font for axis tick labels. The default is*-Courier-Bold-R-Normal-*-100-*.-ticklengthpixels β Sets the length of major and minor ticks (minor ticks are half the length of major ticks). If pixels is less than zero, the axis will be inverted with ticks drawn pointing towards the plot. The default is0.1i.-titletext β Sets the title of the axis. If text is"", no axis title will be displayed.-titlecolorcolor β Sets the color of the axis title. The default isblack.-titlefontfontName β Specifies the font for axis title. The default is*-Helvetica-Bold-R-Normal-*-14-140-*.
Axis configuration options may also be set by the option command. The resource class is Axis. The resource names are the names of the axes (such as x or x2). π«Ά
option add *Barchart.Axis.Color blue
option add *Barchart.x.LogScale true
option add *Barchart.x2.LogScale false
π the axis operations, continued
pathName axis create axisName ?option value?...β makes a brand new axis calledaxisName. bestie, there can't already be an axis with that name, that's the rule π . all theoption valuecombos are the ones we already spilled about up in theaxis configureoperation.pathName axis delete ?axisName?...β deletes the axes you name. lowkey chill about it though: an axis isn't actually gone until nothing's using it anymore, so it's totally safe to delete axes that are mapped to elements. no cap π«ΆpathName axis invtransform axisName valueβ does the reverse transformation: takes a screen coordinatevalueand turns it into a graph coordinate by mapping it toaxisName. returns the graph coordinate. it's giving undo button β¨pathName axis limits axisNameβ hands you a list of the min and max limits foraxisName. the order ismin max. periodt.pathName axis names ?pattern?...β returns a list of axes that match zero or more patterns. if you don't pass any pattern argument, you get the names of all the axes. πpathName axis transform axisName valueβ transforms the coordinatevalueinto a screen coordinate by mapping it toaxisName. returns the transformed screen coordinate. β¨
okay so here's a whole thing: only four axes can be displayed at the same time. by default they're x, y, x2, and y2. wanna swap a different one in? use the use operation on 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 you specified for use actually get displayed on screen, bestie. that's the vibe check. π
the xaxis, x2axis, yaxis, and y2axis components work on an axis location rather than a specific axis the way the more general axis component does. so xaxis manages the X-axis sitting in the bottom margin (whichever axis that happens to be). same energy: yaxis is the Y-axis in the left margin, x2axis is the top X-axis, and y2axis is the right Y-axis. πΈ
they implicitly control whatever axis is currently using that location. default lineup: xaxis uses x, yaxis uses y, x2axis uses x2, y2axis uses y2. ngl these components are way more convenient than constantly figuring out which axes the graph is currently showing. main character energy fr fr. π
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.
pathName axis cget optionpathName axis configure ?option value?...pathName axis invtransform valuepathName axis limitspathName axis transform valuepathName axis use ?axisName?β designates that the axisaxisNameshould be displayed at this location.axisNamecan't already be in use at another location (sorry bestie, no double-booking π). 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 all the way across the plotting area. they exist so you can position the mouse in relation to the coordinate axes. β¨
the way cross hairs differ from line markers? they're implemented using XOR drawing primitives. which means they can be quickly drawn and erased without redrawing the entire widget. iconic behaviour honestly. π
the following operations are available for cross hairs:
pathName crosshairs cget optionβ returns the current value of the cross hairs config option given byoption.optioncan be any option described below for thecrosshairs configureoperation.pathName crosshairs configure ?option value?...β queries or modifies the configuration options of the cross hairs. ifoptionisn't specified, you get back a list describing all the current options for the cross hairs. ifoptionis specified but notvalue, then you get a list describingoption. if one or moreoptionandvaluepairs are given, then for each pair, the cross hairs optionoptiongets set tovalue. π
the following options are available for cross hairs:
-color colorβ sets the color of the cross hairs. default isblack. π€-dashes dashListβ sets the dash style of the cross hairs.dashListis a list of up to 11 numbers that alternately represent the lengths of the dashes and gaps on the cross hair lines. each number must be between 1 and 255. ifdashListis"", the cross hairs will be solid lines.-hide booleanβ says whether cross hairs are drawn. ifbooleanis true, cross hairs are not drawn. default isyes. π-linewidth pixelsβ sets the width of the cross hair lines. default is1.-position posβ specifies the screen position where the cross hairs intersect.posmust be in the form"@x,y", wherexandyare the window coordinates of the intersection.
cross hairs configuration options can also be set by the option command. the resource name and class are crosshairs and Crosshairs respectively. π
option add *Barchart.Crosshairs.LineWidth 2
option add *Barchart.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 π«Ά
π ELEMENTS π
a data element represents a set of data. it holds x and y vectors, which are the coordinates of the data points. elements get displayed as bars, where the length of the bar is proportional to the ordinate of the data point. elements also control how the data looks β color, stipple, relief, etc. π¦
when new data elements are created, they're 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 that the data points of elementelemNameshould be drawn using the active foreground and background colors.elemNameis the name of the element andindexis a number representing the index of the data point. if no indices are present, then all data points become active. π₯pathName element bind tagName ?sequence? ?command?β associatescommandwithtagNamesuch that whenever the event sequence given bysequenceoccurs for an element with this tag,commandgets invoked. the syntax is similar to thebindcommand, except it operates on graph elements rather than widgets. see thebindmanual entry for the full deets onsequenceand the substitutions performed oncommandbefore 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 instead of 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 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 config option given byoption.optioncan be any of the options described below for theelement configureoperation.pathName element closest x y ?option value?... ?elemName?...β finds the data point representing the bar closest to the window coordinatesxandyin the elementelemName.elemNameis the name of an element, which must be displayed. if no elements are specified, then all displayed elements get searched. it returns a list containing the name of the closest element, the index of its closest point, and the graph coordinates of the point. if no data point within the threshold distance can be found,""is returned. π
the following option-value pairs are available:
-halo pixelsβ specifies a threshold distance where selected data points are ignored.pixelsis a valid screen distance, like2or1.2i. if this option isn't specified, it defaults to the value of the barchart's-halooption.
pathName element configure elemName ?elemName... ?option value?...β queries or modifies the configuration options for elements. several elements can be modified at the same time. ifoptionisn't specified, you get a list describing all the current options forelemName. ifoptionis specified but notvalue, then you get a list describing the optionoption. if one or moreoptionandvaluepairs are specified, then for each pair, the element optionoptionis set tovalue. πΈ
the following options are valid for elements:
-activepen penNameβ specifies the pen to use to draw active elements. ifpenNameis"", no active elements get drawn. default isactiveLine. β¨-bindtags tagListβ specifies the binding tags for the element.tagListis a list of binding tag names. the tags and their order determine how events for elements work. 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. default value isall.-background colorβ sets the color of the border around each bar. default iswhite. π€-barwidth valueβ specifies the width of the bars drawn for the element.valueis the width in X-coordinates. if this option isn't specified, the width of each bar is the value of the widget's-barwidthoption.-baseline valueβ specifies the baseline of the bar segments. this affects how bars are drawn since bars get drawn from their respective y-coordinate to the baseline. by default the baseline is0.0. π
-borderwidthpixels β sets how thick that lil 3-D border around the outside of every bar is. Whether that border even shows up is up to the-reliefoption bestie. pixels has to be a valid screen distance, like2or0.25i. Default?2. π-datacoordList β the actual X-Y coordinates of your data. coordList is a list of numeric expressions, each one being an X-Y coordinate pair for a data point. β¨-foregroundcolor β sets the color of the interior of the bars. The inside!! π-hideboolean β is this element showing or not. Default isno(so yes, it's showing, bestie, don't worry). π-labeltext β the element's label in the legend. If text is"", the element gets no entry in the legend at all. Default label is just the element's own name. π-mapxxAxis β picks which X-axis your element's X-coordinates get mapped onto. xAxis must be the name of an axis. Default isx. π¦-mapyyAxis β same vibe but for Y. Picks the Y-axis your element's Y-coordinates get mapped onto. yAxis must be the name of an axis. Default isy. π¦-reliefstring β the 3-D effect you want for your bars. relief says how the interior of the bar should look compared to the chart surface; likeraisedmeans the bar should look like it's protruding out of the plotting area. Default israised. π-stipplebitmap β a stipple pattern to draw the bars with. If bitmap is"", the bar is drawn solid. β-xdataxVector β the x-coordinate vector of the data. xVector is the name of a BLT vector or a list of numeric expressions. π-ydatayVector β the y-coordinate vector of the data. yVector is the name of a BLT vector or a list of numeric expressions. π
Element configuration options can also be set with the option command, okurrr. The resource names in the option database get prefixed with elem. Like:
option add *Barchart.Element.background blue
πΈ ELEMENT OPERATIONS, THE REST OF THEM πΈ
pathName element create elemName ?option value?...
Makes a brand new element called elemName. Element names have to be unique, so an element elemName can't already exist. If you pass extra arguments, they specify any of the element options that are valid for the element configure operation. β¨
pathName element deactivate pattern...
Deactivates all the elements matching pattern for the graph. Elements whose names match any of the patterns given get redrawn using their normal colors. π€
pathName element delete ?pattern?...
Deletes all the elements matching pattern for the graph. Elements whose names match any of the patterns given are gone. The graph gets redrawn without the deleted elements. π
pathName element exists elemName
Returns 1 if an element elemName currently exists and 0 otherwise. Simple as. π«Ά
pathName element names ?pattern?...
Returns the elements matching one or more pattern. If you don't give a pattern, it returns the names of all the elements. π
pathName element show ?nameList?
Queries or modifies the element display list. The element display list is basically the roster of which elements are drawn and in what order. nameList is a list of elements to be displayed, in the order they're named. If there's no nameList argument, the current display list gets returned. π
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". π₯
π 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 grid lines, bestie.
pathName grid cget option
Returns the current value of the grid line configuration option given by option. option can be any option described below for the grid configure operation. π
pathName grid configure ?option value?...
Queries or modifies the configuration options for grid lines. Let's break it down:
- If option isn't specified, you get a list describing all the current grid options for
pathName. π - If option is specified but value isn't, you get a list describing option. π
- 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 options that are valid for grid lines:
-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 alternate between representing the lengths of the dashes and the gaps on the grid lines. Every number has to be between1and255. If dashList is"", the grid will be solid lines. π-hideboolean β whether the grid should be drawn. If boolean is true, grid lines are not shown. Default isyes. π-linewidthpixels β sets the width of grid lines. Default width is1. π-mapxxAxis β specifies the X-axis to display grid lines on. xAxis must be the name of an axis, or""for no grid lines. Default is"". π¦-mapyyAxis β specifies the Y-axis to display grid lines on. yAxis must be the name of an axis, or""for no grid lines. Default isy. π¦-minorboolean β whether the grid lines should be drawn for minor ticks. If boolean is true, the lines will appear at minor tick intervals. Default is1. β
Grid configuration options can also be set with the option command. The resource name and class are grid and Grid respectively. So like:
option add *Barchart.grid.LineWidth 2
option add *Barchart.Grid.Color black
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. Back and forth, back and forth. π
π LEGEND COMPONENT π
The legend displays a list of the data elements. Each entry is the element's symbol plus its label. The legend can live in any margin β default location is the right margin β and it can also be positioned anywhere inside the plotting area. Main character energy fr fr. π
These are the operations that are valid for the legend:
pathName legend activate pattern...
Selects legend entries to be drawn using the active legend colors and relief. All entries whose element names match pattern are selected. To be selected, the element name has to match only one pattern. π₯
pathName legend bind tagName ?sequence? ?command?
Associates command with tagName so that whenever the event sequence given by sequence happens for a legend entry with this tag, command gets invoked. Implicitly, the element names in the entry are tags. The syntax is like the bind command, except it operates on legend entries rather than widgets. Go read the bind manual entry for the full details on sequence and the substitutions done on command before it's invoked. π
Now the deets:
- If all the 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, 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, 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 the legend configure operation. π
pathName legend configure ?option value?...
Queries or modifies the configuration options for the legend.
- If option isn't specified, you get a list describing the current legend options for
pathName. π - If option is specified but value isn't, you get a list describing option. π
- 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 options that are valid for the legend:
-activebackgroundcolor β sets the background color for active legend entries. All legend entries marked active (peep thelegend activateoperation) get drawn with this background color. πΈ-activeborderwidthpixels β sets the width of the 3-D border around the outside edge of the active legend entries. Default is2. π-activeforegroundcolor β sets the foreground color for active legend entries. All legend entries marked as active (again, see thelegend activateoperation) get drawn with this foreground color. πΈ-activereliefrelief β the 3-D effect you want for active legend entries. relief says how the interior of the entry should look relative to the legend; likeraisedmeans the entry should look like it's protruding from the legend, relative to the legend's surface. Default isflat. π-anchoranchor β tells how to position the legend relative to the legend's positioning point. This depends on the value of the-positionoption. Default iscenter. π―leftorrightβ the anchor describes how to position the legend vertically.toporbottomβ the anchor describes how to position the legend horizontally.
@x,yβ okay so the anchor tells us how to place the legend relative to the positioning point. Ifanchoriscenter, the legend is centered on that point; ifanchorisn, the legend gets drawn so the top-center point of the rectangular region occupied by the legend lands on the positioning point. πplotareaβ this anchor says how to position the legend relative to the plotting area. Example: ifanchoriscenter, the legend is centered in the plotting area; ifanchorisne, the legend is drawn so it occupies the upper right corner of the plotting area. π¦-background colorβ sets the background color of the legend. Ifcoloris"", the legend background will be transparent. transparent legend era, we love to see it β¨-bindtags tagListβ specifies the binding tags for legend entries.TagListis a list of binding tag names. The tags and their order will determine how events for legend entries. Each tag in the list matching the current event sequence will have its Tcl command executed. The default value isall. π-borderwidth pixelsβ sets the width of the 3-D border around the outside edge of the legend (if such border is being drawn; the-reliefoption determines this). The default is2pixels. chunky border moment π-font fontNameβfontNamespecifies a font to use when drawing the labels of each element into the legend. The default is*-Helvetica-Bold-R-Normal-*-12-120-*. font lore fr π«Ά-foreground colorβ sets the foreground color of the text drawn for the element's label. The default isblack. π€-hide booleanβ indicates whether the legend should be displayed. Ifbooleanis true, the legend will not be drawn. The default isno. not me hiding the legend when the vibes are off π-ipadx padβ sets the amount of internal padding to be added to the width of each legend entry.Padcan be a list of one or two screen distances. Ifpadhas two elements, the left side of the legend entry is padded by the first distance and the right side by the second. Ifpadis just one distance, both the left and right sides are padded evenly. The default is2. πΈ-ipady padβ sets an amount of internal padding to be added to the height of each legend entry.Padcan be a list of one or two screen distances. Ifpadhas two elements, the top of the entry is padded by the first distance and the bottom by the second. Ifpadis just one distance, both the top and bottom of the entry are padded evenly. The default is2. π-padx padβ sets the padding to the left and right exteriors of the legend.Padcan be a list of one or two screen distances. Ifpadhas two elements, the left side of the legend is padded by the first distance and the right side by the second. Ifpadhas just one distance, both the left and right sides are padded evenly. The default is4. π-pady padβ sets the padding above and below the legend.Padcan be a list of one or two screen distances. Ifpadhas two elements, the area above the legend is padded by the first distance and the area below by the second. Ifpadis just one distance, both the top and bottom areas are padded evenly. The default is0. β-position posβ specifies where the legend is drawn. The-anchoroption also affects where the legend is positioned. Ifposisleft,left,top, orbottom, the legend is drawn in the specified margin. Ifposisplotarea, then the legend is drawn inside the plotting area at a particular anchor. Ifposis in the form"@x,y", wherexandyare the window coordinates, the legend is drawn in the plotting area at the specified coordinates. The default isright. positioning is everything bestie π-raised booleanβ indicates whether the legend is above or below the data elements. This matters only if the legend is in the plotting area. Ifbooleanis true, the legend will be drawn on top of any elements that may overlap it. The default isno. π-relief reliefβ specifies the 3-D effect for the border around the legend.Reliefspecifies how the interior of the legend should appear relative to the bar chart; for example,raisedmeans the legend should appear to protrude from the bar chart, relative to the surface of the bar chart. The default issunken. 3-D drama, but make it sunken π¦
Legend configuration options may also be set by the option command. The resource name and class are legend and Legend respectively.
option add *Barchart.legend.Foreground blue
option add *Barchart.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 matchpatternare selected. To be selected, the element name must match only one pattern. deactivate the extra, activate the main character energy β¨pathName legend get posβ returns the name of the element whose entry is at the screen positionposin the legend.Posmust be in the form"@x,y", wherexandyare window coordinates. If the given coordinates do not lie over a legend entry,""is returned. π―
β¨ PEN COMPONENTS β¨
Pens define attributes 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. A data element may use several pens at once. 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). pens are literally the outfit coordinators of your chart π
One pen, called activeBar, 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 "activeBar" -fg green -bg green4
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 "e1" -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 "e1" -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. weight-based pen switching, iconic behavior π
The following operations are available for pen components.
pathName pen cget penName optionβ returns the current value of the option given byoptionforpenName.Optionmay be any option described below for thepen configureoperation. πpathName pen configure penName ?penName... ?option value?...β queries or modifies the configuration options ofpenName. Several pens can be modified at once. Ifoptionisn't specified, a list describing the current options forpenNameis returned. Ifoptionis specified, but notvalue, then a list describingoptionis returned. If one or moreoptionandvaluepairs are specified, then for each pair, the pen optionoptionis set tovalue. The following options are valid for pens. π οΈ-background colorβ sets the color of the border around each bar. The default iswhite. π€-borderwidth pixelsβ sets the border width of the 3-D border drawn around the outside of each bar. The-reliefoption determines if such a border is drawn.Pixelsmust be a valid screen distance like2or0.25i. The default is2. π-foreground colorβ sets the color of the interior of the bars. π¨-relief stringβ specifies the 3-D effect desired for bars.Reliefindicates how the interior of the bar should appear relative to the surface of the chart; for example,raisedmeans the bar should appear to protrude from the bar chart, relative to the surface of the plotting area. The default israised. protruding bars, we stan π₯-stipple bitmapβ specifies a stipple pattern with which to draw the bars. Ifbitmapis"", then the bar is drawn in a solid fashion. π-type elemTypeβ 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"bar". mixing bars and lines? main character move π
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 *Barchart.Pen.Foreground blue
option add *Barchart.activeBar.foreground green
pathName pen create penName ?option value?...β creates a new pen by the namepenName. No pen by the same name can already exist.Optionandvalueare described above in thepen configureoperation. β¨pathName pen delete ?penName?...β deletes the named pens. A pen is not really deleted until it is no longer in use, so it's safe to delete pens mapped to elements. ghost pen era, but make it safe π«ΆpathName pen names ?pattern?...β returns a list of pens matching zero or more patterns. If nopatternargument is given, the names of all pens are returned. π
β¨ POSTSCRIPT COMPONENT β¨
Okay bestie, this is the glow-up section π β your barchart can literally print. It generates encapsulated PostScript output, and there are a whole bunch of config options to control exactly how that plot comes out. You can mess with the page dimensions and the borders. The plot itself can be scaled, centered, or rotated to landscape. And the PostScript output can go straight into a file, or it can come back to you through the interpreter. Either way. Your call, queen π.
The following postscript operations are available.
pathName postscript cget optionβ Hands you back the current value of the postscript option named by option. And option can be literally any option described below for thepostscript configureoperation. No gatekeeping here π«Ά.pathName postscript configure ?option value?...β Queries or modifies the configuration options for PostScript generation. If option isn't specified, you get a list describing the current postscript options for pathName. If option is specified but value isn't, then you get a list describing option. And if one or more option and value pairs are specified, then for each pair, the postscript option option is set to value. Simple as that β¨.
The following postscript options are available:
-centerboolean β Says whether the plot should be centered on the PostScript page. If boolean is false, the plot gets parked in the upper left corner of the page instead, which is giving "left-aligned and unbothered" π . The default is1.-colormapvarName β VarName has to be the name of a global array variable that specifies a color mapping from the X color name to PostScript. Each element of varName must consist of PostScript code to set a particular color value (e.g.1.0 1.0 0.0 setrgbcolor). When generating color information in PostScript, the array variable varName is checked to see if an element of the name as the color exists. If so, it uses its value as the PostScript command to set the color. If this option hasn't been specified, or if there isn't an entry in varName for a given color, then it uses the red, green, and blue intensities from the X color. Fallback queen behavior, fr fr.-colormodemode β Specifies how to output color information. Mode must be eithercolor(for full color output),gray(convert all colors to their gray-scale equivalents) ormono(convert foreground colors to black and background colors to white). The default mode iscolor. Slay in full saturation π.-fontmapvarName β VarName must be the name of a global array variable that specifies a font mapping from the X font name to PostScript. Each element of varName must consist of a Tcl list with one or two elements: the name and point size of a PostScript font. When outputting PostScript commands for a particular font, the array variable varName is checked to see if an element by the specified font exists. If there is such an element, then the font information contained in that element is used in the PostScript output. (If the point size is omitted from the list, the point size of the X font is used.) Otherwise the X font is examined in an attempt to guess what PostScript font to use. Heads up though β this works only for fonts whose foundry property isAdobe(such as Times, Helvetica, Courier, etc.). And if all of this fails then the font defaults toHelvetica-Bold. The backup plan is always Helvetica-Bold, iconic π.-decorationsboolean β Indicates whether PostScript commands to generate color backgrounds and 3-D borders will be output. If boolean is false, the graph will background will be white and no 3-D borders will be generated β very minimal, very clean girl aesthetic π. The default is1.-heightpixels β Sets the height of the plot. This lets you print the bar chart with a height different from the one drawn on the screen. If pixels is0, the height is the same as the widget's height. The default is0.-landscapeboolean β If boolean is true, this specifies the printed area is to be rotated 90 degrees. In non-rotated output the X-axis of the printed area runs along the short dimension of the page (portraitorientation); in rotated output the X-axis runs along the long dimension of the page (landscapeorientation). Defaults to0.-maxpectboolean β Indicates to scale the plot so that it fills the PostScript page. The aspect ratio of the barchart is still retained though β no squishing, we don't do that here π. The default is0.-padxpad β Sets the horizontal padding for the left and right page borders. The borders are exterior to the plot. Pad can be a list of one or two screen distances. If pad has two elements, the left border is padded by the first distance and the right border by the second. If pad has just one distance, both the left and right borders are padded evenly. The default is1i.-padypad β Sets the vertical padding for the top and bottom page borders. The borders are exterior to the plot. Pad can be a list of one or two screen distances. If pad has two elements, the top border is padded by the first distance and the bottom border by the second. If pad has just one distance, both the top and bottom borders are padded evenly. The default is1i.-paperheightpixels β Sets the height of the postscript page. This can be used to select between different page sizes (letter, A4, etc). The default height is11.0i.-paperwidthpixels β Sets the width of the postscript page. This can be used to select between different page sizes (letter, A4, etc). The default width is8.5i.-widthpixels β Sets the width of the plot. This lets you generate a plot of a width different from that of the widget. If pixels is0, the width is the same as the widget's width. The default is0.
Postscript configuration options may be also be set by the option command. The resource name and class are postscript and Postscript respectively.
option add *Barchart.postscript.Decorations false
option add *Barchart.Postscript.Landscape true
pathName postscript output ?fileName? ?option value?...β Outputs a file of encapsulated PostScript. If a fileName argument isn't present, the command returns the PostScript 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 thepostscript configureoperation above. Chef's kiss π§.
π¦ MARKER COMPONENTS π¦
Markers are simple drawing procedures used to annotate or highlight areas of the graph. Little stickers on your masterpiece, if you will β¨.
Markers have various types: text strings, bitmaps, images, connected lines, windows, or polygons. They can be associated with a particular element, so that when the element is hidden or un-hidden, so is the marker β they match each other's energy, bestie π
. By default, markers are the last items drawn, so that 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 genius, highkey useful πΈ.
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. Queue-jumping, but make it aesthetic.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. This command can be used to control how markers are displayed since markers are drawn in the order of this display list. Main character energy, moved to the front π.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 thebindcommand except that it operates on graph markers, rather than widgets. See thebindmanual 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 β additive, not destructive, we love to see it π«Ά. If no command argument is provided then the command currently associated with tagName and sequence (it's an error occurs if there's no such binding) is returned. If both command and sequence are missing then a list of all the event sequences for which bindings have been defined for tagName.
pathName marker cget optionβ Returns the current value of the marker configuration option given by option. Option may be any option described below in theconfigureoperation.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. Periodt π.
The following options work for every single marker, no matter what type it is. β¨ Each marker type also has its own little type-specific option squad, and those get their own sections down below, bestie.
-bindtags tagListβ sets the binding tags for the marker.tagListis a list of binding tag names. The tags and their order decide how events for markers get handled, so likeβ¦ order matters, okay? Every tag in the list that matches the current event sequence gets its Tcl command executed. Implicitly, the marker's own name is always the first tag in the list. Default isall.-coords coordListβ the marker's coordinates.coordListis a list of graph coordinates, and how many you need depends on the marker type: text, image, and window markers need only two coordinates (an X-Y coordinate); bitmap markers can take either two or four (four = the corners of the bitmap); line markers need at least four; polygons need at least six. IfcoordListis"", the marker just won't be displayed. Default is"".-element elemNameβ links the marker to the elementelemName. The marker only gets drawn if that element is also currently displayed (peep the element'sshowoperation). IfelemNameis"", the marker is always drawn. Default is"".-hide booleanβ says whether the marker is drawn. Ifbooleanis true, the marker is not drawn. Default isno.-mapx xAxisβ the X-axis to map the marker's X-coordinates onto.xAxishas to be the name of an axis. Default isx.-mapy yAxisβ the Y-axis to map the marker's Y-coordinates onto.yAxishas to be the name of an axis. Default isy.-name markerIdβ changes the identifier for the marker. ThatmarkerIdcan not already be used by another marker, bestie, it's taken. If you don't specify this option, the marker's name gets uniquely generated for you. π-under booleanβ says whether the marker is drawn below/above the data elements. Ifbooleanis true, the marker is drawn underneath the data elements. Otherwise, it's drawn on top of the element. Default is0.-xoffset pixelsβ a screen distance to offset the marker horizontally.pixelsis a valid screen distance, like2or1.2i. Default is0.-yoffset pixelsβ a screen distance to offset the marker vertically.pixelsis a valid screen distance, like2or1.2i. Default is0.
Marker configuration options can also be set with the option command, which is giving very resource-database of them. The resource class is either BitmapMarker, ImageMarker, LineMarker, PolygonMarker, TextMarker, or WindowMarker, depending on the type of marker. The resource name is the name of the marker. Slay:
option add *Barchart.TextMarker.Foreground white
option add *Barchart.BitmapMarker.Foreground white
option add *Barchart.m1.Background blue
pathName marker create type ?option value?...β creates a marker of the chosentype.typecan be eithertext,line,bitmap,image,polygon, orwindow. This command hands you back the marker identifier, which you then use as themarkerIdargument in all the other marker-related commands. If the-nameoption is used, it overrides the normal marker identifier. And heads up β if the name you gave is already used by another marker, the new marker replaces the old one. πpathName marker delete ?name?...β removes one or more markers. The graph automatically gets redrawn without the marker, no cap.pathName marker exists markerIdβ returns1if the markermarkerIdexists and0otherwise.pathName marker names ?pattern?β returns the names of all the markers that currently exist. Ifpatternis supplied, only those markers whose names match it get returned.pathName marker type markerIdβ returns the type of the marker given bymarkerId, likelineortext. IfmarkerIdisn't a valid marker identifier,""is returned.
π¦ BITMAP MARKERS π¦
A bitmap marker displays a bitmap, obviously, main character behavior. π The size of the bitmap is controlled by how many coordinates you give it. If it's two coordinates, they specify the position of the top-left corner of the bitmap, and the bitmap keeps its normal width and height. If it's four coordinates, the first and second pairs of coordinates represent the corners of the bitmap, and the bitmap will be stretched or reduced as necessary to fit into that bounding rectangle. Stretch that icon, bestie.
Bitmap markers are created with the marker's create operation, in the form: 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 can also be used with the marker's configure operation.
The following options are specific to bitmap markers:
-background colorβ same as the-filloption.-bitmap bitmapβ the bitmap to be displayed. Ifbitmapis"", the marker will not be displayed. Default is"".-fill colorβ sets the background color of the bitmap. Ifcoloris the empty string, no background will be transparent. The default background color is"".-foreground colorβ same as the-outlineoption.-mask maskβ a mask for the bitmap to be displayed. This mask is a bitmap itself, denoting the pixels that are transparent. Ifmaskis"", all pixels of the bitmap will be drawn. Default is"".-outline colorβ sets the foreground color of the bitmap. Default value isblack.-rotate thetaβ sets the rotation of the bitmap.thetais 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. Iconic, frankly. π«Ά Image markers are created with the marker's create operation in the form: pathName marker create image ?option value?.... There may be many option-value pairs, each one setting a configuration option for the marker. Those same option-value pairs can also be used with the marker's configure operation.
The following options are specific to image markers:
-anchor anchorβanchortells how to position the image relative to the positioning point for the image. For example, ifanchoriscenterthen the image is centered on the point; ifanchorisnthen 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.-image imageβ the image to be drawn. Ifimageis"", 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 one setting a configuration option for the marker. Those same option-value pairs can also be used with the marker's configure operation.
The following options are specific to line markers:
-dashes dashListβ sets the dash style of the line.dashListis a list of up to 11 numbers that alternately represent the lengths of the dashes and the gaps on the line. Each number must be between1and255. IfdashListis"", the marker line will be solid.-fill colorβ sets the background color of the line. This color is used with striped lines (see the-fdashesoption). Ifcoloris the empty string, no background color is drawn (the line will be dashed, not striped). The default background color is"".-linewidth pixelsβ sets the width of the lines. Default width is0.-outline colorβ sets the foreground color of the line. Default value isblack.-stipple bitmapβ a stipple pattern used to draw the line, rather than a solid line.bitmapspecifies a bitmap to use as the stipple pattern. Ifbitmapis"", 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, and it's assumed the first and last points are connected, so don't come for it. 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 one setting a configuration option for the marker. Those same option-value pairs can also be used with the marker configure command to change the marker's configuration. The following options are supported for polygon markers:
-dashes dashListβ sets the dash style of the outline of the polygon.dashListis a list of up to 11 numbers that alternately represent the lengths of the dashes and the gaps on the outline. Each number must be between1and255. IfdashListis"", the outline will be a solid line.-fill colorβ sets the fill color of the polygon. Ifcoloris"", then the interior of the polygon is transparent. Default iswhite.-linewidth pixelsβ sets the width of the outline of the polygon. Ifpixelsis zero, no outline is drawn. Default is0.-outline colorβ 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.-stipple bitmapβ specifies that the polygon should be drawn with a stippled pattern rather than a solid color.bitmapspecifies a bitmap to use as the stipple pattern. Ifbitmapis"", then the polygon is filled with a solid color (if the-filloption is set). Default is"".
β¨ TEXT MARKERS β¨
Ok so a text marker is literally just a string of characters chillin' on one or more lines of text, and you use it to annotate parts of the graph. Embedded newlines = line breaks, periodt. You make one with the create operation, like this:
pathName marker create text ?option value?...
There can be a whole bunch of option-value pairs, and each one sets a configuration option for that text marker. Same pairs work with the marker's configure operation too. π
These are the options that are special to text markers:
-anchoranchor β tells you how to position the text relative to the positioning point for the text. So like, if anchor iscenterthen the text is centered on the point; if anchor isnthen the text gets drawn so the top center point of the rectangle the text takes up is sitting at the positioning point. Default iscenter.-backgroundcolor β same as the-filloption. (Yes bestie, that's literally what it says.)-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 has more than one line of text, so lowkey irrelevant otherwise. Justify must beleft,right, orcenter. Default iscenter.-outlinecolor β sets the color of the text. Default value isblack.-padxpad β sets the padding to the left and right exteriors of the text. Pad can be a list of one or two screen distances. If pad has two elements, the left side of the text is padded by the first distance and the right side by the second. If pad has just one distance, both left and right get padded evenly. Default is4.-padypad β sets the padding above and below the text. Pad can be a list of one or two screen distances. If pad has two elements, the area above the text is padded by the first distance and the area below by the second. If pad is just one distance, top and bottom both get padded evenly. Default is4.-rotatetheta β specifies the number of degrees to rotate the text. Theta is a real number representing the angle of rotation. The marker gets rotated along its center first, and then drawn according to its anchor position. Default is0.0.-texttext β specifies the text of the marker. How the text actually shows up may be affected by other options like-anchoror-rotate, so yeah.
β¨ WINDOW MARKERS β¨
A window marker displays a widget at a given position. πͺ Iconic behaviour honestly. Window markers are created with the marker's create operation, like so:
pathName marker create window ?option value?...
Many option-value pairs may follow, each one setting a configuration option for the marker. And again, the same option-value pairs can be used with the marker's configure command.
The following options are specific to window markers:
-anchoranchor β tells how to position the widget relative to the positioning point for the widget. For example, if anchor iscenterthen the widget is centered on the point; if anchor isnthen the widget will be displayed such that the top center point of the rectangular region occupied by the widget will be at the positioning point. Defaults tocenter.-heightpixels β specifies the height to assign to the marker's window. If this option isn't specified, or if it's specified as"", then the window gets whatever height the widget requests internally. Let it cook. π³-widthpixels β specifies the width to assign to the marker's window. If this option isn't specified, or if it's specified as"", then the window gets whatever width the widget requests internally.-windowpathName β specifies the widget to be managed by the barchart. PathName must be a child of the barchart widget. No exceptions, bestie.
π GRAPH COMPONENT BINDINGS π
Specific barchart components β elements, markers, legend entries β can have a command trigger when an event happens in them, kinda like canvas items in Tk's canvas widget. But not all event sequences are valid, so don't get too excited. The only binding events you may 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 the mouse is directly over both an element and a marker, only the uppermost component gets selected. This isn't true for legend entries though β both a legend entry and an element (or marker) binding command will be invoked if both items are picked. π
It is possible for multiple bindings to match a particular event. This could happen, for example, if one binding is associated with the element name and another is associated with one of the element's tags (see the -bindtags option). When that happens, all of the matching bindings are invoked. A binding associated with the element name is invoked first, followed by one binding for each of the element's bindtags. 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 β just like for the bind command.
The -bindtags option for these components controls additional tag names which can be matched. Implicitly, elements and markers always have tags matching their names. Setting the value of the -bindtags option doesn't change that. Facts only. π
π C LANGUAGE API π
You can manipulate data elements straight from C, and ngl sometimes you need to. There may be situations where translating the data values from ASCII strings is just too expensive, or maybe you want to 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 manipulate the vector from C. The barchart will be redrawn automatically after the vectors are updated. β¨
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 is reset with the new data and at the next idle point (when Tk re-enters its event loop), the graph will be redrawn 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", 50, &xVec) != TCL_OK) ||
(Blt_GetVector(interp, "Y", 50, &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, iykyk. π
π₯ SPEED TIPS π₯
There may be cases where the bar chart needs to be drawn and updated as quickly as possible. If drawing speed becomes a big problem, here are a few tips to speed up displays. Go off:
- Try to minimize the number of data points. The more data points looked at, the more work the bar chart must do.
- If your data is generated as floating point values, the time required to convert the data values to and from ASCII strings can be significant, especially when there are many data points. You can avoid the redundant string-to-decimal conversions using the C API to BLT vectors.
- Don't stipple or dash the element. Solid bars are much faster. ποΈ
- If you update data elements frequently, try turning off the widget's
-bufferelementsoption. When the bar chart is first displayed, it draws data elements into an internal pixmap. The pixmap acts as a cache, so that when the bar chart needs to be redrawn again, and the data elements or coordinate axes haven't changed, the pixmap is simply copied to the screen. This is especially useful when you are using markers to highlight points and regions on the bar chart. But if the bar chart 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. That's just the way it is, bestie.
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 π
bar chart, widget
And that's a wrap on the whole page, fr fr. This one's from BLT, version 2.5, and you're reading blt::barchart(3tcl). Go forth and chart your little heart out. π¦β¨π
π¦ 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