All Manuals > CAPI User Guide and Reference Manual > 23 LW-GT Reference Entries

NextPrevUpTopContentsIndex

generate-labels

Function
Summary

Return the labels of a graph of a function.

Package

lw-gt

Signature

generate-labels horizontal-p start step range &key print-function decimal-point color x-adjust y-adjust absolute-p => labels

Arguments

horizontal-p

A boolean.

start

A real number.

step

A real number.

range

A positive real number.

print-function

nil, or a function of one argument which takes a real and returns a string.

decimal-point

An integer or nil.

color

A color specification in the Color system.

x-adjust, y-adjust

nil, a number, or one of the keywords :center and :end-align.

absolute-p

A boolean.

Values

labels

A list of drawing-objects.

Description

The function generate-labels returns a list labels of drawing-objects, which are supposed to be the labels of a graph of a function.

generate-labels generates a list of drawing objects, which draw strings representing numbers and positioned in regular intervals in one dimension and fixed value in the other dimension.

horizontal-p specifies the dimension. When horizontal-p is true, the objects are placed in a row with regular horizontal intervals, otherwise they are spaced in a column with regular vertical intervals.

start determines the lowest value, range determines the range of values, and step determines the distance between neighbouring values. When step is negative, the start value is on the right (top) and the values increase from right to left (top to bottom).

For each value, generate-labels generates a string. If print-function is a function, it is called with the value and needs to return the string. Otherwise generate-labels uses

(format nil "~,vf" decimal-point value)

to generate the string. It then uses make-draw-string to generate a drawing-object, adjusting the position by x-adjust horizontally and y-adjust vertically and using color as the foreground color and make it "absolute mode" depending on absolute-p . It then positions the object (using position-object) at the right place. The default value of x-adjust is :center if horizontal-p is true, and :end-align otherwise. The default value of y-adjust is -1 if horizontal-p is true, and :center otherwise. The default value of color is :black.

generate-labels returns a list of drawing-objects, which is a valid "drawing-object-spec".

Notes
  1. generate-labels will typically be used in conjunction with generate-grid-lines.
  2. generate-labels is quite a simple function. If it does not do what you want, you can improve it easily by writing your own version.
  3. The defaults for x-adjust and y-adjust are what you typically use when the labels are at the left and bottom of the graph. To put the labels somewhere else in the graph, use position-object on labels to move it around. If you want the labels at the top, change y-adjust to 0 when passing horizontal-p true (so the labels are above the line), and then use position-object with bottom-margin the height of the grid to move the whole row of labels:
  4. (position-object (generate-labels ... :y-adjust 0)
    
                     :bottom-margin 
    grid-height
    )
    

    To move the column to the right, change x-adjust to nil and use left-margin .

  5. The size on the screen would normally be scaled by using fit-object on the result.
See also

fit-object
position-object
generate-grid-lines
drawing-object
Higher level - drawing graphs and bar charts


CAPI User Guide and Reference Manual (Windows version) - 25 Feb 2015

NextPrevUpTopContentsIndex