Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/render/gitStyleTrackGraphRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/render/graphRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand All @@ -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;
}
}
}

Expand Down
22 changes: 9 additions & 13 deletions src/render/matrixDataGenerator.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/render/monthTrackGraphRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 7 additions & 0 deletions src/util/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down