Skip to content

Instantly share code, notes, and snippets.

@vlandham
Created December 3, 2013 18:09
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/7774361 to your computer and use it in GitHub Desktop.
Save vlandham/7774361 to your computer and use it in GitHub Desktop.
diff --git a/coffee/vis.coffee b/coffee/vis.coffee
index d125fe0..6330c16 100644
--- a/coffee/vis.coffee
+++ b/coffee/vis.coffee
@@ -14,6 +14,8 @@ Bubbles = () ->
margin = {top: 5, right: 0, bottom: 0, left: 0}
# largest size for our bubbles
maxRadius = 65
+ clickWait = 200
+ nodeClickInProgress = false
# this scale will be used to size our bubbles
rScale = d3.scale.sqrt().range([0,maxRadius])
@@ -308,7 +310,8 @@ Bubbles = () ->
# adds mouse events to element
# ---
connectEvents = (d) ->
- d.on("click", removeBubble)
+ d.on("dblclick", selectBubble)
+ d.on("click", handleSingleClick)
d.on("mouseover", mouseover)
d.on("mouseout", mouseout)
@@ -318,6 +321,16 @@ Bubbles = () ->
clear = () ->
location.replace("#")
+ handleSingleClick = (d) ->
+ if !nodeClickInProgress
+ nodeClickInProgress = true
+ setTimeout(() ->
+ if nodeClickInProgress
+ nodeClickInProgress = false
+ removeBubble(d)
+ , clickWait)
+ d3.event.preventDefault()
+
removeBubble = (d) ->
currentId = idValue(d)
console.log(currentId)
@@ -325,13 +338,13 @@ Bubbles = () ->
data = data.filter (e) -> idValue(e) != currentId
console.log(data.length)
update()
- d3.event.preventDefault()
# ---
# changes clicked bubble by modifying url
# ---
- click = (d) ->
+ selectBubble = (d) ->
+ nodeClickInProgress = false
location.replace("#" + encodeURIComponent(idValue(d)))
d3.event.preventDefault()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment