Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <script src=""></script>
<div id="body">
  <svg width="600" height="400"></svg>


                .node {
        fill: steelblue;
        stroke: #fff;
        stroke-width: 1.5px;

.link {
        fill: none;
        stroke-width: 1.5px;


                // Step 1: Set up the basic structure
      const svg ="svg");
      const width = +svg.attr("width");
      const height = +svg.attr("height");

const defs = svg.append('defs');
    var lg = defs.append("linearGradient")
        .attr("id", "animate-gradient") //unique id for reference
        .attr('gradientUnits', 'userSpaceOnUse')
        .attr("x1", "0%")
        .attr("y1", "0%")
        .attr("x2", "100%")
        .attr("y2", "0")
        .attr("spreadMethod", "reflect");

    var co = ["#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#00ff00", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000"];
        // .attr("offset", function (d, i) { return i / (co.length - 1); })
        .attr("offset", function (d, i) { return i / (co.length - 1); })
        .attr("stop-color", function (d) { return d; });

        .attr("attributeName", "x1")
        .attr("values", "0%;200%") //let x1 run to 200% instead of 100%
        .attr("dur", "12s")
        .attr("repeatCount", "indefinite");
    // .attr("begin", '6s');

        .attr("attributeName", "x2")
        .attr("values", "100%;300%") //let x2 run to 300% instead of 200%
        .attr("dur", "12s")
        .attr("repeatCount", "indefinite");

      const g = svg.append("g").attr("transform", "translate(50,50)");

      // Step 2: Prepare your data
      const data = {
        name: "A",
        children: [
          { name: "B", children: [{ name: "D" }, { name: "E" }] },
          { name: "C", children: [{ name: "F" }] },

      // Step 3: Create the tree layout
      const treeLayout = d3.tree().size([height - 100, width - 100]);

      // Step 4: Draw the initial tree graph
      const root = d3.hierarchy(data);
      const treeData = treeLayout(root);

      const links = g
        .attr("class", "link")
        .attr("stroke", "url(#animate-gradient)")
        .attr("d", d3.linkHorizontal().x((d) => d.y).y((d) => d.x));

      const nodes = g
        .attr("class", "node")
        .attr("r", 5)
        .attr("cx", (d) => d.y)
        .attr("cy", (d) => d.x);

      // Step 5: Define animation logic
      function animateDataFlow() {
        // Randomly select a link to demonstrate data flow
        const randomLink = links.nodes()[Math.floor(Math.random() * links.size())];

        // Get the source and target nodes of the link
        const sourceNode = randomLink.__data__.source;
        const targetNode =;

        // Animate the data flow by creating a new node and transitioning it from the source to target position
        const newData = { name: "Data" }; // New data to represent flowing data
        const newNode = g.append("circle").datum(newData).attr("class", "node").attr("r", 5).attr("cx", sourceNode.y).attr("cy", sourceNode.x);

          .attr("cx", targetNode.y)
          .attr("cy", targetNode.x)
          .on("end", () => {
            // Remove the temporary node once the animation is complete