Radial Dendrogram in MUI X Charts (JavaScript)

The same plot in 14 other libraries — JavaScript: Chart.js, D3.js, Apache ECharts, Highcharts; Python: Altair, Bokeh, lets-plot, Matplotlib, Plotly, plotnine, Pygal, Seaborn; R: ggplot2; Julia: Makie.jl. Compare all 15 side by side: Radial Dendrogram in Python, R, Julia and JavaScript.

A radial dendrogram renders hierarchical clustering in a circular layout where the root node sits at the center and branches extend outward, with leaf nodes arranged around the circumference. This layout is a space-efficient alternative to linear dendrograms for large hierarchies, making it well-suited for datasets with hundreds of leaves. Branch lengths are proportional to distance or dissimilarity, preserving the quantitative interpretation of cluster merges.

Radial Dendrogram rendered with MUI X Charts

Renders

JavaScript source (MUI X Charts)

// anyplot.ai
// dendrogram-radial: Radial Dendrogram
// Library: muix 9.16.0 | JavaScript 22.23.3
// Quality: 88/100 | Updated: 2026-10-24
//# anyplot-orientation: square

import { ChartsDataProvider } from "@mui/x-charts/ChartsDataProvider";
import { ChartsWrapper } from "@mui/x-charts/ChartsWrapper";
import { ChartsSurface } from "@mui/x-charts/ChartsSurface";
import { ChartsLegend } from "@mui/x-charts/ChartsLegend";
import { ScatterPlot } from "@mui/x-charts/ScatterChart";
import { useXScale, useYScale } from "@mui/x-charts/hooks";

const t = window.ANYPLOT_TOKENS;

// Constants
const TITLE = "dendrogram-radial · javascript · muix · anyplot.ai";
const FONT = "Inter, system-ui, -apple-system, sans-serif";
const REF_RINGS = [0.25, 0.5, 0.75, 1.0];
const RING_INNER = 1.06;
const RING_OUTER = 1.13;
const RING_MID = (RING_INNER + RING_OUTER) / 2;
const LABEL_RADIUS = 1.21;
const DOMAIN_LIMIT = 1.38;
const ARC_STEPS = 14;

// Columns: set these to your data's column names
const SAMPLE_ID = "Sample ID"; // role: labels
const REGION = "Origin region"; // role: clusters
const ACIDITY = "Acidity"; // role: linkage_matrix
const BODY = "Body"; // role: linkage_matrix
const SWEETNESS = "Sweetness"; // role: linkage_matrix
const FLORAL = "Floral aroma"; // role: linkage_matrix
const EARTHINESS = "Earthiness"; // role: linkage_matrix

// Data: replace this block with your own records
const data = (() => {
  const sampleProfiles = [
    { code: "ETH", name: "Ethiopian Highlands", center: [8.5, 3.0, 7.0, 8.5, 1.0] },
    { code: "KEN", name: "Kenyan Highlands", center: [8.8, 4.0, 6.0, 5.0, 1.5] },
    { code: "COL", name: "Colombian Andes", center: [5.5, 6.0, 7.5, 2.5, 2.0] },
    { code: "GUA", name: "Guatemalan Volcanic", center: [6.0, 5.0, 5.5, 4.0, 2.5] },
    { code: "SUM", name: "Sumatran Lowlands", center: [2.0, 8.5, 3.0, 1.0, 8.5] },
  ];
  const rows: Record<string, string | number>[] = [];
  let lcgState = 42 >>> 0;
  for (const reg of sampleProfiles) {
    for (let s = 0; s < 6; s++) {
      const vals: number[] = [];
      for (let d = 0; d < 5; d++) {
        lcgState = (Math.imul(1664525, lcgState) + 1013904223) >>> 0;
        const u1 = Math.max(lcgState / 4294967296, 1e-9);
        lcgState = (Math.imul(1664525, lcgState) + 1013904223) >>> 0;
        const u2 = lcgState / 4294967296;
        const z = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
        vals.push(reg.center[d] + z * 0.7);
      }
      rows.push({
        [SAMPLE_ID]: `${reg.code}-${s + 1}`,
        [REGION]: reg.name,
        [ACIDITY]: vals[0],
        [BODY]: vals[1],
        [SWEETNESS]: vals[2],
        [FLORAL]: vals[3],
        [EARTHINESS]: vals[4],
      });
    }
  }
  return rows;
})();

