Skip to content

Instantly share code, notes, and snippets.

@vlandham
Created October 1, 2012 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlandham/3811943 to your computer and use it in GitHub Desktop.
Save vlandham/3811943 to your computer and use it in GitHub Desktop.
Network visualization with two searches
$(".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)
<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>
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