commit
b6888ad7e1
7 changed files with 214 additions and 0 deletions
@ -0,0 +1,15 @@
|
||||
command: `./github-activity.widget/run.sh`, |
||||
refreshFrequency: 3600000, |
||||
style: "\ |
||||
#github-activity {\ |
||||
position: absolute;\ |
||||
left: 50%;\ |
||||
top: 50%;\ |
||||
transform: translateX(-50%) translateY(-50%);\ |
||||
}", |
||||
render: () => { |
||||
return "<style>#github-activity-widget-index-js { width: 100%; height: 100%; }</style>"; |
||||
}, |
||||
update: (output, domEl) => { |
||||
domEl.innerHTML += output; |
||||
} |
@ -0,0 +1,18 @@
|
||||
{ |
||||
"name": "github-activity.widget", |
||||
"version": "1.0.0", |
||||
"repository": { |
||||
"type": "git", |
||||
"url": "git+https://github.com/shadowfacts/ubersicht-github-activity.git" |
||||
}, |
||||
"author": "shadowfacts", |
||||
"license": "LGPL-3.0", |
||||
"bugs": { |
||||
"url": "https://github.com/shadowfacts/ubersicht-github-activity/issues" |
||||
}, |
||||
"homepage": "https://github.com/shadowfacts/ubersicht-github-activity#readme", |
||||
"dependencies": { |
||||
"axios": "^0.15.3", |
||||
"cheerio": "^0.22.0" |
||||
} |
||||
} |
@ -0,0 +1,9 @@
|
||||
#! /bin/bash |
||||
|
||||
if [ -f /usr/local/bin/node ]; then |
||||
# If node is installed via Homebrew, use it |
||||
/usr/local/bin/node ./github-activity.widget/src/generate.js |
||||
else |
||||
# Fallback to normal |
||||
node ./github-activity.widget/src/generate.js |
||||
fi |
@ -0,0 +1,111 @@
|
||||
// For documentation on these options, see the README at https://github.com/shadowfacts/uebersicht-github-activity/
|
||||
const options = { |
||||
user: "shadowfacts", |
||||
size: 44, |
||||
incrAmount: 6, |
||||
margin: 2, |
||||
vary: ["size", "color"], |
||||
shape: "circle", |
||||
theme: "red", |
||||
colors: { |
||||
overrides: { |
||||
none: [null, null], |
||||
one: [null, null], |
||||
two: [null, null], |
||||
three: [null, null], |
||||
max: [null] |
||||
}, |
||||
red: { |
||||
none: ["#111", "#111"], |
||||
one: ["#640C0B", "#560a09"], |
||||
two: ["#840f03", "#640c0b"], |
||||
three: ["#cc1210", "#840f03"], |
||||
max: ["#e81412", "#cc1210"] |
||||
}, |
||||
green: { |
||||
none: ["#eee", "#eee"], |
||||
one: ["#d6e685", "#c2d179"], |
||||
two: ["#8cc665", "#d6e685"], |
||||
three: ["#44a340", "#8cc665"], |
||||
max: ["#1e6823", "#44a340"] |
||||
} |
||||
} |
||||
}; |
||||
|
||||
const axios = require("axios"); |
||||
const cheerio = require("cheerio"); |
||||
|
||||
axios.get(`https://github.com/${options.user}`) |
||||
.then(generate) |
||||
.catch(console.error); |
||||
|
||||
function generate(res) { |
||||
console.log(`<svg id="github-activity" width="${54 * options.size}" height="${7 * (options.size)}">`); |
||||
|
||||
const $ = cheerio.load(res.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")); |
||||
|
||||
let fill, stroke; |
||||
if (options.vary.includes("color")) { |
||||
[fill, stroke] = getColors(count); |
||||
} else { |
||||
[fill, stroke] = getColors(Number.MAX_VALUE); |
||||
} |
||||
|
||||
if (options.shape == "square") { |
||||
let xPos = x * options.size; |
||||
let yPos = y * options.size; |
||||
|
||||
let size; |
||||
if (options.vary.includes("size")) { |
||||
size = Math.min(count + options.incrAmount, (options.size - options.margin) / 2); |
||||
xPos += (-size + options.size) / 2; |
||||
yPos += (-size + options.size) / 2; |
||||
} else { |
||||
size = options.size - options.margin; |
||||
} |
||||
|
||||
console.log(`\t<rect x="${xPos}" y="${yPos}" width="${size}" height="${size}" fill="${fill}" stroke="${stroke}"></rect>`); |
||||
} else { |
||||
const xPos = x * options.size + (options.size / 2); |
||||
const yPos = y * options.size + (options.size / 2); |
||||
|
||||
let size; |
||||
if (options.vary.includes("size")) { |
||||
size = Math.min(count + options.incrAmount, (options.size - options.margin) / 2); |
||||
} else { |
||||
size = (options.size - options.margin) / 2; |
||||
} |
||||
|
||||
console.log(`\t<circle cx="${xPos}" cy="${yPos}" r="${size}" fill="${fill}" stroke="${stroke}"></circle>`); |
||||
} |
||||
|
||||
y++; |
||||
}); |
||||
|
||||
x++; |
||||
}); |
||||
|
||||
console.log("</svg>"); |
||||
} |
||||
|
||||
function getColorsForPalette(count, palette) { |
||||
if (count == 0) return palette.none; |
||||
else if (count <= 5) return palette.one; |
||||
else if (count <= 10) return palette.two; |
||||
else if (count <= 15) return palette.three; |
||||
else return palette.max; |
||||
} |
||||
|
||||
function getColors(count) { |
||||
const defaults = getColorsForPalette(count, options.colors[options.theme]); |
||||
const overrides = getColorsForPalette(count, options.colors.overrides); |
||||
return [overrides[0] || defaults[0], overrides[1] || defaults[1]]; |
||||
} |
Loading…
Reference in new issue