// Plot: reads only data and the constants above
const FEATURE_COLS = [ACIDITY, BODY, SWEETNESS, FLORAL, EARTHINESS];
const n = data.length;
const nodeCount = 2 * n - 1;
const REGION_NAMES = Array.from(new Set(data.map((d) => String(d[REGION]))));
const REGION_COLORS = Object.fromEntries(
  REGION_NAMES.map((reg, i) => [reg, t.palette[i]]),
);

const D = Array.from({ length: nodeCount }, () => new Array(nodeCount).fill(Infinity));
for (let i = 0; i < n; i++) {
  for (let j = i + 1; j < n; j++) {
    let sumSq = 0;
    for (const col of FEATURE_COLS) {
      const diff = Number(data[i][col]) - Number(data[j][col]);
      sumSq += diff * diff;
    }
    const dist = Math.sqrt(sumSq);
    D[i][j] = dist;
    D[j][i] = dist;
  }
}

const active = new Set(Array.from({ length: n }, (_, i) => i));
const linkage: [number, number, number][] = [];
let nextId = n;
while (active.size > 1) {
  let a = -1;
  let b = -1;
  let best = Infinity;
  const ids = Array.from(active);
  for (let i = 0; i < ids.length; i++) {
    for (let j = i + 1; j < ids.length; j++) {
      if (D[ids[i]][ids[j]] < best) {
        best = D[ids[i]][ids[j]];
        a = ids[i];
        b = ids[j];
      }
    }
  }
  const newId = nextId++;
  active.forEach((c) => {
    if (c === a || c === b) return;
    const d = Math.max(D[a][c], D[b][c]);
    D[newId][c] = d;
    D[c][newId] = d;
  });
  linkage.push([a, b, best]);
  active.delete(a);
  active.delete(b);
  active.add(newId);
}

const root = nextId - 1;
const maxHeight = Math.max(...linkage.map((row) => row[2]));

const order: number[] = [];
const stack: number[] = [root];
while (stack.length > 0) {
  const nodeId = stack.pop()!;
  if (nodeId < n) {
    order.push(nodeId);
  } else {
    const [a, b] = linkage[nodeId - n];
    stack.push(b);
    stack.push(a);
  }
}

const angleOf = new Array(nodeCount).fill(0);
const radiusOf = new Array(nodeCount).fill(0);
const regionOf: (string | null)[] = new Array(nodeCount).fill(null);

order.forEach((leafId, idx) => {
  angleOf[leafId] = Math.PI / 2 - idx * ((2 * Math.PI) / n);
  radiusOf[leafId] = 1;
  regionOf[leafId] = String(data[leafId][REGION]);
});

for (let id = n; id < nodeCount; id++) {
  const [a, b, height] = linkage[id - n];
  angleOf[id] = (angleOf[a] + angleOf[b]) / 2;
  radiusOf[id] = 1 - height / maxHeight;
  regionOf[id] =
    regionOf[a] !== null && regionOf[a] === regionOf[b] ? regionOf[a] : null;
}

const SUBTITLE = `${n} leaves across ${REGION_NAMES.length} ${REGION}s · complete-linkage clustering over ${FEATURE_COLS.length} features`;

