Skip to content

<chart> phase 4: type="box" #1880

Description

@dqnykamp

Part of #437, and depends on the <series> work in Phase 1.

The first type whose series holds raw observations rather than one value per category. A box per series, side by side along the horizontal axis — which is exactly aes(x = group, y = value), so a series being the group is the standard reading rather than a Doenet-specific one.

The five-number summary

<summaryStatistics> already computes min, Q1, median, Q3 and max, and its FIVE_NUMBER_SUMMARY names that set. The quartiles must come from the same definition — math-expressions' quantileSeq, interpolated percentiles — so that a box plot and a <summaryStatistics> of the same data never disagree on the page. Extract the computation into a shared utility rather than reimplementing it.

Note what that means and what the docs must not claim: these are interpolated percentiles, not Tukey's hinges, and they differ on some sample sizes. SummaryStatistics.js already carries the comment explaining why the term "five-number summary" is used unattributed.

Drawing

  • <rectangle> from Q1 to Q3, filled from the series' styleNumber.
  • <line> across the box at the median.
  • <line> whiskers from the box to the furthest observation within 1.5 IQR of it, with a <line> cap at each end.
  • <point> for each observation beyond the whiskers.

The 1.5 IQR rule is the default and the only rule implemented; if a whiskers attribute is wanted later (minMax, a multiplier), it slots in without changing the drawing.

Axis and labels

The horizontal axis carries one <tick-mark> per box, labeled with the series' label. That is the same categorical axis a bar chart draws, so categories is not used by this type — the boxes are the categories — and giving both should warn.

The vertical axis is the data's scale, so unlike a bar chart it does not have to include zero: bounds come from the observations and the outliers, rounded out to the next tick.

Public properties

Each <series> exposes its own summary — minimum, quartile1, median, quartile3, maximum, and the outliers — so a named series can be read into a sentence or an <answer>. This is the same argument #1833 made for binning in the worker rather than in scipy.

Tests

Quartiles agreeing with <summaryStatistics> on the same data, including the sample sizes where hinges and interpolated percentiles differ; whisker ends landing on real observations rather than on the fence; outliers drawn as points and not as whisker ends; a series with one observation and with none; several series side by side; the annotation tree.


🤖 Generated with Claude Code

https://claude.ai/code/session_01RqRJ3QoH4UrHFR41aAkN8e

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions