Created
October 1, 2012 13:58
-
-
Save vlandham/3811943 to your computer and use it in GitHub Desktop.
Network visualization with two searches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".search").keyup () -> | |
# get which search form is being used | |
search_id = d3.select(this).attr("id").replace("_search", "") | |
searchTerm = $(this).val() | |
myNetwork.updateSearch(searchTerm, search_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="search_section" class="control"> | |
<form id="name_search_form" class="search_form" action="" method="post"> | |
<p class="search_title">Search <input type="text" class="text-input search" id="name_search" value="" /></p> | |
</form> | |
</div> | |
<div class="search_section" class="control"> | |
<form id="year_search_form" class="search_form" action="" method="post"> | |
<p class="search_title">Search <input type="text" class="text-input search" id="year_search" value="" /></p> | |
</form> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
network.updateSearch = (searchTerm, searchId) -> | |
searchRegEx = new RegExp(searchTerm.toLowerCase()) | |
node.each (d) -> | |
element = d3.select(this) | |
# change the search to use searchId input instead of 'name' directly | |
match = d[searchId].toLowerCase().search(searchRegEx) | |
if searchTerm.length > 0 and match >= 0 | |
element.style("fill", "#F38630") | |
.style("stroke-width", 2.0) | |
.style("stroke", "#555") | |
d.searched = true | |
else | |
d.searched = false | |
element.style("fill", (d) -> nodeColors(d.artist)) | |
.style("stroke-width", 1.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment