Skip to content

attrize

Applies each key/value in an object as an attr.

Applies every key of an object as an attribute on a d3 selection, one .attr() call per entry. elem uses it for its enter, update, and exit attribute sets; stylize is the same idea for inline styles.

import {select} from "d3-selection";
import {attrize} from "@d3plus/dom";

attrize(select("rect"), {
  width: 120,
  height: 40,
  rx: 6,
  fill: "#1c7ed6",
  "data-label": "attrized",
});

Parameters

import {attrize} from "@d3plus/dom";
erequiredAttrable

The d3 selection to apply attributes to.

aRecordDefault {}

An object of key/value attr pairs.