Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeline category colors #609

Merged
merged 7 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/util/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,19 @@
return e.data.title;
}
}

export function getCategoryColorFromEvent(bucket: IBucket, e: IEvent) {
if (bucket.type == 'currentwindow') {
return getCategoryColorFromString(e.data.app + " " + e.data.title);

Check warning on line 132 in src/util/color.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

Replace `"·"` with `'·'`

Check warning on line 132 in src/util/color.ts

View workflow job for this annotation

GitHub Actions / Build webpack (node-20)

Replace `"·"` with `'·'`
} else if (bucket.type == 'web.tab.current') {
return getCategoryColorFromString(e.data.title + " " + e.data.url);

Check warning on line 134 in src/util/color.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

Replace `"·"` with `'·'`

Check warning on line 134 in src/util/color.ts

View workflow job for this annotation

GitHub Actions / Build webpack (node-20)

Replace `"·"` with `'·'`
} 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
Loading