classed() is a D3 selection method for adding or removing one CSS class without overwriting the selection’s other classes. Pass the class name first and true or false second. section 7.2.2
Unlike attr("class", ...), which replaces the entire class attribute, classed() changes a named class independently. This preserves an existing class such as filter while toggling active. section 7.2.2
Marking the active filter
d3.selectAll(".filter") .classed("active", filter => filter.id === d.id ? true : false); A click callback updates each filter button so only the clicked filter receives the active class, then refreshes the histogram. section 7.2.1
myActiveFilter
.classed("active", true);
Shows the compact form for adding the active class while retaining the existing filter class. section 7.2.2
