diff --git a/src/lib/chart/boxwhisker.typ b/src/lib/chart/boxwhisker.typ index 96b5a0d55..c282e8a57 100644 --- a/src/lib/chart/boxwhisker.typ +++ b/src/lib/chart/boxwhisker.typ @@ -8,19 +8,21 @@ grid: none, ) -/// Add one or more box or whisker plots +/// Add one or more box or whisker plots. /// -/// - data (array, dictionary): dictionary or array of dictionaries containing the +/// - data (array, dictionary): Dictionary or array of dictionaries containing the /// needed entries to plot box and whisker plot. /// -/// *Examples:* -/// - ```( x: 1 // Location on x-axis -/// outliers: (7, 65, 69), // Optional -/// min: 15, max: 60 // Minimum and maximum -/// q1: 25, // Quartiles -/// q2: 35, -/// q3: 50 -/// )``` +/// See `plot.add-boxwhisker` for more details. +/// +/// *Examples:* +/// - ```(x: 1 // Location on x-axis +/// outliers: (7, 65, 69), // Optional +/// min: 15, max: 60 // Minimum and maximum +/// q1: 25, // Quartiles +/// q2: 35, +/// q3: 50 +/// )``` /// - size (array) : Size of chart. If the second entry is auto, it automatically scales to accomodate the number of entries plotted /// - y-min (float) : Lower end of y-axis range. If auto, defaults to lowest outlier or lowest min. /// - y-max (float) : Upper end of y-axis range. If auto, defaults to greatest outlier or greatest max. @@ -29,48 +31,45 @@ /// - whisker-width (float): Width from edge-to-edge of the whisker of the box and whisker in plot units. Defaults to 0.5 /// - mark (string): Mark to use for plotting outliers. Set `none` to disable. Defaults to "x" /// - mark-size (float): Size of marks for plotting outliers. Defaults to 0.15 -/// - ..arguments (variadic): Additional arguments are passed to `plot.plot` -#let boxwhisker( data, - size: (1, auto), - y-min: auto, - y-max: auto, - label-key: 0, - box-width: 0.75, - whisker-width: 0.5, - mark: "*", - mark-size: 0.15, - ..arguments - ) = { - // import draw: * - - if type(data) == dictionary { data = (data,) } - - if size.at(1) == auto {size.at(1) = (data.len() + 1)} +/// - ..arguments (any): Additional arguments are passed to `plot.plot` +#let boxwhisker(data, + size: (1, auto), + y-min: auto, + y-max: auto, + label-key: 0, + box-width: 0.75, + whisker-width: 0.5, + mark: "*", + mark-size: 0.15, + ..arguments + ) = { + if type(data) == dictionary { data = (data,) } - let x-tic-list = data.enumerate().map(((i, t)) => { - (i + 1, t.at(label-key, default: i)) - }) + if size.at(1) == auto {size.at(1) = (data.len() + 1)} - plot.plot( - size: size, - x-tick-step: none, - x-ticks: x-tic-list, - y-min: y-min, - y-max: y-max, - x-label: none, - ..arguments, - { - for (i, row) in data.enumerate() { - plot.add-boxwhisker( - ( x: i + 1, ..row), - box-width: box-width, - whisker-width: whisker-width, - style: (:), - mark: mark, - mark-size: mark-size - ) - } - } - ) + let x-tick-list = data.enumerate().map(((i, t)) => { + (i + 1, t.at(label-key, default: i)) + }) -} \ No newline at end of file + plot.plot( + size: size, + x-tick-step: none, + x-ticks: x-tick-list, + y-min: y-min, + y-max: y-max, + x-label: none, + ..arguments, + { + for (i, row) in data.enumerate() { + plot.add-boxwhisker( + (x: i + 1, ..row), + box-width: box-width, + whisker-width: whisker-width, + style: (:), + mark: mark, + mark-size: mark-size + ) + } + } + ) +} diff --git a/tests/chart/boxwhisker/ref.png b/tests/chart/boxwhisker/ref.png new file mode 100644 index 000000000..a7a649594 Binary files /dev/null and b/tests/chart/boxwhisker/ref.png differ diff --git a/tests/plot/boxwhisker/ref.png b/tests/plot/boxwhisker/ref.png new file mode 100644 index 000000000..37dc3988f Binary files /dev/null and b/tests/plot/boxwhisker/ref.png differ