Skip to content

Instantly share code, notes, and snippets.

@shadowfacts
Last active February 5, 2017 22:55
Show Gist options
  • Save shadowfacts/ecf768359d3c3bcdeb967d3f90101c0b to your computer and use it in GitHub Desktop.
Save shadowfacts/ecf768359d3c3bcdeb967d3f90101c0b to your computer and use it in GitHub Desktop.
Ubersicht widget and Node.js script for a desktop GitHub contributions widget. Example here: http://imgur.com/4WeelK5
command: "curl -s https://github.com/shadowfacts | /Users/shadowfacts/.nvm/versions/node/v7.5.0/bin/node /Users/shadowfacts/Dev/gh-activity/process.js"
refreshFrequency: 3600000
style: """
#canvas {
position: absolute;
left: 50%;
top: 50%;
transform: translateX(-50%) translateY(-50%);
}
"""
render: -> """
<style>
#gh-activity-widget-index-coffee {
width: 100%;
height: 100%;
}
</style>
"""
update: (output, domEl) ->
domEl.innerHTML += output
const cheerio = require("cheerio");
// Green:
// const colors = {
// none: "#eeeeee",
// min: "#d6e685",
// third: "#8cc665",
// second: "#44a340",
// max: "#1e6823",
// };
// Red:
const colors = {
none: ["#111", "#111"],
min: ["#640C0B", "#560a09"],
third: ["#840f03", "#640c0b"],
second: ["#cc1210", "#840f03"],
max: ["#e81412", "#cc1210"],
};
let data = "";
process.stdin.on("data", (buf) => {
data += buf.toString();
});
process.stdin.on("end", () => {
handle();
});
function handle() {
console.log(`<svg id="canvas" width="${54 * 46}" height="${7 * 46}">`);
// console.log(`<rect x="0" y="0" width="2560" height="1440" fill="#ffffff"></rect>`)
const $ = cheerio.load(data);
const columns = $(".js-calendar-graph-svg g > g");
let x = 0;
columns.toArray().forEach((col) => {
let y = 0;
$(col).find("rect.day").toArray().forEach((it) => {
const count = parseInt($(it).data("count"));
const radius = Math.min(count + 5, 21);
const fill = getColor(count)[0];
const stroke = getColor(count)[1];
console.log(`\t<circle cx="${x * 46 + 23}" cy="${y * 46 + 23}" r="${radius}" fill="${fill}" stroke="${stroke}"></circle>`);
y++;
});
x++;
});
console.log("</svg>")
}
function getColor(count) {
if (count == 0) return colors.none;
else if (count <= 5) return colors.min;
else if (count <= 10) return colors.third;
else if (count <= 15) return colors.second;
else return colors.max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment