Back to the library

Spread — box plot keeps its outliers

Variant: Box and outliers

Twenty raw samples appear on an axis, then a box plot is built over them in three beats: the median drops in, the box opens outward from it to the quartiles, and the whiskers reach from the box edges to the furthest samples inside 1.5 × IQR. Only then do the eighteen dots the summary accounts for recede to a quarter strength, while the two it cannot account for stay at full ink under a "2 outliers" label. The order is the argument — raw data first so the summary is visibly derived from it, never asserted. The box and whiskers reveal with clip-path rather than scaleX so their 1.5px strokes never thin mid-open. Use it on performance reports and anywhere a summary is about to replace the rows it came from.

datachartdistributionentranceclip-pathloop

The source

A complete HTML document. Paste it into an empty .html file and it plays — no stylesheet, script, font, or image to fetch.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Spread — box plot keeps its outliers</title>
    <style>
      :root {
        /* Neutrals — fixed, never remixed. */
        --ivory: #faf9f5;
        --paper: #ffffff;
        --oat: #e3dacc;
        --slate: #141413;

        /* Knobs — the remix API. A knob exists iff declared here and used below. */
        --hue: 38.8;
        --lift: 0;
        --chroma: 1;
        --round: 1;
        --speed: 1;

        /* Accents — derived from the knobs with the family's offsets baked in,
           so one hue roll moves them together. Defaults reproduce the original hex. */
        --clay: oklch(calc(0.6724 + var(--lift)) calc(0.1308 * var(--chroma)) var(--hue));
        --clay-d: oklch(calc(0.5797 + var(--lift)) calc(0.127 * var(--chroma)) var(--hue));
        --olive: oklch(
          calc(0.6118 + var(--lift)) calc(0.0713 * var(--chroma)) calc(var(--hue) + 88.3)
        );
        --rust: oklch(
          calc(0.5408 + var(--lift)) calc(0.1357 * var(--chroma)) calc(var(--hue) - 10.3)
        );

        /* Clock — 7s, so 1% is 70ms. Raw samples, then the summary is built
           over them in three beats: median, box, whiskers. */
        --cycle: 7s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

        --_muted: color-mix(in srgb, var(--slate) 50%, transparent);
        --_ink: color-mix(in srgb, var(--slate) 72%, transparent);
        --_rule: color-mix(in srgb, var(--slate) 22%, transparent);
        --_dot: 7px;
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      body {
        min-height: 100vh;
        display: grid;
        place-items: center;
        background: var(--ivory);
        font-family:
          system-ui,
          -apple-system,
          'Segoe UI',
          Roboto,
          sans-serif;
        color: var(--slate);
      }

      .card {
        width: min(296px, 88vw);
        padding: 14px 16px 12px;
        background: var(--paper);
        border: 1px solid var(--oat);
        border-radius: calc(10px * var(--round));
        display: grid;
        gap: 6px;
      }

      .head {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        font-size: 12px;
        margin-bottom: 4px;
      }

      .head b {
        font-weight: 600;
      }

      .head span {
        color: var(--_muted);
      }

      .plot {
        position: relative;
        height: 64px;
        animation: frame var(--t) infinite;
      }

      .note {
        position: absolute;
        top: 0;
        right: 0;
        font-size: 11px;
        color: var(--rust);
        white-space: nowrap;
        opacity: 0;
        animation: note var(--t) infinite;
      }

      .row {
        position: absolute;
        left: 0;
        right: 0;
        top: 16px;
        bottom: 0;
      }

      /* Box: Q1 90ms to Q3 137ms. It opens out of the median (108ms, 38.3% of
         the way across it) with a clip-path, so the 1.5px border never thins the
         way it would under scaleX. */
      .box {
        position: absolute;
        left: 22.5%;
        width: 11.75%;
        top: 50%;
        height: 28px;
        margin-top: -14px;
        border: 1.5px solid var(--_ink);
        border-radius: calc(3px * var(--round));
        background: color-mix(in srgb, var(--clay) 10%, transparent);
        clip-path: inset(-2px 61.7% -2px 38.3%);
        animation: box var(--t) infinite;
      }

      .med {
        position: absolute;
        left: 27%;
        top: 50%;
        width: 2px;
        height: 28px;
        margin: -14px 0 0 -1px;
        background: var(--slate);
        opacity: 0;
        animation: med var(--t) infinite;
      }

      /* Whiskers reach out from the box edge to the furthest sample inside
         1.5 × IQR — 62ms and 170ms — and stop there. */
      .wh {
        position: absolute;
        top: 50%;
        height: 12px;
        margin-top: -6px;
        background: linear-gradient(var(--_ink), var(--_ink)) center / 100% 1.5px no-repeat;
      }

      .wh.lo {
        left: 15.5%;
        width: 7%;
        border-left: 1.5px solid var(--_ink);
        clip-path: inset(0 0 0 100%);
        animation: wh-lo var(--t) infinite;
      }

      .wh.hi {
        left: 34.25%;
        width: 8.25%;
        border-right: 1.5px solid var(--_ink);
        clip-path: inset(0 100% 0 0);
        animation: wh-hi var(--t) infinite;
      }

      .s {
        position: absolute;
        left: var(--_x);
        top: 50%;
        width: var(--_dot);
        height: var(--_dot);
        margin: calc(var(--_dot) / -2) 0 0 calc(var(--_dot) / -2);
        translate: 0 var(--_y);
        opacity: 0;
        animation: land var(--t) infinite;
        animation-delay: calc((0.2s + var(--_i) * 0.032s) / var(--speed));
      }

      .s i {
        position: absolute;
        inset: 0;
        border-radius: 50%;
        background: var(--clay);
        animation: dim var(--t) infinite;
      }

      /* Outliers do not dim — the summary is drawn over the samples it
         accounts for, and what it cannot account for stays at full ink. */
      .s.out i {
        background: var(--rust);
        animation: none;
      }

      .axis {
        position: relative;
        height: 14px;
        border-top: 1px solid var(--_rule);
        font-size: 11px;
        color: var(--_muted);
        font-variant-numeric: tabular-nums;
      }

      .axis span {
        position: absolute;
        top: 2px;
        translate: -50% 0;
      }

      .axis span:first-child {
        translate: 0 0;
      }

      .axis span:last-child {
        translate: -100% 0;
      }

      @keyframes land {
        0% {
          opacity: 0;
          transform: scale(0.8);
          animation-timing-function: var(--ease-out);
        }
        3%,
        86% {
          opacity: 1;
          transform: scale(1);
        }
        86.01%,
        100% {
          opacity: 0;
        }
      }

      @keyframes med {
        0%,
        16% {
          opacity: 0;
          transform: scaleY(0.6);
          animation-timing-function: var(--ease-out);
        }
        20%,
        100% {
          opacity: 1;
          transform: scaleY(1);
        }
      }

      @keyframes box {
        0%,
        19% {
          clip-path: inset(-2px 61.7% -2px 38.3%);
          animation-timing-function: var(--ease-out);
        }
        25%,
        100% {
          clip-path: inset(-2px -2px -2px -2px);
        }
      }

      @keyframes wh-lo {
        0%,
        25% {
          clip-path: inset(0 0 0 100%);
          animation-timing-function: var(--ease-out);
        }
        30%,
        100% {
          clip-path: inset(0 0 0 0);
        }
      }

      @keyframes wh-hi {
        0%,
        25% {
          clip-path: inset(0 100% 0 0);
          animation-timing-function: var(--ease-out);
        }
        30%,
        100% {
          clip-path: inset(0 0 0 0);
        }
      }

      @keyframes dim {
        0%,
        32% {
          opacity: 1;
          animation-timing-function: var(--ease-out);
        }
        38%,
        100% {
          opacity: 0.26;
        }
      }

      @keyframes note {
        0%,
        34% {
          opacity: 0;
          transform: translateY(3px);
          animation-timing-function: var(--ease-out);
        }
        39%,
        100% {
          opacity: 1;
          transform: translateY(0);
        }
      }

      @keyframes frame {
        0%,
        80% {
          opacity: 1;
          animation-timing-function: var(--ease-out);
        }
        86%,
        100% {
          opacity: 0;
        }
      }

      @keyframes rm-box {
        0%,
        19% {
          opacity: 0;
          animation-timing-function: var(--ease-out);
        }
        25%,
        100% {
          opacity: 1;
        }
      }

      @keyframes rm-wh {
        0%,
        25% {
          opacity: 0;
          animation-timing-function: var(--ease-out);
        }
        30%,
        100% {
          opacity: 1;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* The build order is the explanation, so it stays: samples, then the
           summary, then the samples it covers recede. Each piece fades in
           where it ends up — no growing, no opening — at twice the period. */
        .plot,
        .note,
        .med,
        .box,
        .wh,
        .s,
        .s i {
          animation-duration: calc(var(--t) * 2);
        }

        .s {
          animation-delay: calc((0.4s + var(--_i) * 0.064s) / var(--speed));
        }

        .box,
        .wh.lo,
        .wh.hi {
          clip-path: none;
        }

        .box {
          animation-name: rm-box;
        }

        .wh.lo,
        .wh.hi {
          animation-name: rm-wh;
        }

        .s,
        .med,
        .note,
        .box,
        .wh {
          transform: none !important;
        }
      }
    </style>
  </head>
  <body>
    <div
      class="card"
      role="img"
      aria-label="Twenty checkout latencies appear as dots along a 0 to 400 millisecond axis. A median line drops in among them, a box opens outward from it to the quartiles, and whiskers reach out to the furthest ordinary samples. The eighteen dots the box plot accounts for fade back; two outliers near 320 and 370 milliseconds stay at full strength under a label reading 2 outliers"
    >
      <div class="head"><b>Checkout latency</b><span>20 requests</span></div>
      <div class="plot">
        <span class="note">2 outliers</span>
        <div class="row">
          <span class="wh lo"></span>
          <span class="box"></span>
          <span class="wh hi"></span>
          <span class="s" style="--_x: 15.5%; --_y: 0px; --_i: 8"><i></i></span>
          <span class="s" style="--_x: 17.75%; --_y: -7px; --_i: 3"><i></i></span>
          <span class="s" style="--_x: 19.5%; --_y: 7px; --_i: 6"><i></i></span>
          <span class="s" style="--_x: 21%; --_y: -4px; --_i: 5"><i></i></span>
          <span class="s" style="--_x: 22%; --_y: 5px; --_i: 15"><i></i></span>
          <span class="s" style="--_x: 23%; --_y: -8px; --_i: 16"><i></i></span>
          <span class="s" style="--_x: 23.75%; --_y: 2px; --_i: 2"><i></i></span>
          <span class="s" style="--_x: 24.75%; --_y: 8px; --_i: 12"><i></i></span>
          <span class="s" style="--_x: 25.75%; --_y: -6px; --_i: 0"><i></i></span>
          <span class="s" style="--_x: 26.5%; --_y: 0px; --_i: 1"><i></i></span>
          <span class="s" style="--_x: 27.5%; --_y: 6px; --_i: 13"><i></i></span>
          <span class="s" style="--_x: 28.5%; --_y: -3px; --_i: 10"><i></i></span>
          <span class="s" style="--_x: 29.75%; --_y: -8px; --_i: 19"><i></i></span>
          <span class="s" style="--_x: 31.5%; --_y: 4px; --_i: 9"><i></i></span>
          <span class="s" style="--_x: 33.25%; --_y: -5px; --_i: 14"><i></i></span>
          <span class="s" style="--_x: 35.25%; --_y: 7px; --_i: 11"><i></i></span>
          <span class="s" style="--_x: 38%; --_y: 0px; --_i: 4"><i></i></span>
          <span class="s" style="--_x: 42.5%; --_y: -6px; --_i: 17"><i></i></span>
          <span class="s out" style="--_x: 79.5%; --_y: 0px; --_i: 18"><i></i></span>
          <span class="s out" style="--_x: 92.75%; --_y: 0px; --_i: 7"><i></i></span>
          <span class="med"></span>
        </div>
      </div>
      <div class="axis">
        <span style="left: 0%">0ms</span><span style="left: 25%">100</span
        ><span style="left: 50%">200</span><span style="left: 75%">300</span
        ><span style="left: 100%">400</span>
      </div>
    </div>
  </body>
</html>