Skip to content
animorio
IT
Back to the library

Packed bubble chart

SVG, HoverGSAP, CSS onlyAdvancedCompressed weight: Demo 8.2 KBGSAP 28 KBFreeDownload the zip

Halyard, a made-up analytics dashboard: where this month’s visits came from, as ten packed bubbles whose area is the number of visits. They grow from the middle one after another and settle against each other; pointing at one lifts it with a soft shadow, its neighbours make room and a tag gives the name, visits and share; switching month slides every bubble to its new size on a spring. Minimal style, SVG and GSAP.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Packed bubble chart" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Packed bubble chart</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <!-- Halyard, a made-up analytics dashboard: where this month's visitors came from, as packed bubbles whose area
       is the number of visits. Bubbles grow from the middle and settle against each other; pointing at one lifts it
       and shows its numbers; switching the period slides every bubble to its new size on springs -->
  <main class="stage">
    <section class="panel" aria-label="Traffic sources, Halyard analytics">
      <header class="head">
        <p class="brand"><svg class="brand__mark" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 13 8 3l5 10" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round"/><path d="M5.6 9h4.8" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>Halyard</p>
        <h1 class="title">Where visitors came from</h1>
        <p class="total"><span class="total__num" data-total>0</span> <span class="total__unit">visits</span></p>
      </header>

      <div class="period" role="tablist" aria-label="Period" data-period>
        <span class="period__pill" data-pill aria-hidden="true"></span>
        <button class="period__btn is-on" type="button" role="tab" aria-selected="true" data-tab="now">This month</button>
        <button class="period__btn" type="button" role="tab" aria-selected="false" data-tab="then">Last month</button>
      </div>

      <div class="chart" data-chart>
        <svg class="chart__svg" data-svg role="img" aria-label="Packed bubble chart of traffic sources">
          <defs>
            <radialGradient id="sheen" cx="35%" cy="28%" r="75%">
              <stop offset="0" stop-color="#fff" stop-opacity=".55" />
              <stop offset=".5" stop-color="#fff" stop-opacity=".08" />
              <stop offset="1" stop-color="#fff" stop-opacity="0" />
            </radialGradient>
          </defs>
          <g data-bubbles></g>
        </svg>
        <div class="tip" data-tip aria-live="polite">
          <p class="tip__name" data-tip-name></p>
          <p class="tip__nums"><span data-tip-value></span> <span class="tip__sep">·</span> <span data-tip-share></span></p>
        </div>
      </div>
    </section>
  </main>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

26 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Packed bubble chart” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

At the top the Halyard mark, the title «Where visitors came from» and the total visits rolling. Below, a pill toggle between This month and Last month, with the white pill sliding. Then the chart: ten bubbles, one per traffic source (Search, Direct, AI assistants, Newsletter, Social and the rest), their area proportional to visits. On arrival they grow from the middle one after another, largest first, and settle against each other on springs. The three biggest are dark with light type, the others in ever lighter greys; big bubbles show the name with the visits underneath, small ones only the number, always centred in the circle. Pointing at a bubble turns it blue, lifts it a few pixels with a soft shadow, nudges its neighbours aside and shows a black tag above with name, visits and share. Switching month slides each bubble to its new place and size, the greys reorder and the total rolls.

How it works

The packing

Each bubble’s radius is the square root of its visits, so area is proportional. Largest first, each bubble takes the free spot tangent to two placed bubbles that is closest to their centre of mass: a hand-written greedy algorithm, plenty for ten bubbles. Then the whole thing is centred on its bounding box.

One scale

The two months are packed separately but with the same scale, the one of the wider of the two, so the areas really compare. The scale is recomputed whenever the chart changes size.

The springs

Each bubble’s position and radius chase their targets on a hand-written spring on gsap.ticker (stiffness 170, damping 17): on entry the targets switch on one after another from the middle, on a month change they all change at once.

The pointed bubble

The bubble under the pointer lifts four pixels with two soft shadows, its neighbours move away along the line between centres, more the closer they are, and the tag follows it while staying inside the chart.

Centred labels

Name and number are two texts with dominant-baseline central, shifted by half their block: together they sit in the middle of the circle. Small bubbles keep only the number, centred.

Values to change

NameFileDefaultWhat it changes
SPEEDscript.js1Speed of everything.
STIFFNESSscript.js170Stiffness of the bubble springs.
DAMPINGscript.js17Spring damping: lower means more bounce.
GAPscript.js0.035Space between bubbles, as a share of the largest one.
STAGGERscript.js0.07Seconds between one bubble and the next on entry.
LIFTscript.js4Pixels the pointed bubble lifts.
PUSHscript.js5Pixels the neighbours move aside.
HOLDscript.js1.4Seconds on each bubble in the self-running loop.

Try them in the Playground

When to use it

For an analytics dashboard, a monthly report, a product’s numbers page or anywhere a share of a total reads better as an area than as a bar.

On phones

The same chart, sized on the shorter side of the screen; a tap points at a bubble.

With reduced motion

No springs and no nudging: the bubbles are already in place and the month change fades.

Pitfalls

  • The radius comes from the square root of the value, not the value: otherwise big bubbles look huge.
  • Both months must share one scale, or a bubble seems to grow only because the chart shrank.
  • The tag is measured after its text is written, and kept inside the chart at the edges.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 8.2 KB; the libraries: GSAP 28 KB.

Testing

Tested on 1 December 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All animations