Skip to content
animorio
IT
Back to the library

Portfolio treemap

SVG, TransitionsGSAP, CSS onlyMediumCompressed weight: Demo 8.1 KBGSAP 28 KBFreeDownload the zip

The allocation card of Tessly, a made-up investing app: a $248,310 portfolio drawn as a treemap, worked out with the real squarified algorithm. The pill on top regroups it by sector, asset class or region, and every tile springs from its old box to its new one while the percentages roll; green says what is up today, a soft red what is down. On hover a tile rises a hair with a thin outline and its value in dollars. Minimal style.

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>
<!--
  "Portfolio treemap" 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>Portfolio treemap</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the allocation card of a made-up investing app: a treemap of the portfolio, worked out with the squarified
         algorithm. The pill on top regroups it by sector, asset class or region, and every tile springs from its old
         box to its new one. Hover or tap a tile to read its value. -->
    <section class="card" data-card aria-labelledby="titolo">
      <span class="card__sheen" aria-hidden="true"></span>

      <header class="head">
        <div class="head__left">
          <span class="brand">
            <svg class="brand__mark" viewBox="0 0 20 20" aria-hidden="true"><rect x="2.5" y="2.5" width="8.5" height="15" rx="2" fill="currentColor"/><rect x="12.5" y="2.5" width="5" height="8" rx="1.6" fill="currentColor" opacity=".55"/><rect x="12.5" y="12" width="5" height="5.5" rx="1.6" fill="currentColor" opacity=".3"/></svg>
            Tessly
          </span>
          <h1 class="title" id="titolo">Allocation</h1>
        </div>
        <div class="head__right">
          <span class="total" data-total>$248,310</span>
          <span class="day"><svg class="day__arrow" viewBox="0 0 10 10" aria-hidden="true"><path d="M5 8V2.4M2.4 4.8 5 2.2l2.6 2.6" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg><span data-day>+1.24%</span> today</span>
        </div>
      </header>

      <div class="pills" role="tablist" aria-label="Group the portfolio by" data-pills>
        <span class="pills__thumb" data-thumb aria-hidden="true"></span>
        <button class="pill is-on" role="tab" aria-selected="true" data-group="sector" type="button">Sector</button>
        <button class="pill" role="tab" aria-selected="false" data-group="asset" type="button">Asset</button>
        <button class="pill" role="tab" aria-selected="false" data-group="region" type="button">Region</button>
      </div>

      <div class="map" data-map>
        <svg class="map__svg" data-svg role="img" aria-label="Portfolio treemap"></svg>
        <div class="tip" data-tip aria-hidden="true">
          <span class="tip__k" data-tip-k>Technology</span>
          <span class="tip__v" data-tip-v>$76,977</span>
          <span class="tip__c" data-tip-c>+2.1% today</span>
        </div>
      </div>

      <footer class="foot">
        <span class="legend"><i class="legend__sw legend__sw--down"></i>Down</span>
        <span class="legend"><i class="legend__sw legend__sw--flat"></i>Flat</span>
        <span class="legend"><i class="legend__sw legend__sw--up"></i>Up today</span>
        <span class="foot__note">Tile size = share of the portfolio</span>
      </footer>
      <p class="sr" data-sr aria-live="polite"></p>
    </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.

32 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 “Portfolio treemap” 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

A made-up $248,310 portfolio split into tiles: the bigger the tile, the bigger its share. On top the pill Sector, Asset, Region; pick a grouping and the tiles divide again, each springing from its old position and size to the new one, one after the other, the names that change fade out and back, the percentages roll, and the tiles no longer needed close into the corner. The colour tells the day: paper for flat, a fuller and fuller green for up, a soft red for down. On hover a tile rises two pixels with a thin outline and a shadow, and the tooltip shows its value in dollars and the change. If nobody touches it, the card regroups by itself and points at the largest tile.

How it works

The squarified treemap

Values, from largest to smallest, are laid in rows along the short side of the remaining rectangle: a tile joins the row as long as the worst aspect ratio does not get worse, then the row closes and a new one starts. That keeps the tiles close to square.

Shape as state

Each tile is an object with x, y, width, height and opacity; GSAP takes it to the new geometry with a back.out and every frame rewrites the attributes of the rect and the labels. It is not a scale: the text never stretches and the corners stay round.

Labels that fit

At the final geometry the name is measured on a canvas: if it does not fit, it stays hidden; the percentage and the change only appear if there is height. During the trip the labels step out in 0.12 s and come back on the new box at seven tenths of the change, while the percentage rolls.

The colour of the day

Today’s change picks the colour: up to ±0.15% the paper, then a green that fills up to full at +2.4%, and for what is down a soft red that never gets full. Above 55% green the label turns white.

The tile that rises

On hover the tile moves to the top of the drawing, rises LIFT pixels with a back.out, gets a thin outline and a double shadow, and the tooltip comes in from 6 pixels lower while staying inside the card.

Values to change

NameFileDefaultWhat it changes
SWITCH_EVERYscript.js3.6How many seconds before the card moves by itself to the next grouping, when nobody touches it.
MORPHscript.js0.8How many seconds a tile takes to spring from its old box to its new one.
OVERSHOOTscript.js1.3How far the tiles overshoot their new box before they settle (0 = none).
STAGGERscript.js0.02Seconds between one tile and the next as they move.
GAPscript.js4The gap between the tiles, in pixels.
RADIUSscript.js7How rounded the tile corners are, in pixels.
LIFTscript.js2How many pixels a tile rises under the pointer.
ROLLscript.js0.6How many seconds a percentage takes to roll to its new value.

Try them in the Playground

When to use it

In the dashboard of an investing or banking app, in a portfolio summary, in an analytics panel showing the parts of a whole (sales by category, disk space, budget by team) that can be grouped in several ways.

On phones

The card is sized in em and the text size follows the window’s width and height together; the treemap is at most 44% of the screen tall and is worked out again at every resize. A tap on a tile opens and closes the tooltip.

With reduced motion

No springs and no moving tiles: the new treemap arrives with a fade, the percentages change without rolling and the tile under the pointer only gets its outline and tooltip.

Pitfalls

  • Interpolate x, y, width and height instead of scaling the group: with a scale the labels would stretch and the round corners would turn oval.
  • Spare tiles (six groups against eight) are not removed: they close to zero in the corner of the last one and start again from there, so the number of elements stays fixed.
  • With an elastic spring the tiles, travelling to different places, overlap for a long time and the labels pile up: a short back.out and labels that step out during the trip and come back on the new box keep the change clean.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0.

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

Testing

Tested on 25 November 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