avatar
EdNovas
人生不止眼前的苟且,还有诗与远方
Follow Me
Announcement
欢迎来到EdNovas的小站!
Info
Article :
294
Run time :
Total Count :
331.6k
UV :
PV :
Last Push :
訪客地圖
Pixiv Top 500
< 2) { return this.color[1] } else if (x < 20) { let i = parseInt(x / 2); return this.color[i] } else { return this.color[9] } }, } }); var apiurl = 'github-calendar-api.vercel.app' ? 'https://github-calendar-api.vercel.app/api?' : 'https://githubapi.ryanchristian.dev/user/' var githubapiurl = apiurl + gitcalendar.user; //canvas绘图 function responsiveChart() { let c = document.getElementById("gitcanvas"); if (c) { let cmessage = document.getElementById("gitmessage"); let ctx = c.getContext("2d"); c.width = document.getElementById("gitcalendarcanvasbox").offsetWidth; let linemaxwitdh = 0.96 * c.width / gitcalendar.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 gitcalendar.data) { weekdata = gitcalendar.data[week]; for (let day in weekdata) { let dataitem = { date: "", count: "", x: 0, y: 0 }; gitcalendar.positionplusdata.push(dataitem); ctx.fillStyle = gitcalendar.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 gitcalendar.monthchange) { ctx.fillText(gitcalendar.monthchange[index], monthindexlist, 0.7 * linemaxwitdh); monthindexlist = monthindexlist + c.width / 12 }; cmessage.onmousemove = function(event) { document.querySelector('.angle-wrapper').style.display = 'none' }; c.onmousemove = function(event) { document.querySelector('.angle-wrapper').style.display = 'none' 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); //console.log("x:"+x+",y:"+y); for (let item of gitcalendar.positionplusdata) { let lenthx = x - item.x; let lenthy = y - item.y; //console.log(lenthx,lenthy); if (0 < lenthx && lenthx < lineminwitdh) { if (0 < lenthy && lenthy < lineminwitdh) { //console.log(item.date,item.count) document.querySelector('.angle-wrapper').style.display = 'block' gitcalendar.span1 = item.date; gitcalendar.span2 = item.count; gitcalendar.x = event.clientX - 100; gitcalendar.y = event.clientY - 60 } } //if(0< x - item.x data.json()) .then(data => { gitcalendar.data = data.contributions; gitcalendar.total = data.total; gitcalendar.first2date = gitcalendar.data[48]; gitcalendar.firstdate = gitcalendar.data[47]; gitcalendar.firstweek = data.contributions[0]; gitcalendar.lastweek = data.contributions[52]; gitcalendar.beforeweek = data.contributions[51]; gitcalendar.thisdayindex = gitcalendar.lastweek.length - 1; gitcalendar.thisday = gitcalendar.lastweek[gitcalendar.thisdayindex].date; gitcalendar.oneyearbeforeday = gitcalendar.firstweek[0].date; gitcalendar.monthindex = gitcalendar.thisday.substring(5, 7) * 1; gitcalendar.montharrbefore = gitcalendar.month.splice(gitcalendar.monthindex, 12 - gitcalendar.monthindex); gitcalendar.monthchange = gitcalendar.montharrbefore.concat(gitcalendar.month); addweek(data); addlastmonth(); responsiveChart(); }) .catch(function(error) { console.log(error); }); //手机版更换为svg绘制 if (document.getElementById("gitcalendarcanvasbox").offsetWidth < 500) { gitcalendar.simplemode = false } //当改变窗口大小时重新绘制canvas window.onresize = function() { if (gitcalendar.simplemode) responsiveChart() } //解决滚动滑轮时出现的标签显示 window.onscroll = function() { if (document.querySelector('.angle-wrapper')) { document.querySelector('.angle-wrapper').style.display = 'none' } };