Skip to content

Add support for weeks starting on monday, but only as an explicit parameter #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -38,6 +38,16 @@
<h4>Some (circles)</h4>
<calendar-heatmap :values="values" :end-date="endDate" :style="{'max-width': orientation === 'vertical' ? '145px' : '675px'}" :round="5"
:vertical="orientation === 'vertical'"/>
<br>
<h4>Some (monday)</h4>
<calendar-heatmap
:values="values"
:end-date="endDate"
:style="{'max-width': orientation === 'vertical' ? '145px' : '675px'}"
:vertical="orientation === 'vertical'"
:week-start="1"
no-data-text="NOTHING"
/>
<br>
<h4>Locale</h4>
<calendar-heatmap :values="values" :end-date="endDate" :style="{'max-width': orientation === 'vertical' ? '145px' : '675px'}" :locale="{
12 changes: 8 additions & 4 deletions src/components/CalendarHeatmap.vue
Original file line number Diff line number Diff line change
@@ -18,19 +18,19 @@
:x="vertical ? SQUARE_SIZE : 0"
:y="vertical ? SQUARE_SIZE - SQUARE_BORDER_SIZE : 20"
>
{{ lo.days[ 1 ] }}
{{ lo.days[ 1 + weekStart ] }}
</text>
<text class="vch__day__label"
:x="vertical ? SQUARE_SIZE * 3 : 0"
:y="vertical ? SQUARE_SIZE - SQUARE_BORDER_SIZE : 44"
>
{{ lo.days[ 3 ] }}
{{ lo.days[ 3 + weekStart ] }}
</text>
<text class="vch__day__label"
:x="vertical ? SQUARE_SIZE * 5 : 0"
:y="vertical ? SQUARE_SIZE - SQUARE_BORDER_SIZE : 69"
>
{{ lo.days[ 5 ] }}
{{ lo.days[ 5 + weekStart ] }}
</text>
</g>

@@ -159,6 +159,10 @@
type : Number,
default: 0
},
weekStart : {
type : Number,
default: 0
},
darkMode : Boolean
},
emits: [ 'dayClick' ],
@@ -273,7 +277,7 @@
watch(
[ values, tooltipUnit, tooltipFormatter, noDataText, max, rangeColor ],
() => {
heatmap.value = new Heatmap(props.endDate as Date, props.values, props.max);
heatmap.value = new Heatmap(props.endDate as Date, props.values, props.max, props.weekStart);
tippyInstances.forEach((item) => item.destroy());
nextTick(initTippy);
}
6 changes: 4 additions & 2 deletions src/components/Heatmap.ts
Original file line number Diff line number Diff line change
@@ -58,15 +58,17 @@ export class Heatmap {
startDate: Date;
endDate: Date;
max: number;
weekStart: number;

private _values: Value[];
private _firstFullWeekOfMonths?: Month[];
private _activities?: Activities;
private _calendar?: Calendar;

constructor(endDate: Date | string, values: Value[], max?: number) {
constructor(endDate: Date | string, values: Value[], max?: number, weekStart?: number) {
this.endDate = this.parseDate(endDate);
this.max = max || Math.ceil((Math.max(...values.map(day => day.count)) / 5) * 4);
this.weekStart = weekStart ?? 0;
this.startDate = this.shiftDate(endDate, -Heatmap.DAYS_IN_ONE_YEAR);
this._values = values;
}
@@ -102,7 +104,7 @@ export class Heatmap {

get calendar() {
if (!this._calendar) {
let date = this.shiftDate(this.startDate, -this.getCountEmptyDaysAtStart());
let date = this.shiftDate(this.startDate, -this.getCountEmptyDaysAtStart() + this.weekStart);
date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
this._calendar = new Array(this.weekCount);
for (let i = 0, len = this._calendar.length; i < len; i++) {