Back to the library

Spread — same mean, different spread

Variant: Same mean

Two servers, both averaging 120ms. Their twelve samples start stacked on the mean, where they read as a single sample — which is all an average tells you — then unfold to their real values and fold back. The move is 640ms on ease-in-out in both directions, because the dots are on screen at both ends: this is travel, not an entrance. Both rows share one clock, so B, whose samples run from 42ms out to 344ms, visibly covers far more ground in the same time. The "avg 120" readouts never change — that is the point — and each row’s range fades in beneath its average as the dots land and leaves as soon as they start back, so the range only ever describes what is on screen. Reach for it when arguing for percentiles over averages, or in A/B comparisons where the means agree.

datachartdistributionmorphloop

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 — same mean, different spread</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 — 6.4s, so 1% is 64ms. Collapsed 768ms, unfold 640ms, a 3.2s
           read, fold 640ms, then rest on the average again. */
        --cycle: 6.4s;
        --t: calc(var(--cycle) / var(--speed));

        --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
        --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

        --_muted: color-mix(in srgb, var(--slate) 50%, transparent);
        --_rule: color-mix(in srgb, var(--slate) 18%, transparent);
        --_mean: 30%;
        --_dot: 8px;
      }

      * {
        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(300px, 88vw);
        padding: 14px 16px;
        background: var(--paper);
        border: 1px solid var(--oat);
        border-radius: calc(10px * var(--round));
        display: grid;
        gap: 8px;
      }

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

      .head b {
        font-weight: 600;
      }

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

      .row {
        display: grid;
        grid-template-columns: 14px 1fr 50px;
        align-items: center;
        gap: 10px;
        height: 32px;
        font-size: 12px;
      }

      .row.axis {
        height: auto;
        margin-top: -4px;
        font-size: 11px;
        color: var(--_muted);
        font-variant-numeric: tabular-nums;
      }

      .scale {
        display: flex;
      }

      .scale span {
        flex: 1;
      }

      .scale span:nth-child(2) {
        text-align: center;
      }

      .scale span:last-child {
        text-align: right;
      }

      .name {
        font-weight: 600;
        color: var(--_muted);
      }

      .plot {
        position: relative;
        height: 100%;
        overflow: hidden;
        background: linear-gradient(var(--_rule), var(--_rule)) center / 100% 1px no-repeat;
      }

      .mean {
        position: absolute;
        left: var(--_mean);
        top: 50%;
        width: 2px;
        height: 18px;
        margin: -9px 0 0 -1px;
        background: var(--slate);
      }

      /* Each sample is a full-width layer translated by its value, so a
         percentage in translateX is a percentage of the axis. Collapsed, all
         twelve sit on the mean and read as one sample — which is exactly how
         much an average tells you. */
      .d {
        position: absolute;
        inset: 0;
        transform: translateX(var(--_mean));
        animation: unfold var(--t) infinite;
      }

      .d::before {
        content: '';
        position: absolute;
        left: calc(var(--_dot) / -2);
        top: 50%;
        width: var(--_dot);
        height: var(--_dot);
        margin-top: calc(var(--_dot) / -2);
        border-radius: 50%;
        background: color-mix(in srgb, var(--clay) 55%, transparent);
      }

      .lump {
        display: none;
      }

      /* The average never leaves — it is the thing both rows agree on. The
         range arrives under it, so the contrast is read against it. */
      .read {
        display: grid;
        justify-items: end;
        line-height: 1.15;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
      }

      .read .range {
        font-size: 11px;
        color: var(--clay-d);
        font-weight: 600;
        opacity: 0;
        animation: range var(--t) infinite;
      }

      /* Unfold and fold are the same move in opposite directions over
         640ms, on an in-out curve: the dots are on screen at both ends, so
         this is travel, not an entrance. Both rows share one clock — row B
         covers more ground in the same time, and that speed is the reading. */
      @keyframes unfold {
        0%,
        12% {
          transform: translateX(var(--_mean));
          animation-timing-function: var(--ease-in-out);
        }
        22%,
        72% {
          transform: translateX(var(--_x));
          animation-timing-function: var(--ease-in-out);
        }
        82%,
        100% {
          transform: translateX(var(--_mean));
        }
      }

      /* The range appears as the dots land and leaves as soon as they start
         back, so it only ever describes what is on screen. It drops in from
         above and leaves upward, toward the average it came out of. */
      @keyframes range {
        0%,
        19% {
          opacity: 0;
          transform: translateY(-3px);
          animation-timing-function: var(--ease-out);
        }
        23%,
        72% {
          opacity: 1;
          transform: translateY(0);
          animation-timing-function: var(--ease-out);
        }
        74.5%,
        100% {
          opacity: 0;
          transform: translateY(-3px);
        }
      }

      @keyframes rm-spread {
        0%,
        12% {
          opacity: 0;
          animation-timing-function: var(--ease-out);
        }
        22%,
        72% {
          opacity: 1;
          animation-timing-function: var(--ease-out);
        }
        82%,
        100% {
          opacity: 0;
        }
      }

      @keyframes rm-lump {
        0%,
        12% {
          opacity: 1;
          animation-timing-function: var(--ease-out);
        }
        22%,
        72% {
          opacity: 0;
          animation-timing-function: var(--ease-out);
        }
        82%,
        100% {
          opacity: 1;
        }
      }

      @media (prefers-reduced-motion: reduce) {
        /* No travel: the samples crossfade in at their values while a single
           dot on the mean fades out, and back. Same story, half the pace. */
        .d {
          transform: translateX(var(--_x));
          animation: rm-spread calc(var(--t) * 2) infinite;
        }

        .lump {
          display: block;
          --_x: var(--_mean);
          animation-name: rm-lump;
        }

        .lump::before {
          background: var(--clay);
        }

        .read .range {
          animation-duration: calc(var(--t) * 2);
          transform: none !important;
        }
      }
    </style>
  </head>
  <body>
    <div
      class="card"
      role="img"
      aria-label="Two servers, A and B, each shown as twelve response times on a shared axis. Both start collapsed onto the same average of 120 milliseconds and read avg 120ms. They unfold to their real values: A's samples stay between 96 and 145 milliseconds, while B's spread from 42 out to 344. Each readout keeps avg 120ms and shows that row's range beneath it while the dots are spread, then the dots fold back onto the average"
    >
      <div class="head"><b>Same average</b><span>12 requests each</span></div>
      <div class="row">
        <span class="name">A</span>
        <div class="plot">
          <span class="d" style="--_x: 24%"></span>
          <span class="d" style="--_x: 26%"></span>
          <span class="d" style="--_x: 27%"></span>
          <span class="d" style="--_x: 28%"></span>
          <span class="d" style="--_x: 29%"></span>
          <span class="d" style="--_x: 29.5%"></span>
          <span class="d" style="--_x: 30.25%"></span>
          <span class="d" style="--_x: 31%"></span>
          <span class="d" style="--_x: 32%"></span>
          <span class="d" style="--_x: 33%"></span>
          <span class="d" style="--_x: 34%"></span>
          <span class="d" style="--_x: 36.25%"></span>
          <span class="d lump"></span>
          <span class="mean"></span>
        </div>
        <span class="read"><span>avg 120</span><span class="range">96–145</span></span>
      </div>
      <div class="row">
        <span class="name">B</span>
        <div class="plot">
          <span class="d" style="--_x: 10.5%"></span>
          <span class="d" style="--_x: 13.75%"></span>
          <span class="d" style="--_x: 15.75%"></span>
          <span class="d" style="--_x: 17.5%"></span>
          <span class="d" style="--_x: 19.5%"></span>
          <span class="d" style="--_x: 21.5%"></span>
          <span class="d" style="--_x: 23.75%"></span>
          <span class="d" style="--_x: 26%"></span>
          <span class="d" style="--_x: 29.5%"></span>
          <span class="d" style="--_x: 35%"></span>
          <span class="d" style="--_x: 61.25%"></span>
          <span class="d" style="--_x: 86%"></span>
          <span class="d lump"></span>
          <span class="mean"></span>
        </div>
        <span class="read"><span>avg 120</span><span class="range">42–344</span></span>
      </div>
      <div class="row axis">
        <span></span>
        <span class="scale"><span>0ms</span><span>200</span><span>400</span></span>
        <span></span>
      </div>
    </div>
  </body>
</html>