const scatterSeries = REGION_NAMES.map((reg) => ({
  type: "scatter" as const,
  id: reg,
  data: data
    .map((row, i) => ({ row, i }))
    .filter(({ row }) => String(row[REGION]) === reg)
    .map(({ row, i }) => ({
      id: String(row[SAMPLE_ID]),
      x: Math.cos(angleOf[i]),
      y: Math.sin(angleOf[i]),
    })),
  label: reg,
  color: REGION_COLORS[reg],
  markerSize: 8,
  xAxisId: "x",
  yAxisId: "y",
}));

function RadialDendrogram() {
  const xs = useXScale("x") as any;
  const ys = useYScale("y") as any;

  const cx = xs(0);
  const cy = ys(0);
  const unitPx = Math.abs(xs(1) - cx);
  const ringThickness = Math.abs(xs(RING_OUTER) - xs(RING_INNER));

  const branches = [];
  for (let id = n; id < nodeCount; id++) {
    const [a, b] = linkage[id - n];
    const rParent = radiusOf[id];
    const bridgeColor =
      regionOf[id] !== null ? REGION_COLORS[regionOf[id]!] : t.inkSoft;

    let diff = angleOf[b] - angleOf[a];
    while (diff > Math.PI) diff -= 2 * Math.PI;
    while (diff < -Math.PI) diff += 2 * Math.PI;
    let dArc = "";
    for (let k = 0; k <= ARC_STEPS; k++) {
      const th = angleOf[a] + (diff * k) / ARC_STEPS;
      const px = xs(rParent * Math.cos(th));
      const py = ys(rParent * Math.sin(th));
      dArc += `${k === 0 ? "M" : "L"}${px.toFixed(1)},${py.toFixed(1)} `;
    }
    branches.push(
      <path
        key={`arc-${id}`}
        d={dArc}
        fill="none"
        stroke={bridgeColor}
        strokeWidth={2.5}
        strokeLinecap="round"
      />,
    );

    for (const child of [a, b]) {
      const childColor =
        regionOf[child] !== null ? REGION_COLORS[regionOf[child]!] : t.inkSoft;
      const th = angleOf[child];
      const rChild = radiusOf[child];
      branches.push(
        <line
          key={`seg-${id}-${child}`}
          x1={xs(rParent * Math.cos(th))}
          y1={ys(rParent * Math.sin(th))}
          x2={xs(rChild * Math.cos(th))}
          y2={ys(rChild * Math.sin(th))}
          stroke={childColor}
          strokeWidth={2.5}
          strokeLinecap="round"
        />,
      );
    }
  }

  const halfLeafSpan = (Math.PI / n) * 0.72;
  const metadataRing = order.map((leafId) => {
    const th0 = angleOf[leafId] - halfLeafSpan;
    const th1 = angleOf[leafId] + halfLeafSpan;
    let dRing = "";
    for (let k = 0; k <= 4; k++) {
      const th = th0 + ((th1 - th0) * k) / 4;
      const px = xs(RING_MID * Math.cos(th));
      const py = ys(RING_MID * Math.sin(th));
      dRing += `${k === 0 ? "M" : "L"}${px.toFixed(1)},${py.toFixed(1)} `;
    }
    return (
      <path
        key={`ring-${leafId}`}
        d={dRing}
        fill="none"
        stroke={REGION_COLORS[String(data[leafId][REGION])]}
        strokeWidth={ringThickness}
        strokeLinecap="butt"
      />
    );
  });

  const labels = order.map((leafId) => {
    const theta = angleOf[leafId];
    const px = xs(LABEL_RADIUS * Math.cos(theta));
    const py = ys(LABEL_RADIUS * Math.sin(theta));
    const rotDeg = (Math.atan2(py - cy, px - cx) * 180) / Math.PI;
    const flip = Math.cos(theta) < 0;
    return (
      <text
        key={`label-${leafId}`}
        x={px}
        y={py}
        transform={`rotate(${flip ? rotDeg + 180 : rotDeg}, ${px}, ${py})`}
        textAnchor={flip ? "end" : "start"}
        dominantBaseline="middle"
        fontSize={14}
        fontWeight={500}
        fontFamily={FONT}
        fill={t.inkSoft}
      >
        {String(data[leafId][SAMPLE_ID])}
      </text>
    );
  });

  return (
    <g>
      {REF_RINGS.map((frac) => (
        <circle
          key={`ref-${frac}`}
          cx={cx}
          cy={cy}
          r={unitPx * frac}
          fill="none"
          stroke={t.grid}
          strokeWidth={1}
        />
      ))}
      {metadataRing}
      {branches}
      <circle cx={cx} cy={cy} r={5} fill={t.inkSoft} />
      {labels}
    </g>
  );
}

