Built on 21st
Community

Dependencies

Tags

Linktypes

Linktypes

here is fully customizable link types of data

Default preview
import React, { useEffect, useRef, useState } from "react";
import TreeChart from "@/components/ui/linktypes";

const settings = {
  layout: "cartesian",
  orientation: "horizontal",
  linkType: "diagonal",
  stepPercent: 0.5,
};

export default function Demo(props: Partial<typeof settings>) {
  const s = { ...settings, ...props };
  const ref = useRef<HTMLDivElement>(null);
  const [size, setSize] = useState({ width: 0, height: 0 });

  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const update = () =>
      setSize({ width: el.clientWidth, height: el.clientHeight });
    update();
    const ro = new ResizeObserver(update);
    ro.observe(el);
    return () => ro.disconnect();
  }, []);

  return (
    <div ref={ref} className="h-screen w-screen">
      {size.width > 0 && (
        <TreeChart
          width={size.width}
          height={size.height}
          layout={s.layout}
          orientation={s.orientation}
          linkType={s.linkType}
          stepPercent={s.stepPercent}
        />
      )}
    </div>
  );
}

Dependencies

d3-shape@visx/group@visx/shape@visx/gradient@visx/hierarchy

Tags

Data VisualizationLinkFile TreeSVG AnimationTree

Source

airbnb.io/visx/linktypes

Published

5/22/2025