Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created August 22, 2014 19:28
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kentcdodds/542e6320a0fa0d6bea03 to your computer and use it in GitHub Desktop.
Save kentcdodds/542e6320a0fa0d6bea03 to your computer and use it in GitHub Desktop.
github contribution graph fake
var colors = [
'rgb(30, 104, 35)', 'rgb(68, 163, 64)', 'rgb(140, 198, 101)', 'rgb(214, 230, 133)', 'rgb(238, 238, 238)'
];
var days = $('#calendar-graph').find('rect.day');
days.css({
fill: colors[4]
});
days.on('click', function(e) {
e.stopPropagation();
$this = $(this);
var colorIndex = ~~$this.data('nextColorIndex');
$this.css('fill', colors[colorIndex]);
colorIndex++;
if (colorIndex >= colors.length) {
colorIndex = 0;
}
$this.data('nextColorIndex', colorIndex);
});
// above code adds click handler to each square. Click the ones you want to change.
// Then call this randomize method to make it look less fake...
function randomize() {
days.each(function() {
var $this = $(this);
var fill = $this.css('fill');
var shouldChange = Math.random() > .65;
if (!shouldChange) return;
var colorIndex = 4;
if (fill === colors[4] || fill === colors[3]) {
colorIndex = Math.random() > .65 ? 3 : 4;
} else {
colorIndex = Math.random() > .65 ? Math.random() > .65 ? 2 : 1 : 0;
}
$this.css('fill', colors[colorIndex]);
});
}
@kentcdodds
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment