selection.properties()

selection.properties(values)

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

selection.properties({foo: "foo-value", id: function(d, i) { return "id-" + i; }});

If a value is a constant, all elements are given the same property 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 properties. A null value will remove the specified properties.

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 properties on the current element. For example:

selection.properties(function(d, i) { return {foo: "foo-value", id: "id-" + i}; });

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

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

Please login to continue.