> For the complete documentation index, see [llms.txt](https://www.lisppad.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.lisppad.app/libraries/lispkit/lispkit-draw-chart.md).

# (lispkit draw chart)

Library `(lispkit draw chart)` provides abstractions that are shared between the various chart libraries of LispKit, such as `(lispkit draw chart bar)` and `(lispkit draw chart function)`. Currently, this library defines a single record type, `legend-config`, which encapsulates the parameters needed for drawing a legend within a chart. A legend links labels (e.g. names of bar segments or function graphs) to the colors used to visually distinguish them in a chart.

Chart-specific libraries typically provide their own constructor for legend configurations (e.g. `make-bar-chart-config` from `(lispkit draw chart bar)` or `make-function-legend-config` from `(lispkit draw chart function)`) that come with defaults tailored to the corresponding chart type. The accessor and mutator procedures for legend configuration objects, however, are defined once, centrally, by this library and are used by all chart libraries.

## Legends

A *legend configuration* is a record encapsulating all parameters needed for drawing a legend. Legend configurations are mutable objects that are created via procedure `make-legend-config` (or via a chart-specific constructor such as `make-bar-chart-config` or `make-function-legend-config`). For every parameter, there is an accessor and a setter procedure.

**(make-legend-config&#x20;*****key val ...*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Creates a new legend configuration object from the provided keyword/value pairs. The following keyword arguments are supported. The default value is provided in parenthesis.

* `font:` Font used for all text in a legend (Helvetica 10).
* `color:` Color used for legend labels and the border of the legend's bounding box (black).
* `bg-color:` Background color of the legend's bounding box (white).
* `stroke-width:` Width of a stroke for drawing the bounding box of the legend (1).
* `corner-radius:` Corner radius for a rounded bounding box; `0` results in a rectangular bounding box with square corners (0).
* `horizontal-offset:` Horizontal offset from chart bounds. A non-negative value is interpreted as an offset from the left bound; a negative value is interpreted as an offset from the right bound (70).
* `vertical-offset:` Vertical offset from chart bounds. A non-negative value is interpreted as an offset from the top bound; a negative value is interpreted as an offset from the bottom bound (10).
* `sample-area-width:` Width of the area reserved for the color sample box in front of each legend label (17).
* `sample-length:` Height and width of the color sample box shown for each entry of the legend (10).
* `line-pad:` Padding between two consecutive lines/entries of the legend (3).
* `entry-pad:` Top/bottom and left/right padding between the legend entries and the bounding box of the legend (6).

```scheme
(make-legend-config
  'font: (font "Helvetica" 7)
  'stroke-width: 0.4
  'entry-pad: 5
  'sample-area-width: 16
  'sample-length: 8
  'horizontal-offset: 50)
```

**(legend-config?&#x20;*****obj*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns `#t` if *obj* is a legend configuration object, `#f` otherwise.

**(legend-font&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the font defined by the given legend configuration *lconf*.

**(legend-font-set!&#x20;*****lconf font*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the font for the given legend configuration *lconf* to *font*.

**(legend-color&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the color used for legend labels and the bounding box border defined by the given legend configuration *lconf*. Some chart libraries fall back to a chart-specific default color if *lconf* does not define a color (i.e. `legend-color` returns `#f`).

**(legend-color-set!&#x20;*****lconf color*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the color used for legend labels and the bounding box border for the given legend configuration *lconf* to *color*.

**(legend-bg-color&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the background color of the legend's bounding box defined by the given legend configuration *lconf*. Some chart libraries fall back to a chart-specific default background color if *lconf* does not define a background color (i.e. `legend-bg-color` returns `#f`).

**(legend-bg-color-set!&#x20;*****lconf color*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the background color of the legend's bounding box for the given legend configuration *lconf* to *color*.

**(legend-stroke-width&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the stroke width defined by the given legend configuration *lconf*, i.e. the width used for drawing the border of the legend's bounding box.

**(legend-stroke-width-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the stroke width for the given legend configuration *lconf* to *val*.

**(legend-corner-radius&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the corner radius defined by the given legend configuration *lconf*, used for drawing a rounded bounding box around the legend. A value of `0` results in a rectangular bounding box with square corners.

**(legend-corner-radius-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the corner radius for the given legend configuration *lconf* to *val*.

**(legend-horizontal-offset&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the horizontal offset defined by the given legend configuration *lconf*. A non-negative value is interpreted as an offset of the legend from the left bound of the chart; a negative value is interpreted as an offset from the right bound.

**(legend-horizontal-offset-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the horizontal offset for the given legend configuration *lconf* to *val*.

**(legend-vertical-offset&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the vertical offset defined by the given legend configuration *lconf*. A non-negative value is interpreted as an offset of the legend from the top bound of the chart; a negative value is interpreted as an offset from the bottom bound.

**(legend-vertical-offset-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the vertical offset for the given legend configuration *lconf* to *val*.

**(legend-sample-area-width&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the sample area width defined by the given legend configuration *lconf*, i.e. the width reserved in front of each label for the color sample box.

**(legend-sample-area-width-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the sample area width for the given legend configuration *lconf* to *val*.

**(legend-sample-length&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the sample length defined by the given legend configuration *lconf*, i.e. the height and width of the color sample box (for bar charts) or the length of the color sample line (for function charts) shown for each legend entry.

**(legend-sample-length-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the sample length for the given legend configuration *lconf* to *val*.

**(legend-line-pad&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the line padding defined by the given legend configuration *lconf*, i.e. the vertical padding between two consecutive legend entries.

**(legend-line-pad-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the line padding for the given legend configuration *lconf* to *val*.

**(legend-entry-pad&#x20;*****lconf*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Returns the entry padding defined by the given legend configuration *lconf*, i.e. the top/bottom and left/right padding between the legend entries and the bounding box of the legend.

**(legend-entry-pad-set!&#x20;*****lconf val*****)** <img src="https://1467949168-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fna2foeoaXHYkSD3fhs0t%2Fuploads%2Fgit-blob-d20368c588cfbb523beb2fae4f8be0f8ef011884%2Fproc.png?alt=media" alt="" data-size="line">

Sets the entry padding for the given legend configuration *lconf* to *val*.
