Last active
November 2, 2016 16:21
-
-
Save codementum/6e50c07132b3891fa5d2ac6582ede41c to your computer and use it in GitHub Desktop.
Applying HindSight to @nytgraphics scatterplot in http://www.nytimes.com/2016/11/03/upshot/why-republicans-dont-even-try-to-win-cities-anymore.html?smid=tw-upshotnyt&smtyp=cur&_r=1
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
// Adding HindSight to @nytgraphics "Why Republicans Don't Even Try to Win Cities Anymore" | |
// url: http://www.nytimes.com/2016/11/03/upshot/why-republicans-dont-even-try-to-win-cities-anymore.html?smid=tw-upshotnyt&smtyp=cur&_r=1 | |
// To try this out, open the JavaScript console in your browser and paste this entire script. | |
// Select the main element in the Vis (circles) | |
d3.selectAll('circle') | |
.on('mouseover', function() { | |
var that = this; | |
// Trigger HindSight after 1 second (indicates intention on the reader's part, and not an accidental mouseover) | |
var t = setTimeout(function() { | |
d3.select(that) | |
.style('fill', 'steelblue'); | |
}, 1000); | |
// Store timeout id so we can clear it on mouseout | |
d3.select(this).data()[0]['trigger'] = t; | |
}) | |
.on('mouseout', function() { | |
// If the timeout id exists, clear the timeout before HindSight is triggered | |
if( d3.select(this).data()[0]['trigger'] ) | |
clearTimeout( d3.select(this).data()[0]['trigger'] ) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment