Created
April 24, 2016 05:50
-
-
Save haydenbleasel/a5c2ed4d0c6ed34be6165916904d6ab2 to your computer and use it in GitHub Desktop.
GitHub chart for website.
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
#github | |
.row.clearfix | |
#canvas-container.hidden-xs | |
canvas#repositories | |
noscript Sorry, you need Javascript enabled to view this chart. |
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
$(() => { | |
'use strict'; | |
const access_token = 'your_access_token', | |
user = 'your_username', | |
chart = $('#repositories').get(0); | |
$.getJSON(`https://api.github.com/users/${user}/repos?callback=?`, { access_token }, (repos) => { | |
const repositories = new Chart(chart.getContext('2d')).Bar({ | |
labels: repos.data.map((repo) => repo.name), | |
datasets: [{ | |
label: 'Stargazers', | |
fillColor: '#D8D9DC', | |
strokeColor: '#D8D9DC', | |
highlightFill: '#B0B2B9', | |
highlightStroke: '#B0B2B9', | |
data: repos.data.map((repo) => repo.stargazers_count) | |
}] | |
}, { showScale: false }), | |
originalShowTooltip = repositories.showTooltip; | |
// Open repositories on click | |
chart.onclick = (e) => { | |
const activeElements = repositories.getBarsAtEvent(e), | |
popup = window.open(`http://github.com/${user}/${activeElements[0].label}`, '_blank'); | |
popup.focus(); | |
}; | |
// Piggyback the showTooltip function for mouse cursor | |
repositories.showTooltip = function showTooltip (activeElements) { | |
$('#github').css('cursor', activeElements.length ? 'pointer' : 'default'); | |
Reflect.apply(originalShowTooltip, this, arguments); | |
}; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment