fix: git style graph render incorrectly if startOfWeek is not specified with api (#38)

This commit is contained in:
vran 2024-01-09 09:42:03 +08:00 committed by GitHub
parent 7937f3c62b
commit 46ff4b5292
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 11 deletions

View file

@ -46,7 +46,7 @@ export class GitStyleTrackGraphRender extends BaseGraphRender {
cls: "column",
parent: chartsEl,
});
this.renderWeekIndicator(weekTextColumns, graphConfig.startOfWeek);
this.renderWeekIndicator(weekTextColumns, graphConfig.startOfWeek || 0);
const contributionData: ContributionCellData[] =
this.generateContributionData(graphConfig);
@ -56,7 +56,7 @@ export class GitStyleTrackGraphRender extends BaseGraphRender {
const from = new Date(contributionData[0].date);
const weekDayOfFromDate = from.getDay();
const firstHoleCount = distanceBeforeTheStartOfWeek(
graphConfig.startOfWeek,
graphConfig.startOfWeek || 0,
weekDayOfFromDate
);
for (let i = 0; i < firstHoleCount; i++) {

View file

@ -88,8 +88,7 @@ export abstract class BaseGraphRender implements GraphRender {
if (graphConfig.days) {
return generateByLatestDays(
graphConfig.days,
graphConfig.data,
graphConfig.startOfWeek || 0
graphConfig.data
);
} else if (graphConfig.fromDate && graphConfig.toDate) {
const fromDate = parseDate(graphConfig.fromDate);
@ -97,8 +96,7 @@ export abstract class BaseGraphRender implements GraphRender {
return generateByFixedDate(
fromDate,
toDate,
graphConfig.data,
graphConfig.startOfWeek || 0
graphConfig.data
);
} else {
return generateByData(graphConfig.data);

View file

@ -30,8 +30,7 @@ export function generateByData(data: Contribution[]) {
export function generateByFixedDate(
from: Date,
to: Date,
data: Contribution[],
startOfWeek = 0
data: Contribution[]
) {
const days = diffDays(from, to) + 1;
// convert contributions to map: date(yyyy-MM-dd) -> value(sum)
@ -66,12 +65,11 @@ export function generateByFixedDate(
*/
export function generateByLatestDays(
days: number,
data: Contribution[] = [],
startOfWeek = 0
data: Contribution[] = []
): ContributionCellData[] {
const fromDate = new Date();
fromDate.setDate(fromDate.getDate() - days + 1);
return generateByFixedDate(fromDate, new Date(), data, startOfWeek);
return generateByFixedDate(fromDate, new Date(), data);
}
function contributionToMap(data: Contribution[]) {