Skip to content

Commit

Permalink
feat: use category colors in the timeline view (#609)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
davidfraser and ErikBjare authored Aug 19, 2024
1 parent e6ad4cd commit 0cf7831
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/util/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ export function getTitleAttr(bucket: IBucket, e: IEvent) {
return e.data.title;
}
}

export function getCategoryColorFromEvent(bucket: IBucket, e: IEvent) {
if (bucket.type == 'currentwindow') {
// NOTE: this will not work/break category rules which reference `$` or `^`
return getCategoryColorFromString(e.data.app + ' ' + e.data.title);
} else if (bucket.type == 'web.tab.current') {
// NOTE: same as above
return getCategoryColorFromString(e.data.title + ' ' + e.data.url);
} else if (bucket.type == 'afkstatus') {
return getColorFromString(e.data.status);
} else if (bucket.type?.startsWith('app.editor')) {
return getCategoryColorFromString(e.data.file);
} else if (bucket.type?.startsWith('general.stopwatch')) {
return getCategoryColorFromString(e.data.label);
} else {
return getCategoryColorFromString(e.data.title);
}
}
4 changes: 2 additions & 2 deletions src/visualizations/VisTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import _ from 'lodash';
import moment from 'moment';
import Color from 'color';
import { buildTooltip } from '../util/tooltip.js';
import { getColorFromString, getTitleAttr } from '../util/color';
import { getTitleAttr, getCategoryColorFromEvent } from '../util/color';
import { Timeline } from 'vis-timeline/esnext';
import 'vis-timeline/styles/vis-timeline-graph2d.css';
Expand Down Expand Up @@ -116,7 +116,7 @@ export default {
buildTooltip(bucket, e),
new Date(e.timestamp),
new Date(moment(e.timestamp).add(e.duration, 'seconds').valueOf()),
getColorFromString(getTitleAttr(bucket, e)),
getCategoryColorFromEvent(bucket, e),
e,
]);
});
Expand Down

1 comment on commit 0cf7831

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are screenshots of this commit:

Screenshots using aw-server v0.12.3b18 (click to expand)

Screenshots using aw-server-rust master (click to expand)

Screenshots using aw-server-rust v0.12.3b18 (click to expand)

Please sign in to comment.