パッケージの詳細

d3-attrs

frolovfsoft10.1kISC1.0.4

Attributes and styles as object for D3-selection

d3, d3-selection, attrs, styles

readme

D3-attrs

Allows to set attributes and styles for d3 selection as objects. Works fine with D3 v7 (d3-selection v3) and NodeJS v16.

Install

$ npm i d3-attrs -s

Use

import 'd3-attrs';

d3.select( 'svg' ).append( 'line' )
  .attrs({
    class: 'red_line',
    x1: d => d.x1,
    y1: 0,
    x2: 100, y2: 50
  })
  .styles( d => ({
    stroke: `#${ d.color }`,
    'stroke-width': d.width
  }) );