mirror of
https://github.com/vran-dev/obsidian-contribution-graph.git
synced 2026-07-22 09:20:23 +00:00
fix: git style graph render incorrectly if startOfWeek is not specified with api (#38)
This commit is contained in:
parent
7937f3c62b
commit
46ff4b5292
3 changed files with 7 additions and 11 deletions
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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[]) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue