1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
| const calendar = new Vue({ el: '#calendar', data: { simplemode: false, user: 'LeeDebug', fixed: 'fixed', px: 'px', x: '', y: '', span1: '', span2: '', month: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], monthchange: [], oneyearbeforeday: '', thisday: '', amonthago: '', aweekago: '', weekdatacore: 0, datacore: 0, total: 0, datadate: '', data: [], positionplusdata: [], firstweek: [], lastweek: [], beforeweek: [], thisweekdatacore: 0, mounthbeforeday: 0, mounthfirstindex: 0, crispedges: 'crispedges', thisdayindex: 0, amonthagoindex: 0, amonthagoweek: [], firstdate: [], first2date: [], montharrbefore: [], monthindex: 0, leeGreen: ['#ebedf0', '#9be9a8', '#40c463', '#30a14e', '#216e39'], purple: ['#ebedf0', '#fdcdec', '#fc9bd9', '#fa6ac5', '#f838b2', '#f5089f', '#c4067e', '#92055e', '#540336', '#48022f', '#30021f',], green: ['#ebedf0', '#f0fff4', '#dcffe4', '#bef5cb', '#85e89d', '#34d058', '#28a745', '#22863a', '#176f2c', '#165c26', '#144620'], blue: ['#ebedf0', '#f1f8ff', '#dbedff', '#c8e1ff', '#79b8ff', '#2188ff', '#0366d6', '#005cc5', '#044289', '#032f62', '#05264c',], color: ['#ebedf0', '#fdcdec', '#fc9bd9', '#fa6ac5', '#f838b2', '#f5089f', '#c4067e', '#92055e', '#540336', '#48022f', '#30021f',] }, methods: { selectStyle(data, event) { $('.angle-wrapper').show(); this.span1 = data.date; this.span2 = data.count; this.x = event.clientX - 100; this.y = event.clientY - 60 }, outStyle() { $('.angle-wrapper').hide() }, thiscolor(x) { if (x === 0) { return this.leeGreen[0] } else if (x <= 5) { return this.leeGreen[1] } else if (x <= 10) { return this.leeGreen[2] } else if (x <= 18) { return this.leeGreen[3] } else { return this.leeGreen[4] } }, } }); let githubapiurl = "https://githubapi.ryanchristian.dev/user/" + calendar.user; $(function () { $.ajax({ type: "GET", url: githubapiurl, dataType: "json", success: function (data) { ; calendar.data = data.contributions; calendar.total = data.total; calendar.first2date = calendar.data[48]; calendar.firstdate = calendar.data[47]; calendar.firstweek = data.contributions[0]; calendar.lastweek = data.contributions[52]; calendar.beforeweek = data.contributions[51]; calendar.thisdayindex = calendar.lastweek.length - 1; calendar.thisday = calendar.lastweek[calendar.thisdayindex].date; calendar.oneyearbeforeday = calendar.firstweek[0].date; calendar.monthindex = calendar.thisday.substring(5, 7) * 1; calendar.montharrbefore = calendar.month.splice(calendar.monthindex, 12 - calendar.monthindex); calendar.monthchange = calendar.montharrbefore.concat(calendar.month); addweek(); addlastmonth();
function responsiveChart() { let c = document.getElementById("gitcanvas"); let cmessage = document.getElementById("gitmessage"); let ctx = c.getContext("2d"); c.width = document.getElementById("calendarcanvasbox").offsetWidth; let linemaxwitdh = 0.96 * c.width / calendar.data.length; c.height = 9 * linemaxwitdh; let lineminwitdh = 0.8 * linemaxwitdh; let setposition = { x: 0.02 * c.width, y: 0.025 * c.width }; for (let week in calendar.data) { weekdata = calendar.data[week]; for (let day in weekdata) { let dataitem = {date: "", count: "", x: 0, y: 0}; calendar.positionplusdata.push(dataitem); ctx.fillStyle = calendar.thiscolor(weekdata[day].count); setposition.y = Math.round(setposition.y * 100) / 100; dataitem.date = weekdata[day].date; dataitem.count = weekdata[day].count; dataitem.x = setposition.x; dataitem.y = setposition.y; ctx.fillRect(setposition.x, setposition.y, lineminwitdh, lineminwitdh); setposition.y = setposition.y + linemaxwitdh } ; setposition.y = 0.025 * c.width; setposition.x = setposition.x + linemaxwitdh } ; ctx.font = "600 Arial"; ctx.fillStyle = '#aaa'; ctx.fillText("日", 0, 1.9 * linemaxwitdh); ctx.fillText("二", 0, 3.9 * linemaxwitdh); ctx.fillText("四", 0, 5.9 * linemaxwitdh); ctx.fillText("六", 0, 7.9 * linemaxwitdh); let monthindexlist = c.width / 24; for (let index in calendar.monthchange) { ctx.fillText(calendar.monthchange[index], monthindexlist, 0.7 * linemaxwitdh); monthindexlist = monthindexlist + c.width / 12 } ; cmessage.onmousemove = function (event) { $('.angle-wrapper').hide() }; c.onmousemove = function (event) { $('.angle-wrapper').hide() getMousePos(c, event); };
function getMousePos(canvas, event) { var rect = canvas.getBoundingClientRect(); var x = event.clientX - rect.left * (canvas.width / rect.width); var y = event.clientY - rect.top * (canvas.height / rect.height); for (let item of calendar.positionplusdata) { let lenthx = x - item.x; let lenthy = y - item.y; if (0 < lenthx && lenthx < lineminwitdh) { if (0 < lenthy && lenthy < lineminwitdh) { $('.angle-wrapper').show(); calendar.span1 = item.date; calendar.span2 = item.count; calendar.x = event.clientX - 100; calendar.y = event.clientY - 60 } } } } }
responsiveChart(); $(window).on('resize', responsiveChart); window.onscroll = function () { $('.angle-wrapper').hide() }; console.log(calendar.positionplusdata)
function addlastmonth() { if (calendar.thisdayindex === 0) { thisweekcore(52); thisweekcore(51); thisweekcore(50); thisweekcore(49); thisweekcore(48); calendar.thisweekdatacore += calendar.firstdate[6].count; calendar.amonthago = calendar.firstdate[6].date } else { thisweekcore(52); thisweekcore(51); thisweekcore(50); thisweekcore(49); thisweek2core(); calendar.amonthago = calendar.first2date[calendar.thisdayindex - 1].date } };
function thisweek2core() { for (let i = calendar.thisdayindex - 1; i < calendar.first2date.length; i++) { calendar.thisweekdatacore += calendar.first2date[i].count } };
function thisweekcore(index) { for (let item of calendar.data[index]) { calendar.thisweekdatacore += item.count } };
function addlastweek() { for (let item of calendar.lastweek) { calendar.weekdatacore += item.count } };
function addbeforeweek() { for (let i = calendar.thisdayindex; i < calendar.beforeweek.length; i++) { calendar.weekdatacore += calendar.beforeweek[i].count } };
function addweek() { if (calendar.thisdayindex === 6) { calendar.aweekago = calendar.lastweek[0].date; addlastweek() } else { lastweek = data.contributions[51]; calendar.aweekago = lastweek[calendar.thisdayindex + 1].date; addlastweek(); addbeforeweek() } } } }) }); if(document.getElementById("calendarcanvasbox").offsetWidth<500){calendar.simplemode=false}
|