selection.attrs()

selection.attrs(values)

A convenience method on top of selection.attr for setting multiple attributes. If the specified values is an object, the values may be specified either as strings or functions. For example:

selection.attrs({foo: "foo-value", bar: function(d) { return d.bar; }});

If a value is a constant, all elements are given the same attribute value; otherwise, if a value is a function, the function is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element. The function’s return value is then used to set each element’s attribute. A null value will remove the specified attribute.

If the specified values is a function, the function is evaluated for each selected element, in order, being passed the current datum (d), the current index (i), and the current group (nodes), with this as the current DOM element. The function’s return value must be an object with string values, which are then used to set attributes on the current element. For example:

selection.attrs(function(d) { return {foo: "foo-value", bar: d.bar}; });

Passing a function to selection.attrs is convenient for sharing some computational effort or state across multiple attributes, or for specifying dynamically which attributes to set.

doc_D3_Js
2016-11-24 10:28:51
Comments
Leave a Comment

Please login to continue.