Skip to content

Instantly share code, notes, and snippets.

@codementum
Last active November 2, 2016 16:21
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 codementum/6e50c07132b3891fa5d2ac6582ede41c to your computer and use it in GitHub Desktop.
Save codementum/6e50c07132b3891fa5d2ac6582ede41c to your computer and use it in GitHub Desktop.
// 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