Skip to content

Instantly share code, notes, and snippets.

@haydenbleasel
Created April 24, 2016 05:50
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 haydenbleasel/a5c2ed4d0c6ed34be6165916904d6ab2 to your computer and use it in GitHub Desktop.
Save haydenbleasel/a5c2ed4d0c6ed34be6165916904d6ab2 to your computer and use it in GitHub Desktop.
GitHub chart for website.
#github
.row.clearfix
#canvas-container.hidden-xs
canvas#repositories
noscript Sorry, you need Javascript enabled to view this chart.
$(() => {
'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