Fix activity calendar for desktop widget (#5200)

* Fix activity calendar for desktop widget

* fetch past 21 weeks for activity widgets

* Cleanup

* forEach -> map

* Revert "forEach -> map"

This reverts commit b72e180ee4a788ff1a3c2955a061646561b2b735.
This commit is contained in:
Satsuki Yanagi 2019-07-21 19:12:16 +09:00 committed by syuilo
parent 95900dc6fc
commit e85897c367
3 changed files with 8 additions and 8 deletions

View file

@ -5,7 +5,7 @@
:x="record.x" :y="record.date.weekday"
rx="1" ry="1"
fill="transparent">
<title>{{ record.date.year }}/{{ record.date.month }}/{{ record.date.day }}</title>
<title>{{ record.date.year }}/{{ record.date.month + 1 }}/{{ record.date.day }}</title>
</rect>
<rect v-for="record in data" class="day"
:width="record.v" :height="record.v"
@ -39,17 +39,17 @@ export default Vue.extend({
const month = now.getMonth();
const day = now.getDate();
let x = 0;
this.data.slice().reverse().forEach((d, i) => {
let x = 20;
this.data.slice().forEach((d, i) => {
d.x = x;
const date = new Date(year, month, day - i);
d.date = {
year: date.getFullYear(),
month: date.getMonth(),
day: date.getDate()
day: date.getDate(),
weekday: date.getDay()
};
d.date.weekday = (new Date(d.date.year, d.date.month - 1, d.date.day)).getDay();
d.v = peak == 0 ? 0 : d.total / (peak / 2);
if (d.v > 1) d.v = 1;
@ -58,7 +58,7 @@ export default Vue.extend({
const cl = 15 + ((1 - d.v) * 80);
d.color = `hsl(${ch}, ${cs}%, ${cl}%)`;
if (d.date.weekday == 6) x++;
if (d.date.weekday == 0) x--;
});
}
});

View file

@ -46,7 +46,7 @@ export default Vue.extend({
props: ['data'],
data() {
return {
viewBoxX: 140,
viewBoxX: 147,
viewBoxY: 60,
zoom: 1,
pos: 0,

View file

@ -48,7 +48,7 @@ export default Vue.extend({
this.$root.api('charts/user/notes', {
userId: this.user.id,
span: 'day',
limit: 7 * 20
limit: 7 * 21
}).then(activity => {
this.activity = activity.diffs.normal.map((_, i) => ({
total: activity.diffs.normal[i] + activity.diffs.reply[i] + activity.diffs.renote[i],