Skip to content
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

Auto detect first day of the week #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion dist/vue-calendar-heatmap.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/vue-calendar-heatmap.common.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"vue-loader": "^10.0.0",
"vue-template-compiler": "^2.1.6",
"webpack": "^2.1.0-beta.28",
"webpack-merge": "^1.1.2"
"webpack-merge": "^1.1.2",
"weekstart": "^1.0.1"
},
"dependencies": {
"v-tooltip": "^2.0.0-rc.32"
Expand Down
12 changes: 7 additions & 5 deletions src/components/CalendarHeatmap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
text.vch__day__label(
:x="vertical ? SQUARE_SIZE * 1 : 0",
:y="vertical ? SQUARE_SIZE - SQUARE_BORDER_SIZE : 20"
) {{ lo.days[1] }}
) {{ lo.days[1 + weekstart] }}
text.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.vch__day__label(
:x="vertical ? SQUARE_SIZE * 5 : 0",
:y="vertical ? SQUARE_SIZE - SQUARE_BORDER_SIZE : 69"
) {{ lo.days[5] }}
) {{ lo.days[5 + weekstart] }}

g.vch__legend__wrapper(:transform="legendWrapperTransform[position]")
text(
Expand Down Expand Up @@ -62,6 +62,7 @@
import { VTooltip } from 'v-tooltip'
import Heatmap from './Heatmap'
import { DAYS_IN_WEEK, DEFAULT_LOCALE, DEFAULT_RANGE_COLOR, DEFAULT_TOOLTIP_UNIT, SQUARE_SIZE } from './consts.js'
import { getWeekStartByLocale } from 'weekstart'

VTooltip.enabled = window.innerWidth > 768

Expand Down Expand Up @@ -108,7 +109,8 @@ export default {

data () {
return {
now: new Date()
now: new Date(),
weekstart: getWeekStartByLocale(navigator.language)
}
},

Expand All @@ -120,7 +122,7 @@ export default {
return `translate(${this.tooltipX}, ${this.tooltipY})`
},
heatmap () {
return new Heatmap(this.endDate, this.values, this.max)
return new Heatmap(this.endDate, this.values, this.max, this.weekstart)
},
width () {
return {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Heatmap.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { DAYS_IN_ONE_YEAR, DAYS_IN_WEEK } from './consts'

export default class CalendarHeatmap {
constructor (endDate, values, max) {
constructor (endDate, values, max, weekstart) {
this.endDate = this._parseDate(endDate)
this.max = max || Math.ceil((Math.max(...values.map(day => day.count)) / 5) * 4)
this.startDate = this._shiftDate(endDate, -DAYS_IN_ONE_YEAR)
this.values = values
this.weekstart = weekstart
}

get activities () {
Expand All @@ -23,7 +24,7 @@ export default class CalendarHeatmap {
}

get calendar () {
let date = this._shiftDate(this.startDate, -this.getCountEmptyDaysAtStart())
let date = this._shiftDate(this.startDate, -this.getCountEmptyDaysAtStart() + this.weekstart)
return Array.from({ length: this.weekCount },
() => Array.from({ length: DAYS_IN_WEEK },
() => {
Expand Down