Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

graph

Maps and dataAlso inScroll scenes

@dioramajs/data/graphSource

A list or a table of links drawn as a network graph: partners, integrations, teams, knowledge maps.

View as Markdown
On this page

Works with the tools you already use

Live preview needs WebGPU or WebGL 2. The integrations of an invoicing app as a network around it, grouped by kind, that grows out of the middle on scroll.

This example failed to draw.

Hover a node to keep its links and see what it connects to. The nested list under the graph stays the same in every mode.
Params of graph
motion

grow pops the nodes up and draws each link from its start.

mode

radial puts the first item in the middle and the rest in rings around it, for partners around a product.

Usage

Put it on a <ul> or <ol> whose items are the nodes (nested lists link an item to the one it sits in, data-dio-to links any two), or a <table> whose rows link the names in their first two cells, sized with CSS. start() registers graph, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.

To change its code, copy the source into your effects folder; the copy replaces the built-in.

Terminal window
npx @dioramajs/diorama add graph
<div class="gr-frame">
<p
class="gr-title"
id="gr-integrations"
>Works with the tools you already use</p>
<ul
class="gr-graph"
aria-labelledby="gr-integrations"
data-dio="graph"
data-dio-mode="radial"
>
<li>Ledgerly
<ul data-dio-group="Payments">
<li>
<a href="/stripe">Stripe</a>
cards, wallets and payouts
</li>
<li><a href="/paypal">PayPal</a></li>
<li><a href="/adyen">Adyen</a></li>
</ul>
<ul data-dio-group="Accounting">
<li>
<a href="/xero">Xero</a>
two-way sync of invoices
</li>
<li><a href="/quickbooks">QuickBooks</a></li>
</ul>
<ul data-dio-group="Chat">
<li>
<a href="/slack">Slack</a>
alerts for late payments
</li>
<li><a href="/teams">Teams</a></li>
</ul>
<ul data-dio-group="Storage">
<li><a href="/drive">Google Drive</a></li>
<li><a href="/dropbox">Dropbox</a></li>
</ul>
</li>
</ul>
</div>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.gr-graph', 'graph', {
motion: 'grow',
mode: 'radial',
radius: 6,
thickness: 1.25,
labels: true,
arrows: false,
dim: 0.75,
duration: 0.6,
stagger: 0.12,
})
import { start } from '@dioramajs/diorama'
import graph from '@dioramajs/data/graph'
const app = start()
app.attach('.gr-graph', graph({
motion: 'grow',
mode: 'radial',
radius: 6,
thickness: 1.25,
labels: true,
arrows: false,
dim: 0.75,
duration: 0.6,
stagger: 0.12,
}))

Markup it reads

  • data-dio-to: On a list item: ids or names of the items it links to, separated by spaces.
  • data-dio-group: On a list item, a list or a table cell: the group that colors the node and the items inside.
  • data-dio-value: On a list item: a number that sizes the node instead of its count of links.

Parts

Its own controls take your styles through ::part().

  • tooltip: The tooltip with the node name, the rest of its item text and the names it links to.

Page transitions

Fades with the page. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
moderebuildsdata-dio-mode'force' | 'radial' | 'tree' | 'circle''force'
  • force spreads linked nodes as a network, for ecosystems and knowledge maps.
  • radial puts the first item in the middle and the rest in rings around it, for partners around a product.
  • tree hangs the list top down by its nesting, for team structure and sitemaps.
  • circle sets the nodes on a ring grouped by color with links bowed through the middle, for who works with whom.
motionrebuildsdata-dio-motion'grow' | 'spread' | 'fade''grow'
  • grow pops the nodes up and draws each link from its start.
  • spread flies the nodes out of the first item.
  • fade fades everything in place.
colorsrebuildsdata-dio-colorsstring''Group colors in the order groups first appear, separated by spaces; empty uses a colorblind-safe set.
seedrebuildsdata-dio-seednumber1 to 10001Seed of the force layout: another number gives another arrangement of the same graph.
radiusdata-dio-radiusnumber2 to 24 px6Radius of an average node; nodes with more links or a bigger value grow to 1.6 times it.
thicknessdata-dio-thicknessnumber0.5 to 6 px1.25Width of a link.
labelsdata-dio-labelsbooleantrueDraws the names beside the nodes, leaving out the ones that would overlap.
arrowsdata-dio-arrowsbooleanfalseDraws an arrowhead where a link ends, for a graph with direction.
dimdata-dio-dimnumber0 to 10.75How much a lit node dims the nodes it does not link to; 0 keeps them as they are.
durationdata-dio-durationnumber0 to 3 s0.6Time one node takes to come in; 0 shows the graph at once.
staggerdata-dio-staggernumber0 to 0.5 s0.12Delay between one step away from the first item and the next; 0 brings every node in at once.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads delta, height, opacity, reducedMotion, width and y . Draws only while something on it moves, then stops. Only while the nodes come in and for a few frames as a lit node fades in or out; none at rest. How a frame is decided.

Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. The graph stands complete from the first frame; hover, focus and the tooltip still work.

Runs on every device. A tap on a node lights it and shows its tooltip, a second tap follows its link, a tap elsewhere clears it.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { graph: { reducedMotion: 'off' } } })

Cost and quality

Download
8.0 KB min+gzip the first time a page uses it
GPU
Four draw calls: all links, all arrowheads, all nodes as one instanced call, and the labels texture.
Memory
One canvas texture the size of the box at up to 2x pixel ratio, plus about 100 bytes per node and link. The layout runs once on the CPU: about 30 ms for 200 nodes.
Frames
Idle at rest

It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.

Recipes

A team structure

A nested list already is a tree: each item links to the one it sits in. The tree mode hangs it top down, a level per step, with each name under its node. data-dio-group on an item colors it and everything inside it.

How the studio is organized

  • Studio lead
    • Design
      • Brand
      • Product
      • Motion
    • Engineering
      • Web
      • Apps
    • Accounts
      • New business
      • Support

Live preview needs WebGPU or WebGL 2. A studio's teams as a tree from the lead down, colored by department.

This example failed to draw.

Params of graph
<div class="gr-frame">
<p
class="gr-title"
id="gr-team"
>How the studio is organized</p>
<ul
class="gr-graph"
aria-labelledby="gr-team"
data-dio="graph"
data-dio-mode="tree"
data-dio-motion="fade"
>
<li>Studio lead
<ul>
<li data-dio-group="Design">
Design
<ul>
<li>Brand</li>
<li>Product</li>
<li>Motion</li>
</ul>
</li>
<li data-dio-group="Build">
Engineering
<ul>
<li>Web</li>
<li>Apps</li>
</ul>
</li>
<li data-dio-group="Clients">
Accounts
<ul>
<li>New business</li>
<li>Support</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

A map of topics

Any item can link to any other with data-dio-to, by id or by name. The force mode spreads linked items as a network: related topics cluster, bridges sit between clusters. arrows marks the direction, here from a lesson to what it builds on. Each item keeps its link, so a click on a node opens the lesson and the keyboard reaches every one.

Live preview needs WebGPU or WebGL 2. A photography course as a network of lessons with arrows to what each builds on.

This example failed to draw.

Params of graph
motion

grow pops the nodes up and draws each link from its start.

mode

force spreads linked nodes as a network, for ecosystems and knowledge maps.

<div class="gr-frame">
<p
class="gr-title"
id="gr-topics"
>A course map: what each lesson builds on</p>
<ul
class="gr-graph"
aria-labelledby="gr-topics"
data-dio="graph"
data-dio-arrows=""
>
<li id="light"><a href="#light">Light</a></li>
<li id="exposure" data-dio-to="light">
<a href="#exposure">Exposure</a>
</li>
<li id="aperture" data-dio-to="exposure">
<a href="#aperture">Aperture</a>
</li>
<li id="shutter" data-dio-to="exposure">
<a href="#shutter">Shutter speed</a>
</li>
<li id="iso" data-dio-to="exposure">
<a href="#iso">ISO</a>
</li>
<li id="depth" data-dio-to="aperture">
<a href="#depth">Depth of field</a>
</li>
<li id="motion" data-dio-to="shutter">
<a href="#motion">Motion blur</a>
</li>
<li id="color" data-dio-to="light">
<a href="#color">Color temperature</a>
</li>
<li id="raw" data-dio-to="color iso">
<a href="#raw">Shooting raw</a>
</li>
<li id="portrait" data-dio-to="depth color">
<a href="#portrait">Portraits</a>
</li>
<li id="night" data-dio-to="iso motion shutter">
<a href="#night">Night scenes</a>
</li>
</ul>
</div>

A table works too: each row links the names in its first two cells, and a number in the third makes the link thicker. The circle mode sets the nodes on a ring grouped by color, with links bowed through the middle, so who works with whom reads at a glance.

<table
class="flows"
data-dio="graph"
data-dio-mode="circle"
data-dio-arrows
>
<thead>
<tr>
<th>From</th>
<th>To</th>
<th>Orders</th>
</tr>
</thead>
<tbody>
<tr>
<td data-dio-group="hub">Warehouse</td>
<td>Berlin</td>
<td>420</td>
</tr>
<tr><td>Warehouse</td><td>Paris</td><td>310</td></tr>
<tr><td>Berlin</td><td>Prague</td><td>90</td></tr>
</tbody>
</table>

Notes

The list or table is the source of truth. It stays in the page for screen readers, search engines and the keyboard, hidden only while the graph is drawn, and it shows as is without WebGL. Focus on an item’s link lights its node and shows its tooltip, so a keyboard user sees where they are. Size the element with CSS; overflow: auto keeps a long list inside the same box when it shows.

The layout is worked out once on the CPU from seed and the box’s proportions, so the picture is the same on every visit and does not drift. A resize lays it out again only when the proportions change noticeably. Nodes grow with their number of links, or with data-dio-value when the items give one. Names that would overlap are left out of the picture and appear when their node is lit.

It draws only while the nodes come in and for a few frames as a lit node fades in or out. Under reduced motion the graph stands complete from the first frame. A tap on a node lights it, a second tap follows its link. Style the tooltip with ::part(tooltip).

mode, motion, colors and seed rebuild the graph when they change; sizes, labels, arrows and the timing change live. One graph draws up to 400 nodes.