Graph crosshairs CROSSHAIRS command

Commands in this namespace document the graph crosshairs.

CROSSHAIRS is used below as a placeholder for:

GRAPHINST crosshairs

Crosshairs are a pair of horizontal and vertical lines that intersect at a selected position in the plotting area.

For example:

graph .g
.g crosshairs configure -position @100,80 -hide no

The vertical line extends across the height of the plotting area and the horizontal line extends across its width.

The crosshairs are a single graph component. There are no named crosshair objects.

Crosshair position

The -position option specifies the point where the horizontal and vertical lines intersect.

Positions use widget screen coordinates rather than graph data coordinates and have the form:

@x,y

For example:

.g crosshairs configure -position @120,75

Both x and y are Tk screen distances, so standard Tk distance units may be used:

.g crosshairs configure -position @2c,1c

An empty -position value leaves the crosshairs without a drawable position.

Crosshairs are displayed only when their position lies inside the graph plotting area. Therefore making the crosshairs visible does not cause lines to be drawn if the configured position is outside that area.

Crosshair positions are commonly updated from pointer events:

bind .g <Motion> {
    %W crosshairs configure -position @%x,%y
}

Crosshairs when the graph changes

Ordinary crosshair lines retain their configured widget-coordinate position when axis ranges or plotted data change. The graph coordinates beneath that position can therefore change while the lines remain at the same screen location.

<<RbcGraphChanged>> reports changes to the displayed mapping or plotted element geometry, but does not itself modify the crosshair -position. Applications can use this event to update coordinate readouts or other annotations without waiting for a <Motion> event.

The graphtoolbar provides this behavior automatically for its enhanced current and closest modes. Current-position annotations follow the physical pointer, while closest-point annotations are recalculated from the current plotted data.

Showing and hiding crosshairs

-hide controls whether the crosshairs are enabled. Actual drawing also depends on the configured position. Crosshairs whose position is empty or outside the plotting area remain logically enabled but are not drawn.

For example:

.g crosshairs configure -position {} -hide no

leaves -hide set to no, but no crosshair lines are visible until a drawable position is configured.

CROSSHAIRS on, CROSSHAIRS off, and CROSSHAIRS toggle provide convenient alternatives:

.g crosshairs on
.g crosshairs off
.g crosshairs toggle

These operations change the same state represented by -hide.

For example:

.g crosshairs off
puts [.g crosshairs cget -hide]

reports a true value.

Crosshairs are hidden by default.

Crosshair appearance

The crosshair lines may be configured independently of graph elements:

.g crosshairs configure -color red -linewidth 1 -dashes {4 2}

An empty -dashes value selects solid lines.

Crosshairs are drawn directly over the graph and can therefore be moved or removed without requiring the graph contents to be redrawn.

Crosshairs options

Option

Database name

Database class

Description

-color color

color

Color

Sets the color used to draw the crosshairs. The default is black.

-dashes dashes

dashes

Dashes

Sets the dash pattern used to draw the crosshairs. An empty value selects solid lines. Each numeric list item accepts a Tcl integer expression.

-hide boolean

hide

Hide

Controls whether the crosshairs are enabled. The default is yes. When enabled, the crosshairs are visible only while their position is inside the plotting area.

-linewidth distance

lineWidth

Linewidth

Sets the non-negative width of the crosshair lines. Values 0 and 1 use the native thin-line width. The default is 0.

-position position

position

Position

Specifies the crosshair position as @x,y in graph-window coordinates.

Crosshair configuration options may also be supplied through Tk’s option database. The resource name is crosshairs and the resource class is Crosshairs.

For example:

option add *Graph.crosshairs.Color red
option add *Graph.Crosshairs.Linewidth 1

Copyright (c) George Yashin