diff --git a/src/render/gitStyleTrackGraphRender.ts b/src/render/gitStyleTrackGraphRender.ts index d842a02..199d6f9 100644 --- a/src/render/gitStyleTrackGraphRender.ts +++ b/src/render/gitStyleTrackGraphRender.ts @@ -48,8 +48,7 @@ export class GitStyleTrackGraphRender extends BaseGraphRender { // fill HOLE cell at the left most column if start date is not ${startOfWeek} if (contributionData.length > 0) { - const from = new Date(contributionData[0].date); - const weekDayOfFromDate = from.getDay(); + const weekDayOfFromDate = contributionData[0].weekDay; const firstHoleCount = distanceBeforeTheStartOfWeek( graphConfig.startOfWeek || 0, weekDayOfFromDate diff --git a/src/render/graphRender.ts b/src/render/graphRender.ts index 480f142..b9fe992 100644 --- a/src/render/graphRender.ts +++ b/src/render/graphRender.ts @@ -242,6 +242,12 @@ export abstract class BaseGraphRender implements GraphRender { ) { if (graphConfig.cellStyle) { Object.assign(cellEl.style, graphConfig.cellStyle); + if (graphConfig.cellStyle.minWidth) { + cellEl.style.width = graphConfig.cellStyle.minWidth; + } + if (graphConfig.cellStyle.minHeight) { + cellEl.style.height = graphConfig.cellStyle.minHeight; + } } } @@ -257,6 +263,12 @@ export abstract class BaseGraphRender implements GraphRender { return acc; }, {}); Object.assign(cellEl.style, partialStyle); + if (props.includes("minWidth") && graphConfig.cellStyle.minWidth) { + cellEl.style.width = graphConfig.cellStyle.minWidth; + } + if (props.includes("minHeight") && graphConfig.cellStyle.minHeight) { + cellEl.style.height = graphConfig.cellStyle.minHeight; + } } } diff --git a/src/render/matrixDataGenerator.ts b/src/render/matrixDataGenerator.ts index 428dc30..8e4fc5c 100644 --- a/src/render/matrixDataGenerator.ts +++ b/src/render/matrixDataGenerator.ts @@ -1,25 +1,21 @@ -import { diffDays } from "../util/dateUtils"; +import { diffDays, parseDate } from "../util/dateUtils"; import { Contribution, ContributionCellData } from "../types"; import { DateTime } from "luxon"; + export function generateByData(data: Contribution[]) { if (!data || data.length === 0) { return []; } const dateData = data.map((item) => { - if (item.date instanceof Date) { - return { - ...item, - timestamp: item.date.getTime(), - }; - } else { - return { - ...item, - date: new Date(item.date), - timestamp: new Date(item.date).getTime(), - }; - } + const localDate = parseDate(item.date); + + return { + ...item, + date: localDate, + timestamp: localDate.getTime(), + }; }); const sortedData = dateData.sort((a, b) => b.timestamp - a.timestamp); diff --git a/src/render/monthTrackGraphRender.ts b/src/render/monthTrackGraphRender.ts index 428da86..ce5899c 100644 --- a/src/render/monthTrackGraphRender.ts +++ b/src/render/monthTrackGraphRender.ts @@ -108,8 +108,7 @@ export class MonthTrackGraphRender extends BaseGraphRender { // fill hole at start month, if start month date is not 1 if (i == 0) { - const startDate = new Date(contributionItem.date).getDate(); - const fillMax = startDate - 1; + const fillMax = contributionItem.monthDate - 1; for (let j = 0; j < fillMax; j++) { const cellEl = document.createElement("div"); cellEl.className = "cell"; diff --git a/src/util/dateUtils.ts b/src/util/dateUtils.ts index c07e4db..731a698 100644 --- a/src/util/dateUtils.ts +++ b/src/util/dateUtils.ts @@ -2,6 +2,13 @@ import { DateTime } from "luxon"; export function parseDate(date: string | Date) { if (typeof date === "string") { + // Check whether it is pure date format (yyyy-MM-dd) + // if so, parse it to local timezone + if (/^\d{4}-\d{2}-\d{2}$/.test(date)) { + const [y, m, d] = date.split('-').map(Number); + // new Date(y, m, d) create 00:00:00 in local timezone + return new Date(y, m - 1, d); + } return new Date(date); } else { return date;