Skip to main content
100%

Enter, Update, Exit

✓ Published0🌍 Public
Xxinyuwangxyw
Last edited Mar 19, 2023
Created on Mar 19, 2023
Forked from Sol LeWitt with D3

Four bars in a static HTML layout demonstrate a D3 data join, showing how elements enter, update, and exit based on an array of heights. Using `d3.select` and `selection.data`, the code binds the values `[100, 200, 300, 400]` to existing `.bar` divs, then applies inline styles for height and vertical margin to position them. The example also includes a separate SVG mask with a circle and horizontal rectangles, though it does not interact with the bars. This is a minimal v3-era reproduction using the D3 7.8.2 library.

AI-generated description

A reproduction of a Sol LeWitt art piece.

  // creating a mask
  const mask_front = document.createElementNS(
    'http://www.w3.org/2000/svg',
    'mask'
  );
  mask_front.setAttribute('id', 'mask_front');
  svg.appendChild(mask_front);

  // creating a circle in this mask
  const circle = document.createElementNS(
    'http://www.w3.org/2000/svg',
    'circle'
  );
  circle.setAttribute('cx', width / 2);
  circle.setAttribute('cy', height / 2);
  circle.setAttribute('r', 250);
  circle.setAttribute('fill', "white");
  mask_front.appendChild(circle);
  
  // creating horizontal bars
  const m = 100;
  for (let i = 0; i < m; i++) {
    const rect = document.createElementNS(
      'http://www.w3.org/2000/svg',
      'rect'
    );
    rect.setAttribute('y', 20 * i);
    rect.setAttribute('width', 1000);
    rect.setAttribute('height', 10);
    rect.setAttribute("mask", "url(#mask_front)");
    svg.appendChild(rect);
  }
MIT Licensed

Similar vizzes