user3582734
user3582734

Reputation: 3

How to get a subselection of a D3.js selection

I am trying to get a subselection of a given D3.js selection.

This part of the code creates the paths:

pieces.paths = pieces.groups
    .append("path")
    .attr("fill", function (d) { return d.data.color; });

Then, I set de "d" attribute:

pieces.paths
    .attr("d", arc);

Working perfect. But pieces.paths has 3 elements, and I want to set the class of the first two elements to "highest". How may I do that?

Upvotes: 0

Views: 404

Answers (1)

James Trimble
James Trimble

Reputation: 1866

selection.filter() is one option:

pieces.paths
    .filter(function(d, i) {return i<2;})
    .attr("class", "highest");

Upvotes: 2

Related Questions