Skip to content

Commit 0cf7831

Browse files
feat: use category colors in the timeline view (#609)
* Use configured category colors in the timeline view This currently uses a slightly different strategy from where colors are used elsewhere * Some debug logging for color categories * Rather go in one step from bucket+event to category color This allows doing something different for afk * Remove unused code added along the way * Removed verbose logging * Prettier spacing to please the linter * docs: added note about incompatibility with certain category rules --------- Co-authored-by: Erik Bjäreholt <[email protected]>
1 parent e6ad4cd commit 0cf7831

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/util/color.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,21 @@ export function getTitleAttr(bucket: IBucket, e: IEvent) {
126126
return e.data.title;
127127
}
128128
}
129+
130+
export function getCategoryColorFromEvent(bucket: IBucket, e: IEvent) {
131+
if (bucket.type == 'currentwindow') {
132+
// NOTE: this will not work/break category rules which reference `$` or `^`
133+
return getCategoryColorFromString(e.data.app + ' ' + e.data.title);
134+
} else if (bucket.type == 'web.tab.current') {
135+
// NOTE: same as above
136+
return getCategoryColorFromString(e.data.title + ' ' + e.data.url);
137+
} else if (bucket.type == 'afkstatus') {
138+
return getColorFromString(e.data.status);
139+
} else if (bucket.type?.startsWith('app.editor')) {
140+
return getCategoryColorFromString(e.data.file);
141+
} else if (bucket.type?.startsWith('general.stopwatch')) {
142+
return getCategoryColorFromString(e.data.label);
143+
} else {
144+
return getCategoryColorFromString(e.data.title);
145+
}
146+
}

src/visualizations/VisTimeline.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import _ from 'lodash';
3838
import moment from 'moment';
3939
import Color from 'color';
4040
import { buildTooltip } from '../util/tooltip.js';
41-
import { getColorFromString, getTitleAttr } from '../util/color';
41+
import { getTitleAttr, getCategoryColorFromEvent } from '../util/color';
4242
4343
import { Timeline } from 'vis-timeline/esnext';
4444
import 'vis-timeline/styles/vis-timeline-graph2d.css';
@@ -116,7 +116,7 @@ export default {
116116
buildTooltip(bucket, e),
117117
new Date(e.timestamp),
118118
new Date(moment(e.timestamp).add(e.duration, 'seconds').valueOf()),
119-
getColorFromString(getTitleAttr(bucket, e)),
119+
getCategoryColorFromEvent(bucket, e),
120120
e,
121121
]);
122122
});

0 commit comments

Comments
 (0)