export default function Chart() {
  const W = window.ANYPLOT_SIZE.width;
  const H = window.ANYPLOT_SIZE.height;
  const HEADER_H = 84;
  const LEGEND_H = 76;
  const chartSize = Math.min(W, H - HEADER_H - LEGEND_H);

  return (
    <div
      style={{
        width: W,
        height: H,
        background: t.pageBg,
        fontFamily: FONT,
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
      }}
    >
      <div
        style={{
          height: HEADER_H,
          display: "flex",
          flexDirection: "column",
          alignItems: "center",
          justifyContent: "center",
          gap: 4,
          paddingTop: 10,
        }}
      >
        <span style={{ fontSize: 22, fontWeight: 700, color: t.ink }}>{TITLE}</span>
        <span style={{ fontSize: 15, color: t.inkSoft }}>{SUBTITLE}</span>
      </div>
      <ChartsDataProvider
        width={chartSize}
        height={chartSize}
        skipAnimation
        series={scatterSeries}
        margin={{ top: 16, right: 16, bottom: 16, left: 16 }}
        xAxis={[{ id: "x", min: -DOMAIN_LIMIT, max: DOMAIN_LIMIT, position: "none" }]}
        yAxis={[{ id: "y", min: -DOMAIN_LIMIT, max: DOMAIN_LIMIT, position: "none" }]}
      >
        <ChartsWrapper
          legendPosition={{ horizontal: "center", vertical: "bottom" }}
          legendDirection="horizontal"
        >
          <ChartsLegend sx={{ fontSize: 14, fontFamily: FONT, color: t.ink, gap: 3.5, pt: 3 }} />
          <ChartsSurface>
            <RadialDendrogram />
            <ScatterPlot />
          </ChartsSurface>
        </ChartsWrapper>
      </ChartsDataProvider>
    </div>
  );
}

Retrieve this implementation

Runnable source as JSON, for any HTTP client: https://api.anyplot.ai/specs/dendrogram-radial/muix/code. Any spec id and library id listed in llms-full.txt fit the same URL shape; every URL below is complete and callable.

{
  "spec_id": "dendrogram-radial",
  "language": "javascript",
  "library": "muix",
  "page": "https://anyplot.ai/dendrogram-radial/javascript/muix",
  "hub": "https://anyplot.ai/dendrogram-radial",
  "code_json": "https://api.anyplot.ai/specs/dendrogram-radial/muix/code",
  "spec_json": "https://api.anyplot.ai/specs/dendrogram-radial",
  "render_light_png": "https://storage.googleapis.com/anyplot-images/plots/dendrogram-radial/javascript/muix/plot-light.png",
  "render_dark_png": "https://storage.googleapis.com/anyplot-images/plots/dendrogram-radial/javascript/muix/plot-dark.png",
  "interactive_light_html": "https://storage.googleapis.com/anyplot-images/plots/dendrogram-radial/javascript/muix/plot-light.html",
  "interactive_dark_html": "https://storage.googleapis.com/anyplot-images/plots/dendrogram-radial/javascript/muix/plot-dark.html",
  "quality_score": 88.0,
  "license": "MIT",
  "guide": "https://anyplot.ai/llms.txt"
}

Part of Radial Dendrogram on anyplot.ai.

Other implementations