Selections

Before a transformation can be applied, elements on the template need to be selected in D3, hence selections are a very important aspect of D3 and the first step before applying any logic. Luckily, similar to AngularJS, D3 uses a declarative approach, meaning you can select elements collectively:

d3.selectAll("p").style("color", "red");

If the D3 library is loaded in the web page, the example would color all paragraph elements in red.

Selecting elements can be done using either d3.select(this) or d3.selectAll(this) where this is the specific element(s) you are attempting to select. The first method, .select(), will just select the first element that matches to the criteria specified in document traversal order. The second method, .selectAll(), will simply select all the elements that match the criteria specified and return them as an array of elements. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.117.233