77 aw-devonly( v-if ="periodLength === 'day'" reason ="Not ready for production, still experimenting" )
88 div.row.mb-4
99 div.col-md-12
10- aw-timeline-barchart ( :height = "100" , :datasets = "datasets ")
10+ aw-selectable-vis ( :id = "index" type = "timeline_barchart ")
1111</template >
1212
1313<script >
14- import _ from ' lodash' ;
15- import moment from ' moment' ;
16-
17- import { build_category_hierarchy } from ' ~/util/classes' ;
18-
19- function pick_subname_as_name (c ) {
20- c .name = c .subname ;
21- c .children = c .children .map (pick_subname_as_name);
22- return c;
23- }
24-
25- // TODO: Move somewhere else, possibly turn into a serverside transform
26- function split_by_hour_into_data (events ) {
27- if (events === undefined || events === null || events .length == 0 ) return [];
28- const d = moment (events[0 ].timestamp ).startOf (' day' );
29- return _ .range (0 , 24 ).map (h => {
30- let duration = 0 ;
31- const d_start = d .clone ().hour (h);
32- const d_end = d .clone ().hour (h + 1 );
33- // This can be made faster by not checking every event per hour, but since number of events is small anyway this and this is a lot shorter and easier to read it doesn't really matter.
34- events .map (e => {
35- const e_start = moment (e .timestamp );
36- const e_end = e_start .clone ().add (e .duration , ' seconds' );
37- if (
38- e_start .isBetween (d_start, d_end) ||
39- e_end .isBetween (d_start, d_end) ||
40- d_start .isBetween (e_start, e_end)
41- ) {
42- if (d_start < e_start && e_end < d_end) {
43- // If entire event is contained within the hour
44- duration += e .duration ;
45- } else if (d_start < e_start) {
46- // If start of event is within the hour, but not the end
47- duration += (d_end - e_start) / 1000 ;
48- } else if (e_end < d_end) {
49- // If end of event is within the hour, but not the start
50- duration += (e_end - d_start) / 1000 ;
51- } else {
52- // Happens if event covers entire hour and more
53- duration += 3600 ;
54- }
55- }
56- });
57- return duration / 60 / 60 ;
58- });
59- }
60-
6114export default {
6215 name: ' Activity' ,
6316 props: {
@@ -71,44 +24,6 @@ export default {
7124 views: this .loadSummaryFavoriteViews (),
7225 };
7326 },
74- computed: {
75- top_apps : function () {
76- return this .$store .state .activity .window .top_apps ;
77- },
78- top_titles : function () {
79- return this .$store .state .activity .window .top_titles ;
80- },
81- top_categories : function () {
82- return this .$store .state .activity .category .top ;
83- },
84- top_domains : function () {
85- return this .$store .state .activity .browser .top_domains ;
86- },
87- top_categories_hierarchy : function () {
88- if (this .top_categories ) {
89- const categories = this .top_categories .map (c => {
90- return { name: c .data .$category , size: c .duration };
91- });
92-
93- return {
94- name: ' All' ,
95- children: build_category_hierarchy (categories).map (c => pick_subname_as_name (c)),
96- };
97- } else {
98- return null ;
99- }
100- },
101- datasets : function () {
102- const data = split_by_hour_into_data (this .$store .state .activity .active .events );
103- return [
104- {
105- label: ' Total time' ,
106- backgroundColor: ' #6699ff' ,
107- data,
108- },
109- ];
110- },
111- },
11227 methods: {
11328 onTypeChange (id , type ) {
11429 this .views [id] = type;
0 commit comments