Skip to content

Commit 724d4ce

Browse files
hpjack666D-Sketon
andauthored
fix: 日期热力图月份重合 (#114)
* 修改热力图的月份显示样式 * 修改热力图的月份显示样式 * 优化热力图月份显示逻辑,避免重叠并简化周日计数 --------- Co-authored-by: D-Sketon <2055272094@qq.com>
1 parent 5ef9ba7 commit 724d4ce

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

source/js/heat_map.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ function createCalendar(element, contributionData) {
190190
const monthFragment = document.createDocumentFragment();
191191
const tilesFragment = document.createDocumentFragment();
192192

193+
let lastGridColumn = -1;
194+
193195
const [tiles, totalStatistical] = data.reduce(
194196
([tiles, stats], c, i) => {
195197
const date = new Date(c.date);
@@ -201,7 +203,11 @@ function createCalendar(element, contributionData) {
201203

202204
// 处理月份标签
203205
if (date.getDay() === 0 && month !== latestMonth) {
204-
const gridColumn = 2 + Math.floor((i + startRow) / 7);
206+
let gridColumn = 2 + Math.floor((i + startRow) / 7);
207+
if (gridColumn - lastGridColumn <= 1) {
208+
gridColumn += (2 - gridColumn + lastGridColumn); // 防止重叠
209+
}
210+
lastGridColumn = gridColumn;
205211
latestMonth = month;
206212
const monthLabel = document.createElement("span");
207213
monthLabel.className = "month";

0 commit comments

Comments
 (0)