Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/10010846 to your computer and use it in GitHub Desktop.
Save peterhellberg/10010846 to your computer and use it in GitHub Desktop.
Rendering public GitHub contributions using Lineman.js and Obelisk.js
window.drawContributions = (data) ->
s = 12
canvas = document.getElementById('contributions')
point = new obelisk.Point(200, 100)
pixelView = new obelisk.PixelView(canvas, point)
color = new obelisk.SideColor().getByInnerColor(0xFEFEFE)
color.border = 0x14000000
for day in [1..7]
for week in [1..51]
dimension = new obelisk.BrickDimension(s, s)
brick = new obelisk.Brick(dimension, color)
p3D = new obelisk.Point3D(s * week, s * day, 0)
pixelView.renderObject(brick, p3D)
for day in [1..7]
for week in [1..52]
n = (week*7)+day
d = data[n]
colors = [
0xf7ffd8,
0xf3ffc4,
0xefffb1,
0xebff9d,
0xe7ff89,
0xe4ff76,
0xe0ff62,
0xdcff4e,
0xd8ff3b,
0xd4ff27,
0xd0ff14,
0xccff00,
]
if d
c = d[1]
if c > 0
g = colors[c-1]
g = 0xbceb00 if !g
dimension = new obelisk.CubeDimension(s, s, c*5)
p3d = new obelisk.Point3D(s * week, s * day, 0)
color = new obelisk.CubeColor().getByHorizontalColor(g)
color.border = 0xEE1f2700
cube = new obelisk.Cube(dimension, color, true)
pixelView.renderObject(cube, p3d)
window.contributions = ->
html = JST['app/templates/contributions.us'](
width: window.innerWidth,
height: window.innerHeight
)
document.body.innerHTML += html
req = new XMLHttpRequest()
req.addEventListener 'readystatechange', ->
if req.readyState is 4
if req.status in [200]
drawContributions(JSON.parse(req.responseText))
req.open 'GET', '/api/data.json', false
req.send()
if window.addEventListener
window.addEventListener('DOMContentLoaded', contributions, false)
else
window.attachEvent('onload', contributions)
var request = require('request');
module.exports = {
drawRoutes: function(app) {
app.get('/api/data.json', function(req, res) {
var url = 'https://github.com/users/peterhellberg/contributions_calendar_data';
request(url, function(e, r, b) {
if (!e && r.statusCode == 200) {
res.json(JSON.parse(b));
}
});
})
}
};
@peterhellberg
Copy link
Author

Example

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