Radial tree

structure (radial)

The same tree bent into a circle. Fits more depth on a slide, costs you easy comparison.

Radial tree — structure (radial): rendered example
Rendered by Gnomon from the source below. No edits.

The source

69 lines of D3 JavaScript, and uses only the bundled D3 build. Copy it, or open the template inside Gnomon and render it as it is.

// Radial tree — the same layout as a tidy tree, wrapped into a circle.
// Fits far more leaves in the same pane; costs you the easy left-to-right
// read of depth.

const data = {
  name: 'root',
  children: [
    { name: 'ingest', children: [
      { name: 'events' }, { name: 'batch' }, { name: 'cdc' }, { name: 'api' },
    ]},
    { name: 'store', children: [
      { name: 'bronze' }, { name: 'silver' }, { name: 'gold' },
      { name: 'archive' }, { name: 'vault' },
    ]},
    { name: 'serve', children: [
      { name: 'bi' }, { name: 'ml' }, { name: 'reverse-etl' }, { name: 'exports' },
    ]},
    { name: 'govern', children: [
      { name: 'catalog' }, { name: 'lineage' }, { name: 'quality' },
      { name: 'access' },
    ]},
  ],
};

const radius = Math.min(width, height) / 2 - 80;

const root = d3.tree()
    .size([2 * Math.PI, radius])
    .separation((a, b) => (a.parent === b.parent ? 1 : 2) / a.depth)(
  d3.hierarchy(data).sort((a, b) => d3.ascending(a.data.name, b.data.name)),
);

const color = d3.scaleOrdinal(data.children.map(c => c.name), theme.palette);
const topOf = d => d.ancestors().find(a => a.depth === 1)?.data.name ?? '';

const svg = d3.select(container).append('svg')
    .attr('viewBox', [-width / 2, -height / 2, width, height])
    .attr('width', width)
    .attr('height', height)
    .attr('font-family', 'system-ui, sans-serif')
    .attr('font-size', 11);

svg.append('g')
    .attr('fill', 'none')
    .attr('stroke-opacity', 0.5)
    .attr('stroke-width', 1.5)
  .selectAll('path')
  .data(root.links())
  .join('path')
    .attr('stroke', d => d.target.depth === 1 ? theme.muted : color(topOf(d.target)))
    .attr('d', d3.linkRadial().angle(d => d.x).radius(d => d.y));

const node = svg.append('g')
  .selectAll('g')
  .data(root.descendants())
  .join('g')
    .attr('transform', d => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);

node.append('circle')
    .attr('r', d => d.depth === 0 ? 5 : 3.5)
    .attr('fill', d => d.depth === 0 ? theme.foreground : color(topOf(d)));

node.append('text')
    .attr('dy', '0.31em')
    .attr('x', d => (d.x < Math.PI) === !d.children ? 7 : -7)
    .attr('text-anchor', d => (d.x < Math.PI) === !d.children ? 'start' : 'end')
    .attr('transform', d => d.x >= Math.PI ? 'rotate(180)' : null)
    .attr('fill', theme.foreground)
    .text(d => d.data.name);

Render this offline

This template ships in Gnomon and renders on your machine, with no account and no diagram uploads. The browser editor is free and needs no install.

Get GnomonOpen the browser editor

Others in D3 visualisations

Analytics cookies (optional)

May we use Google Analytics to understand visits, product links and feature use? If you accept, Google receives usage and device information, including your IP address, and sets analytics cookies. We do not send your documents, filenames or account details. Advertising features are disabled.

Analytics is off until you accept. Your choice is saved on this browser for 180 days using necessary local storage. You can change it at any time in Analytics preferences. Closing this message rejects analytics. Read our privacy policy.