yumechi-no-kuni/src/client/app/mobile/views/components/activity.vue

63 lines
1.3 KiB
Vue
Raw Normal View History

2018-02-15 03:33:34 -06:00
<template>
2018-02-23 11:46:09 -06:00
<div class="mk-activity">
2018-02-15 03:33:34 -06:00
<svg v-if="data" ref="canvas" viewBox="0 0 30 1" preserveAspectRatio="none">
2018-02-22 02:32:58 -06:00
<g v-for="(d, i) in data">
2018-04-07 12:30:37 -05:00
<rect width="0.8" :height="d.notesH"
:x="i + 0.1" :y="1 - d.notesH - d.repliesH - d.renotesH"
2018-02-15 03:33:34 -06:00
fill="#41ddde"/>
<rect width="0.8" :height="d.repliesH"
2018-04-07 12:30:37 -05:00
:x="i + 0.1" :y="1 - d.repliesH - d.renotesH"
2018-02-15 03:33:34 -06:00
fill="#f7796c"/>
2018-04-07 12:30:37 -05:00
<rect width="0.8" :height="d.renotesH"
:x="i + 0.1" :y="1 - d.renotesH"
2018-02-15 03:33:34 -06:00
fill="#a1de41"/>
</g>
</svg>
</div>
</template>
<script lang="ts">
import Vue from 'vue';
export default Vue.extend({
props: ['user'],
data() {
return {
fetching: true,
data: [],
peak: null
};
},
mounted() {
2018-02-17 21:35:18 -06:00
(this as any).api('aggregation/users/activity', {
2018-03-29 00:48:47 -05:00
userId: this.user.id,
2018-02-15 03:33:34 -06:00
limit: 30
}).then(data => {
2018-04-07 12:30:37 -05:00
data.forEach(d => d.total = d.notes + d.replies + d.renotes);
2018-02-15 03:33:34 -06:00
this.peak = Math.max.apply(null, data.map(d => d.total));
data.forEach(d => {
2018-04-07 12:30:37 -05:00
d.notesH = d.notes / this.peak;
2018-02-15 03:33:34 -06:00
d.repliesH = d.replies / this.peak;
2018-04-07 12:30:37 -05:00
d.renotesH = d.renotes / this.peak;
2018-02-15 03:33:34 -06:00
});
2018-02-22 02:32:58 -06:00
data.reverse();
2018-02-15 03:33:34 -06:00
this.data = data;
});
}
});
</script>
<style lang="stylus" scoped>
2018-02-23 11:46:09 -06:00
.mk-activity
2018-02-15 03:33:34 -06:00
max-width 600px
margin 0 auto
> svg
display block
width 100%
height 80px
> rect
transform-origin center
</style>