diff options
| author | Bobby <[email protected]> | 2022-03-19 20:23:21 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-03-19 20:23:21 -0400 |
| commit | 3f35dba42517061760aa174c82c4e48d6478fe3e (patch) | |
| tree | 01800ac35e6fb8497b5c043d1feaf1129d940754 /static | |
| parent | 72f04261bf13c959c9874fbd4f3436699f8b6c18 (diff) | |
| download | luciferreeves.github.io-3f35dba42517061760aa174c82c4e48d6478fe3e.tar.xz luciferreeves.github.io-3f35dba42517061760aa174c82c4e48d6478fe3e.zip | |
Added chart for contributions
Diffstat (limited to 'static')
| -rw-r--r-- | static/assets/js/pages/repositories.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/static/assets/js/pages/repositories.js b/static/assets/js/pages/repositories.js index 70207ba..821b83c 100644 --- a/static/assets/js/pages/repositories.js +++ b/static/assets/js/pages/repositories.js @@ -61,6 +61,81 @@ $.getJSON("api/user", function (data) { githubText.appendChild(githubContainer); ghParagraph.appendChild(githubText); userData.appendChild(ghParagraph); + const contributions = data.contributions; + const canvas = document.createElement("canvas"); + canvas.id = "contributionsChart"; + const ctx = canvas.getContext("2d"); + const color = "#000083"; + // Generate Dates of past 53 weeks + const dates = []; + const today = new Date(); + const startDate = new Date( + today.getFullYear(), + today.getMonth(), + today.getDate() - 53 * 7 + ); + for (let i = 0; i < 53; i++) { + const date = new Date( + startDate.getFullYear(), + startDate.getMonth(), + startDate.getDate() + i * 7 + ); + const datePlusSevenDays = new Date( + date.getFullYear(), + date.getMonth(), + date.getDate() + 6 + ); + const sd = date.toLocaleDateString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + }); + const ed = datePlusSevenDays.toLocaleDateString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + }); + dates.push(sd + " - " + ed); + } + const contributionsChart = new Chart(ctx, { + type: "bar", + data: { + labels: dates, + datasets: [ + { + label: "Weekly Contributions", + data: contributions, + backgroundColor: color, + }, + ], + }, + options: { + plugins: { + subtitle: { + display: true, + text: "Weekly Contributions (Past Year)\n", + }, + legend: { + display: false, + }, + }, + scales: { + x: { + ticks: { + display: false + } + }, + y: { + ticks: { + display: false, + beginAtZero: true + } + } + } + }, + }); + canvas.height = "200px"; + userData.appendChild(canvas); }); const repos = document.getElementById("repos"); |
