Janet 1.41.2-0fea20c Documentation
(Other Versions: 1.41.1 1.40.1 1.40.0 1.39.1 1.38.0 1.37.1 1.36.0 1.35.0 1.34.0 1.31.0 1.29.1 1.28.0 1.27.0 1.26.0 1.25.1 1.24.0 1.23.0 1.22.0 1.21.0 1.20.0 1.19.0 1.18.1 1.17.1 1.16.1 1.15.0 1.13.1 1.12.2 1.11.1 1.10.1 1.9.1 1.8.1 1.7.0 1.6.0 1.5.1 1.5.0 1.4.0 1.3.1 )

charts

High quality data visualization and charting

Reference

charts/*background-color* charts/*color-seed* charts/*font* charts/*grid-color* charts/*padding* charts/*stroke-color* charts/*text-color* charts/color-lerp charts/color-map charts/color-maps charts/dark-mode charts/draw-axes charts/draw-heat-legend charts/draw-legend charts/heat-map-chart charts/invert-color-map charts/light-mode charts/line-chart charts/plot-heat-map charts/plot-line-graph


charts/*background-color* keyword source
Default background color for chart rendering

charts/*color-seed* keyword source
Random seed to use when picking psuedo-random colors for charts

charts/*font* keyword source
Default font for chart rendering

charts/*grid-color* keyword source
Default color for grid lines

charts/*padding* keyword source
Default padding for charts

charts/*stroke-color* keyword source
Default color for drawn lines such as frame borders

charts/*text-color* keyword source
Default font color for title and axis labels

charts/color-lerp function source
(color-lerp a b t)


charts/color-map function source
(color-map & colors)

Create a function that linearly interpolates between colors for colormapping.

charts/color-maps table source
A table containing various default color maps that can be used for rendering heat map data.
Each value is a function mapping real numbers in the range [0, 1] to colors represented as 32 bit integers.

charts/dark-mode function source
(dark-mode)

Set dynamic color defaults to dark mode

charts/draw-axes function source
(draw-axes canvas &named padding inner-padding font x-min x-max y-min y-max min-x-spacing min-y-spacing grid format-x format-y x-label y-label tick-length x-suffix x-prefix y-suffix y-prefix x-ticks x-minor-ticks y-minor-ticks x-labels-vertical)

Draw the axis for the chart. Also return a function that can be used
to convert a coordinate in the metric space to the screen space. Most parameters
are optional with sane defaults, but canvas, x-min, x-max, y-min, y-max are all required.

* :x-label - optional label for the x axis
* :y-label - optional label for the y axis
* :padding - the number of pixels to leave around all drawn content
* :inner-padding - how many pixels to add between the axes frame and the internal graphing area. Defaults to 8.
* :font - the font to use for axis text
* :{x,y}-{min,max} - The bounds for coordinate system to draw
* :grid - Style for drawing grid-lines. Can be nil (none), :none, :solid, or :stipple
* :format-x - unary function (fn [x] ...) that returns a string to label x axis tick marks with
* :format-y - unary function (fn [y] ...) that returns a string to label y axis tick marks with
* :x-prefix - if format-x not provided, allows easily adding a string prefix to x axis tick mark labels
* :y-prefix - if format-y not provided, allows easily adding a string prefix to y axis tick mark labels
* :x-suffix - if format-x not provided, allows easily adding a string suffix to x axis tick mark labels
* :y-suffix - if format-y not provided, allows easily adding a string suffix to y axis tick mark labels
* :x-ticks - Allow setting specific tick marks to be used marking the x axis rather than making a guess.
* :x-minor-ticks - How many minor tick marks, if any, to place between major tick marks on the x axis
* :y-minor-ticks - How many minor tick marks, if any, to place between major tick marks on the y axis
* :x-labels-vertical - Turn x labels vertical so more can fit on the axis
* :min-x-spacing - When guessing x ticks, allow setting a lower limit to the metric spacing between ticks
* :min-y-spacing - When guessing y ticks, allow setting a lower limit to the metric spacing between ticks
* :tick-length - how many pixels long to make major tick marks (minor tick marks are 1/2 major tick marks)

Returns a tuple [view:gfx2d/Image to-pixel-space:fn to-metric-space:fn]

* `view` is an image that can be used to draw inside the chart, clipped so you don't overwrite that axes.
* `(to-pixel-space metric-x metric-y)` converts metric space coordinates to pixel space for plotting on `view`.
* `(to-metric-space pixel-x pixel-y)` converts pixel coordinates to the metric space.

charts/draw-heat-legend function source
(draw-heat-legend canvas &named swatch-width swatch-height background-color font padding color-map frame line-color text-color layout labels)

Draw a legend that describes a heat-map color range.

`canvas` can be either nil to skip drawing or a gfx2d/Image.

* :swatch-width - width of the color gradient in pixels
* :swatch-height - height of the color gradient in pixels
* :background-color - the color of the background of the legend
* :font - the font to use for legend text
* :padding - the number of pixels to leave around all drawn content
* :color-map - a table/struct that maps labels to colors
* :line-color - color to draw frame border
* :text-color - color of text
* :labels - a list of labels to draw in the legend
* :frame - whether or not to draw a frame around the legend

Return [w h] of the area that was or would be drawn if the legend were to be drawn.

charts/draw-legend function source
(draw-legend canvas &named background-color font padding color-map labels view-width frame color-seed legend-map line-color text-color)

Draw a legend given a set of labels and colors

`canvas` can be either nil to skip drawing or a gfx2d/Image.

* :background-color - the color of the background of the legend
* :font - the font to use for legend text
* :padding - the number of pixels to leave around all drawn content
* :color-map - a table/struct that maps labels to colors
* :legend-map - a table/struct that maps labels to text to draw
* :line-color - color to draw frame border
* :text-color - color of text
* :labels - a list of labels to draw in the legend
* :view-width - width of the enclosing view in pixels to help hint how to size the legend.
* :frame - whether or not to draw a frame around the legend

Return [w h] of the area that was or would be drawn if the legend were to be drawn.

charts/heat-map-chart function source
(heat-map-chart &named width height data data-scale xs ys color-fn cell-text-fn num-columns num-rows font title-font cell-font color-map background-color text-color cell-text-color x-min x-max y-min y-max format-x format-y padding title box-gap legend legend-frame legend-labels x-label y-label x-suffix x-prefix y-suffix y-prefix x-ticks x-minor-ticks y-minor-ticks tick-length x-labels-vertical legend-width legend-height save-as)

Generate a heat map.

Render a heat map on a set of axis. Will nicely fill the passed in image, so use a subview to draw to a section of the chart.

Basic Parameters
* :width - New canvas width in pixels
* :height - New canvas height in pixels
* :color-map - a color map keyword or function used to map numbers 0
* :save-as - optional path to save the chart

Function Callback Input
* :num-columns - Number of columns to draw.
* :num-rows - Number of rows to draw.
* :color-fn - Function `(color-fn x y)` that returns a gfx2d color used to color each cell in the heat-map. If color-fn evaluates to a falsey value, that cell will be left blank.
* :cell-text-fn - Function `(cell-text-fn x y)` that returns an optional string to render for each cell. If the function evaluates to nil, no text will be drawn for that cell.

Data Frame Input
* :data - a dataframe table that contains a grid of cell
* :data-scale - map numeric data to a [0.0, 1.0] range with a scale factor or function. Is the constant 1.0 by default.
 and maximum values in data to 0 and 1 respectively.
* :xs - a list of x columns - these are keys in `data`
* :ys - (optional) keys into each column - by default this is just (range num-rows-in-data).

Axes Styling
* :grid - how to draw grid lines. One of :none, :solid, or :stipple
* :x-ticks - manually set the tick marks on the X axis instead of auto-detecting them
* :x-label - optional label for the x axis
* :y-label - optional label for the y axis
* :x-suffix - add a string suffix to each tick label on the x-axis
* :y-suffix - add a string suffix to each tick label on the x-axis
* :x-prefix - add a string prefix to each tick label on the y-axis
* :y-prefix - add a string prefix to each tick label on the y-axis
* :x-minor-ticks - how many, if any, small ticks to add between each large tick mark on the x axis
* :y-minor-ticks - how many, if any, small ticks to add between each large tick mark on the y axis
* :x-labels-vertical - Turn x labels vertical so more can fit on the axis
* :tick-length - how long to make major tick marks

Chart Styling
* :box-gap - Number of pixels between boxes on the heat map. Default is 0.
* :cell-font - font used to draw optional text in cells
* :cell-text-color - color of text, defaults to black or white, depending on cell color
* :font - font used to draw axes
* :title-font - font used to draw title. Defaults to font.
* :text-color - color of axes and title text
* :padding - Number of pixels to separate various elements of the chart
* :background-color - chart background color
* :legend - one of :top, :bottom, :left, :right, :top-left, :top-right, :bottom-left, :bottom-right, or :none
* :legend-labels - an array of evenly-spaced markers to put on the color map legend.
* :legend-width - width of color map gradient in the legend in pixels
* :legend-height - height of the color map gradient in the legend in pixels

Returns a new canvas.

charts/invert-color-map function source
(invert-color-map mapping)

Create an inverted color-map from an existing color map.

charts/light-mode function source
(light-mode)

Set dynamic color defaults to light mode

charts/line-chart function source
(line-chart &named width height data font background-color text-color color-map point-radius x-min x-max y-min y-max padding inner-padding title circle-points scatter grid legend super-sample stroke-thickness format-x format-y save-as legend-map tick-length line-style line-style-per-column x-label y-label x-suffix x-prefix y-suffix y-prefix x-column y-column x-ticks x-minor-ticks y-minor-ticks x-labels-vertical)

Render a line chart. Returns a gfx2d/Image which can be further manipulated with the spork/gfx2d module.

Basic Parameters
* :width - canvas width
* :height - canvas height
* :data - a data frame to use for data
* :title - an optional title to add to the rendered image
* :font - font used to draw text, including title, legend, and axes labels
* :save-as - save the generated image to file. Can be any format supported by the gfx2d module
* :x-column - the name of the data frame column to use for the x axis
* :y-column - a single column or array of column names to use for the chart
* :x-ticks - manually set the tick marks on the X axis instead of auto-detecting them

Axes Styling
* :inner-padding - the number of pixels of white space between x-min and the x-axes as well as y-min and the y-axes.
* :x-label - optional label for the x axis
* :y-label - optional label for the y axis
* :grid - how to draw grid lines. One of :none, :solid, or :stipple
* :x-suffix - add a string suffix to each tick label on the x-axis
* :y-suffix - add a string suffix to each tick label on the x-axis
* :x-prefix - add a string prefix to each tick label on the y-axis
* :y-prefix - add a string prefix to each tick label on the y-axis
* :x-minor-ticks - how many, if any, small ticks to add between each large tick mark on the x axis
* :y-minor-ticks - how many, if any, small ticks to add between each large tick mark on the y axis
* :x-labels-vertical - Turn x labels vertical so more can fit on the axis
* :tick-length - how long to make major tick marks

Chart Styling
* :padding - the number of pixels of white space around various elements of the chart
* :background-color - color of background, defaults to white
* :text-color - color of text, defaults to black
* :color-map - a dictionary mapping columns to colors. By default will hash column name to pseudo-random colors
* :scatter - set to true to disable lines connecting points
* :legend - set to true to add a legend to the top of the chart
* :legend-map - a dictionary mapping column names to pretty text for the chart
* :point-radius - radius of points when drawing a scatter plot
* :line-style - How to draw lines. Can be one of :stroke, :plot, :none, :bar, :area, or :stipple. Default is :plot.
* :line-style-per-column - Optional dictionary to override line style by y-column name.
* :super-sample - Super Sample anti-aliasing for chart lines. Is a bit slow, but makes smooth plots. Works best with :stroke and :bar
* :stroke-thickness - thickness in pixels of the stroke of the graph when :line-type = :stroke

Axis Boundaries
* :x-min - minimum x coordinate on chart
* :x-max - maximum x coordinate on chart
* :y-min - minimum y coordinate on chart
* :y-max - maximum y coordinate on chart

charts/plot-heat-map function source
(plot-heat-map &named canvas color-fn cell-text-fn num-columns num-rows box-gap font cell-text-color)

Render a heat map on a set of axis. Will nicely fill the passed in image, so use a subview to draw to a section of the chart.

Basic Parameters
* :canvas - A gfx2d/Image to draw on
* :color-fn - Function `(color-fn x y)` that returns a gfx2d color (32 bit integer) used to color each cell in the heat-map. If color-fn evaluates to a falsey value, that cell will be left blank.
* :cell-text-fn - Function `(cell-text-fn x y)` that returns an optional string to render for each cell.
* :num-columns - Number of columns to draw.
* :num-rows - Number of rows to draw.
* :box-gap - Number of pixels between boxes on the heat map
* :font - font used to draw optional text in cells
* :cell-text-color - color of text, defaults to black

Returns the modified original canvas.

charts/plot-line-graph function source
(plot-line-graph &named canvas data to-pixel-space line-style line-style-per-column x-column y-column circle-points point-radius x-colors bar-padding stroke-thickness super-sample color-map)

Plot a line graph or scatter graph on a canvas. This function does not add a set of axis, title, or chart legend, it will only plot the graph lines and points from data.

* :canvas - a gfx2d/Image to draw on
* :to-pixel-space - optional function (f x y) -> [pixel-x pixel-y]. Used to convert the metric space to pixel space when plotting points.
* :data - a data frame to use for x and y data
* :x-column - the name of the data frame column to use for the x axis
* :y-column - a single column name or list of column names to use for the y coordinates and connected lines
* :color-map - a dictionary mapping columns to colors. By default will hash column name to pseudo-random colors
* :line-style - How to draw lines. Can be one of :stroke, :plot, :none, :bar, :area, or :stipple. Default is :plot.
* :line-style-per-column - Optional dictionary to override line style by y-column name.
* :circle-points - add circles around each point
* :point-radius - how large to make the circles around each point in pixels
* :super-sample - use super sampling to draw a larger image and then scale it down for anti-aliasing.
* :bar-padding - space between bars in bar-charts
* :stroke-thickness - thickness in pixels of the stroke of the graph when :line-type = :stroke
* :x-colors - for bar and scatter plots, optionally set per-point/per-bar colors with an function (f x y index) called on each point.