Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show/hide layers in d3.js

First of all: I'm new to d3.js!

I have a map and some points displayed on it. Now I want to add buttons to show/hide the points. What I have until now:

function checkAll(){
    d3.selectAll("g").attr("visibility", "visible");
}
function uncheckAll(){
    d3.selectAll("g").attr("visibility", "hidden");
}

This works so far but hides/shows the whole map.

I have a function "drawpoints()" that draws the points on the map. How can I change my code that it only shows/hides the points and not the whole map?

like image 515
user3346326 Avatar asked Mar 07 '14 14:03

user3346326


1 Answers

You would need to select only the elements that you want to hide. If, for example, they are identified by a class, you would do the following:

d3.selectAll(".classOfCircles").attr("visibility", "hidden");
like image 148
Lars Kotthoff Avatar answered Oct 05 '22 01:10

Lars Kotthoff