selection.styles()

selection.styles(values[, priority])

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

selection.styles({fill: "red", stroke: function(d) { return d.stroke; }});

If a value is a constant, all elements are given the same style 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 style properties. A null value will remove the specified style 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 style properties on the current element. For example:

selection.styles(function(d) { return {fill: "red", stroke: d.stroke}; });

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

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

Please login to continue.